Skip to content

Commit

Permalink
Fix jest snapshot testing on windows
Browse files Browse the repository at this point in the history
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
  • Loading branch information
sam-vdp authored and facebook-github-bot committed May 31, 2018
1 parent fecfa2a commit 216bce3
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion jest-preset.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
],
"transform": {
"^.+\\.js$": "babel-jest",
"^[./a-zA-Z0-9$_-]+\\.(bmp|gif|jpg|jpeg|mp4|png|psd|svg|webp)$": "<rootDir>/node_modules/react-native/jest/assetFileTransformer.js"
"^.+\\.(bmp|gif|jpg|jpeg|mp4|png|psd|svg|webp)$": "<rootDir>/node_modules/react-native/jest/assetFileTransformer.js"
},
"transformIgnorePatterns": [
"node_modules/(?!(jest-)?react-native|react-clone-referenced-element)"
Expand Down
5 changes: 4 additions & 1 deletion jest/assetFileTransformer.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ module.exports = {
// the Jest snapshot.
process: (_, filename) =>
`module.exports = {
testUri: ${JSON.stringify(path.relative(__dirname, filename))}
testUri:
${JSON.stringify(
path.relative(__dirname, filename).replace(/\\/g, '/'),
)}
};`,
getCacheKey: createCacheKeyFunction([__filename]),
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
},
"jest": {
"transform": {
"^[./a-zA-Z0-9$_-]+\\.(bmp|gif|jpg|jpeg|mp4|png|psd|svg|webp)$": "<rootDir>/jest/assetFileTransformer.js",
"^.+\\.(bmp|gif|jpg|jpeg|mp4|png|psd|svg|webp)$": "<rootDir>/jest/assetFileTransformer.js",
".*": "./jest/preprocessor.js"
},
"setupFiles": [
Expand Down

0 comments on commit 216bce3

Please sign in to comment.