forked from pamepeixinho/jest-coverage-badges
-
Notifications
You must be signed in to change notification settings - Fork 1
/
cli.test.js
43 lines (37 loc) · 1.34 KB
/
cli.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
const { spawnSync } = require('child_process');
const fs = require('fs');
const EXPECTED_PATH = 'test/expected';
const RESULT_PATH = 'test/badges';
const expectedFiles = {};
describe('validate badge generation', () => {
beforeAll(() => {
// load the expected files content to an object in order to compare it later with actual results
fs.readdirSync(EXPECTED_PATH, (err, files) => {
expect(err).toBeNull();
files.forEach((file) => {
const content = fs.readFileSync(`${EXPECTED_PATH}/${file}`, 'utf8');
expectedFiles[file] = content;
});
});
});
beforeEach(() => {
fs.readdirSync(RESULT_PATH, (err, files) => {
expect(err).toBeNull();
files.forEach((file) => {
fs.unlink(`${RESULT_PATH}/${file}`, () => {});
});
});
});
it('should output a line coverage file', () => {
// jest-coverage-badges --input './coverage/coverage-summary.json' --output 'badges'
const result = spawnSync('node', ['cli.js', '--input', 'test/coverage-summary.json', '--output', RESULT_PATH]);
expect(result.status).toBe(0);
fs.readdirSync(EXPECTED_PATH, (err, files) => {
expect(err).toBeNull();
files.forEach((file) => {
const content = fs.readFileSync(`${RESULT_PATH}/${file}`, 'utf8');
expect(content).toEqual(expectedFiles[file]);
});
});
});
});