Skip to content

Commit 216bce3

Browse files
sam-vdpfacebook-github-bot
authored andcommitted
Fix jest snapshot testing on windows
Summary: Fixes #19370 Applied changes to existing project that uses jest snapshot testing. Testing was broken before and now works. To verify: Run any snapshot test containing an image reference on Windows before and after this PR. [WINDOWS][BUGFIX][jest] - Fixed jest snapshot testing on windows Closes #19496 Differential Revision: D8195947 Pulled By: hramos fbshipit-source-id: 909b5fe7cfd8c6286baf161a227a359854a37603
1 parent fecfa2a commit 216bce3

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

jest-preset.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
],
1616
"transform": {
1717
"^.+\\.js$": "babel-jest",
18-
"^[./a-zA-Z0-9$_-]+\\.(bmp|gif|jpg|jpeg|mp4|png|psd|svg|webp)$": "<rootDir>/node_modules/react-native/jest/assetFileTransformer.js"
18+
"^.+\\.(bmp|gif|jpg|jpeg|mp4|png|psd|svg|webp)$": "<rootDir>/node_modules/react-native/jest/assetFileTransformer.js"
1919
},
2020
"transformIgnorePatterns": [
2121
"node_modules/(?!(jest-)?react-native|react-clone-referenced-element)"

jest/assetFileTransformer.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ module.exports = {
2121
// the Jest snapshot.
2222
process: (_, filename) =>
2323
`module.exports = {
24-
testUri: ${JSON.stringify(path.relative(__dirname, filename))}
24+
testUri:
25+
${JSON.stringify(
26+
path.relative(__dirname, filename).replace(/\\/g, '/'),
27+
)}
2528
};`,
2629
getCacheKey: createCacheKeyFunction([__filename]),
2730
};

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
},
2121
"jest": {
2222
"transform": {
23-
"^[./a-zA-Z0-9$_-]+\\.(bmp|gif|jpg|jpeg|mp4|png|psd|svg|webp)$": "<rootDir>/jest/assetFileTransformer.js",
23+
"^.+\\.(bmp|gif|jpg|jpeg|mp4|png|psd|svg|webp)$": "<rootDir>/jest/assetFileTransformer.js",
2424
".*": "./jest/preprocessor.js"
2525
},
2626
"setupFiles": [

0 commit comments

Comments
 (0)