add --last-run-file CLI parameter
This commit is contained in:
parent
2536da7716
commit
087a57febf
|
|
@ -56,6 +56,7 @@ export class FullConfigInternal {
|
||||||
testIdMatcher?: Matcher;
|
testIdMatcher?: Matcher;
|
||||||
defineConfigWasUsed = false;
|
defineConfigWasUsed = false;
|
||||||
shardingMode: Exclude<PlaywrightTestConfig['shardingMode'], undefined>;
|
shardingMode: Exclude<PlaywrightTestConfig['shardingMode'], undefined>;
|
||||||
|
lastRunFile: string | undefined;
|
||||||
lastRunInfo?: LastRunInfo;
|
lastRunInfo?: LastRunInfo;
|
||||||
|
|
||||||
constructor(location: ConfigLocation, userConfig: Config, configCLIOverrides: ConfigCLIOverrides) {
|
constructor(location: ConfigLocation, userConfig: Config, configCLIOverrides: ConfigCLIOverrides) {
|
||||||
|
|
@ -95,6 +96,7 @@ export class FullConfigInternal {
|
||||||
webServer: null,
|
webServer: null,
|
||||||
};
|
};
|
||||||
this.shardingMode = takeFirst(configCLIOverrides.shardingMode, userConfig.shardingMode, 'partition');
|
this.shardingMode = takeFirst(configCLIOverrides.shardingMode, userConfig.shardingMode, 'partition');
|
||||||
|
this.lastRunFile = configCLIOverrides.lastRunFile;
|
||||||
for (const key in userConfig) {
|
for (const key in userConfig) {
|
||||||
if (key.startsWith('@'))
|
if (key.startsWith('@'))
|
||||||
(this.config as any)[key] = (userConfig as any)[key];
|
(this.config as any)[key] = (userConfig as any)[key];
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,7 @@ export type ConfigCLIOverrides = {
|
||||||
additionalReporters?: ReporterDescription[];
|
additionalReporters?: ReporterDescription[];
|
||||||
shard?: { current: number, total: number };
|
shard?: { current: number, total: number };
|
||||||
shardingMode?: PlaywrightTestConfig['shardingMode'];
|
shardingMode?: PlaywrightTestConfig['shardingMode'];
|
||||||
|
lastRunFile?: string;
|
||||||
timeout?: number;
|
timeout?: number;
|
||||||
ignoreSnapshots?: boolean;
|
ignoreSnapshots?: boolean;
|
||||||
updateSnapshots?: 'all'|'none'|'missing';
|
updateSnapshots?: 'all'|'none'|'missing';
|
||||||
|
|
|
||||||
|
|
@ -285,6 +285,7 @@ function overridesFromOptions(options: { [key: string]: any }): ConfigCLIOverrid
|
||||||
reporter: resolveReporterOption(options.reporter),
|
reporter: resolveReporterOption(options.reporter),
|
||||||
shard: shardPair ? { current: shardPair[0], total: shardPair[1] } : undefined,
|
shard: shardPair ? { current: shardPair[0], total: shardPair[1] } : undefined,
|
||||||
shardingMode: options.shardingMode ? options.shardingMode : undefined,
|
shardingMode: options.shardingMode ? options.shardingMode : undefined,
|
||||||
|
lastRunFile: options.lastRunFile ? path.resolve(process.cwd(), options.lastRunFile) : undefined,
|
||||||
timeout: options.timeout ? parseInt(options.timeout, 10) : undefined,
|
timeout: options.timeout ? parseInt(options.timeout, 10) : undefined,
|
||||||
ignoreSnapshots: options.ignoreSnapshots ? !!options.ignoreSnapshots : undefined,
|
ignoreSnapshots: options.ignoreSnapshots ? !!options.ignoreSnapshots : undefined,
|
||||||
updateSnapshots: options.updateSnapshots ? 'all' as const : undefined,
|
updateSnapshots: options.updateSnapshots ? 'all' as const : undefined,
|
||||||
|
|
@ -351,6 +352,7 @@ const testOptions: [string, string][] = [
|
||||||
['--headed', `Run tests in headed browsers (default: headless)`],
|
['--headed', `Run tests in headed browsers (default: headless)`],
|
||||||
['--ignore-snapshots', `Ignore screenshot and snapshot expectations`],
|
['--ignore-snapshots', `Ignore screenshot and snapshot expectations`],
|
||||||
['--last-failed', `Only re-run the failures`],
|
['--last-failed', `Only re-run the failures`],
|
||||||
|
['--last-run-file', `Path to a json file where the last run information is read from and written to (default: .last-run.json)`],
|
||||||
['--list', `Collect all the tests and report them, but do not run`],
|
['--list', `Collect all the tests and report them, but do not run`],
|
||||||
['--max-failures <N>', `Stop after the first N failures`],
|
['--max-failures <N>', `Stop after the first N failures`],
|
||||||
['--no-deps', 'Do not run project dependencies'],
|
['--no-deps', 'Do not run project dependencies'],
|
||||||
|
|
|
||||||
|
|
@ -160,8 +160,9 @@ async function writeLastRunInfo(testRun: TestRun, status: FullResult['status'])
|
||||||
if (!project)
|
if (!project)
|
||||||
return;
|
return;
|
||||||
const outputDir = project.project.outputDir;
|
const outputDir = project.project.outputDir;
|
||||||
await fs.promises.mkdir(outputDir, { recursive: true });
|
const lastRunReportFile = testRun.config.lastRunFile || path.join(outputDir, '.last-run.json');
|
||||||
const lastRunReportFile = path.join(outputDir, '.last-run.json');
|
const lastRunReportFileDir = path.dirname(lastRunReportFile);
|
||||||
|
await fs.promises.mkdir(lastRunReportFileDir, { recursive: true });
|
||||||
const failedTests = testRun.rootSuite?.allTests().filter(t => !t.ok()).map(t => t.id);
|
const failedTests = testRun.rootSuite?.allTests().filter(t => !t.ok()).map(t => t.id);
|
||||||
const testDurations = testRun.rootSuite?.allTests().reduce((map, t) => {
|
const testDurations = testRun.rootSuite?.allTests().reduce((map, t) => {
|
||||||
if (t.results.length)
|
if (t.results.length)
|
||||||
|
|
@ -178,7 +179,7 @@ export async function readLastRunInfo(config: FullConfigInternal): Promise<LastR
|
||||||
return { status: 'passed', failedTests: [] };
|
return { status: 'passed', failedTests: [] };
|
||||||
const outputDir = project.project.outputDir;
|
const outputDir = project.project.outputDir;
|
||||||
try {
|
try {
|
||||||
const lastRunReportFile = path.join(outputDir, '.last-run.json');
|
const lastRunReportFile = config.lastRunFile || path.join(outputDir, '.last-run.json');
|
||||||
return JSON.parse(await fs.promises.readFile(lastRunReportFile, 'utf8')) as LastRunInfo;
|
return JSON.parse(await fs.promises.readFile(lastRunReportFile, 'utf8')) as LastRunInfo;
|
||||||
} catch {
|
} catch {
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue