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

@jest/globals alternative #42

Open
Jaid opened this issue Jun 14, 2022 · 2 comments
Open

@jest/globals alternative #42

Jaid opened this issue Jun 14, 2022 · 2 comments

Comments

@Jaid
Copy link

Jaid commented Jun 14, 2022

Switching to jest-light-runner with tests that use import {it, expect} from "@jest/globals" currently doesn't work. It's easily fixed by just removing this import and using those magically injected globals, but this way ESLint reports undefined variables and I lose my IDE's type features.

So could you either inject your own globals into from "@jest/globals" imports or expose your own globals, so I can use import {it, expect} from "jest-light-runner"?

Jaid added a commit to Jaid/eslint-config-jaid that referenced this issue Jun 14, 2022
@Alx101
Copy link

Alx101 commented Nov 22, 2022

How does jest-runtime do it today? Maybe it's possible to mock the globals import

I notice if I do not import directly from @jest/globals my jest.spyOn calls get incorrect types

@SimenB
Copy link
Contributor

SimenB commented Dec 16, 2022

jest-runtime does it by intercepting the require (or import) call and returning a module with the correct API (what would be the globals for the currently running module). I'm not sure how this module would do it loaders or module mocks. If globals are enabled it's easy enough (just be a facade for them), but if globals are disabled this module needs to interact with the framework (circus) via https://github.com/facebook/jest/blob/41bf2300895a2c00d0525d21260f0a392819871f/packages/jest-circus/src/legacy-code-todo-rewrite/jestAdapter.ts#L37

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants