stryker-mutator / stryker-js

Mutation testing for JavaScript and friends
https://stryker-mutator.io
Apache License 2.0
2.58k stars 248 forks source link

mochaOptions is not recognised as a Stryker option when mocha-runner is installed #4788

Open SmashingQuasar opened 6 months ago

SmashingQuasar commented 6 months ago

Summary

Hey!

I am trying to run Stryker on a project that uses Mocha. I followed the documentation and added the necessary plugin and fragments within the stryker.conf.json.

Since I am working on an Open Source project, you can directly try it out on the repository.

Please note this is using a pnpm workspace.

Other notes:

Originally, I was having a better time with Stryker (if you reset the previous commit by running git reset HEAD^, git restore . and git clean -df you'll see the state of the repository in a more working state for stryker). The problem was that Stryker was messing up the coverage by adding some code before the tested coded which led to a broken coverage report.

Stryker config

{
    "packageManager": "pnpm",
    "mutate": [
        "./src/**/*.mts"
    ],
    "ignorePatterns": [
        "**/node_modules/**",
        "**/.github/**",
        "**/.husky/**",
        "**/.stryker-tmp/**",
        "**/stats/**",
        "**/docs/**",
        "**/documentations/**",
        "**/reports/**",
        "**/coverage/**",
        "**/build/**",
        "**/dist/**",
        "**/lib/**"
    ],
    "concurrency": 6,
    "reporters": [
        "html",
        "clear-text",
        "progress"
    ],
    "htmlReporter": {
        "fileName": "./reports/stryker/mutation.html"
    },
    "jsonReporter": {
        "fileName": "./reports/stryker/mutation.json"
    },
    "buildCommand": "tsc -b tsconfig.stryker.json",
    "coverageAnalysis": "perTest",
  "mochaOptions": {
    "config": ".mocharc.json",
    "spec": [ "./build/**/*.spec.jts"]
  },
    "ignoreStatic": true,
    "tsconfigFile": "tsconfig.stryker.json",
  "testRunner": "mocha"
}

Test runner config

.mocharc.json

{
    "extension": [
        "mts"
    ],
    "node-option": [
        "experimental-specifier-resolution=node",
        "loader=ts-node/esm"
    ],
    "spec": [
        "test/**/*.spec.mts"
    ],
    "timeout": 5000,
    "parallel": true,
    "checkLeaks": true,
    "diff": true,
    "forbidPending": true
}

Stryker environment

@stryker-mutator/core 8.2.6
@stryker-mutator/mocha-runner 8.2.6
@stryker-mutator/typescript-checker 8.2.6
@types/mocha 10.0.6
mocha 10.3.0
@types/chai 4.3.12
chai 5.1.0
@types/sinon 17.0.3
sinon 17.0.1

Test runner environment

TS_NODE_PROJECT=./tsconfig.mocha.json c8 mocha --parallel

Root level tsconfig.json:

{
    "$schema": "https://json.schemastore.org/tsconfig",
    "compileOnSave": false,
    "compilerOptions": {
        "module": "NodeNext",
        "moduleResolution": "NodeNext",
        "skipLibCheck": true,
        "skipDefaultLibCheck": true,
        "pretty": true,
        "declaration": false,
        "importHelpers": true,
        "newLine": "LF",
        "preserveConstEnums": true,
        "sourceMap": false,
        "allowJs": false,
        "checkJs": false,
        "noStrictGenericChecks": false,
        "allowSyntheticDefaultImports": false,
        "forceConsistentCasingInFileNames": true,
        "experimentalDecorators": true,
        "emitDecoratorMetadata": true,
        "noErrorTruncation": true,
        "target": "ESNext",
        "lib": [
            "ESNext"
        ],
        "allowUnreachableCode": false,
        "allowUnusedLabels": false,
        "alwaysStrict": true,
        "exactOptionalPropertyTypes": true,
        "noFallthroughCasesInSwitch": true,
        "noImplicitAny": true,
        "noImplicitOverride": true,
        "noImplicitReturns": true,
        "noImplicitThis": true,
        "noPropertyAccessFromIndexSignature": true,
        "noUncheckedIndexedAccess": true,
        "noUnusedLocals": true,
        "noUnusedParameters": true,
        "strict": true,
        "strictBindCallApply": true,
        "strictFunctionTypes": true,
        "strictNullChecks": true,
        "strictPropertyInitialization": true,
        "useUnknownInCatchVariables": true
    },
    "exclude": [
        "node_modules"
    ]
}

Package-level tsconfig.json:

{
    "$schema": "https://json.schemastore.org/tsconfig",
    "extends": "../../tsconfig.json",
    "compilerOptions": {
        "allowSyntheticDefaultImports": true
    },
    "include": [
        "./src",
        "./test",
        "./mocks"
    ],
    "exclude": [
        "./node_modules"
    ]
}

Package-level tsconfig.build.json:

{
    "extends": "./tsconfig.json",
    "compilerOptions": {
        "outDir": "./build/esm",
        "declarationDir": "./build/types",
        "rootDir": "./src",
        "declaration": true,
        "declarationMap": false,
        "removeComments": false,
        "sourceMap": false,
        "noEmit": false,
        "listFiles": false,
        "listEmittedFiles": false
    },
    "include": [
        "./src"
    ]
}

Package-level tsconfig.mocha.json:

{
    "extends": "./tsconfig.json",
    "include": [".", "./**/.*", "./**/*.json"],
    "ts-node": {
      "files": true,
      "swc": true
    }
  }

Package-level tsconfig.stryker.json:

{
    "extends": "./tsconfig.json",
    "compilerOptions": {
        "sourceMap": true
    },
    "include": [
        "./src/**/*",
        "./test/**/*",
        "./mocks/**/*"
    ],
    "ts-node": {
      "files": true,
      "swc": true
    }
}

Your Environment

software version(s)
node v20.11.1
npm -
pnpm 8.15.4
Operating System Debian GNU/Linux 12 (bookworm)

Add stryker.log

stryker.log

SmashingQuasar commented 5 months ago

Hey!

As a follow up, we merged the associated branch so any test should be done from main.