Umi: Tests fail without .umi folder

Created on 23 Oct 2019  ·  6Comments  ·  Source: umijs/umi

What happens?

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?

Mini Showcase Repository(REQUIRED)

How To Reproduce

Steps to reproduce the behavior:

  1. Clone github repo
  2. run "umi test"

Context

  • Umi Version: 2.10.7
  • Node Version: v12.12.0
  • Platform: OS X / Linux
type(bug) wontfix

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.

  • In the root folder project, I created server.js in __mock__/react-dom.
  • Add the code: jest.mock('@@/history', () => {}, { virtual: true });

Screen Shot 2020-04-20 at 00 49 27

Hopefully, this will help you!

All 6 comments

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.

  • In the root folder project, I created server.js in __mock__/react-dom.
  • Add the code: jest.mock('@@/history', () => {}, { virtual: true });

Screen Shot 2020-04-20 at 00 49 27

Hopefully, this will help you!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ironyfive picture ironyfive  ·  3Comments

kitebear picture kitebear  ·  3Comments

sorrycc picture sorrycc  ·  4Comments

mizi-lin picture mizi-lin  ·  3Comments

afc163 picture afc163  ·  3Comments