Skip to content

Commit 76faf90

Browse files
committed
fix: vendor node crawler from sane
1 parent d393800 commit 76faf90

15 files changed

Lines changed: 581 additions & 98 deletions

.eslintrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ module.exports = {
100100
'packages/jest-core/src/plugins/UpdateSnapshotsInteractive.ts',
101101
'packages/jest-fake-timers/src/legacyFakeTimers.ts',
102102
'packages/jest-haste-map/src/index.ts',
103-
'packages/jest-haste-map/src/lib/FSEventsWatcher.ts',
103+
'packages/jest-haste-map/src/watchers/FSEventsWatcher.ts',
104104
'packages/jest-jasmine2/src/jasmine/SpyStrategy.ts',
105105
'packages/jest-jasmine2/src/jasmine/Suite.ts',
106106
'packages/jest-leak-detector/src/index.ts',

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
- `[jest-circus]` Fix `testLocation` on Windows when using `test.each` ([#10871](https://github.com/facebook/jest/pull/10871))
2020
- `[jest-console]` `console.dir` now respects the second argument correctly ([#10638](https://github.com/facebook/jest/pull/10638))
2121
- `[jest-environment-jsdom]` Use inner realm’s `ArrayBuffer` constructor ([#10885](https://github.com/facebook/jest/pull/10885))
22+
- `[jest-haste-map]` Vendor `NodeWatcher` from `sane` ([#10919](https://github.com/facebook/jest/pull/10919))
2223
- `[jest-jasmine2]` Fixed the issue of beforeAll & afterAll hooks getting executed even if it is inside a skipped `describe` block when it has child `tests` marked as either `only` or `todo` [#10451](https://github.com/facebook/jest/issues/10451)
2324
- `[jest-jasmine2]` Fixed the issues of child `tests` marked with `only` or `todo` getting executed even if it is inside a skipped parent `describe` block [#10451](https://github.com/facebook/jest/issues/10451)
2425
- `[jest-reporter]` Handle empty files when reporting code coverage with V8 ([#10819](https://github.com/facebook/jest/pull/10819))
@@ -29,7 +30,7 @@
2930
- `[jest-runtime]` Fix stack overflow and promise deadlock when importing mutual dependant ES module ([#10892](https://github.com/facebook/jest/pull/10892))
3031
- `[jest-transform]` Show enhanced `SyntaxError` message for all `SyntaxError`s ([#10749](https://github.com/facebook/jest/pull/10749))
3132
- `[jest-transform]` [**BREAKING**] Refactor API to pass an options bag around rather than multiple boolean options ([#10753](https://github.com/facebook/jest/pull/10753))
32-
- `[jest-transform]` [**BREAKING**] Refactor API of transformers to pass an options bag rather than separate `config` and other options
33+
- `[jest-transform]` [**BREAKING**] Refactor API of transformers to pass an options bag rather than separate `config` and other options ([#10834](https://github.com/facebook/jest/pull/10834))
3334
- `[pretty-format]` [**BREAKING**] Convert to ES Modules ([#10515](https://github.com/facebook/jest/pull/10515))
3435

3536
### Chore & Maintenance

jest.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ module.exports = {
2323
modulePathIgnorePatterns: [
2424
'examples/.*',
2525
'packages/.*/build',
26+
'packages/.*/tsconfig.*',
2627
'packages/jest-runtime/src/__tests__/test_root.*',
2728
'website/.*',
2829
'e2e/runtime-internal-module-registry/__mocks__',

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@
148148
"@testing-library/dom/pretty-format": "26.6.1",
149149
"@types/jest/jest-diff": "^25.1.0",
150150
"@types/jest/pretty-format": "^25.1.0",
151-
"fbjs-scripts": "patch:fbjs-scripts@^1.1.0#./patches/fbjs-scripts.patch",
152-
"jest-haste-map/fsevents": "patch:fsevents@^2.1.2#./patches/fsevents.patch"
151+
"fbjs-scripts": "patch:fbjs-scripts@^1.1.0#./patches/fbjs-scripts.patch"
153152
}
154153
}

packages/jest-haste-map/package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,13 @@
2525
"jest-util": "^26.6.2",
2626
"jest-worker": "^26.6.2",
2727
"micromatch": "^4.0.2",
28-
"sane": "^4.0.3",
2928
"walker": "^1.0.7"
3029
},
3130
"devDependencies": {
3231
"@jest/test-utils": "^26.6.2",
3332
"@types/anymatch": "^1.3.1",
3433
"@types/fb-watchman": "^2.0.0",
3534
"@types/micromatch": "^4.0.0",
36-
"@types/sane": "^2.0.0",
3735
"jest-snapshot-serializer-raw": "^1.1.0",
3836
"slash": "^3.0.0"
3937
},

packages/jest-haste-map/src/__tests__/index.test.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,13 @@ jest.mock('../crawlers/watchman', () =>
7272
const mockWatcherConstructor = jest.fn(root => {
7373
const EventEmitter = require('events').EventEmitter;
7474
mockEmitters[root] = new EventEmitter();
75-
mockEmitters[root].close = jest.fn(callback => callback());
75+
mockEmitters[root].close = jest.fn();
7676
setTimeout(() => mockEmitters[root].emit('ready'), 0);
7777
return mockEmitters[root];
7878
});
7979

80-
jest.mock('sane', () => ({
81-
NodeWatcher: mockWatcherConstructor,
82-
WatchmanWatcher: mockWatcherConstructor,
83-
}));
84-
85-
jest.mock('../lib/WatchmanWatcher', () => mockWatcherConstructor);
80+
jest.mock('../watchers/NodeWatcher', () => mockWatcherConstructor);
81+
jest.mock('../watchers/WatchmanWatcher', () => mockWatcherConstructor);
8682

8783
let mockChangedFiles;
8884
let mockFs;

packages/jest-haste-map/src/index.ts

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import {EventEmitter} from 'events';
1313
import {tmpdir} from 'os';
1414
import * as path from 'path';
1515
import type {Stats} from 'graceful-fs';
16-
import {NodeWatcher, Watcher as SaneWatcher} from 'sane';
1716
import type {Config} from '@jest/types';
1817
import {escapePathForRegex} from 'jest-regex-util';
1918
import serializer from 'jest-serializer';
@@ -24,9 +23,6 @@ import H from './constants';
2423
import nodeCrawl = require('./crawlers/node');
2524
import watchmanCrawl = require('./crawlers/watchman');
2625
import getMockName from './getMockName';
27-
import FSEventsWatcher = require('./lib/FSEventsWatcher');
28-
// @ts-expect-error: not converted to TypeScript - it's a fork: https://github.com/facebook/jest/pull/5387
29-
import WatchmanWatcher from './lib/WatchmanWatcher';
3026
import * as fastPath from './lib/fast_path';
3127
import getPlatformExtension from './lib/getPlatformExtension';
3228
import normalizePathSep from './lib/normalizePathSep';
@@ -44,6 +40,11 @@ import type {
4440
ModuleMetaData,
4541
WorkerMetadata,
4642
} from './types';
43+
import FSEventsWatcher = require('./watchers/FSEventsWatcher');
44+
// @ts-expect-error: not converted to TypeScript - it's a fork
45+
import NodeWatcher = require('./watchers/NodeWatcher');
46+
// @ts-expect-error: not converted to TypeScript - it's a fork: https://github.com/facebook/jest/pull/5387
47+
import WatchmanWatcher from './watchers/WatchmanWatcher';
4748
import {getSha1, worker} from './worker';
4849
// TypeScript doesn't like us importing from outside `rootDir`, but it doesn't
4950
// understand `require`.
@@ -97,7 +98,7 @@ type InternalOptions = {
9798
};
9899

99100
type Watcher = {
100-
close(callback: () => void): void;
101+
close(): Promise<void>;
101102
};
102103

103104
type WorkerInterface = {worker: typeof worker; getSha1: typeof getSha1};
@@ -210,7 +211,7 @@ function invariant(condition: unknown, message?: string): asserts condition {
210211
export default class HasteMap extends EventEmitter {
211212
private _buildPromise: Promise<InternalHasteMapObject> | null;
212213
private _cachePath: Config.Path;
213-
private _changeInterval?: NodeJS.Timeout;
214+
private _changeInterval?: ReturnType<typeof setInterval>;
214215
private _console: Console;
215216
private _options: InternalOptions;
216217
private _watchers: Array<Watcher>;
@@ -781,7 +782,7 @@ export default class HasteMap extends EventEmitter {
781782
this._options.retainAllFiles = true;
782783

783784
// WatchmanWatcher > FSEventsWatcher > sane.NodeWatcher
784-
const Watcher: SaneWatcher =
785+
const Watcher =
785786
canUseWatchman && this._options.useWatchman
786787
? WatchmanWatcher
787788
: FSEventsWatcher.isSupported()
@@ -798,7 +799,6 @@ export default class HasteMap extends EventEmitter {
798799
let mustCopy = true;
799800

800801
const createWatcher = (root: Config.Path): Promise<Watcher> => {
801-
// @ts-expect-error: TODO how? "Cannot use 'new' with an expression whose type lacks a call or construct signature."
802802
const watcher = new Watcher(root, {
803803
dot: true,
804804
glob: extensions.map(extension => '**/*.' + extension),
@@ -824,10 +824,7 @@ export default class HasteMap extends EventEmitter {
824824
mustCopy = true;
825825
const changeEvent: ChangeEvent = {
826826
eventsQueue,
827-
hasteFS: new HasteFS({
828-
files: hasteMap.files,
829-
rootDir,
830-
}),
827+
hasteFS: new HasteFS({files: hasteMap.files, rootDir}),
831828
moduleMap: new HasteModuleMap({
832829
duplicates: hasteMap.duplicates,
833830
map: hasteMap.map,
@@ -1043,20 +1040,18 @@ export default class HasteMap extends EventEmitter {
10431040
}
10441041
}
10451042

1046-
end(): Promise<void> {
1047-
// @ts-expect-error: TODO TS cannot decide if `setInterval` and `clearInterval` comes from NodeJS or the DOM
1048-
clearInterval(this._changeInterval);
1043+
async end(): Promise<void> {
1044+
if (this._changeInterval) {
1045+
clearInterval(this._changeInterval);
1046+
}
1047+
10491048
if (!this._watchers.length) {
1050-
return Promise.resolve();
1049+
return;
10511050
}
10521051

1053-
return Promise.all(
1054-
this._watchers.map(
1055-
watcher => new Promise(resolve => watcher.close(resolve)),
1056-
),
1057-
).then(() => {
1058-
this._watchers = [];
1059-
});
1052+
await Promise.all(this._watchers.map(watcher => watcher.close()));
1053+
1054+
this._watchers = [];
10601055
}
10611056

10621057
/**
File renamed without changes.

0 commit comments

Comments
 (0)