Skip to content

Commit

Permalink
cherry-pick(#22609): chore: fix list-files
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelfeldman committed Apr 24, 2023
1 parent eed6c33 commit adef765
Showing 1 changed file with 15 additions and 31 deletions.
46 changes: 15 additions & 31 deletions packages/playwright-test/src/runner/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,26 @@ export class Runner {
}

async listTestFiles(projectNames: string[] | undefined): Promise<any> {
type ProjectConfigWithFiles = {
name: string;
testDir: string;
use: { testIdAttribute?: string };
files: string[];
};

type ConfigListFilesReport = {
projects: ProjectConfigWithFiles[];
};

const projects = filterProjects(this._config.projects, projectNames);
const report: any = {
const report: ConfigListFilesReport = {
projects: []
};
for (const project of projects) {
report.projects.push({
...sanitizeConfigForJSON(project, new Set()),
name: project.project.name,
testDir: project.project.testDir,
use: { testIdAttribute: project.project.use.testIdAttribute },
files: await collectFilesForProject(project)
});
}
Expand Down Expand Up @@ -99,32 +112,3 @@ export class Runner {
return await runUIMode(config);
}
}

function sanitizeConfigForJSON(object: any, visited: Set<any>): any {
const type = typeof object;
if (type === 'function' || type === 'symbol')
return undefined;
if (!object || type !== 'object')
return object;

if (object instanceof RegExp)
return String(object);
if (object instanceof Date)
return object.toISOString();

if (visited.has(object))
return undefined;
visited.add(object);

if (Array.isArray(object))
return object.map(a => sanitizeConfigForJSON(a, visited));

const result: any = {};
const keys = Object.keys(object).slice(0, 100);
for (const key of keys) {
if (key.startsWith('_'))
continue;
result[key] = sanitizeConfigForJSON(object[key], visited);
}
return result;
}

0 comments on commit adef765

Please sign in to comment.