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