mirror of https://github.com/status-im/metro.git
Update Jest + jest-haste-map
Reviewed By: matryoshcow Differential Revision: D4149694 fbshipit-source-id: 4f8378c419ddc7978e05dfcf2112e833775391be
This commit is contained in:
parent
31c7108806
commit
5dab7599d3
|
@ -8,104 +8,13 @@
|
||||||
*/
|
*/
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
jest.autoMockOff();
|
jest.disableAutomock();
|
||||||
jest.useRealTimers();
|
jest.useRealTimers();
|
||||||
jest
|
jest
|
||||||
.mock('fs')
|
.mock('fs')
|
||||||
.mock('../../Logger')
|
.mock('../../Logger')
|
||||||
.mock('../../lib/TransformCache');
|
.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$/;
|
const mocksPattern = /(?:[\\/]|^)__mocks__[\\/]([^\/]+)\.js$/;
|
||||||
|
|
||||||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000;
|
jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000;
|
||||||
|
@ -192,6 +101,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',
|
||||||
|
|
|
@ -55,6 +55,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,
|
||||||
|
@ -88,6 +89,7 @@ class DependencyGraph {
|
||||||
roots,
|
roots,
|
||||||
ignoreFilePath,
|
ignoreFilePath,
|
||||||
fileWatcher,
|
fileWatcher,
|
||||||
|
forceNodeFilesystemAPI,
|
||||||
assetRoots_DEPRECATED,
|
assetRoots_DEPRECATED,
|
||||||
assetExts,
|
assetExts,
|
||||||
providesModuleNodeModules,
|
providesModuleNodeModules,
|
||||||
|
@ -112,6 +114,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,
|
||||||
|
@ -136,6 +139,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,
|
||||||
|
@ -171,6 +175,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: '',
|
||||||
|
|
Loading…
Reference in New Issue