-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest.js
54 lines (47 loc) · 1.41 KB
/
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
const { execSync } = require('child_process');
const fs = require('fs');
process.env.FAIL_ON_WARNINGS = '1';
describe('Linting fixture files', () => {
fs.readdirSync('fixtures/lint').forEach(filename => {
const expect = filename.endsWith('-fail.yaml') ? 'fail' : 'pass';
it(`${filename} should ${expect} linting`, () => {
let failed = false;
let out = null;
try {
out = execSync(`./entrypoint.js fixtures/lint/${filename}`, {
stdio: 'pipe',
encoding: 'utf8'
});
} catch (err) {
failed = true;
if (expect === 'pass') {
if (out) console.log(out.stdout, out.stderr);
else console.log(err);
throw new Error('Linting failed when it should pass');
}
}
if (!failed && expect === 'fail') {
if (out) console.log(out.stdout, out.stderr);
throw new Error('Linting passed when it should fail');
}
});
});
});
describe('Disable rules test', () => {
it('should pass when rule is disabled', () => {
const cwd = process.cwd();
process.env.ISP_RULES_PREFIX = '../../';
process.chdir('fixtures/disable');
try {
const out = execSync('../../entrypoint.js', {
stdio: 'pipe',
encoding: 'utf8'
});
} catch (err) {
throw new Error(err.stdout);
} finally {
process.env.ISP_RULES_PREFIX = '';
process.chdir(cwd);
}
});
});