stryker-js
stryker-js copied to clipboard
config for compile => jest workflow?
Question
I try to treat js files as objects. So my workflow is
- edit .ts files
- compile them using tsc (in watch mode ofc)
- run jest on the compiled files. testmatch is
**/*.test.js
Now stryker says that there were no tests running in the initial test run.
However if I go to the sandbox directory, run npx jest
, tests run all fine.
I also noticed that while the ts files are mutated, the js files do not change in the sandbox.
So I guess stryker should do something along the lines of:
- copy project to sandbox (ok)
- mutate .ts files (ok)
- tsc (not done)
- jest initial run, just doing the same what jest does (apparently it does not do the same)
- doing its magic (?)
I can run stryker by changing the file pattern from src/**/*.ts
to dist/**/*.js
, but that way a lot of false positive mutations show up which are not rejected because types do not match. So it is not a viable alternative
My question is how to configure jest to do this (or whatever is needed to work correctly)?
the error message:
12:59:52 (657519) INFO ProjectReader Found 35 of 203 file(s) to be mutated.
`isModuleDeclaration` has been deprecated, please migrate to `isImportOrExportDeclaration`
at Object.isModuleDeclaration (/home/mag/project/KodeKonveyor/cdd-ts/node_modules/@babel/types/lib/validators/generated/index.js:3940:35)
at isValidParent (file:///home/mag/project/KodeKonveyor/cdd-ts/node_modules/@stryker-mutator/instrumenter/dist/src/mutators/string-literal-mutator.js:19:15)
12:59:53 (657519) INFO Instrumenter Instrumented 35 source file(s) with 227 mutant(s)
12:59:53 (657519) INFO ConcurrencyTokenProvider Creating 2 test runner process(es).
12:59:56 (657519) INFO DryRunExecutor Starting initial test run (jest test runner with "perTest" coverage analysis). This may take a while.
12:59:56 (657519) INFO DryRunExecutor Initial test run succeeded. Ran 0 tests in 0 seconds (net 0 ms, overhead 509 ms).
12:59:56 (657519) ERROR Stryker No tests were executed. Stryker will exit prematurely. Please check your configuration.
But after that the tests run fine in the sandbox:
mag@mag-Librem-15-v4:~/project/KodeKonveyor/cdd-ts$ cd .stryker-tmp/sandbox2846030/
mag@mag-Librem-15-v4:~/project/KodeKonveyor/cdd-ts/.stryker-tmp/sandbox2846030$ npx jest
PASS dist/test/stub.test.js
PASS dist/test/runAllContracts.test.js
Test Suites: 2 passed, 2 total
Tests: 2 passed, 2 total
Snapshots: 0 total
Time: 2.476 s
Ran all test suites.
Stryker environment
├── @stryker-mutator/[email protected]
├── @stryker-mutator/[email protected]
├── [email protected]```
├── @stryker-mutator/[email protected]
├── @types/[email protected]
├── [email protected]
├── [email protected]```
Additional context
tsconfig.json
{
"compileOnSave": true,
"compilerOptions": {
"baseUrl": "./",
"outDir": "dist",
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitOverride": true,
"noPropertyAccessFromIndexSignature": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"sourceMap": true,
"declaration": true,
"downlevelIteration": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"moduleResolution": "node",
"importHelpers": true,
"target": "ES5",
"module": "Node16",
"esModuleInterop": true,
"useDefineForClassFields": false,
"lib": [
"ES2022",
"dom"
],
"types": [
"jest"
]
},
"files": [
"src/cdd-ts.ts",
"./src/contract/ParameterGetters.ts",
],
"include": [
"**/*.ts",
],
"exclude": [
".stryker-tmp",
"dist",
"node_modules"
],
}
package.json
{
"name": "cdd-ts",
"version": "1.0.8",
"description": "Test-time Contract Development framework for TypeScript",
"main": "dist/cdd-ts.js",
"type": "commonjs",
"directories": {
"test": "test"
},
"scripts": {
"qa": "npm run lint &&npm run test&& npm run mutate",
"prepublishOnly": "npx tsc",
"mutate": "stryker run",
"test": "jest",
"lint": "eslint . --ext .ts"
},
"jest": {
"testEnvironment": "node",
"testMatch": [
"**/*.test.js"
],
"roots": [
"<rootDir>/dist"
],
"modulePaths": [
"<rootDir>/dist"
],
"moduleDirectories": [
"node_modules"
]
},
"dependencies": {
"colors": "^1.4.0",
"diff": "^5.1.0",
"fast-deep-equal": "^3.1.3",
"fast-glob": "^3.2.12",
"jest-mock": "^29.4.3"
},
"devDependencies": {
"@stryker-mutator/core": "^6.4.1",
"@stryker-mutator/jest-runner": "^6.4.1",
"@types/diff": "^5.0.2",
"@types/jest": "^29.4.0",
"@typescript-eslint/eslint-plugin": "^5.54.1",
"eslint": "^8.30.0",
"eslint-config-prettier": "^8.7.0",
"eslint-config-standard-with-typescript": "^24.0.0",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-n": "^15.6.1",
"eslint-plugin-promise": "^6.1.1",
"jest": "^29.5.0",
"stryker-cli": "^1.0.2",
"typescript": "~4.8.2"
}
}
stryker.conf.json:
{
"$schema": "./node_modules/@stryker-mutator/core/schema/stryker-schema.json",
"mutate": [
"src/**/*.ts"
],
"thresholds": {
"low": 100,
"high": 100
},
"ignoreStatic": false,
"warnings": {
"slow": false
},
"testRunner": "jest",
"reporters": [
"progress",
"clear-text",
"html",
"json"
],
"concurrency": 2,
"coverageAnalysis": "perTest"
}
Hi again @magwas 👋
This is very strange. The @stryker-mutator/jest-runner
plugin should automatically pick up the jest
config from your package.json
file. It logs it on debug
level here:
https://github.com/stryker-mutator/stryker-js/blob/16c1edc6de10973881fff082e18a21f5b1118a7f/packages/jest-runner/src/config-loaders/custom-jest-config-loader.ts#L44-L53
Could you try running with --logLevel debug
and locate this line?
The project I have ran it on is commit 5f94497926c77d00748cfe5bf620122c26d3e80b of https://github.com/kode-konveyor/cdd-ts
Stryker log: stryker.log
The command line was npx stryker run --fileLogLevel trace