Update Jest + jest-haste-map

Reviewed By: voideanvalue

Differential Revision: D4180887

fbshipit-source-id: f6ee6901e63206824f0639c81b64167b66da2168
This commit is contained in:
Christoph Pojer 2016-11-15 06:48:09 -08:00 committed by Facebook Github Bot
parent 3b20a39f7b
commit 3bd949cac7
4 changed files with 16 additions and 99 deletions

View File

@ -15,7 +15,7 @@
"<rootDir>/node_modules/react-native/Libraries/react-native/", "<rootDir>/node_modules/react-native/Libraries/react-native/",
"<rootDir>/node_modules/react-native/packager/" "<rootDir>/node_modules/react-native/packager/"
], ],
"preprocessorIgnorePatterns": [ "transformIgnorePatterns": [
"node_modules/(?!(jest-)?react-native|react-clone-referenced-element)" "node_modules/(?!(jest-)?react-native|react-clone-referenced-element)"
], ],
"setupFiles": [ "setupFiles": [

View File

@ -12,7 +12,9 @@
}, },
"jest": { "jest": {
"automock": true, "automock": true,
"scriptPreprocessor": "jest/preprocessor.js", "transform": {
".*": "jest/preprocessor.js"
},
"setupFiles": [ "setupFiles": [
"jest/setup.js" "jest/setup.js"
], ],
@ -171,7 +173,7 @@
"immutable": "~3.7.6", "immutable": "~3.7.6",
"imurmurhash": "^0.1.4", "imurmurhash": "^0.1.4",
"inquirer": "^0.12.0", "inquirer": "^0.12.0",
"jest-haste-map": "15.0.1", "jest-haste-map": "17.0.2",
"joi": "^6.6.1", "joi": "^6.6.1",
"json-stable-stringify": "^1.0.1", "json-stable-stringify": "^1.0.1",
"json5": "^0.4.0", "json5": "^0.4.0",
@ -208,7 +210,7 @@
"ws": "^1.1.0", "ws": "^1.1.0",
"xcode": "^0.8.9", "xcode": "^0.8.9",
"xmldoc": "^0.4.0", "xmldoc": "^0.4.0",
"yargs": "^3.24.0", "yargs": "^6.4.0",
"yeoman-environment": "1.5.3", "yeoman-environment": "1.5.3",
"yeoman-generator": "0.21.2" "yeoman-generator": "0.21.2"
}, },
@ -223,9 +225,9 @@
"flow-bin": "^0.35.0", "flow-bin": "^0.35.0",
"graphlib-dot": "0.6.2", "graphlib-dot": "0.6.2",
"graphql": "0.6.2", "graphql": "0.6.2",
"jest": "16.0.1", "jest": "17.0.2",
"jest-repl": "16.0.0", "jest-repl": "17.0.2",
"jest-runtime": "16.0.0", "jest-runtime": "17.0.2",
"mock-fs": "^3.11.0", "mock-fs": "^3.11.0",
"opener": "1.4.2", "opener": "1.4.2",
"portfinder": "0.4.0", "portfinder": "0.4.0",

View File

@ -8,7 +8,7 @@
*/ */
'use strict'; 'use strict';
jest.autoMockOff(); jest.disableAutomock();
jest.useRealTimers(); jest.useRealTimers();
jest jest
.mock('fs') .mock('fs')
@ -18,97 +18,6 @@ jest
.mock('child_process', () => ({})) .mock('child_process', () => ({}))
; ;
// 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$/; const mocksPattern = /(?:[\\/]|^)__mocks__[\\/]([^\/]+)\.js$/;
// This doesn't have state, and it's huge (Babel) so it's much faster to // This doesn't have state, and it's huge (Babel) so it's much faster to
@ -201,6 +110,7 @@ describe('DependencyGraph', function() {
assetExts: ['png', 'jpg'], assetExts: ['png', 'jpg'],
cache: new Cache(), cache: new Cache(),
fileWatcher, fileWatcher,
forceNodeFilesystemAPI: true,
providesModuleNodeModules: [ providesModuleNodeModules: [
'haste-fbjs', 'haste-fbjs',
'react-haste', 'react-haste',

View File

@ -53,6 +53,7 @@ class DependencyGraph {
roots: Array<string>, roots: Array<string>,
ignoreFilePath: (filePath: string) => boolean, ignoreFilePath: (filePath: string) => boolean,
fileWatcher: FileWatcher, fileWatcher: FileWatcher,
forceNodeFilesystemAPI: boolean,
assetRoots_DEPRECATED: Array<string>, assetRoots_DEPRECATED: Array<string>,
assetExts: Array<string>, assetExts: Array<string>,
providesModuleNodeModules: mixed, providesModuleNodeModules: mixed,
@ -85,6 +86,7 @@ class DependencyGraph {
roots, roots,
ignoreFilePath, ignoreFilePath,
fileWatcher, fileWatcher,
forceNodeFilesystemAPI,
assetRoots_DEPRECATED, assetRoots_DEPRECATED,
assetExts, assetExts,
providesModuleNodeModules, providesModuleNodeModules,
@ -108,6 +110,7 @@ class DependencyGraph {
roots: Array<string>, roots: Array<string>,
ignoreFilePath: (filePath: string) => boolean, ignoreFilePath: (filePath: string) => boolean,
fileWatcher: FileWatcher, fileWatcher: FileWatcher,
forceNodeFilesystemAPI?: boolean,
assetRoots_DEPRECATED: Array<string>, assetRoots_DEPRECATED: Array<string>,
assetExts: Array<string>, assetExts: Array<string>,
providesModuleNodeModules: mixed, providesModuleNodeModules: mixed,
@ -131,6 +134,7 @@ class DependencyGraph {
roots, roots,
ignoreFilePath: ignoreFilePath || (() => {}), ignoreFilePath: ignoreFilePath || (() => {}),
fileWatcher, fileWatcher,
forceNodeFilesystemAPI: !!forceNodeFilesystemAPI,
assetRoots_DEPRECATED: assetRoots_DEPRECATED || [], assetRoots_DEPRECATED: assetRoots_DEPRECATED || [],
assetExts: assetExts || [], assetExts: assetExts || [],
providesModuleNodeModules, providesModuleNodeModules,
@ -165,6 +169,7 @@ class DependencyGraph {
const mw = this._opts.maxWorkers; const mw = this._opts.maxWorkers;
const haste = new JestHasteMap({ const haste = new JestHasteMap({
extensions: this._opts.extensions.concat(this._opts.assetExts), extensions: this._opts.extensions.concat(this._opts.assetExts),
forceNodeFilesystemAPI: this._opts.forceNodeFilesystemAPI,
ignorePattern: {test: this._opts.ignoreFilePath}, ignorePattern: {test: this._opts.ignoreFilePath},
maxWorkers: typeof mw === 'number' && mw >= 1 ? mw : getMaxWorkers(), maxWorkers: typeof mw === 'number' && mw >= 1 ? mw : getMaxWorkers(),
mocksPattern: '', mocksPattern: '',