Skip to content

Commit

Permalink
format code manually to get snap with consistent filename
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Nov 1, 2020
1 parent e751fbb commit 0998a8b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
4 changes: 3 additions & 1 deletion packages/babel-plugin-jest-hoist/package.json
Expand Up @@ -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"
Expand Down
Expand Up @@ -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,
Expand All @@ -28,6 +30,14 @@ pluginTester({
code: `
jest.mock('./App', () => () => <div>Hello world</div>);
`,
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': {
Expand Down
2 changes: 2 additions & 0 deletions yarn.lock
Expand Up @@ -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

Expand Down

0 comments on commit 0998a8b

Please sign in to comment.