/
applyExtendsIfSpecified.test.js
executable file
·150 lines (135 loc) · 4.41 KB
/
applyExtendsIfSpecified.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
const applyExtendsIfSpecified = require('../../../src/config/applyExtendsIfSpecified');
describe('applyExtendsIfSpecified Unit Tests', () => {
test('when file has local extends (valid - js), a config object is returned', () => {
const expectedConfigObj = {
extends: './test/fixtures/extendsLocal/npmpackagejsonlint.config.js',
rules: {
'require-author': 'error',
'require-description': 'error'
},
overrides: [
{
patterns: ['**/package.json'],
rules: {
'require-author': 'warning'
}
}
]
};
const passedConfig = {
extends: './test/fixtures/extendsLocal/npmpackagejsonlint.config.js',
rules: {
'require-author': 'error'
}
};
const filePath = './test/fixtures/extendsLocal/package.json';
const result = applyExtendsIfSpecified(passedConfig, filePath);
expect(result).toStrictEqual(expectedConfigObj);
});
test('when file has local extends (valid - json), a config object is returned', () => {
const expectedConfigObj = {
extends: './test/fixtures/extendsLocal/.npmpackagejsonlintrc.json',
rules: {
'require-author': 'error',
'require-description': 'error'
},
overrides: [
{
patterns: ['**/package.json'],
rules: {
'require-author': 'warning'
}
}
]
};
const passedConfig = {
extends: './test/fixtures/extendsLocal/.npmpackagejsonlintrc.json',
rules: {
'require-author': 'error'
}
};
const filePath = './test/fixtures/extendsLocal/package.json';
const result = applyExtendsIfSpecified(passedConfig, filePath);
expect(result).toStrictEqual(expectedConfigObj);
});
test('when file has local extends (invalid), a config object is returned', () => {
const passedConfig = {
extends: './npmpackagejsonlint.config.js',
rules: {
'require-author': 'error'
}
};
const filePath = './test/fixtures/extendsLocalInvalid/package.json';
expect(() => {
applyExtendsIfSpecified(passedConfig, filePath);
}).toThrow('');
});
test('when file has local extends (invalid extension type), a config object is returned', () => {
const passedConfig = {
extends: './npmpackagejsonlintrc.md',
rules: {
'require-author': 'error'
}
};
const filePath = './test/fixtures/extendsLocalInvalid/package.json';
expect(() => {
applyExtendsIfSpecified(passedConfig, filePath);
}).toThrow('');
});
test('when file has module extends (valid), a config object is returned', () => {
const expectedConfigObj = {
extends: 'npm-package-json-lint-config-default',
rules: {
'bin-type': 'error',
'config-type': 'error',
'cpu-type': 'error',
'dependencies-type': 'error',
'description-type': 'error',
'devDependencies-type': 'error',
'directories-type': 'error',
'engines-type': 'error',
'files-type': 'error',
'homepage-type': 'error',
'keywords-type': 'error',
'license-type': 'error',
'main-type': 'error',
'man-type': 'error',
'name-format': 'error',
'name-type': 'error',
'optionalDependencies-type': 'error',
'os-type': 'error',
'peerDependencies-type': 'error',
'preferGlobal-type': 'error',
'private-type': 'error',
'repository-type': 'error',
'require-author': 'error',
'require-name': 'error',
'require-version': 'error',
'scripts-type': 'error',
'version-format': 'error',
'version-type': 'error'
}
};
const passedConfig = {
extends: 'npm-package-json-lint-config-default',
rules: {
'require-author': 'error'
}
};
const filePath = './test/fixtures/extendsModule/package.json';
const result = applyExtendsIfSpecified(passedConfig, filePath);
expect(result).toStrictEqual(expectedConfigObj);
});
test('when file module extends (invalid), a config object is returned', () => {
const filePath = './test/fixtures/extendsModuleInvalid/package.json';
const passedConfig = {
extends: 'npm-package-json-lint-config-awesome-module',
rules: {
'require-author': 'error'
}
};
expect(() => {
applyExtendsIfSpecified(passedConfig, filePath);
}).toThrow('');
});
});