-
Notifications
You must be signed in to change notification settings - Fork 4
/
staging.spec.js
65 lines (59 loc) · 1.56 KB
/
staging.spec.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
const exec = require('util').promisify(require('child_process').execFile);
const ESLint = require("eslint7").ESLint;
const assert = require('assert');
const WORKING_CONFIG = {
baseConfig:{
"plugins": [
"self"
],
"rules": {
"self/no-secrets": "error"
}
},
extensions:['.js','.json']
}
const BUGGED_CONFIG = {
baseConfig:{
"plugins": [
"self",
"json",
],
"rules": {
"self/no-secrets": "error",
"json/undefined":"error"
}
},
extensions:['.js','.json']
}
const TESTS = [
{
name:'Should not detect non-secrets',
file:'./staging/has-no-secret.json',
errorCount: 0
},
{
name:'Should detect secrets in json files',
file:'./staging/has-secret.json',
errorCount: 1
}
];
describe('Staged Testing', () => {
const files = TESTS.map(test => test.file);
async function testConfig(config){
const cli = new ESLint(config);
const results = await cli.lintFiles(files);
for(let i=0;i < TESTS.length;i++){
const test = TESTS[i];
const report = results[i];
it(test.name,() => {
assert.strictEqual(test.errorCount,report.errorCount);
});
}
}
describe('Bugged Config',async () => {
await testConfig(BUGGED_CONFIG);
});
describe('Working Config',async () => {
await testConfig(WORKING_CONFIG);
});
})