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

"Cannot read property 'runCLI' of undefined" with Jest 25.1.0 #1983

Closed
mike-dazn opened this issue Jan 23, 2020 · 14 comments
Closed

"Cannot read property 'runCLI' of undefined" with Jest 25.1.0 #1983

mike-dazn opened this issue Jan 23, 2020 · 14 comments
Assignees
Labels
🐛 Bug Something isn't working
Projects

Comments

@mike-dazn
Copy link

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.
@mike-dazn mike-dazn added the 🐛 Bug Something isn't working label Jan 23, 2020
@bartekleon
Copy link
Member

I think it is related to #1979

@spacecowboy23
Copy link

spacecowboy23 commented Jan 24, 2020

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 jestjs/jest#8874

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

update jest@25.1.0 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 :)

@bartekleon
Copy link
Member

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

@thewilkybarkid
Copy link

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).

@simondel
Copy link
Member

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

@bartekleon
Copy link
Member

bartekleon commented Jan 24, 2020

@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]);

@spacecowboy23
Copy link

spacecowboy23 commented Jan 24, 2020

@kmdrGroch seems right:

from jest@25.1.0, 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 jest@25.1.0, can anyone confirm this?

@danielnixon
Copy link

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

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

@rodoabad
Copy link

rodoabad commented Feb 5, 2020

@danielnixon where's the patch at?

@danielnixon
Copy link

https://github.com/oaf-project/oaf-side-effects/blob/master/patches/%40stryker-mutator%2Bjest-runner%2B2.5.0.patch

@simondel simondel added this to Planning in Backlog Feb 12, 2020
@nicojs nicojs moved this from Planning to In Progress in Backlog Feb 14, 2020
@nicojs nicojs closed this as completed in b45e872 Feb 14, 2020
Backlog automation moved this from In Progress to Done Feb 14, 2020
@nicojs
Copy link
Member

nicojs commented Feb 14, 2020

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. 🤞

@jimmyandrade
Copy link

Looking forward for this 😄

@simondel
Copy link
Member

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

@rodoabad
Copy link

FYI, I can confirm it works!

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
Development

No branches or pull requests

9 participants