-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
fix: hoist imports of @jest/globals
correctly
#9806
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
Merged
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
8e1319b
fix: hoist imports of `@jest/globals` correctly
SimenB 9b91b62
add VariableDeclaration visitor
SimenB 9ebd34f
rewrite babel-plugin-jest-hoist
jeysal c7a16bf
remove unused import
jeysal fcca78b
cleanup
jeysal b4dc590
lint cleanup
jeysal 78a44b6
correct test
jeysal b18ac40
fix by using post hook
jeysal 066deab
almost fix namespace import
jeysal 20c8f58
finally fixed I think 💪
jeysal 530c788
Merge branch 'master' into hoist-global-import
SimenB 6df0341
Merge branch 'master' into hoist-global-import
SimenB db4785a
remove unused import
SimenB cd059ec
test aliased import
jeysal b29d972
computed check, thanks nicolo
jeysal 36ad2f4
optional chaining HYPE
jeysal f547d25
test file fixes
jeysal 80dabd0
hoist within scope
jeysal 76f0c38
Merge remote-tracking branch 'upstream/master' into hoist-global-import
jeysal 9a022c1
test count
jeysal d528e1b
don't declare getJestObj if unnecessary
jeysal e4778f8
snapshot updates, idk...
jeysal 5d352b4
Revert "snapshot updates, idk..."
SimenB File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
*/ | ||
|
||
/* eslint-disable import/no-duplicates */ | ||
import {jest} from '@jest/globals'; | ||
import {jest as aliasedJest} from '@jest/globals'; | ||
import * as JestGlobals from '@jest/globals'; | ||
/* eslint-enable import/no-duplicates */ | ||
|
||
import a from '../__test_modules__/a'; | ||
import b from '../__test_modules__/b'; | ||
import c from '../__test_modules__/c'; | ||
import d from '../__test_modules__/d'; | ||
|
||
// These will be hoisted above imports | ||
|
||
jest.unmock('../__test_modules__/a'); | ||
aliasedJest.unmock('../__test_modules__/b'); | ||
JestGlobals.jest.unmock('../__test_modules__/c'); | ||
|
||
// These will not be hoisted above imports | ||
|
||
{ | ||
const jest = {unmock: () => {}}; | ||
jest.unmock('../__test_modules__/d'); | ||
} | ||
|
||
// tests | ||
|
||
test('named import', () => { | ||
expect(a._isMockFunction).toBe(undefined); | ||
expect(a()).toBe('unmocked'); | ||
}); | ||
|
||
test('aliased named import', () => { | ||
expect(b._isMockFunction).toBe(undefined); | ||
expect(b()).toBe('unmocked'); | ||
}); | ||
|
||
test('namespace import', () => { | ||
expect(c._isMockFunction).toBe(undefined); | ||
expect(c()).toBe('unmocked'); | ||
}); | ||
|
||
test('fake jest, shadowed import', () => { | ||
expect(d._isMockFunction).toBe(true); | ||
expect(d()).toBe(undefined); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.