facebook-atom / jest-electron-runner

custom test runner for Jest that allows tests to be run in Electron environment
MIT License
189 stars 33 forks source link

Not working in Jest 25.4.0 version #61

Closed alejandroclaro closed 4 years ago

alejandroclaro commented 4 years ago

It's working after recent Jest updates. I get the following error:

TypeError: runtime.unstable_shouldLoadAsEsm is not a function
        at jasmine2 (node_modules/@jest/core/node_modules/jest-jasmine2/build/index.js:210:23)
        at node_modules/@jest-runner/electron/node_modules/jest-runner/build/runTest.js:385:24
huboneo commented 4 years ago

same here

danielweck commented 4 years ago

Different line numbers, but same error:

    TypeError: runtime.unstable_shouldLoadAsEsm is not a function
        at jasmine2 (/node_modules/@jest/core/node_modules/jest-jasmine2/build/index.js:188:25)
        at /node_modules/@jest-runner/electron/node_modules/jest-runner/build/runTest.js:385:24
        at Generator.next (<anonymous>)
        at asyncGeneratorStep (/node_modules/@jest-runner/electron/node_modules/jest-runner/build/runTest.js:161:24)
        at _next (/node_modules/@jest-runner/electron/node_modules/jest-runner/build/runTest.js:181:9)

      at jasmine2 (node_modules/@jest/core/node_modules/jest-jasmine2/build/index.js:188:25)
      at Server.emit (node_modules/event-pubsub/es5.js:74:21)
      at Server.gotData (node_modules/node-ipc/dao/socketServer.js:194:14)
danielweck commented 4 years ago

My temporary fix is to patch / replace const esm = runtime.unstable_shouldLoadAsEsm(xxx); with const esm = false; in node_modules/jest-jasmine2/build/index.js (which could be a subfolder of node_modules/@jest/core/, depending on your local NPM/Yarn setup)

Source code references:

https://github.com/facebook/jest/blob/7a7710d2c9cdc7da97a3674c36f1ca46f7068f78/packages/jest-jasmine2/src/index.ts#L159

https://github.com/facebook/jest/blob/7a7710d2c9cdc7da97a3674c36f1ca46f7068f78/packages/jest-jasmine2/src/index.ts#L180

danielweck commented 4 years ago

There are many ways to implement the aforementioned patch, but as this is a temporary measure, FYI I simply wrote a quick postinstall script in my package.json to patch jest-electron-runner until it is upgraded to the latest Jest 25.4.x:

"patchElectronJestJasmine": "node scripts/replace-in-file.js './node_modules/@jest/core/node_modules/jest-jasmine2/build/index.js' 'const esm = runtime.unstable_shouldLoadAsEsm' 'const esm = false; // runtime.unstable_shouldLoadAsEsm'",

...where scripts/replace-in-file.js is:

const path = require('path');
const fs = require('fs');
const args = process.argv.slice(2);
const filePath = path.join(process.cwd(), args[0]);
let fileStr = fs.readFileSync(filePath, { encoding: "utf8" });
const regex = new RegExp(args[1], "g");
fileStr = fileStr.replace(regex, args[2]);
fs.writeFileSync(filePath, fileStr, { encoding: "utf8" });

Quick and dirty :)

phamhongphuc commented 4 years ago

I founded a way to fix this: Yarn: https://classic.yarnpkg.com/en/docs/selective-version-resolutions/ Npm: https://github.com/rogeriochaves/npm-force-resolutions

In your package.json, add:

  "resolutions": {
    "@jest-runner/electron/jest-haste-map": "^25.4.0",
    "@jest-runner/electron/jest-mock": "^25.4.0",
    "@jest-runner/electron/jest-runner": "^25.4.0",
    "@jest-runner/electron/jest-runtime": "^25.4.0",
    "@jest-runner/electron/jest-util": "^25.4.0"
  }

And run yarn install. This even fixes the console error #54

image

Pipeline: https://dev.azure.com/ai-scanlation/ai.scanlation/_build/results?buildId=969&view=logs&j=12f1170f-54f2-53f3-20dd-22fc7dff55f9&t=bd05475d-acb5-5619-3ccb-c46842dbc997&l=34

It's a temporary way until jest-electron-runner is updated.

aaronabramov commented 4 years ago

https://github.com/facebook-atom/jest-electron-runner/pull/62 should have fixed it! sorry about the breakage

aaronabramov commented 4 years ago

published @jest-runner/electron@3.0.0