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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Cannot read property 'context' of undefined #7740

Closed
kentcdodds opened this issue Jan 28, 2019 · 7 comments 路 Fixed by #7745
Closed

TypeError: Cannot read property 'context' of undefined #7740

kentcdodds opened this issue Jan 28, 2019 · 7 comments 路 Fixed by #7745

Comments

@kentcdodds
Copy link
Contributor

馃悰 Bug Report

When you have a globalSetup script, this error shows up when trying to start jest with watch mode:

TypeError: Cannot read property 'context' of undefined

To Reproduce

Steps to reproduce the behavior:

git clone -b context-issue --single-branch https://github.com/kentcdodds/jest-transform-self-transform-bug.git
cd jest-transform-self-transform-bug
yarn
npx jest --watch

Expected behavior

It should start Jest in watch mode.

Link to repl or repo (highly encouraged)

I just reused the same repo from my other issue. It's on the context-issues branch here: https://github.com/kentcdodds/jest-transform-self-transform-bug/tree/context-issue

Here's the difference for the initiated: https://github.com/kentcdodds/jest-transform-self-transform-bug/compare/context-issue

Run npx envinfo --preset jest

Paste the results here:

  System:
    OS: macOS 10.14.3
    CPU: (8) x64 Intel(R) Core(TM) i7-4980HQ CPU @ 2.80GHz
  Binaries:
    Node: 8.11.4 - ~/n/bin/node
    Yarn: 1.12.3 - /usr/local/bin/yarn
    npm: 6.5.0 - ~/n/bin/npm
  npmPackages:
    jest: ^24.0.0 => 24.0.0 

I pulled this up in a debugger and got this:

screen shot 2019-01-28 at 4 45 12 pm

This code is here: https://github.com/facebook/jest/blob/2e2d2c8dedb76e71c0dfa85ed36b81d1f89e0d87/packages/jest-cli/src/runGlobalHook.js#L41-L48

The modulePath variable is the path to the globalSetup file.

Note that the tests run fine when not in watch mode.

@jeysal
Copy link
Contributor

jeysal commented Jan 29, 2019

Confirmed. Probably introduced by #7562

@SimenB
Copy link
Member

SimenB commented Jan 29, 2019

It happens since we run both setup and teardown even if there's no tests.

So it also happens if there are no tests found, and jest is run with --pass-with-no-tests

@SimenB
Copy link
Member

SimenB commented Jan 29, 2019

See #7745. Missing a test, if anybody feels like adding one 馃榾

@kentcdodds
Copy link
Contributor Author

Thanks friends 馃

@SimenB
Copy link
Member

SimenB commented Feb 5, 2019

@kentcdodds release is out 8a2ea1e

@kentcdodds
Copy link
Contributor Author

Sweet!

@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 12, 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.

3 participants