From e53c5c6e6ae5a3f1ada8474223de49cb128088bc Mon Sep 17 00:00:00 2001 From: Simon Knott Date: Mon, 26 Aug 2024 10:04:19 +0200 Subject: [PATCH] queue up dirtyTestFiles --- packages/playwright/src/runner/watchMode.ts | 32 ++++++++++++--------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/packages/playwright/src/runner/watchMode.ts b/packages/playwright/src/runner/watchMode.ts index 7a5273df5f..d7d90cd6c7 100644 --- a/packages/playwright/src/runner/watchMode.ts +++ b/packages/playwright/src/runner/watchMode.ts @@ -26,7 +26,6 @@ import { PlaywrightServer } from 'playwright-core/lib/remote/playwrightServer'; import { TestServerDispatcher } from './testServer'; import { EventEmitter } from 'stream'; import { type TestServerTransport, TestServerConnection } from '../isomorphic/testServerConnection'; -import { createFileMatcherFromArguments } from '../util'; import { TeleSuiteUpdater } from '../isomorphic/teleSuiteUpdater'; class InMemoryTransport extends EventEmitter implements TestServerTransport { @@ -95,24 +94,31 @@ export async function runWatchModeLoop(configLocation: ConfigLocation, initialOp const dirtyTestFiles = new Set(); const onDirtyTestFiles: { resolve?(): void } = {}; - testServerConnection.onTestFilesChanged(async ({ testFiles: changedFiles }) => { + let queue = Promise.resolve(); + + testServerConnection.onTestFilesChanged(({ testFiles: changedFiles }) => { if (changedFiles.length === 0) return; - const { report } = await testServerConnection.listTests({ locations: options.files, projects: options.projects, grep: options.grep }); - teleSuiteUpdater.processListReport(report); + queue = queue.then(async () => { + const { report } = await testServerConnection.listTests({ locations: options.files, projects: options.projects, grep: options.grep }); + teleSuiteUpdater.processListReport(report); - for (const project of teleSuiteUpdater.rootSuite!.suites) { - for (const suite of project.suites) { - if (suite.location?.file && changedFiles.includes(suite.location.file)) - dirtyTestFiles.add(suite.location.file); + for (const project of teleSuiteUpdater.rootSuite!.suites) { + for (const suite of project.suites) { + if (suite.location?.file && changedFiles.includes(suite.location.file)) + dirtyTestFiles.add(suite.location.file); + } } - } - if (dirtyTestFiles.size === 0) - return; - - onDirtyTestFiles.resolve?.(); + // if listTests takes longer than the debouncing interval of onTestFilesChanged, + // then the queue might contain another listTests call. + // appending `resolve` to the queue ensures that all pending listTests calls are executed first. + queue = queue.then(() => { + if (dirtyTestFiles.size > 0) + onDirtyTestFiles.resolve?.(); + }); + }); }); testServerConnection.onReport(report => teleSuiteUpdater.processTestReportEvent(report));