The instructions for setting up an Angular application project are straightforward. I have had no issue with setting up and running Stryker on an application project using default settings for Karma. I am having trouble getting it to work correctly when it is a Library project instead, however.
I have looked through the configuration documentation for Stryker and I have tried adjusting the paths to the relevant files (for mutation and the karma.config)
stryker.conf.json
"mutate": [
"projects/ecc-lib/src/**/*.ts",
"!projects/ecc-lib/src/**/*.spec.ts",
"!projects/ecc-lib/src/test.ts",
"!projects/ecc-lib/src/environments/*.ts"
],
"checkers": ["typescript"],
"tsconfigFile": "projects/ecc-lib/tsconfig.spec.json",
"testRunner": "karma",
"karma": {
"configFile": "projects/ecc-lib/karma.stryker.conf.js",
"projectType": "angular-cli",
"config": {
"browsers": [
"ChromeHeadless"
]
}
},
This just seems to have the process hang at the startup of tests. I can verify this by switching to Chrome type for browsers and I can see the browser window(s) come up but nothing ever fills them. If I close them, the process retries and opens new windows. I don't think that I have let it hang for much more than 30 minutes, but that seemed sufficient amount of time to think it would never finish.
14:00:29 (22792) WARN InputFileResolver Glob pattern "!projects/ecc-lib/src/environments/*.ts" did not exclude any files.
14:00:30 (22792) INFO InputFileResolver Found 31 of 374 file(s) to be mutated.
14:00:30 (22792) INFO Instrumenter Instrumented 31 source file(s) with 629 mutant(s)
14:00:31 (22792) INFO ConcurrencyTokenProvider Creating 2 checker process(es) and 2 test runner process(es).
That having failed, the next thing I tried is to specify a custom runner:
stryker.conf.json
"testRunner": "command",
"commandRunner": { "command": "npm run test-stryker" },
test-stryker in package.json is just running the karma tests and passes successfully when run
package.json
"test-stryker": "ng test ecc-lib --codeCoverage=true --watch=false --browsers=ChromeHeadless",
npm run test-stryker
> [email protected] test-stryker C:\git\EnterpriseCalendarComponent
> ng test ecc-lib --codeCoverage=true --watch=false --browsers=ChromeHeadless
⠙ Generating browser application bundles (phase: building)...29 08 2021 14:35:51.866:INFO [karma-server]: Karma v6.1.2 server started at http://localhost:9876/
29 08 2021 14:35:51.869:INFO [launcher]: Launching browsers ChromeHeadless with concurrency unlimited
29 08 2021 14:35:51.872:INFO [launcher]: Starting browser ChromeHeadless
✔ Browser application bundle generation complete.
29 08 2021 14:35:57.194:INFO [Chrome Headless 92.0.4515.107 (Windows 10)]: Connected on socket zwyDv5WL6Mvi6CuqAAAB with id 56501263
WARN: 'NOT_STARTED', 'Time tracked (ms)', 'requested, but timer not started'
Chrome Headless 92.0.4515.107 (Windows 10): Executed 26 of 134 (skipped 1) SUCCESS (0 secs / 0.302 secs)
LOG: 'TestName', ['Timer started', 1630262160083]
Chrome Headless 92.0.4515.107 (Windows 10): Executed 27 of 134 (skipped 1) SUCCESS (0 secs / 0.304 secs)
.
.
.
TOTAL: 132 SUCCESS
=============================== Coverage summary ===============================
Statements : 100% ( 392/392 )
Branches : 100% ( 133/133 )
Functions : 100% ( 122/122 )
Lines : 100% ( 368/368 )
================================================================================
But running Stryker with these settings causes the initial test run to fail
> [email protected] stryker:ecc-lib C:\git\EnterpriseCalendarComponent
> npx stryker run projects/ecc-lib/stryker.conf.json
[32m14:43:14 (33692) INFO BroadcastReporter[39m Detected that current console does not support the "progress" reporter, downgrading to "progress-append-only" reporter
[33m14:43:14 (33692) WARN InputFileResolver[39m Glob pattern "!projects/ecc-lib/src/environments/*.ts" did not exclude any files.
[32m14:43:14 (33692) INFO InputFileResolver[39m Found 31 of 375 file(s) to be mutated.
[32m14:43:15 (33692) INFO Instrumenter[39m Instrumented 31 source file(s) with 629 mutant(s)
[32m14:43:15 (33692) INFO ConcurrencyTokenProvider[39m Creating 2 checker process(es) and 2 test runner process(es).
[32m14:43:22 (33692) INFO DryRunExecutor[39m Starting initial test run (command test runner with "all" coverage analysis). This may take a while.
[91m14:43:41 (33692) ERROR DryRunExecutor[39m One or more tests failed in the initial test run:
All tests
> [email protected] test-stryker C:\git\EnterpriseCalendarComponent\.stryker-tmp\sandbox4442701
> ng test ecc-lib --codeCoverage=true --watch=false --browsers=ChromeHeadless
- Generating browser application bundles...
29 08 2021 14:43:33.232:INFO [karma-server]: Karma v6.1.2 server started at http://localhost:9876/
29 08 2021 14:43:33.235:INFO [launcher]: Launching browsers ChromeHeadless with concurrency unlimited
29 08 2021 14:43:33.238:INFO [launcher]: Starting browser ChromeHeadless
Γ£ö Browser application bundle generation complete.
Error: projects/ecc-lib/src/lib/components/calendar-panel/calendar-panel/calendar-panel.component.ts:13:3 - error TS2539: Cannot assign to 'stryNS_9fa48' because it is not a variable.
13 stryNS_9fa48 = retrieveNS;
~~~~~~~~~~~~
Error: projects/ecc-lib/src/lib/components/calendar-panel/calendar-panel/calendar-panel.component.ts:40:3 - error TS2539: Cannot assign to 'stryCov_9fa48' because it is not a variable.
40 stryCov_9fa48 = cover;
~~~~~~~~~~~~~
.
.
.
npm
ERR! [email protected] test-stryker: `ng test ecc-lib --codeCoverage=true --watch=false --browsers=ChromeHeadless`
npm ERR! Exit status 1
npm ERR!
npm ERR!
Failed at the [email protected] test-stryker script.
npm ERR!
This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm
ERR! C:\Users\{username removed}\AppData\Roaming\npm-cache\_logs\2021-08-29T18_43_41_276Z-debug.log
[91m14:43:41 (33692) ERROR Stryker[39m There were failed tests in the initial test run.
The additional log file was no help:
0 info it worked if it ends with ok
1 verbose cli [
1 verbose cli 'C:\\Program Files\\nodejs\\node.exe',
1 verbose cli 'C:\\Users\\{username removed}\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli 'run',
1 verbose cli 'stryker:ecc-lib'
1 verbose cli ]
2 info using [email protected]
3 info using [email protected]
4 verbose run-script [ 'prestryker:ecc-lib', 'stryker:ecc-lib', 'poststryker:ecc-lib' ]
5 info lifecycle [email protected]~prestryker:ecc-lib: [email protected]
6 info lifecycle [email protected]~stryker:ecc-lib: [email protected]
7 verbose lifecycle [email protected]~stryker:ecc-lib: unsafe-perm in lifecycle true
8 verbose lifecycle [email protected]~stryker:ecc-lib: PATH: C:\Users\{username removed}\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;C:\git\EnterpriseCalendarComponent\node_modules\.bin;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files\Strawberry\c\bin;C:\Program Files\Strawberry\perl\site\bin;C:\Program Files\Strawberry\perl\bin;C:\Program Files (x86)\Pulse Secure\VC142.CRT\X64\;C:\Program Files (x86)\Pulse Secure\VC142.CRT\X86\;C:\Program Files\nodejs\;C:\Users\{username removed}\AppData\Local\Microsoft\WindowsApps;C:\Users\{username removed}\AppData\Local\Programs\Git\cmd;C:\Users\{username removed}\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\{username removed}\AppData\Roaming\npm;C:\tools\apache-ant-1.8.1\bin;C:\tools\maven-3.6.0\bin;C:\tools\gradle-4.10.2\bin;C:\Program Files\Cloud Foundry;C:\tools\flyway-7.0.4;C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.0\;C:\Program Files\Microsoft SQL Server\120\Tools\Binn\;C:\PROGRA~1\IBM\IBM DATA SERVER DRIVER\BIN;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\150\DTS\Binn\;C:\Program Files\Azure Data Studio\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\Perforce\;C:\Portable Apps\helm;C:\Users\{username removed}\AppData\Local\Microsoft\WindowsApps;C:\Users\{username removed}\AppData\Local\Programs\Git\cmd;C:\Users\{username removed}\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\{username removed}\AppData\Roaming\npm;C:\Program Files\Azure Data Studio\bin;
9 verbose lifecycle [email protected]~stryker:ecc-lib: CWD: C:\git\EnterpriseCalendarComponent
10 silly lifecycle [email protected]~stryker:ecc-lib: Args: [ '/d /s /c', 'npx stryker run projects/ecc-lib/stryker.conf.json' ]
11 silly lifecycle [email protected]~stryker:ecc-lib: Returned: code: 1 signal: null
12 info lifecycle [email protected]~stryker:ecc-lib: Failed to exec stryker:ecc-lib script
13 verbose stack Error: [email protected] stryker:ecc-lib: `npx stryker run projects/ecc-lib/stryker.conf.json`
13 verbose stack Exit status 1
13 verbose stack at EventEmitter.<anonymous> (C:\Users\{username removed}\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\index.js:332:16)
13 verbose stack at EventEmitter.emit (events.js:315:20)
13 verbose stack at ChildProcess.<anonymous> (C:\Users\{username removed}\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\lib\spawn.js:55:14)
13 verbose stack at ChildProcess.emit (events.js:315:20)
13 verbose stack at maybeClose (internal/child_process.js:1021:16)
13 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:286:5)
14 verbose pkgid [email protected]
15 verbose cwd C:\git\EnterpriseCalendarComponent
16 verbose Windows_NT 10.0.18363
17 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\{username removed}\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js" "run" "stryker:ecc-lib"
18 verbose node v12.18.4
19 verbose npm v6.14.8
20 error code ELIFECYCLE
21 error errno 1
22 error [email protected] stryker:ecc-lib: `npx stryker run projects/ecc-lib/stryker.conf.json`
22 error Exit status 1
23 error Failed at the [email protected] stryker:ecc-lib script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]
I should also note that I have pulled the code out of this library into an application type project and have successfully ran Stryker on it. Am I missing some crucial configuration piece or is Stryker just not setup to handle such a project configuration yet?
With help from nicojs, I was able to get basic Stryker functionality working on my library project.
As it turns out I was missing some critical configuration.
I was able to set the testRunner as karma. I added karma.ngConfig.testArguments.project and disableTypeChecks values in stryker.conf.json
I do still have issues to work out with the typechecker, but reason for OP is resolved.