When umi dev has not been run and the .umi folder does not exist the tests fail when the tested component imports router.
import router from 'umi/router';
When now running
umi test
The tests will fail with the following exception
FAIL src/pages/__tests__/index.test.js
● Test suite failed to run
Cannot find module '@tmp/history' from 'router.js'
However, Jest was able to find:
'lib/router.js'
You might want to include a file extension in your import, or update your 'moduleFileExtensions', which is currently ['js', 'jsx', 'ts', 'tsx', 'json'].
See https://jestjs.io/docs/en/configuration#modulefileextensions-array-string
at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:259:17)
at Object.require (node_modules/umi/lib/router.js:13:39)
If umi dev is run before and the .umi folder exists the tests will pass without issues
Is there a way to manually trigger the creation of .umi folder without running the dev server?
Steps to reproduce the behavior:
Any updates or workarounds for this? This is quite a big issue for me as it currently means I need to run npm start before I can run npm test and on a CI environment that means a significant increase in costs (dev builds of umi take ages for us somehow).
@leomeloxp yes this definitely is an issue for me as well still. Do you mind me asking how have you solved the npm start for CI. How do you cancel it to run the tests and how do you detect when can you do it?
@madisvain I wasn't the one dealing with fixing the issue directly but all my team mate could do was to "guesstimate" how long a build would take and quit the process after a set timeout.
My current actual solution to this is going to be to migrate out of umi (into a simpler custom CRA setup) as it's causing us more trouble than it's worth.
@leomeloxp yes the same "solution" is also what I'm considering. Thanks for the information :)
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Hi all, I've just resolved this problem. Currently, I've worked with antd pro v2 and upgrade umi to 2.11.1.
__mock__/react-dom.jest.mock('@@/history', () => {}, { virtual: true });
Hopefully, this will help you!
Most helpful comment
Hi all, I've just resolved this problem. Currently, I've worked with antd pro v2 and upgrade umi to 2.11.1.
__mock__/react-dom.jest.mock('@@/history', () => {}, { virtual: true });Hopefully, this will help you!