fet(list-files): report per-project test dir and filters (#11764)
This commit is contained in:
parent
c5d852f1bb
commit
c82f2641d7
|
|
@ -246,7 +246,7 @@ if (!process.env.PW_LANG_NAME) {
|
|||
if (playwrightTestPackagePath) {
|
||||
require(playwrightTestPackagePath).addTestCommand(program);
|
||||
require(playwrightTestPackagePath).addShowReportCommand(program);
|
||||
require(playwrightTestPackagePath).addListTestsCommand(program);
|
||||
require(playwrightTestPackagePath).addListFilesCommand(program);
|
||||
} else {
|
||||
{
|
||||
const command = program.command('test').allowUnknownOption(true);
|
||||
|
|
|
|||
|
|
@ -73,14 +73,14 @@ Examples:
|
|||
$ npx playwright test --browser=webkit`);
|
||||
}
|
||||
|
||||
export function addListTestsCommand(program: Command) {
|
||||
const command = program.command('list-tests [test-filter...]', { hidden: true });
|
||||
command.description('List tests with Playwright Test');
|
||||
export function addListFilesCommand(program: Command) {
|
||||
const command = program.command('list-files [file-filter...]', { hidden: true });
|
||||
command.description('List files with Playwright Test tests');
|
||||
command.option('-c, --config <file>', `Configuration file, or a test directory with optional ${kDefaultConfigFiles.map(file => `"${file}"`).join('/')}`);
|
||||
command.option('--project <project-name...>', `Only run tests from the specified list of projects (default: list all projects)`);
|
||||
command.action(async (args, opts) => {
|
||||
try {
|
||||
await listTests(opts);
|
||||
await listTestFiles(opts);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
process.exit(1);
|
||||
|
|
@ -167,11 +167,11 @@ async function runTests(args: string[], opts: { [key: string]: any }) {
|
|||
}
|
||||
|
||||
|
||||
async function listTests(opts: { [key: string]: any }) {
|
||||
async function listTestFiles(opts: { [key: string]: any }) {
|
||||
const configFile = opts.config ? path.resolve(process.cwd(), opts.config) : process.cwd();
|
||||
const runner = new Runner({}, { defaultConfig: {} });
|
||||
const config = await runner.loadConfigFromFile(configFile);
|
||||
const report = await runner.listAllTestFiles(config, opts.project);
|
||||
await runner.loadConfigFromFile(configFile);
|
||||
const report = await runner.listTestFiles(configFile, opts.project);
|
||||
process.stdout.write(JSON.stringify(report), () => {
|
||||
process.exit(0);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ import * as fs from 'fs';
|
|||
import * as path from 'path';
|
||||
import { promisify } from 'util';
|
||||
import { Dispatcher, TestGroup } from './dispatcher';
|
||||
import { createFileMatcher, createTitleMatcher, FilePatternFilter } from './util';
|
||||
import { createFileMatcher, createTitleMatcher, FilePatternFilter, serializeError } from './util';
|
||||
import { TestCase, Suite } from './test';
|
||||
import { Loader } from './loader';
|
||||
import { FullResult, Reporter, TestError } from '../types/testReporter';
|
||||
|
|
@ -39,7 +39,6 @@ import { Config, FullConfig } from './types';
|
|||
import { WebServer } from './webServer';
|
||||
import { raceAgainstTimeout } from 'playwright-core/lib/utils/async';
|
||||
import { SigIntWatcher } from 'playwright-core/lib/utils/utils';
|
||||
import { serializeError } from './util';
|
||||
|
||||
const removeFolderAsync = promisify(rimraf);
|
||||
const readDirAsync = promisify(fs.readdir);
|
||||
|
|
@ -155,15 +154,15 @@ export class Runner {
|
|||
return fullResult;
|
||||
}
|
||||
|
||||
async listAllTestFiles(config: Config, projectNames: string[] | undefined): Promise<any> {
|
||||
async listTestFiles(configFile: string, projectNames: string[] | undefined): Promise<any> {
|
||||
const filesByProject = await this._collectFiles([], projectNames);
|
||||
const report: any = {
|
||||
testDir: config.testDir,
|
||||
projects: []
|
||||
};
|
||||
for (const [project, files] of filesByProject) {
|
||||
report.projects.push({
|
||||
name: project.config.name,
|
||||
testDir: path.resolve(configFile, project.config.testDir),
|
||||
files: files
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue