Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using workerIdleMemoryLimit configuration option in Jest does not work with Stryker #5155

Open
kenluu3 opened this issue Jan 24, 2025 · 0 comments
Labels
🐛 Bug Something isn't working

Comments

@kenluu3
Copy link

kenluu3 commented Jan 24, 2025

Summary

I'm trying to integrate Stryker into an Nx Angular project and in our Jest configuration, we have enabled the workerIdleMemoryLimit option to alleviate issues with Jest memory leaks. However, with this configuration enabled, it is causing Stryker to fail.

Stryker config

{
  packageManager: 'npm',
  reporters: ['html', 'clear-text', 'progress'],
  testRunner: 'jest',
  coverageAnalysis: 'perTest',
  ignoreStatic: true,
  mutate: [
    "./my-lib/src/lib/**/*.ts",
    "!./my-lib/src/lib/**/*.spec.ts"
  ],
  jest: {
    configFile: "./my-lib/jest.config.ts",
    config: {
      testEnvironment: "jsdom"
    }
  },
  cleanTempDir: "always",
  commandRunner: {
    command: "nx test my-lib",
  },
  fileLogLevel: 'trace',
}

Test runner config

export default {
  displayName: 'my-lib',
  preset: '../jest.preset.js',
  setupFilesAfterEnv: ['<rootDir>/src/test-setup.ts'],
  coverageDirectory: '../coverage/my-lib',
  transform: {
    '^.+\\.(ts|mjs|js|html)$': [
      'jest-preset-angular',
      {
        tsconfig: '<rootDir>/tsconfig.spec.json',
        stringifyContentPathRegex: '\\.(html|svg)$',
      },
    ],
  },
  transformIgnorePatterns: ['node_modules/(?!.*\\.mjs$)'],
  snapshotSerializers: [
    'jest-preset-angular/build/serializers/no-ng-attributes',
    'jest-preset-angular/build/serializers/ng-snapshot',
    'jest-preset-angular/build/serializers/html-comment',
  ],
  workerIdleMemoryLimit: 0.5,
};

Stryker environment

    "@stryker-mutator/core": "^8.7.1",
    "@stryker-mutator/jest-runner": "^8.7.1",
    "jest": "^29.7.0",
    "jest-environment-jsdom": "^29.7.0",
    "jest-preset-angular": "~14.4.0",

Test runner environment

npx stryker run

Your Environment

software version(s)
node 18.20.0
npm 10.5.0
Operating System Sonoma 14.7.1

Add stryker.log

Loader Loading plugin @stryker-mutator/jest-runner
15:41:17 (36158) DEBUG ChildProcessProxyWorker Changing current working directory for this process to /.stryker-tmp/sandbox-WKv2IO
15:41:17 (36158) DEBUG jestTestAdapterFactory Detected Jest version 29.7.0
15:41:17 (36158) DEBUG JestTestRunner Running jest with --findRelatedTests flag. Set jest.enableFindRelatedTests to false to run all tests on every mutant.
15:41:17 (36158) DEBUG CustomJestConfigLoader Read config from "my-lib/jest.config.ts" (used native `readInitialOptions` from jest-config).
15:41:17 (36158) DEBUG JestTestRunner Merging file-based config {
  "displayName": "my-lib",
  "preset": "../jest.preset.js",
  "setupFilesAfterEnv": [
    "<rootDir>/src/test-setup.ts"
  ],
  "coverageDirectory": "../coverage/my-lib",
  "transform": {
    "^.+\\.(ts|mjs|js|html)$": [
      "jest-preset-angular",
      {
        "tsconfig": "<rootDir>/tsconfig.spec.json",
        "stringifyContentPathRegex": "\\.(html|svg)$"
      }
    ]
  },
  "transformIgnorePatterns": [
    "node_modules/(?!.*\\.mjs$)"
  ],
  "snapshotSerializers": [
    "jest-preset-angular/build/serializers/no-ng-attributes",
    "jest-preset-angular/build/serializers/ng-snapshot",
    "jest-preset-angular/build/serializers/html-comment"
  ],
  "workerIdleMemoryLimit": 0.5,
  "rootDir": "/Users/kenluu/Projects/demo/.stryker-tmp/sandbox-WKv2IO/my-lib"
}
      with custom config {
  "testEnvironment": "jsdom"
}
      and default (internal) stryker config {
  "collectCoverage": false,
  "verbose": false,
  "notify": false,
  "bail": false,
  "reporters": []
}
15:41:18 (36113) ERROR DryRunExecutor One or more tests resulted in an error:
	
Missing coverage results for:
  * my-lib/src/lib/my-lib/my-lib.component.spec.ts
  * my-lib/src/lib/random-file.spec.ts

You probably configured a test environment in jest that is not reporting code coverage to Stryker. 
See also https://jestjs.io/docs/en/configuration.html#testenvironment-string

Are you using node, jsdom or jsdom-sixteen as a test environment? Please change that:
  * node -> @stryker-mutator/jest-runner/jest-env/node
  * jsdom -> @stryker-mutator/jest-runner/jest-env/jsdom
  * jest-environment-jsdom-sixteen -> @stryker-mutator/jest-runner/jest-env/jsdom-sixteen

If you're using your own custom test environment, please enrich the environment with this mixin: 

const { mixinJestEnvironment} = require('@stryker-mutator/jest-runner');
module.exports = mixinJestEnvironment(MyCustomTestEnvironment);

For more info, see https://stryker-mutator.io/docs/stryker-js/jest-runner#coverage-analysis
15:41:18 (36113) ERROR Stryker Unexpected error occurred while running Stryker Error: Something went wrong in the initial test run
    at DryRunExecutor.validateResultCompleted (file:///path/node_modules/@stryker-mutator/core/dist/src/process/3-dry-run-executor.js:76:15)
    at DryRunExecutor.executeDryRun (file:///path/node_modules/@stryker-mutator/core/dist/src/process/3-dry-run-executor.js:96:14)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async WorkItem.execute (file:///path/@stryker-mutator/core/dist/src/concurrent/pool.js:32:28)
    at async file:///path/node_modules/@stryker-mutator/core/dist/src/concurrent/pool.js:69:13
15:41:18 (36113) INFO Stryker This might be a known problem with a solution documented in our troubleshooting guide.
15:41:18 (36113) INFO Stryker You can find it at https://stryker-mutator.io/docs/stryker-js/troubleshooting/
@kenluu3 kenluu3 added the 🐛 Bug Something isn't working label Jan 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant