From 216bce31632480ce70cc03b1b2a57ec12440afd7 Mon Sep 17 00:00:00 2001 From: sAm_vdP Date: Thu, 31 May 2018 12:49:00 -0700 Subject: [PATCH] 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 --- jest-preset.json | 2 +- jest/assetFileTransformer.js | 5 ++++- package.json | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/jest-preset.json b/jest-preset.json index afd12eb96..c7fb437e4 100644 --- a/jest-preset.json +++ b/jest-preset.json @@ -15,7 +15,7 @@ ], "transform": { "^.+\\.js$": "babel-jest", - "^[./a-zA-Z0-9$_-]+\\.(bmp|gif|jpg|jpeg|mp4|png|psd|svg|webp)$": "/node_modules/react-native/jest/assetFileTransformer.js" + "^.+\\.(bmp|gif|jpg|jpeg|mp4|png|psd|svg|webp)$": "/node_modules/react-native/jest/assetFileTransformer.js" }, "transformIgnorePatterns": [ "node_modules/(?!(jest-)?react-native|react-clone-referenced-element)" diff --git a/jest/assetFileTransformer.js b/jest/assetFileTransformer.js index da6cf34a0..85f4a7bce 100644 --- a/jest/assetFileTransformer.js +++ b/jest/assetFileTransformer.js @@ -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]), }; diff --git a/package.json b/package.json index d619cb176..373cdc2e6 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,7 @@ }, "jest": { "transform": { - "^[./a-zA-Z0-9$_-]+\\.(bmp|gif|jpg|jpeg|mp4|png|psd|svg|webp)$": "/jest/assetFileTransformer.js", + "^.+\\.(bmp|gif|jpg|jpeg|mp4|png|psd|svg|webp)$": "/jest/assetFileTransformer.js", ".*": "./jest/preprocessor.js" }, "setupFiles": [