chore(ui): do not watch output folders (#27694)
This commit is contained in:
parent
6e62a11643
commit
d003945a7b
|
|
@ -179,9 +179,12 @@ class UIMode {
|
||||||
await reporter.onExit();
|
await reporter.onExit();
|
||||||
|
|
||||||
const projectDirs = new Set<string>();
|
const projectDirs = new Set<string>();
|
||||||
for (const p of this._config.projects)
|
const projectOutputs = new Set<string>();
|
||||||
|
for (const p of this._config.projects) {
|
||||||
projectDirs.add(p.project.testDir);
|
projectDirs.add(p.project.testDir);
|
||||||
this._globalWatcher.update([...projectDirs], false);
|
projectOutputs.add(p.project.outputDir);
|
||||||
|
}
|
||||||
|
this._globalWatcher.update([...projectDirs], [...projectOutputs], false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async _runTests(testIds: string[], projects: string[]) {
|
private async _runTests(testIds: string[], projects: string[]) {
|
||||||
|
|
@ -217,7 +220,7 @@ class UIMode {
|
||||||
files.add(fileName);
|
files.add(fileName);
|
||||||
dependenciesForTestFile(fileName).forEach(file => files.add(file));
|
dependenciesForTestFile(fileName).forEach(file => files.add(file));
|
||||||
}
|
}
|
||||||
this._testWatcher.update([...files], true);
|
this._testWatcher.update([...files], [], true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async _stopTests() {
|
private async _stopTests() {
|
||||||
|
|
@ -259,6 +262,7 @@ type FSEvent = { event: 'add' | 'addDir' | 'change' | 'unlink' | 'unlinkDir', fi
|
||||||
class Watcher {
|
class Watcher {
|
||||||
private _onChange: (events: FSEvent[]) => void;
|
private _onChange: (events: FSEvent[]) => void;
|
||||||
private _watchedFiles: string[] = [];
|
private _watchedFiles: string[] = [];
|
||||||
|
private _ignoredFolders: string[] = [];
|
||||||
private _collector: FSEvent[] = [];
|
private _collector: FSEvent[] = [];
|
||||||
private _fsWatcher: FSWatcher | undefined;
|
private _fsWatcher: FSWatcher | undefined;
|
||||||
private _throttleTimer: NodeJS.Timeout | undefined;
|
private _throttleTimer: NodeJS.Timeout | undefined;
|
||||||
|
|
@ -269,14 +273,15 @@ class Watcher {
|
||||||
this._onChange = onChange;
|
this._onChange = onChange;
|
||||||
}
|
}
|
||||||
|
|
||||||
update(watchedFiles: string[], reportPending: boolean) {
|
update(watchedFiles: string[], ignoredFolders: string[], reportPending: boolean) {
|
||||||
if (JSON.stringify(this._watchedFiles) === JSON.stringify(watchedFiles))
|
if (JSON.stringify([this._watchedFiles, this._ignoredFolders]) === JSON.stringify(watchedFiles, ignoredFolders))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (reportPending)
|
if (reportPending)
|
||||||
this._reportEventsIfAny();
|
this._reportEventsIfAny();
|
||||||
|
|
||||||
this._watchedFiles = watchedFiles;
|
this._watchedFiles = watchedFiles;
|
||||||
|
this._ignoredFolders = ignoredFolders;
|
||||||
void this._fsWatcher?.close();
|
void this._fsWatcher?.close();
|
||||||
this._fsWatcher = undefined;
|
this._fsWatcher = undefined;
|
||||||
this._collector.length = 0;
|
this._collector.length = 0;
|
||||||
|
|
@ -286,7 +291,7 @@ class Watcher {
|
||||||
if (!this._watchedFiles.length)
|
if (!this._watchedFiles.length)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
this._fsWatcher = chokidar.watch(watchedFiles, { ignoreInitial: true }).on('all', async (event, file) => {
|
this._fsWatcher = chokidar.watch(watchedFiles, { ignoreInitial: true, ignored: this._ignoredFolders }).on('all', async (event, file) => {
|
||||||
if (this._throttleTimer)
|
if (this._throttleTimer)
|
||||||
clearTimeout(this._throttleTimer);
|
clearTimeout(this._throttleTimer);
|
||||||
if (this._mode === 'flat' && event !== 'add' && event !== 'change')
|
if (this._mode === 'flat' && event !== 'add' && event !== 'change')
|
||||||
|
|
|
||||||
|
|
@ -103,7 +103,11 @@ export const UIModeView: React.FC<{}> = ({
|
||||||
inputRef.current?.focus();
|
inputRef.current?.focus();
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
connect({ onEvent: dispatchEvent, onClose: () => setIsDisconnected(true) }).then(send => {
|
connect({ onEvent: dispatchEvent, onClose: () => setIsDisconnected(true) }).then(send => {
|
||||||
sendMessage = send;
|
sendMessage = async (method, params) => {
|
||||||
|
const logForTest = (window as any).__logForTest;
|
||||||
|
logForTest?.({ method, params });
|
||||||
|
await send(method, params);
|
||||||
|
};
|
||||||
reloadTests();
|
reloadTests();
|
||||||
});
|
});
|
||||||
}, [reloadTests]);
|
}, [reloadTests]);
|
||||||
|
|
|
||||||
|
|
@ -262,3 +262,30 @@ test('should queue watches', async ({ runUITest, writeFiles, createLatch }) => {
|
||||||
|
|
||||||
await expect(page.getByTestId('status-line')).toHaveText('3/3 passed (100%)');
|
await expect(page.getByTestId('status-line')).toHaveText('3/3 passed (100%)');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should not watch output', async ({ runUITest }) => {
|
||||||
|
const { page } = await runUITest({
|
||||||
|
'a.test.ts': `
|
||||||
|
import { test, expect } from '@playwright/test';
|
||||||
|
test('passes', ({}, testInfo) => {
|
||||||
|
require('fs').writeFileSync(testInfo.outputPath('output.txt'), 'DATA');
|
||||||
|
});
|
||||||
|
`,
|
||||||
|
});
|
||||||
|
|
||||||
|
await expect.poll(dumpTestTree(page)).toBe(`
|
||||||
|
▼ ◯ a.test.ts
|
||||||
|
◯ passes
|
||||||
|
`);
|
||||||
|
|
||||||
|
const commands: string[] = [];
|
||||||
|
await page.exposeBinding('__logForTest', (source, arg) => {
|
||||||
|
commands.push(arg.method);
|
||||||
|
});
|
||||||
|
|
||||||
|
await page.getByTitle('Run all').click();
|
||||||
|
|
||||||
|
await expect(page.getByTestId('status-line')).toHaveText('1/1 passed (100%)');
|
||||||
|
expect(commands).toContain('run');
|
||||||
|
expect(commands).not.toContain('list');
|
||||||
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue