kayahr / jest-electron-runner

Custom test runner for Jest that allows tests to be run in Electron environment
https://www.npmjs.com/package/@kayahr/jest-electron-runner
MIT License
20 stars 4 forks source link

Testrunner crashes with `TypeError: Illegal invocation` #15

Closed MareikeTaeubner closed 1 year ago

MareikeTaeubner commented 1 year ago

Maybe I'm just using the runner wrong, but when I try to run the tests, jest crashes with this error:

 ● Test suite failed to run

        TypeError: Illegal invocation

          25 | electron_1.ipcRenderer.on("run-test", async (event, testData, workerID) => {
          26 |     try {
        > 27 |         const result = await (0, runTest_1.default)(testData.path, testData.globalConfig, testData.config, (0, resolver_1.getResolver)(testData.config, testData.serializableModuleMap));
             |                        ^
          28 |         electron_1.ipcRenderer.send(workerID, result);
          29 |     }
          30 |     catch (error) {

          at withGlobal (node_modules/@sinonjs/fake-timers/src/fake-timers-src.js:146:35)
          at new FakeTimers (node_modules/@jest/fake-timers/build/modernFakeTimers.js:38:53)
          at runTestInternal (node_modules/@kayahr/jest-electron-runner/lib/main/electron/runTest.js:65:25)
          at async runTest (node_modules/@kayahr/jest-electron-runner/lib/main/electron/runTest.js:198:38)
          at async EventEmitter.<anonymous> (file:/D:/workspace-js2/swift/node_modules/@kayahr/jest-electron-runner/lib/main/electron/browser_window_injected_code.js:27:24)

Installed libraries:

This is my jest.config.js

module.exports = {
  // Indicates whether the coverage information should be collected while executing the test
  collectCoverage: true,

  // Indicates which provider should be used to instrument code for coverage
  coverageProvider: 'v8',

  // Allows you to use a custom runner instead of Jest's default test runner
  runner: '@kayahr/jest-electron-runner',

  // The test environment that will be used for testing
  testEnvironment: 'node',
};

Is there a way on my side to fix this?

kayahr commented 1 year ago

Looks like you mixed up the setup. Either you are testing in the main process with the node environment, then you have to use @kayahr/jest-electron-runner/main as runner. Or you are testing in the renderer process with the @kayahr/jest-electron-runner test runner, then you have to use the @kayahr/jest-electron-runner/environment test environment. See the examples in the README.

MareikeTaeubner commented 1 year ago

ok, it is monday and the problem was sitting in the chair before the pc. ^^"

I completely overlooked the /main part. Thank you very much for helping me out.

It works fine now. Thank you again.

kayahr commented 1 year ago

You are welcome :relaxed: