Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setting testEnvironment to node causes jest functions to be undefined #9538

Closed
alyhegazy opened this issue Feb 8, 2020 · 14 comments · Fixed by #9708
Closed

setting testEnvironment to node causes jest functions to be undefined #9538

alyhegazy opened this issue Feb 8, 2020 · 14 comments · Fixed by #9708

Comments

@alyhegazy
Copy link

🐛 Bug Report

When setting testEnvironment to node and running a test I get ReferenceError: test is not defined. If I remove testEnvironment: 'node' from the config it runs fine. The same applies to describe, beforeAll...etc.

Note: it works fine on node 10.16.0

 FAIL  test/1.test.js
  ● Test suite failed to run

    ReferenceError: test is not defined

    > 1 | test('test1', () => {
        | ^
      2 |   expect(1).toBe(1);
      3 | });

      at Object.<anonymous> (test/1.test.js:1:1)

Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        0.333s
Ran all test suites.
npm ERR! Test failed.  See above for more details.

To Reproduce

Steps to reproduce the behavior:

jest.config.js

module.exports = {
  testEnvironment: 'node'
}

test/1.test.js

test('test1', () => {
  expect(1).toBe(1);
});

Expected behavior

Tests should run without errors when testEnvironment is set to node.

Link to repl or repo (highly encouraged)

envinfo

  System:
    OS: macOS 10.15.3
    CPU: (12) x64 Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz
  Binaries:
    Node: 10.14.0 - /usr/local/bin/node
    npm: 6.13.7 - /usr/local/bin/npm
  npmPackages:
    jest: ^25.1.0 => 25.1.0 
@SimenB
Copy link
Member

SimenB commented Feb 8, 2020

Jest itself sets it to node in our own tests, so your reproduction is not enough. Can you put together a repository or a repl/codesandbox

@alyhegazy
Copy link
Author

Here's a simple test https://github.com/alyhegazy/jest-tests-bug.git
I get the error in the description on node 10.14.0

@SimenB
Copy link
Member

SimenB commented Feb 8, 2020

Right, that's a bug in node 10.14.0 and 10.14.1 (possibly earlier as well, didn't check) - 10.14.2 (and newer) works correctly. Fix is nodejs/node#23206.

(duplicate of #9453)

@manwithsteelnerves
Copy link

manwithsteelnerves commented Mar 13, 2020

Damn, I wasted one whole day :|
10.14.2 worked! Thanks a lot!

@alyhegazy
Copy link
Author

Tell me about it!

@manwithsteelnerves
Copy link

@alyhegazy What you want to know?

@uloga
Copy link

uloga commented Mar 25, 2020

Wasted few hours on this. :( Thanks for the fix.

@SimenB
Copy link
Member

SimenB commented Mar 26, 2020

I've published 25.2.2 which has a workaround for this issue on the buggy versions of node

@enuchi
Copy link

enuchi commented May 12, 2020

Thanks for this -- had issues using 10.13.0. Seems like jest 26 no longer works with node 10.13, but downgrading to 25.2.2 does. Any way to get 26 to support the buggy versions of node?

@thymikee
Copy link
Collaborator

@enuchi Jest 26 requires Node >=10.14.2

@SimenB
Copy link
Member

SimenB commented May 12, 2020

Precisely because of this issue

@enuchi
Copy link

enuchi commented May 12, 2020

Cool. Thanks!

@ajoshi31
Copy link

This was such a stupid big and I spent nearly 1 hour exploring it.

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants