remove dev-server hook

This commit is contained in:
Simon Knott 2024-07-25 17:11:51 +02:00
parent c4da68d7ce
commit 92b6b52c14
No known key found for this signature in database
GPG key ID: 8CEDC00028084AEC
5 changed files with 21 additions and 9 deletions

View file

@ -16,7 +16,6 @@
const { test: baseTest, expect, devices, defineConfig: originalDefineConfig } = require('playwright/test'); const { test: baseTest, expect, devices, defineConfig: originalDefineConfig } = require('playwright/test');
const { fixtures } = require('./lib/mount'); const { fixtures } = require('./lib/mount');
const { runDevServerCommand } = require('./lib/cliOverrides');
const { createPlugin } = require('./lib/vitePlugin'); const { createPlugin } = require('./lib/vitePlugin');
const defineConfig = (...configs) => { const defineConfig = (...configs) => {
@ -29,9 +28,6 @@ const defineConfig = (...configs) => {
babelPlugins: [ babelPlugins: [
[require.resolve('./lib/tsxTransform')] [require.resolve('./lib/tsxTransform')]
], ],
cli: {
'dev-server': runDevServerCommand,
},
} }
}; };
}; };

View file

@ -32,6 +32,8 @@ import type { ComponentRegistry } from './viteUtils';
import { createConfig, frameworkConfig, hasJSComponents, populateComponentsFromTests, resolveDirs, resolveEndpoint, transformIndexFile } from './viteUtils'; import { createConfig, frameworkConfig, hasJSComponents, populateComponentsFromTests, resolveDirs, resolveEndpoint, transformIndexFile } from './viteUtils';
import { resolveHook } from 'playwright/lib/transform/transform'; import { resolveHook } from 'playwright/lib/transform/transform';
import { removeFolderAndLogToConsole } from 'playwright/lib/runner/testServer'; import { removeFolderAndLogToConsole } from 'playwright/lib/runner/testServer';
import { runDevServer } from './devServer';
import type { FullConfigInternal } from 'playwright/lib/common/config';
const log = debug('pw:vite'); const log = debug('pw:vite');
@ -79,6 +81,10 @@ export function createPlugin(): TestRunnerPlugin {
const dirs = await resolveDirs(configDir, config); const dirs = await resolveDirs(configDir, config);
if (dirs) if (dirs)
await removeFolderAndLogToConsole(dirs.outDir); await removeFolderAndLogToConsole(dirs.outDir);
},
runDevServer: async (config: FullConfigInternal) => {
await runDevServer(config);
} }
}; };
} }

View file

@ -15,6 +15,7 @@
*/ */
import type { FullConfig, Suite } from '../../types/testReporter'; import type { FullConfig, Suite } from '../../types/testReporter';
import type { FullConfigInternal } from '../common/config';
import type { ReporterV2 } from '../reporters/reporterV2'; import type { ReporterV2 } from '../reporters/reporterV2';
export interface TestRunnerPlugin { export interface TestRunnerPlugin {
@ -26,7 +27,7 @@ export interface TestRunnerPlugin {
teardown?(): Promise<void>; teardown?(): Promise<void>;
clearCache?(): Promise<void>; clearCache?(): Promise<void>;
runDevServer?(): Promise<void>; runDevServer?(config: FullConfigInternal): Promise<() => Promise<void>>;
} }
export type TestRunnerPluginRegistration = { export type TestRunnerPluginRegistration = {

View file

@ -97,8 +97,10 @@ function addDevServerCommand(program: Command) {
const configInternal = await loadConfigFromFileRestartIfNeeded(options.config); const configInternal = await loadConfigFromFileRestartIfNeeded(options.config);
if (!configInternal) if (!configInternal)
return; return;
const { config } = configInternal;
const implementation = (config as any)['@playwright/test']?.['cli']?.['dev-server']; await testServer.setupPlugins(configInternal);
const implementation = configInternal.plugins.map(p => p.instance!).find(p => p.runDevServer)?.runDevServer;
if (implementation) { if (implementation) {
await implementation(configInternal); await implementation(configInternal);
} else { } else {

View file

@ -192,7 +192,10 @@ class TestServerDispatcher implements TestServerInterface {
reporter.onError(error!); reporter.onError(error!);
return { status: 'failed', report }; return { status: 'failed', report };
} }
const devServerCommand = (config.config as any)['@playwright/test']?.['cli']?.['dev-server'];
await setupPlugins(config);
const devServerCommand = config.plugins.map(p => p.instance!).find(p => p.runDevServer)?.runDevServer;
if (!devServerCommand) { if (!devServerCommand) {
reporter.onError({ message: 'No dev-server command found in the configuration' }); reporter.onError({ message: 'No dev-server command found in the configuration' });
return { status: 'failed', report }; return { status: 'failed', report };
@ -515,7 +518,7 @@ export async function resolveCtDirs(config: FullConfigInternal) {
}; };
} }
export async function clearCacheAndLogToConsole(config: FullConfigInternal) { export async function setupPlugins(config: FullConfigInternal) {
const errors: reporterTypes.TestError[] = []; const errors: reporterTypes.TestError[] = [];
const errorReporter = wrapReporterAsV2({ const errorReporter = wrapReporterAsV2({
onError(error: reporterTypes.TestError) { onError(error: reporterTypes.TestError) {
@ -526,6 +529,10 @@ export async function clearCacheAndLogToConsole(config: FullConfigInternal) {
await taskRunner.run(new TestRun(config), 0); await taskRunner.run(new TestRun(config), 0);
if (errors.length > 0) if (errors.length > 0)
throw new Error('Failed to clear cache: ' + errors); throw new Error('Failed to clear cache: ' + errors);
}
export async function clearCacheAndLogToConsole(config: FullConfigInternal) {
await setupPlugins(config);
for (const plugin of config.plugins) { for (const plugin of config.plugins) {
if (!plugin.instance) if (!plugin.instance)