mirror of
				https://github.com/microsoft/playwright.git
				synced 2025-06-26 21:40:17 +00:00 
			
		
		
		
	fix(test runner): --list should ignore '.only' annotations (#20868)
This commit is contained in:
		
							parent
							
								
									fdcd7b549d
								
							
						
					
					
						commit
						6d03211439
					
				| @ -27,7 +27,7 @@ import { requireOrImport } from '../common/transform'; | |||||||
| import { buildFileSuiteForProject, filterByFocusedLine, filterByTestIds, filterOnly, filterTestsRemoveEmptySuites } from '../common/suiteUtils'; | import { buildFileSuiteForProject, filterByFocusedLine, filterByTestIds, filterOnly, filterTestsRemoveEmptySuites } from '../common/suiteUtils'; | ||||||
| import { filterForShard } from './testGroups'; | import { filterForShard } from './testGroups'; | ||||||
| 
 | 
 | ||||||
| export async function loadAllTests(mode: 'out-of-process' | 'in-process', config: FullConfigInternal, projectsToIgnore: Set<FullProjectInternal>, fileMatcher: Matcher, errors: TestError[]): Promise<Suite> { | export async function loadAllTests(mode: 'out-of-process' | 'in-process', config: FullConfigInternal, projectsToIgnore: Set<FullProjectInternal>, fileMatcher: Matcher, errors: TestError[], shouldFilterOnly: boolean): Promise<Suite> { | ||||||
|   const projects = filterProjects(config.projects, config._internal.cliProjectFilter); |   const projects = filterProjects(config.projects, config._internal.cliProjectFilter); | ||||||
| 
 | 
 | ||||||
|   let filesToRunByProject = new Map<FullProjectInternal, string[]>(); |   let filesToRunByProject = new Map<FullProjectInternal, string[]>(); | ||||||
| @ -118,6 +118,7 @@ export async function loadAllTests(mode: 'out-of-process' | 'in-process', config | |||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   // Filter only for leaf projects.
 |   // Filter only for leaf projects.
 | ||||||
|  |   if (shouldFilterOnly) | ||||||
|     filterOnly(rootSuite); |     filterOnly(rootSuite); | ||||||
| 
 | 
 | ||||||
|   // Prepend the projects that are dependencies.
 |   // Prepend the projects that are dependencies.
 | ||||||
|  | |||||||
| @ -53,7 +53,7 @@ export type TaskRunnerState = { | |||||||
| export function createTaskRunner(config: FullConfigInternal, reporter: Multiplexer): TaskRunner<TaskRunnerState> { | export function createTaskRunner(config: FullConfigInternal, reporter: Multiplexer): TaskRunner<TaskRunnerState> { | ||||||
|   const taskRunner = new TaskRunner<TaskRunnerState>(reporter, config.globalTimeout); |   const taskRunner = new TaskRunner<TaskRunnerState>(reporter, config.globalTimeout); | ||||||
|   addGlobalSetupTasks(taskRunner, config); |   addGlobalSetupTasks(taskRunner, config); | ||||||
|   taskRunner.addTask('load tests', createLoadTask('in-process')); |   taskRunner.addTask('load tests', createLoadTask('in-process', true)); | ||||||
|   addRunTasks(taskRunner, config); |   addRunTasks(taskRunner, config); | ||||||
|   return taskRunner; |   return taskRunner; | ||||||
| } | } | ||||||
| @ -66,7 +66,7 @@ export function createTaskRunnerForWatchSetup(config: FullConfigInternal, report | |||||||
| 
 | 
 | ||||||
| export function createTaskRunnerForWatch(config: FullConfigInternal, reporter: Multiplexer, projectsToIgnore?: Set<FullProjectInternal>, additionalFileMatcher?: Matcher): TaskRunner<TaskRunnerState> { | export function createTaskRunnerForWatch(config: FullConfigInternal, reporter: Multiplexer, projectsToIgnore?: Set<FullProjectInternal>, additionalFileMatcher?: Matcher): TaskRunner<TaskRunnerState> { | ||||||
|   const taskRunner = new TaskRunner<TaskRunnerState>(reporter, 0); |   const taskRunner = new TaskRunner<TaskRunnerState>(reporter, 0); | ||||||
|   taskRunner.addTask('load tests', createLoadTask('out-of-process', projectsToIgnore, additionalFileMatcher)); |   taskRunner.addTask('load tests', createLoadTask('out-of-process', true, projectsToIgnore, additionalFileMatcher)); | ||||||
|   addRunTasks(taskRunner, config); |   addRunTasks(taskRunner, config); | ||||||
|   return taskRunner; |   return taskRunner; | ||||||
| } | } | ||||||
| @ -94,7 +94,7 @@ function addRunTasks(taskRunner: TaskRunner<TaskRunnerState>, config: FullConfig | |||||||
| 
 | 
 | ||||||
| export function createTaskRunnerForList(config: FullConfigInternal, reporter: Multiplexer): TaskRunner<TaskRunnerState> { | export function createTaskRunnerForList(config: FullConfigInternal, reporter: Multiplexer): TaskRunner<TaskRunnerState> { | ||||||
|   const taskRunner = new TaskRunner<TaskRunnerState>(reporter, config.globalTimeout); |   const taskRunner = new TaskRunner<TaskRunnerState>(reporter, config.globalTimeout); | ||||||
|   taskRunner.addTask('load tests', createLoadTask('in-process')); |   taskRunner.addTask('load tests', createLoadTask('in-process', false)); | ||||||
|   taskRunner.addTask('report begin', async ({ reporter, rootSuite }) => { |   taskRunner.addTask('report begin', async ({ reporter, rootSuite }) => { | ||||||
|     reporter.onBegin?.(config, rootSuite!); |     reporter.onBegin?.(config, rootSuite!); | ||||||
|     return () => reporter.onEnd(); |     return () => reporter.onEnd(); | ||||||
| @ -155,12 +155,12 @@ function createRemoveOutputDirsTask(): Task<TaskRunnerState> { | |||||||
|   }; |   }; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| function createLoadTask(mode: 'out-of-process' | 'in-process', projectsToIgnore = new Set<FullProjectInternal>(), additionalFileMatcher?: Matcher): Task<TaskRunnerState> { | function createLoadTask(mode: 'out-of-process' | 'in-process', shouldFilterOnly: boolean, projectsToIgnore = new Set<FullProjectInternal>(), additionalFileMatcher?: Matcher): Task<TaskRunnerState> { | ||||||
|   return async (context, errors) => { |   return async (context, errors) => { | ||||||
|     const { config } = context; |     const { config } = context; | ||||||
|     const cliMatcher = config._internal.cliArgs.length ? createFileMatcherFromArguments(config._internal.cliArgs) : () => true; |     const cliMatcher = config._internal.cliArgs.length ? createFileMatcherFromArguments(config._internal.cliArgs) : () => true; | ||||||
|     const fileMatcher = (value: string) => cliMatcher(value) && (additionalFileMatcher ? additionalFileMatcher(value) : true); |     const fileMatcher = (value: string) => cliMatcher(value) && (additionalFileMatcher ? additionalFileMatcher(value) : true); | ||||||
|     context.rootSuite = await loadAllTests(mode, config, projectsToIgnore, fileMatcher, errors); |     context.rootSuite = await loadAllTests(mode, config, projectsToIgnore, fileMatcher, errors, shouldFilterOnly); | ||||||
|     // Fail when no tests.
 |     // Fail when no tests.
 | ||||||
|     if (!context.rootSuite.allTests().length && !config._internal.passWithNoTests && !config.shard) |     if (!context.rootSuite.allTests().length && !config._internal.passWithNoTests && !config.shard) | ||||||
|       throw new Error(`No tests found`); |       throw new Error(`No tests found`); | ||||||
|  | |||||||
| @ -151,3 +151,24 @@ test('should report errors', async ({ runInlineTest }) => { | |||||||
|   expect(result.exitCode).toBe(1); |   expect(result.exitCode).toBe(1); | ||||||
|   expect(result.output).toContain('> 6 |       oh = 2;'); |   expect(result.output).toContain('> 6 |       oh = 2;'); | ||||||
| }); | }); | ||||||
|  | 
 | ||||||
|  | test('should ignore .only', async ({ runInlineTest }) => { | ||||||
|  |   const result = await runInlineTest({ | ||||||
|  |     'a.test.js': ` | ||||||
|  |       const { test } = pwt; | ||||||
|  |       test('example1', async ({}) => { | ||||||
|  |         expect(1 + 1).toBe(2); | ||||||
|  |       }); | ||||||
|  |       test.only('example2', async ({}) => { | ||||||
|  |         expect(1 + 1).toBe(2); | ||||||
|  |       }); | ||||||
|  |     ` | ||||||
|  |   }, { 'list': true }); | ||||||
|  |   expect(result.exitCode).toBe(0); | ||||||
|  |   expect(result.output).toContain([ | ||||||
|  |     `Listing tests:`, | ||||||
|  |     `  a.test.js:6:7 › example1`, | ||||||
|  |     `  a.test.js:9:12 › example2`, | ||||||
|  |     `Total: 2 tests in 1 file` | ||||||
|  |   ].join('\n')); | ||||||
|  | }); | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Dmitry Gozman
						Dmitry Gozman