Stryker: "Cannot read property 'runCLI' of undefined" with Jest 25.1.0

Created on 23 Jan 2020  ·  14Comments  ·  Source: stryker-mutator/stryker

Running the latest (2.5.0) of Stryker with Jest 25.1.0 results in:

13:33:15 (23461) ERROR InitialTestExecutor One or more tests resulted in an error:
        Test runner crashed. Tried twice to restart it without any luck. Last time the error message was: Error: TypeError: Cannot read property 'runCLI' of undefined
TypeError: Cannot read property 'runCLI' of undefined
    at JestPromiseTestAdapter.run (<snip>/node_modules/@stryker-mutator/jest-runner/src/jestTestAdapters/JestPromiseTestAdapter.js:17:31)

This is consistent on Node 8 through 12, and doesn't happen with Jest 24.9.0.

According to Jest's changelog, 25.1.0 has changed some exports, but I couldn't find anything obvious that causes this breakage.

Here is the full debug log (with a couple of file paths omitted):

13:36:54 (25019) DEBUG ConfigReader Loading config tests/config/stryker.config.js
13:36:54 (25019) DEBUG ConfigReader Loaded config: {
  "mutate": [
    "functions/**/*.js",
    "!**/node_modules/**/*",
    "!**/*.test.js"
  ],
  "logLevel": "debug",
  "fileLogLevel": "trace",
  "timeoutMS": 5000,
  "timeoutFactor": 1.5,
  "plugins": [
    "@stryker-mutator/*"
  ],
  "reporters": [
    "clear-text",
    "progress",
    "html"
  ],
  "coverageAnalysis": "off",
  "testRunner": "jest",
  "mutator": "javascript",
  "transpilers": [],
  "maxConcurrentTestRunners": null,
  "symlinkNodeModules": true,
  "thresholds": {
    "break": 100
  },
  "allowConsoleColors": true,
  "dashboard": {
    "baseUrl": "https://dashboard.stryker-mutator.io/api/reports",
    "reportType": "mutationScore"
  },
  "tempDirName": ".stryker-tmp",
  "packageManager": "yarn",
  "files": [
    "functions/**/*.{js,json}",
    "tests/**/*.{js,json}"
  ],
  "jest": {
    "config": {
      "collectCoverageFrom": [
        "**/*.{js,jsx}",
        "!**/node_modules/**",
        "!**/vendor/**",
        "!**/tests/config/**",
        "!Gulpfile.js",
        "!build/**"
      ],
      "coverageReporters": [
        "lcov",
        "text"
      ],
      "coverageDirectory": "<rootDir>/reports/coverage",
      "setupFilesAfterEnv": [
        "<rootDir>/tests/config/jest.setup.js"
      ],
      "rootDir": "../../",
      "clearMocks": true,
      "testEnvironment": "node",
      "roots": [
        "functions/"
      ],
      "coverageThreshold": {
        "global": {
          "statements": 100,
          "branches": 100,
          "functions": 100,
          "lines": 100
        }
      },
      "reporters": [
        "default",
        [
          "jest-html-reporters",
          {
            "publicPath": "reports/unit",
            "filename": "index.html"
          }
        ]
      ]
    },
    "enableFindRelatedTests": true
  },
  "htmlReporter": {
    "baseDir": "reports/mutation/html"
  },
  "configFile": "tests/config/stryker.config.js"
}
13:36:54 (25019) DEBUG PluginLoader Loading @stryker-mutator/* from <snip>/node_modules/@stryker-mutator
13:36:54 (25019) DEBUG PluginLoader Loading plugin "<snip>/node_modules/@stryker-mutator/html-reporter" (matched with expression @stryker-mutator/*)
13:36:54 (25019) DEBUG PluginLoader Loading plugin "<snip>/node_modules/@stryker-mutator/javascript-mutator" (matched with expression @stryker-mutator/*)
13:36:54 (25019) DEBUG PluginLoader Loading plugin "<snip>/node_modules/@stryker-mutator/jest-runner" (matched with expression @stryker-mutator/*)
13:36:54 (25019) DEBUG PluginLoader Loading plugins <snip>/node_modules/@stryker-mutator/html-reporter
13:36:54 (25019) DEBUG PluginLoader Loading plugins <snip>/node_modules/@stryker-mutator/javascript-mutator
13:36:54 (25019) DEBUG PluginLoader Loading plugins <snip>/node_modules/@stryker-mutator/jest-runner
13:36:54 (25019) DEBUG PluginLoader Loading plugins <snip>/node_modules/@stryker-mutator/core/src/reporters/index.js
13:36:54 (25019) DEBUG BroadcastReporter Broadcasting to reporters ["clear-text","progress","html"]
13:36:58 (25019) INFO InputFileResolver Found 8 of 32 file(s) to be mutated.
13:36:58 (25019) DEBUG InputFileResolver All input files: [
  <snip>
]
13:36:58 (25019) DEBUG InputFileResolver Files to mutate: [
  <snip>
]
13:36:58 (25019) DEBUG TemporaryDirectory Using temp directory "<snip>/.stryker-tmp"
13:36:58 (25019) DEBUG TestFrameworkOrchestrator The `coverageAnalysis` setting is "off", not hooking into the test framework to achieve performance benefits.
13:36:58 (25019) INFO InitialTestExecutor Starting initial test run. This may take a while.
13:36:58 (25019) DEBUG Sandbox Creating a sandbox for files in <snip>/.stryker-tmp/sandbox1703488
13:36:58 (25019) DEBUG Sandbox Creating test runner 0
13:36:59 (25019) DEBUG ChildProcessProxy Starting <snip>/node_modules/@stryker-mutator/core/src/test-runner/ChildProcessTestRunnerWorker.js in child process 25033
13:36:59 (25033) DEBUG ChildProcessProxyWorker Changing current working directory for this process to <snip>/.stryker-tmp/sandbox1703488
13:36:59 (25033) DEBUG PluginLoader Loading @stryker-mutator/* from <snip>/node_modules/@stryker-mutator
13:36:59 (25033) DEBUG PluginLoader Loading plugin "<snip>/node_modules/@stryker-mutator/html-reporter" (matched with expression @stryker-mutator/*)
13:36:59 (25033) DEBUG PluginLoader Loading plugin "<snip>/node_modules/@stryker-mutator/javascript-mutator" (matched with expression @stryker-mutator/*)
13:36:59 (25033) DEBUG PluginLoader Loading plugin "<snip>/node_modules/@stryker-mutator/jest-runner" (matched with expression @stryker-mutator/*)
13:36:59 (25033) DEBUG PluginLoader Loading plugins <snip>/node_modules/@stryker-mutator/html-reporter
13:36:59 (25033) DEBUG PluginLoader Loading plugins <snip>/node_modules/@stryker-mutator/javascript-mutator
13:36:59 (25033) DEBUG PluginLoader Loading plugins <snip>/node_modules/@stryker-mutator/jest-runner
13:36:59 (25033) DEBUG PluginLoader Loading plugins <snip>/node_modules/@stryker-mutator/core/src/reporters/index.js
13:36:59 (25033) DEBUG JestTestRunner Running jest with --findRelatedTests flag. Set jest.enableFindRelatedTests to false to run all tests on every mutant.
13:36:59 (25033) DEBUG JestTestRunner Project root is <snip>/.stryker-tmp/sandbox1703488
13:36:59 (25019) DEBUG TimeoutDecorator Starting timeout timer (300000 ms) for a test run
13:36:59 (25019) DEBUG ChildProcessProxy Disposing of worker process 25033
13:36:59 (25019) DEBUG ChildProcessProxy Kill 25033
13:36:59 (25019) DEBUG ChildProcessProxy Starting <snip>/node_modules/@stryker-mutator/core/src/test-runner/ChildProcessTestRunnerWorker.js in child process 25035
13:36:59 (25019) DEBUG TimeoutDecorator Starting timeout timer (300000 ms) for a test run
13:36:59 (25035) DEBUG ChildProcessProxyWorker Changing current working directory for this process to <snip>/.stryker-tmp/sandbox1703488
13:36:59 (25035) DEBUG PluginLoader Loading @stryker-mutator/* from <snip>/node_modules/@stryker-mutator
13:36:59 (25035) DEBUG PluginLoader Loading plugin "<snip>/node_modules/@stryker-mutator/html-reporter" (matched with expression @stryker-mutator/*)
13:36:59 (25035) DEBUG PluginLoader Loading plugin "<snip>/node_modules/@stryker-mutator/javascript-mutator" (matched with expression @stryker-mutator/*)
13:36:59 (25035) DEBUG PluginLoader Loading plugin "<snip>/node_modules/@stryker-mutator/jest-runner" (matched with expression @stryker-mutator/*)
13:36:59 (25035) DEBUG PluginLoader Loading plugins <snip>/node_modules/@stryker-mutator/html-reporter
13:36:59 (25035) DEBUG PluginLoader Loading plugins <snip>/node_modules/@stryker-mutator/javascript-mutator
13:36:59 (25035) DEBUG PluginLoader Loading plugins <snip>/node_modules/@stryker-mutator/jest-runner
13:36:59 (25035) DEBUG PluginLoader Loading plugins <snip>/node_modules/@stryker-mutator/core/src/reporters/index.js
13:36:59 (25035) DEBUG JestTestRunner Running jest with --findRelatedTests flag. Set jest.enableFindRelatedTests to false to run all tests on every mutant.
13:36:59 (25035) DEBUG JestTestRunner Project root is <snip>/.stryker-tmp/sandbox1703488
13:36:59 (25019) DEBUG ChildProcessProxy Disposing of worker process 25035
13:36:59 (25019) DEBUG ChildProcessProxy Kill 25035
13:36:59 (25019) DEBUG ChildProcessProxy Starting <snip>/node_modules/@stryker-mutator/core/src/test-runner/ChildProcessTestRunnerWorker.js in child process 25037
13:36:59 (25037) DEBUG ChildProcessProxyWorker Changing current working directory for this process to <snip>/.stryker-tmp/sandbox1703488
13:36:59 (25037) DEBUG PluginLoader Loading @stryker-mutator/* from <snip>/node_modules/@stryker-mutator
13:36:59 (25037) DEBUG PluginLoader Loading plugin "<snip>/node_modules/@stryker-mutator/html-reporter" (matched with expression @stryker-mutator/*)
13:36:59 (25037) DEBUG PluginLoader Loading plugin "<snip>/node_modules/@stryker-mutator/javascript-mutator" (matched with expression @stryker-mutator/*)
13:36:59 (25037) DEBUG PluginLoader Loading plugin "<snip>/node_modules/@stryker-mutator/jest-runner" (matched with expression @stryker-mutator/*)
13:36:59 (25037) DEBUG PluginLoader Loading plugins <snip>/node_modules/@stryker-mutator/html-reporter
13:36:59 (25037) DEBUG PluginLoader Loading plugins <snip>/node_modules/@stryker-mutator/javascript-mutator
13:36:59 (25037) DEBUG PluginLoader Loading plugins <snip>/node_modules/@stryker-mutator/jest-runner
13:36:59 (25037) DEBUG PluginLoader Loading plugins <snip>/node_modules/@stryker-mutator/core/src/reporters/index.js
13:37:00 (25037) DEBUG JestTestRunner Running jest with --findRelatedTests flag. Set jest.enableFindRelatedTests to false to run all tests on every mutant.
13:37:00 (25037) DEBUG JestTestRunner Project root is <snip>/.stryker-tmp/sandbox1703488
13:37:00 (25019) DEBUG ChildProcessProxy Disposing of worker process 25037
13:37:00 (25019) DEBUG ChildProcessProxy Kill 25037
13:37:00 (25019) DEBUG ChildProcessProxy Starting <snip>/node_modules/@stryker-mutator/core/src/test-runner/ChildProcessTestRunnerWorker.js in child process 25039
13:37:00 (25039) DEBUG ChildProcessProxyWorker Changing current working directory for this process to <snip>/.stryker-tmp/sandbox1703488
13:37:00 (25039) DEBUG PluginLoader Loading @stryker-mutator/* from <snip>/node_modules/@stryker-mutator
13:37:00 (25039) DEBUG PluginLoader Loading plugin "<snip>/node_modules/@stryker-mutator/html-reporter" (matched with expression @stryker-mutator/*)
13:37:00 (25039) DEBUG PluginLoader Loading plugin "<snip>/node_modules/@stryker-mutator/javascript-mutator" (matched with expression @stryker-mutator/*)
13:37:00 (25039) DEBUG PluginLoader Loading plugin "<snip>/node_modules/@stryker-mutator/jest-runner" (matched with expression @stryker-mutator/*)
13:37:00 (25039) DEBUG PluginLoader Loading plugins <snip>/node_modules/@stryker-mutator/html-reporter
13:37:00 (25039) DEBUG PluginLoader Loading plugins <snip>/node_modules/@stryker-mutator/javascript-mutator
13:37:00 (25039) DEBUG PluginLoader Loading plugins <snip>/node_modules/@stryker-mutator/jest-runner
13:37:00 (25039) DEBUG PluginLoader Loading plugins <snip>/node_modules/@stryker-mutator/core/src/reporters/index.js
13:37:00 (25039) DEBUG JestTestRunner Running jest with --findRelatedTests flag. Set jest.enableFindRelatedTests to false to run all tests on every mutant.
13:37:00 (25039) DEBUG JestTestRunner Project root is <snip>/.stryker-tmp/sandbox1703488
13:37:00 (25019) DEBUG ChildProcessProxy Disposing of worker process 25039
13:37:00 (25019) DEBUG ChildProcessProxy Kill 25039
13:37:00 (25019) ERROR InitialTestExecutor One or more tests resulted in an error:
        Test runner crashed. Tried twice to restart it without any luck. Last time the error message was: Error: TypeError: Cannot read property 'runCLI' of undefined
TypeError: Cannot read property 'runCLI' of undefined
    at JestPromiseTestAdapter.run (<snip>/node_modules/@stryker-mutator/jest-runner/src/jestTestAdapters/JestPromiseTestAdapter.js:17:31)
    at JestTestRunner.run (<snip>/node_modules/@stryker-mutator/jest-runner/src/JestTestRunner.js:43:56)
    at ChildProcessTestRunnerWorker.run (<snip>/node_modules/@stryker-mutator/core/src/test-runner/ChildProcessTestRunnerWorker.js:24:56)
    at ChildProcessProxyWorker.doCall (<snip>/node_modules/@stryker-mutator/core/src/child-proxy/ChildProcessProxyWorker.js:75:56)
    at Promise.then.send.correlationId (<snip>/node_modules/@stryker-mutator/core/src/child-proxy/ChildProcessProxyWorker.js:46:53)
    at new Promise (<anonymous>)
    at ChildProcessProxyWorker.handleMessage (<snip>/node_modules/@stryker-mutator/core/src/child-proxy/ChildProcessProxyWorker.js:46:17)
    at process.emit (events.js:210:5)
    at emit (internal/child_process.js:876:12)
    at processTicksAndRejections (internal/process/task_queues.js:81:21)
Error: TypeError: Cannot read property 'runCLI' of undefined
TypeError: Cannot read property 'runCLI' of undefined
    at JestPromiseTestAdapter.run (<snip>/node_modules/@stryker-mutator/jest-runner/src/jestTestAdapters/JestPromiseTestAdapter.js:17:31)
    at JestTestRunner.run (<snip>/node_modules/@stryker-mutator/jest-runner/src/JestTestRunner.js:43:56)
    at ChildProcessTestRunnerWorker.run (<snip>/node_modules/@stryker-mutator/core/src/test-runner/ChildProcessTestRunnerWorker.js:24:56)
    at ChildProcessProxyWorker.doCall (<snip>/node_modules/@stryker-mutator/core/src/child-proxy/ChildProcessProxyWorker.js:75:56)
    at Promise.then.send.correlationId (<snip>/node_modules/@stryker-mutator/core/src/child-proxy/ChildProcessProxyWorker.js:46:53)
    at new Promise (<anonymous>)
    at ChildProcessProxyWorker.handleMessage (<snip>/node_modules/@stryker-mutator/core/src/child-proxy/ChildProcessProxyWorker.js:46:17)
    at process.emit (events.js:210:5)
    at emit (internal/child_process.js:876:12)
    at processTicksAndRejections (internal/process/task_queues.js:81:21)
    at ChildProcess.<anonymous> (<snip>/node_modules/@stryker-mutator/core/src/child-proxy/ChildProcessProxy.js:133:68)
    at ChildProcess.emit (events.js:210:5)
    at emit (internal/child_process.js:876:12)
    at processTicksAndRejections (internal/process/task_queues.js:81:21)
13:37:00 (25019) ERROR StrykerCli an error occurred Error: Something went wrong in the initial test run
    at InitialTestExecutor.validateResult (<snip>/node_modules/@stryker-mutator/core/src/process/InitialTestExecutor.js:86:15)
    at InitialTestExecutor.run (<snip>/node_modules/@stryker-mutator/core/src/process/InitialTestExecutor.js:41:14)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async Stryker.runMutationTest (<snip>/node_modules/@stryker-mutator/core/src/Stryker.js:54:38)
error Command failed with exit code 130.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
🐛 Bug

Most helpful comment

Hi! Jest 25 support has been released with @stryker-mutator version 3! You can read all about it here: https://stryker-mutator.io/blog/2020-03-11/stryker-version-3

All 14 comments

I think it is related to #1979

Hello,

According to Jest's changelog, 25.1.0 has changed some exports, but I couldn't find anything obvious that causes this breakage.

this seems to me for the reason. IMHO Jest have changed the exports slightly, see https://github.com/facebook/jest/pull/8874

I tried to fix this in TS, but i'm not into TS. In the compiled JS this fix worked for me:

update [email protected] for package jest-runner

file: jest-runner/src/jestTestAdapters/JestPromiseTestAdapter.js

line 5:

- const jest_1 = tslib_1.__importDefault(require("jest"));
+ const jest_1 = tslib_1.__importStar(require("jest"))

line 17:

- return jest_1.default.runCLI(Object.assign(Object.assign({}, (fileNameUnderTest && { _: [fileNameUnderTest], findRelatedTests: true })), { config, runInBand: true, silent: true }), [projectRoot]);
+  return jest_1.runCLI(Object.assign(Object.assign({}, (fileNameUnderTest && { _: [fileNameUnderTest], findRelatedTests: true })), { config, runInBand: true, silent: true }), [projectRoot]);

Maybe this helps to resolve this issue

Thanks for developing stryker :)

@nicojs it's a high time to update @types/jest... We are getting errors which are not caught by TS itself and should be ._.

Not sure what level's causing it, but we're seeing the wrong exit code (https://github.com/libero/article-store/pull/167/checks?check_run_id=407401318#step:5:17 is passing when it shouldn't).

Thanks for opening this detailed issue! ♥ I'll see if I can add Jest 25 compatibility this weekend.

@simondel I guess we should make check while importing from JEST.
Based on @spacecowboy23 check - runCLI was probably moved from export default to just export

- return jest_1.default.runCLI(Object.assign(Object.assign({}, (fileNameUnderTest && { _: [fileNameUnderTest], findRelatedTests: true })), { config, runInBand: true, silent: true }), [projectRoot]);
+  return jest_1.runCLI(Object.assign(Object.assign({}, (fileNameUnderTest && { _: [fileNameUnderTest], findRelatedTests: true })), { config, runInBand: true, silent: true }), [projectRoot]);

@kmdrGroch seems right:

from [email protected], jest.js, line 30

Object.defineProperty(exports, 'runCLI', {
  enumerable: true,
  get: function() {
    return _core().runCLI;
  }
});

therefore you can do simple (in JS):

- const jest_1 = tslib_1.__importDefault(require("jest"));
+ const { runCLI } = require("jest");

and then

- return jest_1.default.runCLI(Object.assign(Object.assign({}, (fileNameUnderTest && { _: [fileNameUnderTest], findRelatedTests: true })), { config, runInBand: true, silent: true }), [projectRoot]);
+ return runCLI(Object.assign(Object.assign({}, (fileNameUnderTest && { _: [fileNameUnderTest], findRelatedTests: true })), { config, runInBand: true, silent: true }), [projectRoot]);

Sorry, again only plain JS, shame on me...
At least this solution works on my machine for [email protected], can anyone confirm this?

Thanks @spacecowboy23! Confirmed that patch works. Here's an example of it applied using patch-package:

https://github.com/oaf-project/oaf-side-effects

@danielnixon where's the patch at?

Thanks for all the comments in this thread. We've merged a fix to master. We will be releasing it in v3 of Stryker, hopefully next week. 🤞

Looking forward for this 😄

Hi! Jest 25 support has been released with @stryker-mutator version 3! You can read all about it here: https://stryker-mutator.io/blog/2020-03-11/stryker-version-3

FYI, I can confirm it works!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Lakitna picture Lakitna  ·  97Comments

Zorin95670 picture Zorin95670  ·  18Comments

simondel picture simondel  ·  25Comments

nicojs picture nicojs  ·  33Comments

trollepierre picture trollepierre  ·  18Comments