Skip to content

Commit

Permalink
chore: update babel-plugin-tester (#13804)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Jan 24, 2023
1 parent b9282e1 commit e0b1249
Show file tree
Hide file tree
Showing 3 changed files with 183 additions and 192 deletions.
2 changes: 1 addition & 1 deletion packages/babel-plugin-jest-hoist/package.json
Expand Up @@ -32,7 +32,7 @@
"@types/babel__template": "^7.0.2",
"@types/node": "*",
"@types/prettier": "^2.1.5",
"babel-plugin-tester": "^10.0.0",
"babel-plugin-tester": "^11.0.2",
"prettier": "^2.1.1"
},
"publishConfig": {
Expand Down
@@ -1,32 +1,10 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`babel-plugin-jest-hoist TS typeof usage in jest.mock: TS typeof usage in jest.mock 1`] = `
jest.mock('some-module', () => {
const actual = jest.requireActual('some-module');
return jest.fn<typeof actual.method>();
});
↓ ↓ ↓ ↓ ↓ ↓
_getJestObj().mock('some-module', () => {
const actual = jest.requireActual('some-module');
return jest.fn();
});
function _getJestObj() {
const {jest} = require('@jest/globals');
_getJestObj = () => jest;
return jest;
}
`;

exports[`babel-plugin-jest-hoist automatic react runtime: automatic react runtime 1`] = `
exports[`babel-plugin-jest-hoist 1. automatic react runtime: 1. automatic react runtime 1`] = `
jest.mock('./App', () => () => <div>Hello world</div>);
↓ ↓ ↓ ↓ ↓ ↓
var _jsxFileName = '/root/project/src/file.js';
Expand Down Expand Up @@ -55,60 +33,98 @@ function _getJestObj() {
return jest;
}
`;

exports[`babel-plugin-jest-hoist 2. top level mocking: 2. 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 global jest.mock within jest.mock: global jest.mock within jest.mock 1`] = `
exports[`babel-plugin-jest-hoist 3. within a block: 3. within a block 1`] = `
jest.mock('some-module', () => {
jest.mock('some-module');
beforeEach(() => {
require('x');
jest.mock('someNode');
});
↓ ↓ ↓ ↓ ↓ ↓
_getJestObj().mock('some-module', () => {
_getJestObj().mock('some-module');
});
function _getJestObj() {
const {jest} = require('@jest/globals');
_getJestObj = () => jest;
return jest;
}
beforeEach(() => {
_getJestObj().mock('someNode');
require('x');
});
`;

exports[`babel-plugin-jest-hoist global jest.requireActual in jest.mock: global jest.requireActual in jest.mock 1`] = `
exports[`babel-plugin-jest-hoist 4. within a block with no siblings: 4. within a block with no siblings 1`] = `
jest.mock('some-module', () => {
jest.requireActual('some-module');
beforeEach(() => {
jest.mock('someNode');
});
jest.requireActual('some-module');
↓ ↓ ↓ ↓ ↓ ↓
_getJestObj().mock('some-module', () => {
_getJestObj().requireActual('some-module');
});
function _getJestObj() {
const {jest} = require('@jest/globals');
_getJestObj = () => jest;
return jest;
}
jest.requireActual('some-module');
beforeEach(() => {
_getJestObj().mock('someNode');
});
`;

exports[`babel-plugin-jest-hoist 5. required \`jest\` within \`jest\`: 5. required \`jest\` within \`jest\` 1`] = `
const {jest} = require('@jest/globals');
jest.mock('some-module', () => {
jest.requireActual('some-module');
});
↓ ↓ ↓ ↓ ↓ ↓
const {jest} = require('@jest/globals');
jest.mock('some-module', () => {
jest.requireActual('some-module');
});
`;

exports[`babel-plugin-jest-hoist imported jest.mock within jest.mock: imported jest.mock within jest.mock 1`] = `
exports[`babel-plugin-jest-hoist 6. imported jest.mock within jest.mock: 6. imported jest.mock within jest.mock 1`] = `
import {jest} from '@jest/globals';
jest.mock('some-module', () => {
jest.mock('some-module');
});
↓ ↓ ↓ ↓ ↓ ↓
_getJestObj().mock('some-module', () => {
Expand All @@ -121,112 +137,96 @@ function _getJestObj() {
}
import {jest} from '@jest/globals';
`;

exports[`babel-plugin-jest-hoist imported jest.requireActual in jest.mock: imported jest.requireActual in jest.mock 1`] = `
import {jest} from '@jest/globals';
exports[`babel-plugin-jest-hoist 7. global jest.mock within jest.mock: 7. global jest.mock within jest.mock 1`] = `
jest.mock('some-module', () => {
jest.requireActual('some-module');
jest.mock('some-module');
});
jest.requireActual('some-module');
↓ ↓ ↓ ↓ ↓ ↓
_getJestObj().mock('some-module', () => {
_getJestObj().requireActual('some-module');
_getJestObj().mock('some-module');
});
function _getJestObj() {
const {jest} = require('@jest/globals');
_getJestObj = () => jest;
return jest;
}
import {jest} from '@jest/globals';
jest.requireActual('some-module');
`;

exports[`babel-plugin-jest-hoist required \`jest\` within \`jest\`: required \`jest\` within \`jest\` 1`] = `
exports[`babel-plugin-jest-hoist 8. imported jest.requireActual in jest.mock: 8. imported jest.requireActual in jest.mock 1`] = `
const {jest} = require('@jest/globals');
jest.mock('some-module', () => {
jest.requireActual('some-module');
});
↓ ↓ ↓ ↓ ↓ ↓
import {jest} from '@jest/globals';
const {jest} = require('@jest/globals');
jest.mock('some-module', () => {
jest.requireActual('some-module');
});
jest.requireActual('some-module');
`;

exports[`babel-plugin-jest-hoist top level mocking: top level mocking 1`] = `
require('x');
jest.enableAutomock();
jest.disableAutomock();
↓ ↓ ↓ ↓ ↓ ↓
_getJestObj().enableAutomock();
_getJestObj().disableAutomock();
_getJestObj().mock('some-module', () => {
_getJestObj().requireActual('some-module');
});
function _getJestObj() {
const {jest} = require('@jest/globals');
_getJestObj = () => jest;
return jest;
}
require('x');
import {jest} from '@jest/globals';
jest.requireActual('some-module');
`;

exports[`babel-plugin-jest-hoist within a block with no siblings: within a block with no siblings 1`] = `
exports[`babel-plugin-jest-hoist 9. global jest.requireActual in jest.mock: 9. global jest.requireActual in jest.mock 1`] = `
beforeEach(() => {
jest.mock('someNode');
jest.mock('some-module', () => {
jest.requireActual('some-module');
});
jest.requireActual('some-module');
↓ ↓ ↓ ↓ ↓ ↓
_getJestObj().mock('some-module', () => {
_getJestObj().requireActual('some-module');
});
function _getJestObj() {
const {jest} = require('@jest/globals');
_getJestObj = () => jest;
return jest;
}
beforeEach(() => {
_getJestObj().mock('someNode');
});
jest.requireActual('some-module');
`;

exports[`babel-plugin-jest-hoist within a block: within a block 1`] = `
exports[`babel-plugin-jest-hoist 10. TS typeof usage in jest.mock: 10. TS typeof usage in jest.mock 1`] = `
beforeEach(() => {
require('x');
jest.mock('someNode');
jest.mock('some-module', () => {
const actual = jest.requireActual('some-module');
return jest.fn<typeof actual.method>();
});
↓ ↓ ↓ ↓ ↓ ↓
_getJestObj().mock('some-module', () => {
const actual = jest.requireActual('some-module');
return jest.fn();
});
function _getJestObj() {
const {jest} = require('@jest/globals');
_getJestObj = () => jest;
return jest;
}
beforeEach(() => {
_getJestObj().mock('someNode');
require('x');
});
`;

0 comments on commit e0b1249

Please sign in to comment.