feat: --pass-with-no-tests option (#16902)

This commit is contained in:
Yury Semikhatsky 2022-08-29 15:46:34 -07:00 committed by GitHub
parent 84888737e2
commit 11dfd31dd9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 1 deletions

View File

@ -50,6 +50,7 @@ function addTestCommand(program: Command) {
command.option('--list', `Collect all the tests and report them, but do not run`);
command.option('--max-failures <N>', `Stop after the first N failures`);
command.option('--output <dir>', `Folder for output artifacts (default: "test-results")`);
command.option('--pass-with-no-tests', `Makes test run succeed even if no tests were found`);
command.option('--quiet', `Suppress stdio`);
command.option('--repeat-each <N>', `Run each test N times (default: 1)`);
command.option('--reporter <reporter>', `Reporter to use, comma-separated, can be ${builtInReporters.map(name => `"${name}"`).join(', ')} (default: "${baseFullConfig.reporter[0]}")`);
@ -165,6 +166,7 @@ async function runTests(args: string[], opts: { [key: string]: any }) {
testFileFilters,
projectFilter: opts.project || undefined,
watchMode: !!process.env.PW_TEST_WATCH,
passWithNoTests: opts.passWithNoTests,
});
await stopProfiling(undefined);

View File

@ -56,6 +56,7 @@ type RunOptions = {
testFileFilters?: TestFileFilter[];
projectFilter?: string[];
watchMode?: boolean;
passWithNoTests?: boolean;
};
export type ConfigCLIOverrides = {
@ -337,7 +338,7 @@ export class Runner {
// 7. Fail when no tests.
let total = rootSuite.allTests().length;
if (!total)
if (!total && !options.passWithNoTests)
fatalErrors.push(createNoTestsError());
// 8. Compute shards.

View File

@ -156,6 +156,16 @@ test('should exit with code 1 if passed a file name', async ({ runInlineTest })
expect(result.output).toContain(`no tests found.`);
});
test('should exit with code 0 with --pass-with-no-tests', async ({ runInlineTest }) => {
const result = await runInlineTest({
'playwright.config.ts': `
module.exports = { testDir: 'unknown' };
`,
}, undefined, undefined, { additionalArgs: ['--pass-with-no-tests'] });
expect(result.exitCode).toBe(0);
expect(result.output).toContain(`Running 0 tests using 0 workers`);
});
test('should exit with code 1 when config is not found', async ({ runInlineTest }) => {
const result = await runInlineTest({ 'my.config.js': '' }, { 'config': 'foo.config.js' });
expect(result.exitCode).toBe(1);