mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
chore: dedup mergeReport fixture (#23762)
This commit is contained in:
parent
ba9666bb0c
commit
426d6dde0e
@ -85,27 +85,6 @@ export async function writeFiles(testInfo: TestInfo, files: Files, initial: bool
|
|||||||
|
|
||||||
export const cliEntrypoint = path.join(__dirname, '../../packages/playwright-test/cli.js');
|
export const cliEntrypoint = path.join(__dirname, '../../packages/playwright-test/cli.js');
|
||||||
|
|
||||||
const mergeReports = async (childProcess: CommonFixtures['childProcess'], cwd: string, env: NodeJS.ProcessEnv = {}, reporter: string | undefined, configFile: string | undefined) => {
|
|
||||||
const command = ['node', cliEntrypoint, 'merge-reports'];
|
|
||||||
if (reporter)
|
|
||||||
command.push('--reporter', reporter);
|
|
||||||
if (configFile)
|
|
||||||
command.push('--config', configFile);
|
|
||||||
command.push('blob-report');
|
|
||||||
const testProcess = childProcess({
|
|
||||||
command,
|
|
||||||
env: cleanEnv({
|
|
||||||
PW_TEST_DEBUG_REPORTERS: '1',
|
|
||||||
PW_TEST_DEBUG_REPORTERS_PRINT_STEPS: '1',
|
|
||||||
PWTEST_TTY_WIDTH: '80',
|
|
||||||
...env
|
|
||||||
}),
|
|
||||||
cwd,
|
|
||||||
});
|
|
||||||
const { exitCode } = await testProcess.exited;
|
|
||||||
return { exitCode, output: testProcess.output.toString() };
|
|
||||||
};
|
|
||||||
|
|
||||||
const configFile = (baseDir: string, files: Files): string | undefined => {
|
const configFile = (baseDir: string, files: Files): string | undefined => {
|
||||||
for (const [name, content] of Object.entries(files)) {
|
for (const [name, content] of Object.entries(files)) {
|
||||||
if (name.includes('playwright.config')) {
|
if (name.includes('playwright.config')) {
|
||||||
@ -116,7 +95,7 @@ const configFile = (baseDir: string, files: Files): string | undefined => {
|
|||||||
return undefined;
|
return undefined;
|
||||||
};
|
};
|
||||||
|
|
||||||
async function runPlaywrightTest(childProcess: CommonFixtures['childProcess'], baseDir: string, params: any, env: NodeJS.ProcessEnv, options: RunOptions, files: Files, useIntermediateMergeReport: boolean): Promise<RunResult> {
|
async function runPlaywrightTest(childProcess: CommonFixtures['childProcess'], baseDir: string, params: any, env: NodeJS.ProcessEnv, options: RunOptions, files: Files, mergeReports: (reportFolder: string, env?: NodeJS.ProcessEnv, options?: RunOptions) => Promise<CliRunResult>, useIntermediateMergeReport: boolean): Promise<RunResult> {
|
||||||
let reporter;
|
let reporter;
|
||||||
if (useIntermediateMergeReport) {
|
if (useIntermediateMergeReport) {
|
||||||
reporter = params.reporter;
|
reporter = params.reporter;
|
||||||
@ -148,7 +127,13 @@ async function runPlaywrightTest(childProcess: CommonFixtures['childProcess'], b
|
|||||||
}, options.sendSIGINTAfter);
|
}, options.sendSIGINTAfter);
|
||||||
|
|
||||||
if (useIntermediateMergeReport) {
|
if (useIntermediateMergeReport) {
|
||||||
const mergeResult = await mergeReports(childProcess, cwd, env, reporter, configFile(baseDir, files));
|
const additionalArgs = [];
|
||||||
|
if (reporter)
|
||||||
|
additionalArgs.push('--reporter', reporter);
|
||||||
|
const config = configFile(baseDir, files);
|
||||||
|
if (config)
|
||||||
|
additionalArgs.push('--config', config);
|
||||||
|
const mergeResult = await mergeReports('blob-report', env, { cwd, additionalArgs });
|
||||||
expect(mergeResult.exitCode).toBe(0);
|
expect(mergeResult.exitCode).toBe(0);
|
||||||
output = mergeResult.output;
|
output = mergeResult.output;
|
||||||
}
|
}
|
||||||
@ -290,6 +275,7 @@ type Fixtures = {
|
|||||||
runListFiles: (files: Files) => Promise<{ output: string, exitCode: number }>;
|
runListFiles: (files: Files) => Promise<{ output: string, exitCode: number }>;
|
||||||
runWatchTest: (files: Files, env?: NodeJS.ProcessEnv, options?: RunOptions) => Promise<TestChildProcess>;
|
runWatchTest: (files: Files, env?: NodeJS.ProcessEnv, options?: RunOptions) => Promise<TestChildProcess>;
|
||||||
runTSC: (files: Files) => Promise<TSCResult>;
|
runTSC: (files: Files) => Promise<TSCResult>;
|
||||||
|
mergeReports: (reportFolder: string, env?: NodeJS.ProcessEnv, options?: RunOptions) => Promise<CliRunResult>
|
||||||
useIntermediateMergeReport: boolean;
|
useIntermediateMergeReport: boolean;
|
||||||
nodeVersion: { major: number, minor: number, patch: number };
|
nodeVersion: { major: number, minor: number, patch: number };
|
||||||
};
|
};
|
||||||
@ -309,11 +295,11 @@ export const test = base
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
runInlineTest: async ({ childProcess, useIntermediateMergeReport }, use, testInfo: TestInfo) => {
|
runInlineTest: async ({ childProcess, mergeReports, useIntermediateMergeReport }, use, testInfo: TestInfo) => {
|
||||||
const cacheDir = await fs.promises.mkdtemp(path.join(os.tmpdir(), 'playwright-test-cache-'));
|
const cacheDir = await fs.promises.mkdtemp(path.join(os.tmpdir(), 'playwright-test-cache-'));
|
||||||
await use(async (files: Files, params: Params = {}, env: NodeJS.ProcessEnv = {}, options: RunOptions = {}) => {
|
await use(async (files: Files, params: Params = {}, env: NodeJS.ProcessEnv = {}, options: RunOptions = {}) => {
|
||||||
const baseDir = await writeFiles(testInfo, files, true);
|
const baseDir = await writeFiles(testInfo, files, true);
|
||||||
return await runPlaywrightTest(childProcess, baseDir, params, { ...env, PWTEST_CACHE_DIR: cacheDir }, options, files, useIntermediateMergeReport);
|
return await runPlaywrightTest(childProcess, baseDir, params, { ...env, PWTEST_CACHE_DIR: cacheDir }, options, files, mergeReports, useIntermediateMergeReport);
|
||||||
});
|
});
|
||||||
await removeFolderAsync(cacheDir);
|
await removeFolderAsync(cacheDir);
|
||||||
},
|
},
|
||||||
@ -354,6 +340,28 @@ export const test = base
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
mergeReports: async ({ childProcess }, use) => {
|
||||||
|
await use(async (reportFolder: string, env: NodeJS.ProcessEnv = {}, options: RunOptions = {}) => {
|
||||||
|
const command = ['node', cliEntrypoint, 'merge-reports', reportFolder];
|
||||||
|
if (options.additionalArgs)
|
||||||
|
command.push(...options.additionalArgs);
|
||||||
|
|
||||||
|
const cwd = options.cwd ? path.resolve(test.info().outputDir, options.cwd) : test.info().outputDir;
|
||||||
|
const testProcess = childProcess({
|
||||||
|
command,
|
||||||
|
env: cleanEnv({
|
||||||
|
PW_TEST_DEBUG_REPORTERS: '1',
|
||||||
|
PW_TEST_DEBUG_REPORTERS_PRINT_STEPS: '1',
|
||||||
|
PWTEST_TTY_WIDTH: '80',
|
||||||
|
...env
|
||||||
|
}),
|
||||||
|
cwd,
|
||||||
|
});
|
||||||
|
const { exitCode } = await testProcess.exited;
|
||||||
|
return { exitCode, output: testProcess.output.toString() };
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
nodeVersion: async ({}, use) => {
|
nodeVersion: async ({}, use) => {
|
||||||
const [major, minor, patch] = process.versions.node.split('.');
|
const [major, minor, patch] = process.versions.node.split('.');
|
||||||
await use({ major: +major, minor: +minor, patch: +patch });
|
await use({ major: +major, minor: +minor, patch: +patch });
|
||||||
|
@ -15,21 +15,19 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
|
import type { PlaywrightTestConfig } from 'packages/playwright-test';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import url from 'url';
|
import url from 'url';
|
||||||
import type { HttpServer } from '../../packages/playwright-core/src/utils';
|
import type { HttpServer } from '../../packages/playwright-core/src/utils';
|
||||||
import { startHtmlReportServer } from '../../packages/playwright-test/lib/reporters/html';
|
import { startHtmlReportServer } from '../../packages/playwright-test/lib/reporters/html';
|
||||||
import { type CliRunResult, type RunOptions, stripAnsi } from './playwright-test-fixtures';
|
import { expect as baseExpect, test as baseTest, stripAnsi } from './playwright-test-fixtures';
|
||||||
import { cleanEnv, cliEntrypoint, expect as baseExpect, test as baseTest } from './playwright-test-fixtures';
|
|
||||||
import type { PlaywrightTestConfig } from 'packages/playwright-test';
|
|
||||||
|
|
||||||
const DOES_NOT_SUPPORT_UTF8_IN_TERMINAL = process.platform === 'win32' && process.env.TERM_PROGRAM !== 'vscode' && !process.env.WT_SESSION;
|
const DOES_NOT_SUPPORT_UTF8_IN_TERMINAL = process.platform === 'win32' && process.env.TERM_PROGRAM !== 'vscode' && !process.env.WT_SESSION;
|
||||||
const POSITIVE_STATUS_MARK = DOES_NOT_SUPPORT_UTF8_IN_TERMINAL ? 'ok' : '✓ ';
|
const POSITIVE_STATUS_MARK = DOES_NOT_SUPPORT_UTF8_IN_TERMINAL ? 'ok' : '✓ ';
|
||||||
const NEGATIVE_STATUS_MARK = DOES_NOT_SUPPORT_UTF8_IN_TERMINAL ? 'x ' : '✘ ';
|
const NEGATIVE_STATUS_MARK = DOES_NOT_SUPPORT_UTF8_IN_TERMINAL ? 'x ' : '✘ ';
|
||||||
|
|
||||||
const test = baseTest.extend<{
|
const test = baseTest.extend<{
|
||||||
showReport: (reportFolder?: string) => Promise<void>,
|
showReport: (reportFolder?: string) => Promise<void>
|
||||||
mergeReports: (reportFolder: string, env?: NodeJS.ProcessEnv, options?: RunOptions) => Promise<CliRunResult>
|
|
||||||
}>({
|
}>({
|
||||||
showReport: async ({ page }, use) => {
|
showReport: async ({ page }, use) => {
|
||||||
let server: HttpServer | undefined;
|
let server: HttpServer | undefined;
|
||||||
@ -40,22 +38,6 @@ const test = baseTest.extend<{
|
|||||||
await page.goto(location);
|
await page.goto(location);
|
||||||
});
|
});
|
||||||
await server?.stop();
|
await server?.stop();
|
||||||
},
|
|
||||||
mergeReports: async ({ childProcess }, use) => {
|
|
||||||
await use(async (reportFolder: string, env: NodeJS.ProcessEnv = {}, options: RunOptions = {}) => {
|
|
||||||
const command = ['node', cliEntrypoint, 'merge-reports', reportFolder];
|
|
||||||
if (options.additionalArgs)
|
|
||||||
command.push(...options.additionalArgs);
|
|
||||||
|
|
||||||
const cwd = options.cwd ? path.resolve(test.info().outputDir, options.cwd) : test.info().outputDir;
|
|
||||||
const testProcess = childProcess({
|
|
||||||
command,
|
|
||||||
env: cleanEnv(env),
|
|
||||||
cwd,
|
|
||||||
});
|
|
||||||
const { exitCode } = await testProcess.exited;
|
|
||||||
return { exitCode, output: testProcess.output.toString() };
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -379,7 +361,7 @@ test('merge into list report by default', async ({ runInlineTest, mergeReports }
|
|||||||
const reportFiles = await fs.promises.readdir(reportDir);
|
const reportFiles = await fs.promises.readdir(reportDir);
|
||||||
reportFiles.sort();
|
reportFiles.sort();
|
||||||
expect(reportFiles).toEqual([expect.stringMatching(/report-1-of-3.*.zip/), expect.stringMatching(/report-2-of-3.*.zip/), expect.stringMatching(/report-3-of-3.*.zip/), 'resources']);
|
expect(reportFiles).toEqual([expect.stringMatching(/report-1-of-3.*.zip/), expect.stringMatching(/report-2-of-3.*.zip/), expect.stringMatching(/report-3-of-3.*.zip/), 'resources']);
|
||||||
const { exitCode, output } = await mergeReports(reportDir, { PW_TEST_DEBUG_REPORTERS: '1', PW_TEST_DEBUG_REPORTERS_PRINT_STEPS: '1', PWTEST_TTY_WIDTH: '80' }, { additionalArgs: ['--reporter', 'list'] });
|
const { exitCode, output } = await mergeReports(reportDir, undefined, { additionalArgs: ['--reporter', 'list'] });
|
||||||
expect(exitCode).toBe(0);
|
expect(exitCode).toBe(0);
|
||||||
|
|
||||||
const text = stripAnsi(output);
|
const text = stripAnsi(output);
|
||||||
@ -662,7 +644,7 @@ test('multiple output reports', async ({ runInlineTest, mergeReports, showReport
|
|||||||
const reportFiles = await fs.promises.readdir(reportDir);
|
const reportFiles = await fs.promises.readdir(reportDir);
|
||||||
reportFiles.sort();
|
reportFiles.sort();
|
||||||
expect(reportFiles).toEqual([expect.stringMatching(/report-1-of-2.*.zip/), 'resources']);
|
expect(reportFiles).toEqual([expect.stringMatching(/report-1-of-2.*.zip/), 'resources']);
|
||||||
const { exitCode, output } = await mergeReports(reportDir, { 'PW_TEST_HTML_REPORT_OPEN': 'never', 'PW_TEST_DEBUG_REPORTERS': '1' }, { additionalArgs: ['--reporter', 'html,line'] });
|
const { exitCode, output } = await mergeReports(reportDir, { 'PW_TEST_HTML_REPORT_OPEN': 'never' }, { additionalArgs: ['--reporter', 'html,line'] });
|
||||||
expect(exitCode).toBe(0);
|
expect(exitCode).toBe(0);
|
||||||
|
|
||||||
// Check that line reporter was called.
|
// Check that line reporter was called.
|
||||||
@ -723,7 +705,7 @@ test('multiple output reports based on config', async ({ runInlineTest, mergeRep
|
|||||||
const reportFiles = await fs.promises.readdir(reportDir);
|
const reportFiles = await fs.promises.readdir(reportDir);
|
||||||
reportFiles.sort();
|
reportFiles.sort();
|
||||||
expect(reportFiles).toEqual([expect.stringMatching(/report-1-of-2.*.zip/), expect.stringMatching(/report-2-of-2.*.zip/), 'resources']);
|
expect(reportFiles).toEqual([expect.stringMatching(/report-1-of-2.*.zip/), expect.stringMatching(/report-2-of-2.*.zip/), 'resources']);
|
||||||
const { exitCode, output } = await mergeReports(reportDir, { 'PW_TEST_DEBUG_REPORTERS': '1' }, { additionalArgs: ['--config', test.info().outputPath('merged/playwright.config.ts')] });
|
const { exitCode, output } = await mergeReports(reportDir, undefined, { additionalArgs: ['--config', test.info().outputPath('merged/playwright.config.ts')] });
|
||||||
expect(exitCode).toBe(0);
|
expect(exitCode).toBe(0);
|
||||||
|
|
||||||
// Check that line reporter was called.
|
// Check that line reporter was called.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user