threepointone / esjest-transform

A fast jest transform
MIT License
45 stars 0 forks source link

can not find jest globals in tests using jest/require.requireActual #2

Open Haroenv opened 3 years ago

Haroenv commented 3 years ago
 FAIL  src/widgets/pagination/__tests__/pagination-test.js
  ● Test suite failed to run

    Cannot find module '@jest/globals' from 'pagination-test.js'

      23 | });
      24 | 
    > 25 | describe('Usage', () => {
         |       ^
      26 |   it('throws without container', () => {
      27 |     expect(() => {
      28 |       pagination({ container: undefined });

      at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:276:11)
      at _getJestObj (src/widgets/pagination/__tests__/pagination-test.js:25:7)
      at Object.<anonymous> (src/widgets/pagination/__tests__/pagination-test.js:8:1)

this didn't happen in every test, and on different spots in the code, some describe, some expect, some an unrelated code point

threepointone commented 3 years ago

That's... odd. Any chance you could make a reduced reproduction so I can hack on it?

Haroenv commented 3 years ago

haven't yet made a smaller reproduction, but our code is open source: https://github.com/algolia/instantsearch.js/tree/poc/esbuild-jest

Haroenv commented 3 years ago

I think the tests which fail use require.requireActual or jest.requireActual like here:

https://github.com/algolia/instantsearch.js/blob/1553aa36c8bb8664b5e74fd2378ea2ef45a52acf/src/widgets/pagination/__tests__/pagination-test.js#L8-L23

when I comment out the requireActual the test only fails where I call .mockClear

threepointone commented 3 years ago

odder and odder. I'll try to reproduce this locally

threepointone commented 3 years ago

oh hmm ok this actually makes sense, since when it hoists, jest goes out of scope of the import call. I wonder how this is solved with actual babel. I'll give it a look later this evening

yamafaktory commented 3 years ago

Hi and thanks for this awesome initiative πŸ‘.

You might already be aware of this other project which might actually be facing the same issue https://github.com/aelbore/esbuild-jest.

If not, the interesting part (also visible via the readme) is this related issue https://github.com/aelbore/esbuild-jest/issues/12.

Hope it help ☺️.