Closed aubrey-ford-nutrien closed 2 years ago
Can you please share your test
script from your package.json
, your jest config file and your babel config?
"scripts": {
"build": "react-app-rewired --max_old_space_size=4096 build",
"create:env": "node -r fs -e \"fs.copyFileSync('.env.sample', '.env', fs.constants.COPYFILE_EXCL)\"",
"eject": "react-scripts eject",
"lighthouse": "node lighthouse",
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"lint:staged": "lint-staged",
"start": "react-app-rewired start",
"start:dev": "react-app-rewired start",
"storybook": "start-storybook -p 9009 -s public",
"storybook:build": "build-storybook -s public",
"pretest": "babel node_modules/ol/ --out-dir src/__mocks__/ol --presets \"@babel/preset-env\"",
"test": "cross-env TZ=UTC CI=true FORCE_COLOR=true react-scripts test --env=jsdom --coverage",
"posttest": "rimraf src/__mocks__/ol",
"pretest:watch": "npm run pretest",
"test:watch": "react-scripts test --env=jsdom",
"posttest:watch": "npm run posttest",
"test:debug": "react-scripts --inspect-brk test --runInBand --no-cache --env=jsdom",
"preinstall": "npx npm-force-resolutions"
}
JEST CONFIG:
"jest": {
"collectCoverageFrom": [
"src/**",
"!src/helpers/entities.mock.js",
"!**/*.json",
"!**/*.stories.js"
]
}
BABEL CONFIG:
{
"presets": [
[
"@babel/preset-env",
{
"useBuiltIns": "usage",
"corejs": 3,
"shippedProposals": true
}
],
"@babel/preset-react",
"module:metro-react-native-babel-preset"
],
"plugins": [
[
"@babel/plugin-transform-runtime",
{
"corejs": {
"version": 3,
"proposals": true
},
"helpers": true,
"version": "^7.13.15"
}
]
]
}
Thanks for providing the details. We have created this sample repo with your dependencies, configs and a simple Signup
test and Wallaby is working as expected.
Can you please clone the repo, run npm i
and run Wallaby to see if it's working for you? If it's working, please try running npx jest --clearCache
and restarting Wallaby in your real repo to see if it helps.
If the sample repo is working and cache reset in your project doesn't help, we will need a repro of the issue, that should hopefully be relatively simple to create. You may either try adding the details that we are missing to reproduce to our sample repo, or simply copy/paste your project to a new folder, delete all source code except the failing test and configs (so that the issue is still reproducible) and share it with us either via Github or via hello@wallabyjs.com.
Just pushed a new commit with the package that is causing the problem. It is pulled in through a proprietary dependency in the real repo, but this does the same thing. It gives the same error with Wallaby but running the test script works fine.
Just pushed a new commit with the package that is causing the problem.
I can't see any pull requests with the mentioned commit in the sample repo https://github.com/wallabyjs/wallaby-2897. Have you forked it or created a separate repo? Can you please share it?
Sorry here you go: https://github.com/aubrey-ford-nutrien/wallaby-2897
Also created pull request. I'm guessing it has something to do with the pretest hook. Maybe older version of Wallaby/IntelliJ ran the pretest hook and now it doesn't? I've been running those same tests for months with no issue and none of that codee has changed...
Thanks for sharing the repo and creating the pull request. We can reproduce the issue now, but it doesn't seem to be Wallaby specific, because running npm run test
in your repo is producing the same result:
Please note that I had to add SKIP_PREFLIGHT_CHECK=true
env var to the test command to run it because it was complaining about incompatible babel-jest version: "test": "cross-env TZ=UTC CI=true SKIP_PREFLIGHT_CHECK=true FORCE_COLOR=true react-scripts test --env=jsdom --coverage",
Works fine for me. Didn't need to add the SKIP_PREFLIGHT_CHECK:
Oh, in my case neither pretest
nor posttest
hooks run when I run npm run test
for some reason. If I run the pretest
hook manually, then npm run test
starts working for me, but so does Wallaby - it also works once I run npm run pretest
(and don't run posttest afterwards).
Maybe older version of Wallaby/IntelliJ ran the pretest hook and now it doesn't?
Wallaby never ran pretest hook. It doesn't run/use any of your package.json scripts. My guess is that maybe in your case the "posttest"
hook (that deletes the results of the pretest hook required for the successful run) was missing (or recently added)?
There are a few possible solutions in your case:
rimraf src/__mocks__/ol
in pretest hook before babel, so that you can run npm run pretest
once and then the mocks are sitting locally until the next run and Wallaby works.babel node_modules/ol/ --out-dir src/__mocks__/ol --presets \"@babel/preset-env\"
via const { exec } = require("child_process");
.babel node_modules/ol/ --out-dir src/__mocks__/ol --presets \"@babel/preset-env\"
via const { exec } = require("child_process");
Ah you're right. It must have something to do with how I was running the test script and posttest wasn't being run. Thanks for your help, not sure how I didn't see that myself. It's been a crazy week.
No worries, glad that we have sorted the issue out for you.
Issue description or question
I've reset everything back to the exact state (git commit, node version, wallaby version, node_modules reinstall, ect) it was in a couple weeks ago when everything worked fine, but now no matter what I do I keep getting that error for 3 of 100+ tests. Running jest on its own works fine. All three are ultimately caused by the same file import, but it works fine running regular tests. Nothing special about the tests themselves except that down the line that file is imported.
Wallaby diagnostics report