@playwright/test 1.32.0-beta-1679517005000 → 1.32.0-beta-1679601059000

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -34,6 +34,7 @@ class UIMode {
34
34
  this._page = void 0;
35
35
  this._testRun = void 0;
36
36
  this.globalCleanup = void 0;
37
+ this._globalWatcher = void 0;
37
38
  this._testWatcher = void 0;
38
39
  this._originalStderr = void 0;
39
40
  this._config = config;
@@ -53,25 +54,19 @@ class UIMode {
53
54
  sources: false
54
55
  };
55
56
  this._originalStderr = process.stderr.write.bind(process.stderr);
56
- this._installGlobalWatcher();
57
- }
58
- _installGlobalWatcher() {
59
- const projectDirs = new Set();
60
- for (const p of this._config.projects) projectDirs.add(p.testDir);
61
- let coalescingTimer;
62
- const watcher = _utilsBundle.chokidar.watch([...projectDirs], {
63
- ignoreInitial: true,
64
- persistent: true
65
- }).on('all', async event => {
66
- if (event !== 'add' && event !== 'change' && event !== 'unlink') return;
67
- if (coalescingTimer) clearTimeout(coalescingTimer);
68
- coalescingTimer = setTimeout(() => {
69
- this._dispatchEvent({
70
- method: 'listChanged'
71
- });
72
- }, 200);
57
+ this._globalWatcher = new Watcher('deep', () => this._dispatchEvent({
58
+ method: 'listChanged'
59
+ }));
60
+ this._testWatcher = new Watcher('flat', events => {
61
+ const collector = new Set();
62
+ events.forEach(f => (0, _compilationCache.collectAffectedTestFiles)(f.file, collector));
63
+ this._dispatchEvent({
64
+ method: 'testFilesChanged',
65
+ params: {
66
+ testFileNames: [...collector]
67
+ }
68
+ });
73
69
  });
74
- return watcher;
75
70
  }
76
71
  async runGlobalSetup() {
77
72
  const reporter = await (0, _reporters.createReporter)(this._config, 'watch');
@@ -175,6 +170,9 @@ class UIMode {
175
170
  reporter.onExit({
176
171
  status
177
172
  });
173
+ const projectDirs = new Set();
174
+ for (const p of this._config.projects) projectDirs.add(p.testDir);
175
+ this._globalWatcher.update([...projectDirs], false);
178
176
  }
179
177
  async _runTests(testIds) {
180
178
  await this._stopTests();
@@ -212,43 +210,7 @@ class UIMode {
212
210
  files.add(fileName);
213
211
  (0, _compilationCache.dependenciesForTestFile)(fileName).forEach(file => files.add(file));
214
212
  }
215
- const watchedFiles = [...files].sort();
216
- if (this._testWatcher && JSON.stringify(this._testWatcher.watchedFiles) === JSON.stringify(watchedFiles)) return;
217
- if (this._testWatcher) {
218
- if (this._testWatcher.collector.size) this._dispatchEvent({
219
- method: 'filesChanged',
220
- params: {
221
- fileNames: [...this._testWatcher.collector]
222
- }
223
- });
224
- clearTimeout(this._testWatcher.timer);
225
- this._testWatcher.watcher.close().then(() => {});
226
- this._testWatcher = undefined;
227
- }
228
- if (!watchedFiles.length) return;
229
- const collector = new Set();
230
- const watcher = _utilsBundle.chokidar.watch(watchedFiles, {
231
- ignoreInitial: true
232
- }).on('all', async (event, file) => {
233
- if (event !== 'add' && event !== 'change') return;
234
- (0, _compilationCache.collectAffectedTestFiles)(file, collector);
235
- if (this._testWatcher.timer) clearTimeout(this._testWatcher.timer);
236
- this._testWatcher.timer = setTimeout(() => {
237
- const fileNames = [...collector];
238
- collector.clear();
239
- this._dispatchEvent({
240
- method: 'filesChanged',
241
- params: {
242
- fileNames
243
- }
244
- });
245
- }, 250);
246
- });
247
- this._testWatcher = {
248
- watcher,
249
- watchedFiles,
250
- collector
251
- };
213
+ this._testWatcher.update([...files], true);
252
214
  }
253
215
  async _stopTests() {
254
216
  var _this$_testRun, _this$_testRun$stop, _this$_testRun2;
@@ -276,4 +238,44 @@ function chunkToPayload(type, chunk) {
276
238
  type,
277
239
  text: chunk
278
240
  };
241
+ }
242
+ class Watcher {
243
+ constructor(mode, onChange) {
244
+ this._onChange = void 0;
245
+ this._watchedFiles = [];
246
+ this._collector = [];
247
+ this._fsWatcher = void 0;
248
+ this._throttleTimer = void 0;
249
+ this._mode = void 0;
250
+ this._mode = mode;
251
+ this._onChange = onChange;
252
+ }
253
+ update(watchedFiles, reportPending) {
254
+ var _this$_fsWatcher;
255
+ if (JSON.stringify(this._watchedFiles) === JSON.stringify(watchedFiles)) return;
256
+ if (reportPending) this._reportEventsIfAny();
257
+ this._watchedFiles = watchedFiles;
258
+ (_this$_fsWatcher = this._fsWatcher) === null || _this$_fsWatcher === void 0 ? void 0 : _this$_fsWatcher.close().then(() => {});
259
+ this._fsWatcher = undefined;
260
+ this._collector.length = 0;
261
+ clearTimeout(this._throttleTimer);
262
+ this._throttleTimer = undefined;
263
+ if (!this._watchedFiles.length) return;
264
+ this._fsWatcher = _utilsBundle.chokidar.watch(watchedFiles, {
265
+ ignoreInitial: true
266
+ }).on('all', async (event, file) => {
267
+ if (this._throttleTimer) clearTimeout(this._throttleTimer);
268
+ if (this._mode === 'flat' && event !== 'add' && event !== 'change') return;
269
+ if (this._mode === 'deep' && event !== 'add' && event !== 'change' && event !== 'unlink' && event !== 'addDir' && event !== 'unlinkDir') return;
270
+ this._collector.push({
271
+ event,
272
+ file
273
+ });
274
+ this._throttleTimer = setTimeout(() => this._reportEventsIfAny(), 250);
275
+ });
276
+ }
277
+ _reportEventsIfAny() {
278
+ if (this._collector.length) this._onChange(this._collector.slice());
279
+ this._collector.length = 0;
280
+ }
279
281
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@playwright/test",
3
- "version": "1.32.0-beta-1679517005000",
3
+ "version": "1.32.0-beta-1679601059000",
4
4
  "description": "A high-level API to automate web browsers",
5
5
  "repository": "github:Microsoft/playwright",
6
6
  "homepage": "https://playwright.dev",
@@ -34,7 +34,7 @@
34
34
  "license": "Apache-2.0",
35
35
  "dependencies": {
36
36
  "@types/node": "*",
37
- "playwright-core": "1.32.0-beta-1679517005000"
37
+ "playwright-core": "1.32.0-beta-1679601059000"
38
38
  },
39
39
  "optionalDependencies": {
40
40
  "fsevents": "2.3.2"