/
angular-starter.spec.ts
96 lines (86 loc) · 3.05 KB
/
angular-starter.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
import { LoggerFactoryMethod } from '@stryker-mutator/api/logging';
import { testInjector } from '@stryker-mutator/test-helpers';
import * as utils from '@stryker-mutator/util';
import { expect } from 'chai';
import * as sinon from 'sinon';
import * as sut from '../../../src/starters/angular-starter';
describe('angularStarter', () => {
let requireModuleStub: sinon.SinonStub;
let cliStub: sinon.SinonStub;
let getLogger: LoggerFactoryMethod;
beforeEach(() => {
cliStub = sinon.stub();
requireModuleStub = sinon.stub(utils, 'requireResolve');
requireModuleStub.withArgs('@angular/cli').returns(cliStub);
getLogger = () => testInjector.logger;
});
it('should throw an error if angular cli version < 6.1.0', async () => {
setAngularVersion('6.0.8');
await expect(sut.start(getLogger)).rejectedWith('Your @angular/cli version (6.0.8) is not supported. Please install 6.1.0 or higher');
});
it('should support version 6.1.0 and up inc release candidates', async () => {
cliStub.resolves();
requireModuleStub
.withArgs('@angular/cli/package')
.onFirstCall()
.returns({ version: '6.1.0-rc.0' })
.onSecondCall()
.returns({ version: '6.2.0' })
.onThirdCall()
.returns({ version: '6.2.0-rc.0' });
await expect(sut.start(getLogger)).not.rejected;
await expect(sut.start(getLogger)).not.rejected;
await expect(sut.start(getLogger)).not.rejected;
});
it('should execute the cli', async () => {
cliStub.resolves();
setAngularVersion();
await sut.start(getLogger);
expect(cliStub).calledWith({
cliArgs: ['test', '--progress=false', `--karma-config=${require.resolve('../../../src/starters/stryker-karma.conf')}`],
inputStream: process.stdin,
outputStream: process.stdout,
});
});
it('should reject if cliStub resolves with `1` (exit code)', async () => {
setAngularVersion();
cliStub.resolves(1);
await expect(sut.start(getLogger)).rejectedWith('`ng test` command failed with exit code 1');
});
it('should forward ngOptions', async () => {
setAngularVersion();
cliStub.resolves();
await sut.start(getLogger, {
testArguments: {
baz: 'true',
foo: 'bar',
fooBar: 'baz',
},
});
expect(cliStub).calledWith({
cliArgs: [
'test',
'--progress=false',
`--karma-config=${require.resolve('../../../src/starters/stryker-karma.conf')}`,
'--baz=true',
'--foo=bar',
'--foo-bar=baz',
],
inputStream: process.stdin,
outputStream: process.stdout,
});
});
it('should reject when ngOptions are prefixed', async () => {
setAngularVersion();
return expect(
sut.start(getLogger, {
testArguments: {
'--project': '@ns/myproj',
},
})
).rejectedWith("Don't prefix arguments with dashes ('-'). Stryker will do this automatically. Problematic arguments are --project");
});
function setAngularVersion(version = '100') {
requireModuleStub.withArgs('@angular/cli/package').returns({ version });
}
});