always use lastrun reporter and keep em internal
This commit is contained in:
parent
e7273de4dd
commit
1eb11ffc0b
|
|
@ -273,7 +273,7 @@ export function toReporters(reporters: BuiltInReporter | ReporterDescription[] |
|
||||||
return reporters;
|
return reporters;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const builtInReporters = ['list', 'line', 'dot', 'json', 'junit', 'null', 'github', 'html', 'blob', 'markdown', 'lastrun'] as const;
|
export const builtInReporters = ['list', 'line', 'dot', 'json', 'junit', 'null', 'github', 'html', 'blob', 'markdown'] as const;
|
||||||
export type BuiltInReporter = typeof builtInReporters[number];
|
export type BuiltInReporter = typeof builtInReporters[number];
|
||||||
|
|
||||||
export type ContextReuseMode = 'none' | 'when-possible';
|
export type ContextReuseMode = 'none' | 'when-possible';
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,6 @@ export async function createReporters(config: FullConfigInternal, mode: 'list' |
|
||||||
null: EmptyReporter,
|
null: EmptyReporter,
|
||||||
html: HtmlReporter,
|
html: HtmlReporter,
|
||||||
markdown: MarkdownReporter,
|
markdown: MarkdownReporter,
|
||||||
lastrun: LastRunReporter,
|
|
||||||
};
|
};
|
||||||
const reporters: ReporterV2[] = [];
|
const reporters: ReporterV2[] = [];
|
||||||
descriptions ??= config.config.reporter;
|
descriptions ??= config.config.reporter;
|
||||||
|
|
@ -78,6 +77,12 @@ export async function createReporters(config: FullConfigInternal, mode: 'list' |
|
||||||
else if (mode !== 'merge')
|
else if (mode !== 'merge')
|
||||||
reporters.unshift(!process.env.CI ? new LineReporter({ omitFailures: true }) : new DotReporter());
|
reporters.unshift(!process.env.CI ? new LineReporter({ omitFailures: true }) : new DotReporter());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!isTestServer && (mode === 'test' || mode === 'merge')) {
|
||||||
|
// If we are not in the test server, always add a last-run reporter.
|
||||||
|
reporters.push(new LastRunReporter(runOptions));
|
||||||
|
}
|
||||||
|
|
||||||
return reporters;
|
return reporters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -94,9 +94,6 @@ export class Runner {
|
||||||
if (modifiedResult && modifiedResult.status)
|
if (modifiedResult && modifiedResult.status)
|
||||||
status = modifiedResult.status;
|
status = modifiedResult.status;
|
||||||
|
|
||||||
if (!listOnly)
|
|
||||||
await writeLastRunInfo(testRun, status);
|
|
||||||
|
|
||||||
await reporter.onExit();
|
await reporter.onExit();
|
||||||
|
|
||||||
// Calling process.exit() might truncate large stdout/stderr output.
|
// Calling process.exit() might truncate large stdout/stderr output.
|
||||||
|
|
@ -150,24 +147,6 @@ export type LastRunInfo = {
|
||||||
testDurations?: { [testId: string]: number };
|
testDurations?: { [testId: string]: number };
|
||||||
};
|
};
|
||||||
|
|
||||||
async function writeLastRunInfo(testRun: TestRun, status: FullResult['status']) {
|
|
||||||
const [project] = filterProjects(testRun.config.projects, testRun.config.cliProjectFilter);
|
|
||||||
if (!project)
|
|
||||||
return;
|
|
||||||
const outputDir = project.project.outputDir;
|
|
||||||
const lastRunReportFile = testRun.config.lastRunFile || 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 testDurations = testRun.rootSuite?.allTests().reduce((map, t) => {
|
|
||||||
if (t.results.length)
|
|
||||||
map[t.id] = t.results.reduce((a, b) => a + b.duration, 0);
|
|
||||||
return map;
|
|
||||||
}, {} as { [testId: string]: number });
|
|
||||||
const lastRunReport = JSON.stringify({ status, failedTests, testDurations }, undefined, 2);
|
|
||||||
await fs.promises.writeFile(lastRunReportFile, lastRunReport);
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function readLastRunInfo(config: FullConfigInternal): Promise<LastRunInfo> {
|
export async function readLastRunInfo(config: FullConfigInternal): Promise<LastRunInfo> {
|
||||||
const [project] = filterProjects(config.projects, config.cliProjectFilter);
|
const [project] = filterProjects(config.projects, config.cliProjectFilter);
|
||||||
if (!project)
|
if (!project)
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ const testCases = {
|
||||||
};
|
};
|
||||||
|
|
||||||
test('report lastrun info', async ({ runInlineTest }) => {
|
test('report lastrun info', async ({ runInlineTest }) => {
|
||||||
const result = await runInlineTest(testCases, { reporter: 'lastrun' });
|
const result = await runInlineTest(testCases, { });
|
||||||
expect(result.exitCode).toBe(1);
|
expect(result.exitCode).toBe(1);
|
||||||
const lastRunFilename = test.info().outputPath('.last-run.json');
|
const lastRunFilename = test.info().outputPath('.last-run.json');
|
||||||
const lastRun = JSON.parse(await fs.promises.readFile(lastRunFilename, 'utf8')) as LastRunReport;
|
const lastRun = JSON.parse(await fs.promises.readFile(lastRunFilename, 'utf8')) as LastRunReport;
|
||||||
|
|
@ -49,7 +49,7 @@ test('report lastrun info', async ({ runInlineTest }) => {
|
||||||
test('keep test-ids consistent when re-run', async ({ runInlineTest }) => {
|
test('keep test-ids consistent when re-run', async ({ runInlineTest }) => {
|
||||||
let lastRun: LastRunReport;
|
let lastRun: LastRunReport;
|
||||||
{
|
{
|
||||||
const result = await runInlineTest(testCases, { reporter: 'lastrun' });
|
const result = await runInlineTest(testCases, { });
|
||||||
expect(result.exitCode).toBe(1);
|
expect(result.exitCode).toBe(1);
|
||||||
const lastRunFilename = test.info().outputPath('.last-run.json');
|
const lastRunFilename = test.info().outputPath('.last-run.json');
|
||||||
const currentRun = JSON.parse(await fs.promises.readFile(lastRunFilename, 'utf8')) as LastRunReport;
|
const currentRun = JSON.parse(await fs.promises.readFile(lastRunFilename, 'utf8')) as LastRunReport;
|
||||||
|
|
@ -58,7 +58,7 @@ test('keep test-ids consistent when re-run', async ({ runInlineTest }) => {
|
||||||
lastRun = currentRun;
|
lastRun = currentRun;
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
const result = await runInlineTest(testCases, { reporter: 'lastrun' });
|
const result = await runInlineTest(testCases, { });
|
||||||
expect(result.exitCode).toBe(1);
|
expect(result.exitCode).toBe(1);
|
||||||
const lastRunFilename = test.info().outputPath('.last-run.json');
|
const lastRunFilename = test.info().outputPath('.last-run.json');
|
||||||
const currentRun = JSON.parse(await fs.promises.readFile(lastRunFilename, 'utf8')) as LastRunReport;
|
const currentRun = JSON.parse(await fs.promises.readFile(lastRunFilename, 'utf8')) as LastRunReport;
|
||||||
|
|
@ -76,7 +76,6 @@ test('keep test-ids consistent when merging reports', async ({ runInlineTest, me
|
||||||
...testCases,
|
...testCases,
|
||||||
'playwright.config.ts': `module.exports = {
|
'playwright.config.ts': `module.exports = {
|
||||||
reporter: [
|
reporter: [
|
||||||
['lastrun'],
|
|
||||||
['blob', { outputDir: 'blob-report' }],
|
['blob', { outputDir: 'blob-report' }],
|
||||||
]
|
]
|
||||||
};`,
|
};`,
|
||||||
|
|
@ -103,7 +102,7 @@ test('keep test-ids consistent when merging reports', async ({ runInlineTest, me
|
||||||
const reportFiles = await fs.promises.readdir(reportDir);
|
const reportFiles = await fs.promises.readdir(reportDir);
|
||||||
reportFiles.sort();
|
reportFiles.sort();
|
||||||
expect(reportFiles).toEqual(['report-1.zip', 'report-2.zip']);
|
expect(reportFiles).toEqual(['report-1.zip', 'report-2.zip']);
|
||||||
const result = await mergeReports(reportDir, { 'PLAYWRIGHT_HTML_OPEN': 'never' }, { additionalArgs: ['--reporter', 'lastrun'] });
|
const result = await mergeReports(reportDir, { 'PLAYWRIGHT_HTML_OPEN': 'never' });
|
||||||
expect(result.exitCode).toBe(0);
|
expect(result.exitCode).toBe(0);
|
||||||
const lastRunFilename = test.info().outputPath('.last-run.json');
|
const lastRunFilename = test.info().outputPath('.last-run.json');
|
||||||
const lastRun = JSON.parse(await fs.promises.readFile(lastRunFilename, 'utf8')) as LastRunReport;
|
const lastRun = JSON.parse(await fs.promises.readFile(lastRunFilename, 'utf8')) as LastRunReport;
|
||||||
|
|
@ -124,7 +123,7 @@ test('keep existing test-ids when test files are modified', async ({ runInlineTe
|
||||||
expect(1 + 1).toBe(2);
|
expect(1 + 1).toBe(2);
|
||||||
});
|
});
|
||||||
`
|
`
|
||||||
}, { reporter: 'lastrun' });
|
}, { });
|
||||||
expect(result.exitCode).toBe(0);
|
expect(result.exitCode).toBe(0);
|
||||||
const lastRunFilename = test.info().outputPath('.last-run.json');
|
const lastRunFilename = test.info().outputPath('.last-run.json');
|
||||||
const lastRun = JSON.parse(await fs.promises.readFile(lastRunFilename, 'utf8')) as LastRunReport;
|
const lastRun = JSON.parse(await fs.promises.readFile(lastRunFilename, 'utf8')) as LastRunReport;
|
||||||
|
|
@ -147,7 +146,7 @@ test('keep existing test-ids when test files are modified', async ({ runInlineTe
|
||||||
expect(1 + 1).toBe(2);
|
expect(1 + 1).toBe(2);
|
||||||
});
|
});
|
||||||
`
|
`
|
||||||
}, { reporter: 'lastrun' });
|
}, { });
|
||||||
expect(result.exitCode).toBe(0);
|
expect(result.exitCode).toBe(0);
|
||||||
const lastRunFilename = test.info().outputPath('.last-run.json');
|
const lastRunFilename = test.info().outputPath('.last-run.json');
|
||||||
const lastRun = JSON.parse(await fs.promises.readFile(lastRunFilename, 'utf8')) as LastRunReport;
|
const lastRun = JSON.parse(await fs.promises.readFile(lastRunFilename, 'utf8')) as LastRunReport;
|
||||||
|
|
@ -167,7 +166,7 @@ test('ensure same tests in different files have distinct test-ids', async ({ run
|
||||||
expect(1 + 1).toBe(2);
|
expect(1 + 1).toBe(2);
|
||||||
});
|
});
|
||||||
`
|
`
|
||||||
}, { reporter: 'lastrun' }, {}, { additionalArgs: ['a.test.js'] });
|
}, { }, {}, { additionalArgs: ['a.test.js'] });
|
||||||
expect(result.exitCode).toBe(0);
|
expect(result.exitCode).toBe(0);
|
||||||
const lastRunFilename = test.info().outputPath('.last-run.json');
|
const lastRunFilename = test.info().outputPath('.last-run.json');
|
||||||
const lastRun = JSON.parse(await fs.promises.readFile(lastRunFilename, 'utf8')) as LastRunReport;
|
const lastRun = JSON.parse(await fs.promises.readFile(lastRunFilename, 'utf8')) as LastRunReport;
|
||||||
|
|
@ -183,7 +182,7 @@ test('ensure same tests in different files have distinct test-ids', async ({ run
|
||||||
expect(1 + 1).toBe(2);
|
expect(1 + 1).toBe(2);
|
||||||
});
|
});
|
||||||
`
|
`
|
||||||
}, { reporter: 'lastrun' }, {}, { additionalArgs: ['b.test.js'] });
|
}, { }, {}, { additionalArgs: ['b.test.js'] });
|
||||||
expect(result.exitCode).toBe(0);
|
expect(result.exitCode).toBe(0);
|
||||||
const lastRunFilename = test.info().outputPath('.last-run.json');
|
const lastRunFilename = test.info().outputPath('.last-run.json');
|
||||||
const lastRun = JSON.parse(await fs.promises.readFile(lastRunFilename, 'utf8')) as LastRunReport;
|
const lastRun = JSON.parse(await fs.promises.readFile(lastRunFilename, 'utf8')) as LastRunReport;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue