move clearCache impl into plugin
This commit is contained in:
parent
66f8b209fc
commit
c4da68d7ce
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
const { test: baseTest, expect, devices, defineConfig: originalDefineConfig } = require('playwright/test');
|
||||
const { fixtures } = require('./lib/mount');
|
||||
const { clearCacheCommand, runDevServerCommand, findRelatedTestFilesCommand } = require('./lib/cliOverrides');
|
||||
const { runDevServerCommand } = require('./lib/cliOverrides');
|
||||
const { createPlugin } = require('./lib/vitePlugin');
|
||||
|
||||
const defineConfig = (...configs) => {
|
||||
|
|
@ -30,7 +30,6 @@ const defineConfig = (...configs) => {
|
|||
[require.resolve('./lib/tsxTransform')]
|
||||
],
|
||||
cli: {
|
||||
'clear-cache': clearCacheCommand,
|
||||
'dev-server': runDevServerCommand,
|
||||
},
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,18 +15,8 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { cacheDir } from 'playwright/lib/transform/compilationCache';
|
||||
import { resolveDirs } from './viteUtils';
|
||||
import { runDevServer } from './devServer';
|
||||
import type { FullConfigInternal } from 'playwright/lib/common/config';
|
||||
import { removeFolderAndLogToConsole } from 'playwright/lib/runner/testServer';
|
||||
|
||||
export async function clearCacheCommand(config: FullConfigInternal) {
|
||||
const dirs = await resolveDirs(config.configDir, config.config);
|
||||
if (dirs)
|
||||
await removeFolderAndLogToConsole(dirs.outDir);
|
||||
await removeFolderAndLogToConsole(cacheDir);
|
||||
}
|
||||
|
||||
export async function runDevServerCommand(config: FullConfigInternal) {
|
||||
return await runDevServer(config);
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ import type { ImportInfo } from './tsxTransform';
|
|||
import type { ComponentRegistry } from './viteUtils';
|
||||
import { createConfig, frameworkConfig, hasJSComponents, populateComponentsFromTests, resolveDirs, resolveEndpoint, transformIndexFile } from './viteUtils';
|
||||
import { resolveHook } from 'playwright/lib/transform/transform';
|
||||
import { removeFolderAndLogToConsole } from 'playwright/lib/runner/testServer';
|
||||
|
||||
const log = debug('pw:vite');
|
||||
|
||||
|
|
@ -73,6 +74,12 @@ export function createPlugin(): TestRunnerPlugin {
|
|||
if (stoppableServer)
|
||||
await new Promise(f => stoppableServer.stop(f));
|
||||
},
|
||||
|
||||
clearCache: async () => {
|
||||
const dirs = await resolveDirs(configDir, config);
|
||||
if (dirs)
|
||||
await removeFolderAndLogToConsole(dirs.outDir);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -24,6 +24,9 @@ export interface TestRunnerPlugin {
|
|||
begin?(suite: Suite): Promise<void>;
|
||||
end?(): Promise<void>;
|
||||
teardown?(): Promise<void>;
|
||||
|
||||
clearCache?(): Promise<void>;
|
||||
runDevServer?(): Promise<void>;
|
||||
}
|
||||
|
||||
export type TestRunnerPluginRegistration = {
|
||||
|
|
|
|||
|
|
@ -106,6 +106,15 @@ function addRunTasks(taskRunner: TaskRunner<TestRun>, config: FullConfigInternal
|
|||
return taskRunner;
|
||||
}
|
||||
|
||||
export function createTaskRunnerForPluginSetup(config: FullConfigInternal, reporters: ReporterV2[]): TaskRunner<TestRun> {
|
||||
const taskRunner = TaskRunner.create<TestRun>(reporters, config.config.globalTimeout);
|
||||
|
||||
for (const plugin of config.plugins)
|
||||
taskRunner.addTask('plugin setup', createPluginSetupTask(plugin));
|
||||
|
||||
return taskRunner;
|
||||
}
|
||||
|
||||
export function createTaskRunnerForList(config: FullConfigInternal, reporters: ReporterV2[], mode: 'in-process' | 'out-of-process', options: { failOnLoadErrors: boolean, populatePluginDependencies?: boolean }): TaskRunner<TestRun> {
|
||||
const taskRunner = TaskRunner.create<TestRun>(reporters, config.config.globalTimeout);
|
||||
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ import type * as reporterTypes from '../../types/testReporter';
|
|||
import { collectAffectedTestFiles, dependenciesForTestFile } from '../transform/compilationCache';
|
||||
import type { ConfigLocation, FullConfigInternal } from '../common/config';
|
||||
import { createReporterForTestServer, createReporters } from './reporters';
|
||||
import { TestRun, createTaskRunnerForList, createTaskRunnerForTestServer, createTaskRunnerForWatchSetup, createTaskRunnerForListFiles } from './tasks';
|
||||
import { TestRun, createTaskRunnerForList, createTaskRunnerForTestServer, createTaskRunnerForWatchSetup, createTaskRunnerForListFiles, createTaskRunnerForPluginSetup } from './tasks';
|
||||
import { open } from 'playwright-core/lib/utilsBundle';
|
||||
import ListReporter from '../reporters/list';
|
||||
import { SigIntWatcher } from './sigIntWatcher';
|
||||
|
|
@ -39,6 +39,7 @@ import { serializeError } from '../util';
|
|||
import { cacheDir } from '../transform/compilationCache';
|
||||
import { baseFullConfig } from '../isomorphic/teleReceiver';
|
||||
import { InternalReporter } from '../reporters/internalReporter';
|
||||
import { wrapReporterAsV2 } from '../reporters/reporterV2';
|
||||
|
||||
const originalStdoutWrite = process.stdout.write;
|
||||
const originalStderrWrite = process.stderr.write;
|
||||
|
|
@ -515,11 +516,24 @@ export async function resolveCtDirs(config: FullConfigInternal) {
|
|||
}
|
||||
|
||||
export async function clearCacheAndLogToConsole(config: FullConfigInternal) {
|
||||
const override = (config.config as any)['@playwright/test']?.['cli']?.['clear-cache'];
|
||||
if (override) {
|
||||
await override(config);
|
||||
return;
|
||||
const errors: reporterTypes.TestError[] = [];
|
||||
const errorReporter = wrapReporterAsV2({
|
||||
onError(error: reporterTypes.TestError) {
|
||||
errors.push(error);
|
||||
}
|
||||
});
|
||||
const taskRunner = createTaskRunnerForPluginSetup(config, [errorReporter]);
|
||||
await taskRunner.run(new TestRun(config), 0);
|
||||
if (errors.length > 0)
|
||||
throw new Error('Failed to clear cache: ' + errors);
|
||||
|
||||
for (const plugin of config.plugins) {
|
||||
if (!plugin.instance)
|
||||
throw new Error('Plugin not initialized');
|
||||
|
||||
await plugin.instance.clearCache?.();
|
||||
}
|
||||
|
||||
await removeFolderAndLogToConsole(cacheDir);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue