forked from postmanlabs/openapi-to-postman
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrepository.test.js
179 lines (148 loc) · 6.02 KB
/
repository.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/**
* @fileOverview This test specs runs tests on the package.json file of repository. It has a set of strict tests on the
* content of the file as well. Any change to package.json must be accompanied by valid test case in this spec-sheet.
*/
var _ = require('lodash'),
expect = require('expect.js'),
parseIgnore = require('parse-gitignore');
/* global describe, it */
describe('project repository', function () {
var fs = require('fs');
describe('package.json', function () {
var content,
json;
try {
content = fs.readFileSync('./package.json').toString();
json = JSON.parse(content);
}
catch (e) {
console.error(e);
content = '';
json = {};
}
it('must have readable JSON content', function () {
expect(content).to.be.ok();
expect(json).to.not.eql({});
});
describe('package.json JSON data', function () {
it('must have valid name, description and author', function () {
expect(json).to.have.property('name', 'openapi-to-postmanv2');
expect(json).to.have.property('description',
'Convert a given OpenAPI specification to Postman Collection v2.0');
expect(json).to.have.property('author', 'Postman Labs <[email protected]>');
expect(json).to.have.property('license', 'Apache-2.0');
expect(json).to.have.property('homepage', 'https://github.com/postmanlabs/openapi-to-postman');
expect(json).to.have.property('bugs', 'https://github.com/postmanlabs/openapi-to-postman/issues');
expect(json).to.have.property('repository');
expect(json.repository).to.eql({
type: 'git',
url: 'git://github.com/postmanlabs/openapi-to-postman.git'
});
expect(json).to.have.property('keywords');
expect(json.keywords).to.eql(['openapi', 'postman', 'api', 'schema', 'swagger', 'oas']);
expect(json).to.have.property('engines');
expect(json.engines).to.eql({ node: '>=18' });
});
it('must have a valid version string in form of <major>.<minor>.<revision>', function () {
// eslint-disable-next-line max-len
expect(json.version).to.match(/^((\d+)\.(\d+)\.(\d+))(?:-([\dA-Za-z-]+(?:\.[\dA-Za-z-]+)*))?(?:\+([\dA-Za-z-]+(?:\.[\dA-Za-z-]+)*))?$/);
});
});
describe('binary definitions', function () {
it('must exist', function () {
expect(json.bin).be.ok();
expect(json.bin).to.eql({ 'openapi2postmanv2': './bin/openapi2postmanv2.js' });
});
it('must have valid node shebang', function () {
json.bin && Object.keys(json.bin).forEach(function (scriptName) {
var fileContent = fs.readFileSync(json.bin[scriptName]).toString();
expect((/^#!\/(bin\/bash|usr\/bin\/env\snode)[\r\n][\W\w]*$/g).test(fileContent)).to.be.ok();
});
});
});
describe('dependencies', function () {
it('must exist', function () {
expect(json.dependencies).to.be.a('object');
});
it('should have a valid version string in form of <major>.<minor>.<revision>', function () {
expect(json.version)
// eslint-disable-next-line max-len, security/detect-unsafe-regex
.to.match(/^((\d+)\.(\d+)\.(\d+))(?:-([\dA-Za-z-]+(?:\.[\dA-Za-z-]+)*))?(?:\+([\dA-Za-z-]+(?:\.[\dA-Za-z-]+)*))?$/);
});
});
describe('devDependencies', function () {
it('must exist', function () {
expect(json.devDependencies).to.be.a('object');
});
it('should point to a valid semver', function () {
Object.keys(json.devDependencies).forEach(function (dependencyName) {
// eslint-disable-next-line security/detect-non-literal-regexp
expect(json.devDependencies[dependencyName]).to.match(new RegExp('((\\d+)\\.(\\d+)\\.(\\d+))(?:-' +
'([\\dA-Za-z\\-]+(?:\\.[\\dA-Za-z\\-]+)*))?(?:\\+([\\dA-Za-z\\-]+(?:\\.[\\dA-Za-z\\-]+)*))?$'));
});
});
it('should not overlap devDependencies', function () {
var clean = [];
json.devDependencies && Object.keys(json.devDependencies).forEach(function (item) {
!json.dependencies[item] && clean.push(item);
});
expect(Object.keys(json.devDependencies)).to.eql(clean);
});
});
describe('main entry script', function () {
it('must point to a valid file', function (done) {
expect(json.main).to.equal('index.js');
fs.stat(json.main, done);
});
});
});
describe('README.md', function () {
it('must exist', function (done) {
fs.stat('./README.md', done);
});
it('must have readable content', function () {
expect(fs.readFileSync('./README.md').toString()).to.be.ok();
});
});
describe('LICENSE.md', function () {
it('must exist', function (done) {
fs.stat('./LICENSE.md', done);
});
it('must have readable content', function () {
expect(fs.readFileSync('./LICENSE.md').toString()).to.be.ok();
});
});
describe('.ignore files', function () {
var gitignorePath = '.gitignore',
npmignorePath = '.npmignore',
npmignore = parseIgnore(npmignorePath),
gitignore = parseIgnore(gitignorePath);
describe(gitignorePath, function () {
it('must exist', function (done) {
fs.stat(gitignorePath, done);
});
it('must have valid content', function () {
expect(_.isEmpty(gitignore)).to.not.be.ok();
});
});
describe(npmignorePath, function () {
it('must exist', function (done) {
fs.stat(npmignorePath, done);
});
it('must have valid content', function () {
expect(_.isEmpty(npmignore)).to.not.be.ok();
});
});
it('.gitignore coverage must be a subset of .npmignore coverage', function () {
expect(_.intersection(gitignore, npmignore)).to.eql(gitignore);
});
});
describe('.eslintrc', function () {
it('must exist', function (done) {
fs.stat('./.eslintrc', done);
});
it('must have readable content', function () {
expect(fs.readFileSync('./.eslintrc').toString()).to.be.ok();
});
});
});