chore(watch): run by default again (#20763)

This commit is contained in:
Pavel Feldman 2023-02-08 18:53:07 -08:00 committed by GitHub
parent 027d6b5239
commit 6b0a7003c4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 21 deletions

View file

@ -247,7 +247,7 @@ export class Page extends SdkObject {
this._interceptFileChooser = false; this._interceptFileChooser = false;
await Promise.all([ await Promise.all([
this._delegate.updateEmulatedViewportSize(true), this._delegate.updateEmulatedViewportSize(),
this._delegate.updateEmulateMedia(), this._delegate.updateEmulateMedia(),
this._delegate.updateFileChooserInterception(), this._delegate.updateFileChooserInterception(),
]); ]);

View file

@ -94,7 +94,8 @@ export async function runWatchModeLoop(config: FullConfigInternal): Promise<Full
let result: FullResult['status'] = 'passed'; let result: FullResult['status'] = 'passed';
// Enter the watch loop. // Enter the watch loop.
printConfiguration(config); await runTests(config, failedTestIdCollector);
while (true) { while (true) {
printPrompt(); printPrompt();
const readCommandPromise = readCommand(); const readCommandPromise = readCommand();
@ -109,7 +110,6 @@ export async function runWatchModeLoop(config: FullConfigInternal): Promise<Full
if (command === 'changed') { if (command === 'changed') {
const dirtyFiles = fsWatcher.takeDirtyFiles(); const dirtyFiles = fsWatcher.takeDirtyFiles();
printConfiguration(config, 'files changed');
await runChangedTests(config, failedTestIdCollector, projectClosure, dirtyFiles); await runChangedTests(config, failedTestIdCollector, projectClosure, dirtyFiles);
lastRun = { type: 'changed', dirtyFiles }; lastRun = { type: 'changed', dirtyFiles };
continue; continue;
@ -117,7 +117,6 @@ export async function runWatchModeLoop(config: FullConfigInternal): Promise<Full
if (command === 'run') { if (command === 'run') {
// All means reset filters. // All means reset filters.
printConfiguration(config);
await runTests(config, failedTestIdCollector); await runTests(config, failedTestIdCollector);
lastRun = { type: 'regular' }; lastRun = { type: 'regular' };
continue; continue;
@ -132,8 +131,9 @@ export async function runWatchModeLoop(config: FullConfigInternal): Promise<Full
}).catch(() => ({ projectNames: null })); }).catch(() => ({ projectNames: null }));
if (!projectNames) if (!projectNames)
continue; continue;
config._internal.cliProjectFilter = projectNames; config._internal.cliProjectFilter = projectNames.length ? projectNames : undefined;
printConfiguration(config); await runTests(config, failedTestIdCollector);
lastRun = { type: 'regular' };
continue; continue;
} }
@ -149,7 +149,8 @@ export async function runWatchModeLoop(config: FullConfigInternal): Promise<Full
config._internal.cliArgs = filePattern.split(' '); config._internal.cliArgs = filePattern.split(' ');
else else
config._internal.cliArgs = []; config._internal.cliArgs = [];
printConfiguration(config); await runTests(config, failedTestIdCollector);
lastRun = { type: 'regular' };
continue; continue;
} }
@ -165,30 +166,29 @@ export async function runWatchModeLoop(config: FullConfigInternal): Promise<Full
config._internal.cliGrep = testPattern; config._internal.cliGrep = testPattern;
else else
config._internal.cliGrep = undefined; config._internal.cliGrep = undefined;
printConfiguration(config); await runTests(config, failedTestIdCollector);
lastRun = { type: 'regular' };
continue; continue;
} }
if (command === 'failed') { if (command === 'failed') {
config._internal.testIdMatcher = id => failedTestIdCollector.has(id); config._internal.testIdMatcher = id => failedTestIdCollector.has(id);
const failedTestIds = new Set(failedTestIdCollector); const failedTestIds = new Set(failedTestIdCollector);
printConfiguration(config, 'running failed tests'); await runTests(config, failedTestIdCollector, { title: 'running failed tests' });
await runTests(config, failedTestIdCollector);
config._internal.testIdMatcher = undefined; config._internal.testIdMatcher = undefined;
lastRun = { type: 'failed', failedTestIds }; lastRun = { type: 'failed', failedTestIds };
continue; continue;
} }
if (command === 'repeat') { if (command === 'repeat') {
printConfiguration(config, 're-running tests');
if (lastRun.type === 'regular') { if (lastRun.type === 'regular') {
await runTests(config, failedTestIdCollector); await runTests(config, failedTestIdCollector, { title: 're-running tests' });
continue; continue;
} else if (lastRun.type === 'changed') { } else if (lastRun.type === 'changed') {
await runChangedTests(config, failedTestIdCollector, projectClosure, lastRun.dirtyFiles!); await runChangedTests(config, failedTestIdCollector, projectClosure, lastRun.dirtyFiles!, 're-running tests');
} else if (lastRun.type === 'failed') { } else if (lastRun.type === 'failed') {
config._internal.testIdMatcher = id => lastRun.failedTestIds!.has(id); config._internal.testIdMatcher = id => lastRun.failedTestIds!.has(id);
await runTests(config, failedTestIdCollector); await runTests(config, failedTestIdCollector, { title: 're-running tests' });
config._internal.testIdMatcher = undefined; config._internal.testIdMatcher = undefined;
} }
continue; continue;
@ -211,7 +211,7 @@ export async function runWatchModeLoop(config: FullConfigInternal): Promise<Full
return result === 'passed' ? await globalCleanup() : result; return result === 'passed' ? await globalCleanup() : result;
} }
async function runChangedTests(config: FullConfigInternal, failedTestIdCollector: Set<string>, projectClosure: FullProjectInternal[], changedFiles: Set<string>) { async function runChangedTests(config: FullConfigInternal, failedTestIdCollector: Set<string>, projectClosure: FullProjectInternal[], changedFiles: Set<string>, title?: string) {
const commandLineFileMatcher = config._internal.cliArgs.length ? createFileMatcherFromArguments(config._internal.cliArgs) : () => true; const commandLineFileMatcher = config._internal.cliArgs.length ? createFileMatcherFromArguments(config._internal.cliArgs) : () => true;
// Resolve files that depend on the changed files. // Resolve files that depend on the changed files.
@ -242,15 +242,20 @@ async function runChangedTests(config: FullConfigInternal, failedTestIdCollector
// If there are affected dependency projects, do the full run, respect the original CLI. // If there are affected dependency projects, do the full run, respect the original CLI.
// if there are no affected dependency projects, intersect CLI with dirty files // if there are no affected dependency projects, intersect CLI with dirty files
const additionalFileMatcher = affectsAnyDependency ? () => true : (file: string) => testFiles.has(file); const additionalFileMatcher = affectsAnyDependency ? () => true : (file: string) => testFiles.has(file);
return await runTests(config, failedTestIdCollector, projectsToIgnore, additionalFileMatcher); return await runTests(config, failedTestIdCollector, { projectsToIgnore, additionalFileMatcher, title: title || 'files changed' });
} }
let seq = 0; let seq = 0;
async function runTests(config: FullConfigInternal, failedTestIdCollector: Set<string>, projectsToIgnore?: Set<FullProjectInternal>, additionalFileMatcher?: Matcher) { async function runTests(config: FullConfigInternal, failedTestIdCollector: Set<string>, options?: {
projectsToIgnore?: Set<FullProjectInternal>,
additionalFileMatcher?: Matcher,
title?: string,
}) {
++seq; ++seq;
printConfiguration(config, options?.title);
const reporter = new Multiplexer([new ListReporter()]); const reporter = new Multiplexer([new ListReporter()]);
const taskRunner = createTaskRunnerForWatch(config, reporter, projectsToIgnore, additionalFileMatcher); const taskRunner = createTaskRunnerForWatch(config, reporter, options?.projectsToIgnore, options?.additionalFileMatcher);
const context: TaskRunnerState = { const context: TaskRunnerState = {
config, config,
reporter, reporter,
@ -263,11 +268,11 @@ async function runTests(config: FullConfigInternal, failedTestIdCollector: Set<s
let hasFailedTests = false; let hasFailedTests = false;
for (const test of context.rootSuite?.allTests() || []) { for (const test of context.rootSuite?.allTests() || []) {
if (test.outcome() === 'expected') { if (test.outcome() === 'unexpected') {
failedTestIdCollector.delete(test.id);
} else {
failedTestIdCollector.add(test.id); failedTestIdCollector.add(test.id);
hasFailedTests = true; hasFailedTests = true;
} else {
failedTestIdCollector.delete(test.id);
} }
} }