-
Notifications
You must be signed in to change notification settings - Fork 242
/
verify.ts
69 lines (53 loc) · 2.01 KB
/
verify.ts
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
import { expectMetrics } from '../../../helpers';
import { promises as fsPromises } from 'fs';
import chai from 'chai';
import execa from 'execa';
import rimraf from 'rimraf';
import path from 'path';
import { promisify } from 'util';
import { it } from 'mocha';
import chaiAsPromised from 'chai-as-promised';
chai.use(chaiAsPromised);
const expect = chai.expect;
const rm = promisify(rimraf);
const rootResolve: typeof path.resolve = path.resolve.bind(path, __dirname, '..');
describe('in place', () => {
let originalAddJSContent: string;
function readAddJS(): Promise<string> {
return fsPromises.readFile(rootResolve('src', 'Add.js'), 'utf-8');
}
before(async () => {
originalAddJSContent = await readAddJS();
})
afterEach(async () => {
await rm(rootResolve('reports'));
await rm(rootResolve('.lock'));
})
it('should reset files after a successful run', async () => {
execa.sync('stryker', ['run']);
const addJSContent = await fsPromises.readFile(rootResolve('src', 'Add.js'), 'utf-8');
expect(addJSContent).eq(originalAddJSContent);
});
it('should report correct score', async () => {
execa.sync('stryker', ['run']);
await expectMetrics({ mutationScore: 73.68 });
});
it('should also reset the files if Stryker exits unexpectedly', async () => {
// Arrange
let addJSMutatedContent: string;
await fsPromises.writeFile(rootResolve('.lock'), ''); // this will lock the test run completion
const onGoingStrykerRun = execa('node', [path.resolve('..', '..', 'node_modules', '.bin', 'stryker'), 'run']);
onGoingStrykerRun.stdout.on('data', async (data) => {
if (data.toString().includes('Starting initial test run')) {
addJSMutatedContent = await readAddJS();
// Now, mr bond, it is time to die!
onGoingStrykerRun.kill();
}
});
// Act
await expect(onGoingStrykerRun).rejected;
// Assert
expect(await readAddJS()).eq(originalAddJSContent);
expect(addJSMutatedContent).not.eq(originalAddJSContent);
});
});