-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Preserve order of jest calls when hoisting (#10536)
- Loading branch information
Showing
8 changed files
with
200 additions
and
10 deletions.
There are no files selected for viewing
This file contains 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 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,8 @@ | ||
/** | ||
* 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. | ||
*/ | ||
|
||
export default () => 'unmocked'; |
This file contains 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 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
76 changes: 76 additions & 0 deletions
76
packages/babel-plugin-jest-hoist/src/__tests__/__snapshots__/hoistPlugin.test.ts.snap
This file contains 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,76 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`babel-plugin-jest-hoist top level mocking: top level mocking 1`] = ` | ||
require('x'); | ||
jest.enableAutomock(); | ||
jest.disableAutomock(); | ||
↓ ↓ ↓ ↓ ↓ ↓ | ||
_getJestObj().enableAutomock(); | ||
_getJestObj().disableAutomock(); | ||
function _getJestObj() { | ||
const { jest } = require("@jest/globals"); | ||
_getJestObj = () => jest; | ||
return jest; | ||
} | ||
require("x"); | ||
`; | ||
|
||
exports[`babel-plugin-jest-hoist within a block with no siblings: within a block with no siblings 1`] = ` | ||
beforeEach(() => { | ||
jest.mock('someNode') | ||
}) | ||
↓ ↓ ↓ ↓ ↓ ↓ | ||
function _getJestObj() { | ||
const { jest } = require("@jest/globals"); | ||
_getJestObj = () => jest; | ||
return jest; | ||
} | ||
beforeEach(() => { | ||
_getJestObj().mock("someNode"); | ||
}); | ||
`; | ||
|
||
exports[`babel-plugin-jest-hoist within a block: within a block 1`] = ` | ||
beforeEach(() => { | ||
require('x') | ||
jest.mock('someNode') | ||
}) | ||
↓ ↓ ↓ ↓ ↓ ↓ | ||
function _getJestObj() { | ||
const { jest } = require("@jest/globals"); | ||
_getJestObj = () => jest; | ||
return jest; | ||
} | ||
beforeEach(() => { | ||
_getJestObj().mock("someNode"); | ||
require("x"); | ||
}); | ||
`; |
43 changes: 43 additions & 0 deletions
43
packages/babel-plugin-jest-hoist/src/__tests__/hoistPlugin.test.ts
This file contains 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,43 @@ | ||
/** | ||
* 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. | ||
* | ||
*/ | ||
|
||
import pluginTester from 'babel-plugin-tester'; | ||
import babelPluginJestHoist from '..'; | ||
|
||
pluginTester({ | ||
plugin: babelPluginJestHoist, | ||
pluginName: 'babel-plugin-jest-hoist', | ||
tests: { | ||
'top level mocking': { | ||
code: ` | ||
require('x'); | ||
jest.enableAutomock(); | ||
jest.disableAutomock(); | ||
`, | ||
snapshot: true, | ||
}, | ||
'within a block': { | ||
code: ` | ||
beforeEach(() => { | ||
require('x') | ||
jest.mock('someNode') | ||
}) | ||
`, | ||
snapshot: true, | ||
}, | ||
'within a block with no siblings': { | ||
code: ` | ||
beforeEach(() => { | ||
jest.mock('someNode') | ||
}) | ||
`, | ||
snapshot: true, | ||
}, | ||
}, | ||
}); |
This file contains 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 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