chore: fix list-files (#22609)
This commit is contained in:
		
							parent
							
								
									0c4bed191f
								
							
						
					
					
						commit
						5120e7d541
					
				| 
						 | 
				
			
			@ -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)
 | 
			
		||||
      });
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			@ -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;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue