diff --git a/packages/babel-plugin-jest-hoist/package.json b/packages/babel-plugin-jest-hoist/package.json index b802e6a0fba4..4b0496692f2d 100644 --- a/packages/babel-plugin-jest-hoist/package.json +++ b/packages/babel-plugin-jest-hoist/package.json @@ -23,7 +23,9 @@ "@babel/preset-react": "^7.12.1", "@types/babel__template": "^7.0.2", "@types/node": "*", - "babel-plugin-tester": "^10.0.0" + "@types/prettier": "^2.0.0", + "babel-plugin-tester": "^10.0.0", + "prettier": "^2.1.1" }, "publishConfig": { "access": "public" diff --git a/packages/babel-plugin-jest-hoist/src/__tests__/hoistPlugin.test.ts b/packages/babel-plugin-jest-hoist/src/__tests__/hoistPlugin.test.ts index 37ba4bcffb53..019c41f44d5d 100644 --- a/packages/babel-plugin-jest-hoist/src/__tests__/hoistPlugin.test.ts +++ b/packages/babel-plugin-jest-hoist/src/__tests__/hoistPlugin.test.ts @@ -6,10 +6,12 @@ * */ +import * as path from 'path'; import pluginTester from 'babel-plugin-tester'; +import {format as formatCode} from 'prettier'; import babelPluginJestHoist from '..'; -const fakeAbsolutPath = '/root/project/src/file.js'; +const fakeAbsolutPath = path.resolve(__dirname, '../file.js'); pluginTester({ plugin: babelPluginJestHoist, @@ -28,6 +30,14 @@ pluginTester({ code: ` jest.mock('./App', () => () =>
Hello world
); `, + formatResult(code) { + const codeWithoutSystemPath = code.replace( + new RegExp(fakeAbsolutPath, 'g'), + '/root/project/src/file.js', + ); + + return formatCode(codeWithoutSystemPath, {parser: 'babel'}); + }, snapshot: true, }, 'top level mocking': { diff --git a/yarn.lock b/yarn.lock index 5a59dd079da5..bbd5d5e0e225 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4837,7 +4837,9 @@ __metadata: "@types/babel__template": ^7.0.2 "@types/babel__traverse": ^7.0.6 "@types/node": "*" + "@types/prettier": ^2.0.0 babel-plugin-tester: ^10.0.0 + prettier: ^2.1.1 languageName: unknown linkType: soft