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 https://github.com/facebook/react-native/pull/19496

Differential Revision: D8195947

Pulled By: hramos

fbshipit-source-id: 909b5fe7cfd8c6286baf161a227a359854a37603
This commit is contained in:
sAm_vdP 2018-05-31 12:49:00 -07:00 committed by Facebook Github Bot
parent fecfa2a553
commit 216bce3163
3 changed files with 6 additions and 3 deletions

View File

@ -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)"

View File

@ -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]),
};

View File

@ -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": [