properly clear dirtyTestFiles

This commit is contained in:
Simon Knott 2024-08-23 16:35:30 +02:00
parent 989c9a2d5a
commit c26c6593e2
No known key found for this signature in database
GPG key ID: 8CEDC00028084AEC
2 changed files with 18 additions and 5 deletions

View file

@ -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<string>();
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;
}

View file

@ -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 }) => {