diff --git a/jest-preset.json b/jest-preset.json index a0ecb24f1d..5c337d72e2 100644 --- a/jest-preset.json +++ b/jest-preset.json @@ -15,7 +15,7 @@ "/node_modules/react-native/Libraries/react-native/", "/node_modules/react-native/packager/" ], - "transformIgnorePatterns": [ + "preprocessorIgnorePatterns": [ "node_modules/(?!(jest-)?react-native|react-clone-referenced-element)" ], "setupFiles": [ diff --git a/package.json b/package.json index be414881d5..e2b87bc857 100644 --- a/package.json +++ b/package.json @@ -12,9 +12,7 @@ }, "jest": { "automock": true, - "transform": { - ".*": "jest/preprocessor.js" - }, + "scriptPreprocessor": "jest/preprocessor.js", "setupFiles": [ "jest/setup.js" ], @@ -174,7 +172,7 @@ "immutable": "~3.7.6", "imurmurhash": "^0.1.4", "inquirer": "^0.12.0", - "jest-haste-map": "^17.0.0", + "jest-haste-map": "15.0.1", "joi": "^6.6.1", "json-stable-stringify": "^1.0.1", "json5": "^0.4.0", @@ -226,9 +224,9 @@ "flow-bin": "^0.34.0", "graphlib-dot": "0.6.2", "graphql": "0.6.2", - "jest": "^17.0.0", - "jest-repl": "^17.0.0", - "jest-runtime": "^17.0.0", + "jest": "16.0.1", + "jest-repl": "16.0.0", + "jest-runtime": "16.0.0", "mock-fs": "^3.11.0", "opener": "1.4.2", "portfinder": "0.4.0", diff --git a/packager/react-packager/src/node-haste/__tests__/DependencyGraph-test.js b/packager/react-packager/src/node-haste/__tests__/DependencyGraph-test.js index abcae0c666..83e8db69fe 100644 --- a/packager/react-packager/src/node-haste/__tests__/DependencyGraph-test.js +++ b/packager/react-packager/src/node-haste/__tests__/DependencyGraph-test.js @@ -8,13 +8,104 @@ */ 'use strict'; -jest.disableAutomock(); +jest.autoMockOff(); jest.useRealTimers(); jest .mock('fs') .mock('../../Logger') .mock('../../lib/TransformCache'); +// This is an ugly hack: +// * jest-haste-map uses `find` for fast file system crawling which won't work +// when we mock the file system in node. This mock copies the node crawler's +// implementation and always falls back to the node crawling mechanism. +// Ideally we'll make this an option in jest-haste-map to force it to use +// the node crawler. +jest.mock('jest-haste-map/build/crawlers/node', () => { + const H = require('jest-haste-map/build/constants'); + + const fs = require('fs'); + const path = require('path'); + + function find( + roots, + extensions, + ignore, + callback) + { + const result = []; + let activeCalls = 0; + + function search(directory) { + activeCalls++; + fs.readdir(directory, (err, names) => { + activeCalls--; + + names.forEach(file => { + file = path.join(directory, file); + if (ignore(file)) { + return; + } + activeCalls++; + + fs.lstat(file, (err, stat) => { + activeCalls--; + + if (!err && stat && !stat.isSymbolicLink()) { + if (stat.isDirectory()) { + search(file); + } else { + const ext = path.extname(file).substr(1); + if (extensions.indexOf(ext) !== -1) { + result.push([file, stat.mtime.getTime()]); + } + } + } + if (activeCalls === 0) { + callback(result); + } + }); + }); + + if (activeCalls === 0) { + callback(result); + } + }); + } + + roots.forEach(search); + } + + return function nodeCrawl( + roots, + extensions, + ignore, + data) + { + return new Promise(resolve => { + const callback = list => { + const files = Object.create(null); + list.forEach(fileData => { + const name = fileData[0]; + const mtime = fileData[1]; + const existingFile = data.files[name]; + if (existingFile && existingFile[H.MTIME] === mtime) { + files[name] = existingFile; + } else { + // See ../constants.js + files[name] = ['', mtime, 0, []]; + } + }); + data.files = files; + resolve(data); + }; + + find(roots, extensions, ignore, callback); + }); + }; + +}); + const mocksPattern = /(?:[\\/]|^)__mocks__[\\/]([^\/]+)\.js$/; jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000; @@ -105,7 +196,6 @@ describe('DependencyGraph', function() { assetExts: ['png', 'jpg'], cache: new Cache(), fileWatcher, - forceNodeFilesystemAPI: true, providesModuleNodeModules: [ 'haste-fbjs', 'react-haste', diff --git a/packager/react-packager/src/node-haste/index.js b/packager/react-packager/src/node-haste/index.js index 9946e90aae..d3f964662f 100644 --- a/packager/react-packager/src/node-haste/index.js +++ b/packager/react-packager/src/node-haste/index.js @@ -53,7 +53,6 @@ class DependencyGraph { roots: Array, ignoreFilePath: (filePath: string) => boolean, fileWatcher: FileWatcher, - forceNodeFilesystemAPI: boolean, assetRoots_DEPRECATED: Array, assetExts: Array, providesModuleNodeModules: mixed, @@ -86,7 +85,6 @@ class DependencyGraph { roots, ignoreFilePath, fileWatcher, - forceNodeFilesystemAPI, assetRoots_DEPRECATED, assetExts, providesModuleNodeModules, @@ -110,7 +108,6 @@ class DependencyGraph { roots: Array, ignoreFilePath: (filePath: string) => boolean, fileWatcher: FileWatcher, - forceNodeFilesystemAPI?: boolean, assetRoots_DEPRECATED: Array, assetExts: Array, providesModuleNodeModules: mixed, @@ -134,7 +131,6 @@ class DependencyGraph { roots, ignoreFilePath: ignoreFilePath || (() => {}), fileWatcher, - forceNodeFilesystemAPI: !!forceNodeFilesystemAPI, assetRoots_DEPRECATED: assetRoots_DEPRECATED || [], assetExts: assetExts || [], providesModuleNodeModules, @@ -169,7 +165,6 @@ class DependencyGraph { const mw = this._opts.maxWorkers; const haste = new JestHasteMap({ extensions: this._opts.extensions.concat(this._opts.assetExts), - forceNodeFilesystemAPI: this._opts.forceNodeFilesystemAPI, ignorePattern: {test: this._opts.ignoreFilePath}, maxWorkers: typeof mw === 'number' && mw >= 1 ? mw : getMaxWorkers(), mocksPattern: '',