From c26c6593e2168ac86ac71e0a0c20e37d76dacd03 Mon Sep 17 00:00:00 2001 From: Simon Knott Date: Fri, 23 Aug 2024 16:35:30 +0200 Subject: [PATCH] properly clear dirtyTestFiles --- packages/playwright/src/runner/watchMode.ts | 12 +++++++----- tests/playwright-test/watch.spec.ts | 11 +++++++++++ 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/packages/playwright/src/runner/watchMode.ts b/packages/playwright/src/runner/watchMode.ts index ba691f2210..87dc6eeb3d 100644 --- a/packages/playwright/src/runner/watchMode.ts +++ b/packages/playwright/src/runner/watchMode.ts @@ -92,7 +92,7 @@ export async function runWatchModeLoop(configLocation: ConfigLocation, initialOp const telesuiteUpdater = new TeleSuiteUpdater({ pathSeparator: path.sep, onUpdate() { } }); - const dirtyTestFiles: string[] = []; // we're never clearing this! seems wrong. + const dirtyTestFiles = new Set(); const onDirtyTestFiles: { resolve?(): void } = {}; testServerConnection.onTestFilesChanged(async ({ testFiles: changedFiles }) => { @@ -105,11 +105,11 @@ export async function runWatchModeLoop(configLocation: ConfigLocation, initialOp for (const project of telesuiteUpdater.rootSuite!.suites) { for (const suite of project.suites) { if (suite.location?.file && changedFiles.includes(suite.location.file)) - dirtyTestFiles.push(suite.location.file); + dirtyTestFiles.add(suite.location.file); } } - if (dirtyTestFiles.length === 0) + if (dirtyTestFiles.size === 0) return; onDirtyTestFiles.resolve?.(); @@ -141,8 +141,10 @@ export async function runWatchModeLoop(configLocation: ConfigLocation, initialOp const command = await readCommandPromise; if (command === 'changed') { - await runChangedTests(options, testServerConnection, dirtyTestFiles); - lastRun = { type: 'changed', dirtyTestFiles: [...dirtyTestFiles] }; + const changedFiles = [...dirtyTestFiles]; + dirtyTestFiles.clear(); + await runChangedTests(options, testServerConnection, changedFiles); + lastRun = { type: 'changed', dirtyTestFiles: changedFiles }; continue; } diff --git a/tests/playwright-test/watch.spec.ts b/tests/playwright-test/watch.spec.ts index f5751a43cb..0dba9dd861 100644 --- a/tests/playwright-test/watch.spec.ts +++ b/tests/playwright-test/watch.spec.ts @@ -419,6 +419,17 @@ test('should run on changed files', async ({ runWatchTest, writeFiles }) => { expect(testProcess.output).not.toContain('a.test.ts:3:11 › passes'); expect(testProcess.output).not.toContain('b.test.ts:3:11 › passes'); await testProcess.waitForOutput('Waiting for file changes.'); + + testProcess.clearOutput(); + await writeFiles({ + 'b.test.ts': ` + import { test, expect } from '@playwright/test'; + test('passes', () => {}); + `, + }); + + await testProcess.waitForOutput('b.test.ts:3:11 › passes'); + expect(testProcess.output).not.toContain('c.test.ts:3:11 › passes'); }); test('should run on changed deps', async ({ runWatchTest, writeFiles }) => {