Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(jest-haste-map): Fix slowdown on node versions > 10 #8803

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fix lint errors
vovkasm committed Aug 9, 2019

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 5442bc08c9c33cedf9a57c32620dd4c495fb1c24
85 changes: 47 additions & 38 deletions packages/jest-haste-map/src/index.ts
Original file line number Diff line number Diff line change
@@ -341,37 +341,44 @@ class HasteMap extends EventEmitter {

build(): Promise<InternalHasteMapObject> {
if (!this._buildPromise) {
this._buildPromise = this._buildFileMap().then((data) => {
// Persist when we don't know if files changed (changedFiles undefined)
// or when we know a file was changed or deleted.
if (data.changedFiles === undefined || data.changedFiles.size > 0 || data.removedFiles.size > 0) {
return this._buildHasteMap(data).then((hasteMap) => {
this._persist(hasteMap);
return hasteMap
this._buildPromise = this._buildFileMap()
.then(data => {
// Persist when we don't know if files changed (changedFiles undefined)
// or when we know a file was changed or deleted.
if (
data.changedFiles === undefined ||
data.changedFiles.size > 0 ||
data.removedFiles.size > 0
) {
return this._buildHasteMap(data).then(hasteMap => {
this._persist(hasteMap);
return hasteMap;
});
} else {
return data.hasteMap;
}
})
.then(hasteMap => {
const rootDir = this._options.rootDir;
const hasteFS = new HasteFS({
files: hasteMap.files,
rootDir,
});
} else {
return data.hasteMap;
}
}).then((hasteMap) => {
const rootDir = this._options.rootDir;
const hasteFS = new HasteFS({
files: hasteMap.files,
rootDir,
});
const moduleMap = new HasteModuleMap({
duplicates: hasteMap.duplicates,
map: hasteMap.map,
mocks: hasteMap.mocks,
rootDir,
const moduleMap = new HasteModuleMap({
duplicates: hasteMap.duplicates,
map: hasteMap.map,
mocks: hasteMap.mocks,
rootDir,
});
const __hasteMapForTest =
(process.env.NODE_ENV === 'test' && hasteMap) || null;
this._watch(hasteMap);
return {
__hasteMapForTest,
hasteFS,
moduleMap,
};
});
const __hasteMapForTest = (process.env.NODE_ENV === 'test' && hasteMap) || null;
this._watch(hasteMap);
return {
__hasteMapForTest,
hasteFS,
moduleMap,
};
})
}
return this._buildPromise;
}
@@ -681,15 +688,17 @@ class HasteMap extends EventEmitter {
}
}

return Promise.all(promises).then(() => {
this._cleanup();
hasteMap.map = map;
hasteMap.mocks = mocks;
return hasteMap;
}).catch((error) => {
this._cleanup();
throw error;
})
return Promise.all(promises)
.then(() => {
this._cleanup();
hasteMap.map = map;
hasteMap.mocks = mocks;
return hasteMap;
})
.catch(error => {
this._cleanup();
throw error;
});
}

private _cleanup() {