/
stryker-cli.spec.ts
113 lines (103 loc) · 4.69 KB
/
stryker-cli.spec.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
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
import { Command } from 'commander';
import * as sinon from 'sinon';
import { expect } from 'chai';
import { DashboardOptions, StrykerOptions, ReportType, PartialStrykerOptions } from '@stryker-mutator/api/core';
import { LogConfigurator } from '../../src/logging';
import StrykerCli from '../../src/stryker-cli';
describe(StrykerCli.name, () => {
let runMutationTestingStub: sinon.SinonStub;
let configureLoggerStub: sinon.SinonStub;
beforeEach(() => {
runMutationTestingStub = sinon.stub();
configureLoggerStub = sinon.stub(LogConfigurator, 'configureMainProcess');
});
it('should configure the logger with argument', () => {
runMutationTestingStub.resolves();
actRun(['--logLevel', 'error']);
expect(configureLoggerStub).calledWith('error');
});
it('should accept a config file as last argument', () => {
arrangeActAssertConfigOption(['stryker.foo.js'], { configFile: 'stryker.foo.js' });
});
describe('flat options', () => {
const testCases: Array<[string[], PartialStrykerOptions]> = [
[['--files', 'foo.js,bar.js'], { files: ['foo.js', 'bar.js'] }],
[['--buildCommand', 'npm run build'], { buildCommand: 'npm run build' }],
[['-b', 'npm run build'], { buildCommand: 'npm run build' }],
[['--mutate', 'foo.js,bar.js'], { mutate: ['foo.js', 'bar.js'] }],
[['--reporters', 'foo,bar'], { reporters: ['foo', 'bar'] }],
[['--plugins', 'foo,bar'], { plugins: ['foo', 'bar'] }],
[['--appendPlugins', 'foo,bar'], { appendPlugins: ['foo', 'bar'] }],
[['--timeoutMS', '42'], { timeoutMS: 42 }],
[['--timeoutFactor', '42'], { timeoutFactor: 42 }],
[['--dryRunTimeoutMinutes', '10'], { dryRunTimeoutMinutes: 10 }],
[['--maxConcurrentTestRunners', '42'], { maxConcurrentTestRunners: 42 }],
[['--tempDirName', 'foo-tmp'], { tempDirName: 'foo-tmp' }],
[['--testRunner', 'foo-running'], { testRunner: 'foo-running' }],
[['--testRunnerNodeArgs', '--inspect=1337 --gc'], { testRunnerNodeArgs: ['--inspect=1337', '--gc'] }],
[['--coverageAnalysis', 'all'], { coverageAnalysis: 'all' }],
[['--concurrency', '5'], { concurrency: 5 }],
[['--cleanTempDir', 'false'], { cleanTempDir: false }],
[['-c', '6'], { concurrency: 6 }],
[['--maxTestRunnerReuse', '3'], { maxTestRunnerReuse: 3 }],
];
testCases.forEach(([args, expected]) => {
it(`should parse option "${args.join(' ')}" as ${JSON.stringify(expected)}"`, () => {
arrangeActAssertConfigOption(args, expected);
});
});
});
describe('dashboard options', () => {
beforeEach(() => {
runMutationTestingStub.resolves();
});
it('should parse options to a deep object', () => {
const expectedDashboardOptions: Required<DashboardOptions> = {
baseUrl: 'https://dashboard.qux.io',
module: 'baz/module',
project: 'github.com/fooOrg/barProject',
version: '1.5.3',
reportType: ReportType.Full,
};
actRun([
'--dashboard.version',
expectedDashboardOptions.version,
'--dashboard.project',
expectedDashboardOptions.project,
'--dashboard.module',
expectedDashboardOptions.module,
'--dashboard.baseUrl',
expectedDashboardOptions.baseUrl,
'--dashboard.reportType',
'full',
]);
expect(runMutationTestingStub).calledWithMatch({
dashboard: expectedDashboardOptions,
});
});
it('should remove any lingering options', () => {
actRun(['--dashboard.version', 'foo', '--dashboard.project', 'bar', '--dashboard.module', 'baz', '--dashboard.baseUrl', 'quux']);
const call = runMutationTestingStub.getCall(0);
const actualOptions: StrykerOptions = call.args[0];
const dashboardKeys = Object.keys(actualOptions).filter((key) => key.startsWith('dashboard.'));
expect(dashboardKeys, JSON.stringify(dashboardKeys)).lengthOf(0);
});
});
function actRun(args: string[]): void {
new StrykerCli(['node', 'stryker', 'run', ...args], new Command(), runMutationTestingStub).run();
}
function arrangeActAssertConfigOption(args: string[], expectedOptions: PartialStrykerOptions): void {
runMutationTestingStub.resolves();
actRun(args);
expect(runMutationTestingStub).called;
const actualOptions: PartialStrykerOptions = runMutationTestingStub.getCall(0).args[0];
for (const option in actualOptions) {
// Unfortunately, commander leaves all unspecified options as `undefined` on the object.
// This is not a problem for stryker, so let's clean them for this test.
if (actualOptions[option] === undefined) {
delete actualOptions[option];
}
}
expect(runMutationTestingStub).calledWith(expectedOptions);
}
});