| 
									
										
										
										
											2021-06-07 08:09:53 +08:00
										 |  |  |  | /** | 
					
						
							|  |  |  |  |  * Copyright (c) Microsoft Corporation. | 
					
						
							|  |  |  |  |  * | 
					
						
							|  |  |  |  |  * Licensed under the Apache License, Version 2.0 (the "License"); | 
					
						
							|  |  |  |  |  * you may not use this file except in compliance with the License. | 
					
						
							|  |  |  |  |  * You may obtain a copy of the License at | 
					
						
							|  |  |  |  |  * | 
					
						
							|  |  |  |  |  * http://www.apache.org/licenses/LICENSE-2.0
 | 
					
						
							|  |  |  |  |  * | 
					
						
							|  |  |  |  |  * Unless required by applicable law or agreed to in writing, software | 
					
						
							|  |  |  |  |  * distributed under the License is distributed on an "AS IS" BASIS, | 
					
						
							|  |  |  |  |  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
					
						
							|  |  |  |  |  * See the License for the specific language governing permissions and | 
					
						
							|  |  |  |  |  * limitations under the License. | 
					
						
							|  |  |  |  |  */ | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-08 07:11:44 +08:00
										 |  |  |  | import { test, expect } from './playwright-test-fixtures'; | 
					
						
							| 
									
										
										
										
											2021-06-07 08:09:53 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | test('should fail', async ({ runInlineTest }) => { | 
					
						
							|  |  |  |  |   const result = await runInlineTest({ | 
					
						
							|  |  |  |  |     'one-failure.spec.ts': `
 | 
					
						
							| 
									
										
										
										
											2023-02-15 11:20:56 +08:00
										 |  |  |  |       import { test, expect } from '@playwright/test'; | 
					
						
							| 
									
										
										
										
											2021-06-07 08:09:53 +08:00
										 |  |  |  |       test('fails', () => { | 
					
						
							|  |  |  |  |         expect(1 + 1).toBe(7); | 
					
						
							|  |  |  |  |       }); | 
					
						
							|  |  |  |  |     `
 | 
					
						
							|  |  |  |  |   }); | 
					
						
							|  |  |  |  |   expect(result.exitCode).toBe(1); | 
					
						
							|  |  |  |  |   expect(result.passed).toBe(0); | 
					
						
							|  |  |  |  |   expect(result.failed).toBe(1); | 
					
						
							| 
									
										
										
										
											2023-02-15 11:20:56 +08:00
										 |  |  |  |   expect(result.output).toContain('1) one-failure.spec.ts:3'); | 
					
						
							| 
									
										
										
										
											2021-06-07 08:09:53 +08:00
										 |  |  |  | }); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | test('should timeout', async ({ runInlineTest }) => { | 
					
						
							|  |  |  |  |   const { exitCode, passed, failed, output } = await runInlineTest({ | 
					
						
							| 
									
										
										
										
											2023-02-15 11:20:56 +08:00
										 |  |  |  |     'one-timeout.spec.ts': `
 | 
					
						
							|  |  |  |  |       import { test, expect } from '@playwright/test'; | 
					
						
							| 
									
										
										
										
											2021-06-07 08:09:53 +08:00
										 |  |  |  |       test('timeout', async () => { | 
					
						
							|  |  |  |  |         await new Promise(f => setTimeout(f, 10000)); | 
					
						
							|  |  |  |  |       }); | 
					
						
							|  |  |  |  |     `
 | 
					
						
							|  |  |  |  |   }, { timeout: 100 }); | 
					
						
							|  |  |  |  |   expect(exitCode).toBe(1); | 
					
						
							|  |  |  |  |   expect(passed).toBe(0); | 
					
						
							|  |  |  |  |   expect(failed).toBe(1); | 
					
						
							| 
									
										
										
										
											2023-05-03 00:14:57 +08:00
										 |  |  |  |   expect(output).toContain('Test timeout of 100ms exceeded'); | 
					
						
							| 
									
										
										
										
											2021-06-07 08:09:53 +08:00
										 |  |  |  | }); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | test('should succeed', async ({ runInlineTest }) => { | 
					
						
							|  |  |  |  |   const result = await runInlineTest({ | 
					
						
							| 
									
										
										
										
											2023-02-15 11:20:56 +08:00
										 |  |  |  |     'one-success.spec.ts': `
 | 
					
						
							|  |  |  |  |       import { test, expect } from '@playwright/test'; | 
					
						
							| 
									
										
										
										
											2021-06-07 08:09:53 +08:00
										 |  |  |  |       test('succeeds', () => { | 
					
						
							|  |  |  |  |         expect(1 + 1).toBe(2); | 
					
						
							|  |  |  |  |       }); | 
					
						
							|  |  |  |  |     `
 | 
					
						
							|  |  |  |  |   }); | 
					
						
							|  |  |  |  |   expect(result.exitCode).toBe(0); | 
					
						
							|  |  |  |  |   expect(result.passed).toBe(1); | 
					
						
							|  |  |  |  |   expect(result.failed).toBe(0); | 
					
						
							|  |  |  |  | }); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | test('should report suite errors', async ({ runInlineTest }) => { | 
					
						
							|  |  |  |  |   const { exitCode, failed, output } = await runInlineTest({ | 
					
						
							| 
									
										
										
										
											2023-02-15 11:20:56 +08:00
										 |  |  |  |     'suite-error.spec.ts': `
 | 
					
						
							| 
									
										
										
										
											2023-01-23 07:04:29 +08:00
										 |  |  |  |       if (new Error().stack.includes('workerMain')) | 
					
						
							| 
									
										
										
										
											2021-06-07 08:09:53 +08:00
										 |  |  |  |         throw new Error('Suite error'); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-15 11:20:56 +08:00
										 |  |  |  |       import { test, expect } from '@playwright/test'; | 
					
						
							| 
									
										
										
										
											2021-06-07 08:09:53 +08:00
										 |  |  |  |       test('passes',() => { | 
					
						
							|  |  |  |  |         expect(1 + 1).toBe(2); | 
					
						
							|  |  |  |  |       }); | 
					
						
							|  |  |  |  |     `
 | 
					
						
							|  |  |  |  |   }); | 
					
						
							|  |  |  |  |   expect(exitCode).toBe(1); | 
					
						
							|  |  |  |  |   expect(failed).toBe(1); | 
					
						
							|  |  |  |  |   expect(output).toContain('Suite error'); | 
					
						
							|  |  |  |  | }); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | test('should respect nested skip', async ({ runInlineTest }) => { | 
					
						
							|  |  |  |  |   const { exitCode, passed, failed, skipped } = await runInlineTest({ | 
					
						
							| 
									
										
										
										
											2023-02-15 11:20:56 +08:00
										 |  |  |  |     'nested-skip.spec.ts': `
 | 
					
						
							|  |  |  |  |       import { test, expect } from '@playwright/test'; | 
					
						
							| 
									
										
										
										
											2021-06-07 08:09:53 +08:00
										 |  |  |  |       test.describe('skipped', () => { | 
					
						
							|  |  |  |  |         test.skip(); | 
					
						
							|  |  |  |  |         test('succeeds',() => { | 
					
						
							|  |  |  |  |           expect(1 + 1).toBe(2); | 
					
						
							|  |  |  |  |         }); | 
					
						
							|  |  |  |  |       }); | 
					
						
							|  |  |  |  |     `
 | 
					
						
							|  |  |  |  |   }); | 
					
						
							|  |  |  |  |   expect(exitCode).toBe(0); | 
					
						
							|  |  |  |  |   expect(passed).toBe(0); | 
					
						
							|  |  |  |  |   expect(failed).toBe(0); | 
					
						
							|  |  |  |  |   expect(skipped).toBe(1); | 
					
						
							|  |  |  |  | }); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | test('should respect excluded tests', async ({ runInlineTest }) => { | 
					
						
							|  |  |  |  |   const { exitCode, passed } = await runInlineTest({ | 
					
						
							|  |  |  |  |     'excluded.spec.ts': `
 | 
					
						
							| 
									
										
										
										
											2023-02-15 11:20:56 +08:00
										 |  |  |  |       import { test, expect } from '@playwright/test'; | 
					
						
							| 
									
										
										
										
											2021-06-07 08:09:53 +08:00
										 |  |  |  |       test('included test', () => { | 
					
						
							|  |  |  |  |         expect(1 + 1).toBe(2); | 
					
						
							|  |  |  |  |       }); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-29 04:13:35 +08:00
										 |  |  |  |       test('excluded test 1', () => { | 
					
						
							| 
									
										
										
										
											2021-06-07 08:09:53 +08:00
										 |  |  |  |         test.skip(); | 
					
						
							|  |  |  |  |         expect(1 + 1).toBe(3); | 
					
						
							|  |  |  |  |       }); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-29 04:13:35 +08:00
										 |  |  |  |       test('excluded test 2', () => { | 
					
						
							| 
									
										
										
										
											2021-06-07 08:09:53 +08:00
										 |  |  |  |         test.skip(); | 
					
						
							|  |  |  |  |         expect(1 + 1).toBe(3); | 
					
						
							|  |  |  |  |       }); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |       test.describe('included describe', () => { | 
					
						
							|  |  |  |  |         test('included describe test', () => { | 
					
						
							|  |  |  |  |           expect(1 + 1).toBe(2); | 
					
						
							|  |  |  |  |         }); | 
					
						
							|  |  |  |  |       }); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |       test.describe('excluded describe', () => { | 
					
						
							|  |  |  |  |         test.skip(); | 
					
						
							|  |  |  |  |         test('excluded describe test', () => { | 
					
						
							|  |  |  |  |           expect(1 + 1).toBe(3); | 
					
						
							|  |  |  |  |         }); | 
					
						
							|  |  |  |  |       }); | 
					
						
							|  |  |  |  |     `,
 | 
					
						
							|  |  |  |  |   }); | 
					
						
							|  |  |  |  |   expect(passed).toBe(2); | 
					
						
							|  |  |  |  |   expect(exitCode).toBe(0); | 
					
						
							|  |  |  |  | }); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | test('should respect focused tests', async ({ runInlineTest }) => { | 
					
						
							|  |  |  |  |   const { exitCode, passed } = await runInlineTest({ | 
					
						
							|  |  |  |  |     'focused.spec.ts': `
 | 
					
						
							| 
									
										
										
										
											2023-02-15 11:20:56 +08:00
										 |  |  |  |       import { test, expect } from '@playwright/test'; | 
					
						
							| 
									
										
										
										
											2021-06-07 08:09:53 +08:00
										 |  |  |  |       test('included test', () => { | 
					
						
							|  |  |  |  |         expect(1 + 1).toBe(3); | 
					
						
							|  |  |  |  |       }); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |       test.only('focused test', () => { | 
					
						
							|  |  |  |  |         expect(1 + 1).toBe(2); | 
					
						
							|  |  |  |  |       }); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |       test.only('focused only test', () => { | 
					
						
							|  |  |  |  |         expect(1 + 1).toBe(2); | 
					
						
							|  |  |  |  |       }); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |       test.describe.only('focused describe', () => { | 
					
						
							|  |  |  |  |         test('describe test', () => { | 
					
						
							|  |  |  |  |           expect(1 + 1).toBe(2); | 
					
						
							|  |  |  |  |         }); | 
					
						
							|  |  |  |  |       }); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-16 21:47:23 +08:00
										 |  |  |  |       test.fail.only('focused fail.only test', () => { | 
					
						
							|  |  |  |  |         expect(1 + 1).toBe(3); | 
					
						
							|  |  |  |  |       }); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-07 08:09:53 +08:00
										 |  |  |  |       test.describe('non-focused describe', () => { | 
					
						
							|  |  |  |  |         test('describe test', () => { | 
					
						
							|  |  |  |  |           expect(1 + 1).toBe(3); | 
					
						
							|  |  |  |  |         }); | 
					
						
							|  |  |  |  |       }); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |       test.describe.only('focused describe', () => { | 
					
						
							|  |  |  |  |         test('test1', () => { | 
					
						
							|  |  |  |  |           expect(1 + 1).toBe(2); | 
					
						
							|  |  |  |  |         }); | 
					
						
							|  |  |  |  |         test.only('test2', () => { | 
					
						
							|  |  |  |  |           expect(1 + 1).toBe(2); | 
					
						
							|  |  |  |  |         }); | 
					
						
							|  |  |  |  |         test('test3', () => { | 
					
						
							|  |  |  |  |           expect(1 + 1).toBe(2); | 
					
						
							|  |  |  |  |         }); | 
					
						
							|  |  |  |  |         test.only('test4', () => { | 
					
						
							|  |  |  |  |           expect(1 + 1).toBe(2); | 
					
						
							|  |  |  |  |         }); | 
					
						
							| 
									
										
										
										
											2024-10-16 21:47:23 +08:00
										 |  |  |  |         test.fail.only('test5', () => { | 
					
						
							|  |  |  |  |           expect(1 + 1).toBe(3); | 
					
						
							|  |  |  |  |         }); | 
					
						
							| 
									
										
										
										
											2021-06-07 08:09:53 +08:00
										 |  |  |  |       }); | 
					
						
							|  |  |  |  |     `
 | 
					
						
							|  |  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2024-10-16 21:47:23 +08:00
										 |  |  |  |   expect(passed).toBe(7); | 
					
						
							| 
									
										
										
										
											2021-06-07 08:09:53 +08:00
										 |  |  |  |   expect(exitCode).toBe(0); | 
					
						
							|  |  |  |  | }); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-16 21:47:23 +08:00
										 |  |  |  | test('should respect focused tests with test.fail', async ({ runInlineTest }) => { | 
					
						
							|  |  |  |  |   const result = await runInlineTest({ | 
					
						
							|  |  |  |  |     'fail-only.spec.ts': `
 | 
					
						
							|  |  |  |  |       import { test, expect } from '@playwright/test'; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |       test('test1', () => { | 
					
						
							|  |  |  |  |         console.log('test1 should not run'); | 
					
						
							|  |  |  |  |         expect(1 + 1).toBe(2); | 
					
						
							|  |  |  |  |       }); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |       test.fail.only('test2', () => { | 
					
						
							|  |  |  |  |         console.log('test2 should run and fail'); | 
					
						
							|  |  |  |  |         expect(1 + 1).toBe(3); | 
					
						
							|  |  |  |  |       }); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |       test('test3', () => { | 
					
						
							|  |  |  |  |         console.log('test3 should not run'); | 
					
						
							|  |  |  |  |         expect(1 + 1).toBe(2); | 
					
						
							|  |  |  |  |       }); | 
					
						
							|  |  |  |  |     `,
 | 
					
						
							|  |  |  |  |   }); | 
					
						
							|  |  |  |  |   expect(result.exitCode).toBe(0); | 
					
						
							|  |  |  |  |   expect(result.passed).toBe(1); | 
					
						
							|  |  |  |  |   expect(result.failed).toBe(0); | 
					
						
							|  |  |  |  |   expect(result.skipped).toBe(0); | 
					
						
							|  |  |  |  |   expect(result.output).toContain('test2 should run and fail'); | 
					
						
							|  |  |  |  |   expect(result.output).not.toContain('test1 should not run'); | 
					
						
							|  |  |  |  |   expect(result.output).not.toContain('test3 should not run'); | 
					
						
							|  |  |  |  | }); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-07 08:09:53 +08:00
										 |  |  |  | test('skip should take priority over fail', async ({ runInlineTest }) => { | 
					
						
							|  |  |  |  |   const { passed, skipped, failed } = await runInlineTest({ | 
					
						
							|  |  |  |  |     'test.spec.ts': `
 | 
					
						
							| 
									
										
										
										
											2023-02-15 11:20:56 +08:00
										 |  |  |  |       import { test, expect } from '@playwright/test'; | 
					
						
							| 
									
										
										
										
											2021-06-07 08:09:53 +08:00
										 |  |  |  |       test.describe('failing suite', () => { | 
					
						
							|  |  |  |  |         test.fail(); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         test('skipped', () => { | 
					
						
							|  |  |  |  |           test.skip(); | 
					
						
							|  |  |  |  |           expect(1 + 1).toBe(3); | 
					
						
							|  |  |  |  |         }); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         test('passing', () => { | 
					
						
							|  |  |  |  |           expect(1 + 1).toBe(3); | 
					
						
							|  |  |  |  |         }); | 
					
						
							|  |  |  |  |         test('passing2', () => { | 
					
						
							|  |  |  |  |           expect(1 + 1).toBe(3); | 
					
						
							|  |  |  |  |         }); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         test('failing', () => { | 
					
						
							|  |  |  |  |           expect(1 + 1).toBe(2); | 
					
						
							|  |  |  |  |         }); | 
					
						
							|  |  |  |  |       }); | 
					
						
							|  |  |  |  |     `
 | 
					
						
							|  |  |  |  |   }); | 
					
						
							|  |  |  |  |   expect(passed).toBe(2); | 
					
						
							|  |  |  |  |   expect(skipped).toBe(1); | 
					
						
							|  |  |  |  |   expect(failed).toBe(1); | 
					
						
							|  |  |  |  | }); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-22 02:25:15 +08:00
										 |  |  |  | test('should focus test from one project', async ({ runInlineTest }) => { | 
					
						
							| 
									
										
										
										
											2021-06-07 08:09:53 +08:00
										 |  |  |  |   const { exitCode, passed, skipped, failed } = await runInlineTest({ | 
					
						
							|  |  |  |  |     'playwright.config.ts': `
 | 
					
						
							|  |  |  |  |       import * as path from 'path'; | 
					
						
							|  |  |  |  |       module.exports = { projects: [ | 
					
						
							|  |  |  |  |         { testDir: path.join(__dirname, 'a') }, | 
					
						
							|  |  |  |  |         { testDir: path.join(__dirname, 'b') }, | 
					
						
							|  |  |  |  |       ] }; | 
					
						
							|  |  |  |  |     `,
 | 
					
						
							|  |  |  |  |     'a/afile.spec.ts': `
 | 
					
						
							| 
									
										
										
										
											2023-02-15 11:20:56 +08:00
										 |  |  |  |       import { test, expect } from '@playwright/test'; | 
					
						
							| 
									
										
										
										
											2021-06-07 08:09:53 +08:00
										 |  |  |  |       test('just a test', () => { | 
					
						
							|  |  |  |  |         expect(1 + 1).toBe(3); | 
					
						
							|  |  |  |  |       }); | 
					
						
							|  |  |  |  |     `,
 | 
					
						
							|  |  |  |  |     'b/bfile.spec.ts': `
 | 
					
						
							| 
									
										
										
										
											2023-02-15 11:20:56 +08:00
										 |  |  |  |       import { test, expect } from '@playwright/test'; | 
					
						
							| 
									
										
										
										
											2021-06-07 08:09:53 +08:00
										 |  |  |  |       test.only('focused test', () => { | 
					
						
							|  |  |  |  |         expect(1 + 1).toBe(2); | 
					
						
							|  |  |  |  |       }); | 
					
						
							|  |  |  |  |     `,
 | 
					
						
							|  |  |  |  |   }, { reporter: 'list,json' }); | 
					
						
							|  |  |  |  |   expect(passed).toBe(1); | 
					
						
							|  |  |  |  |   expect(failed).toBe(0); | 
					
						
							|  |  |  |  |   expect(skipped).toBe(0); | 
					
						
							|  |  |  |  |   expect(exitCode).toBe(0); | 
					
						
							|  |  |  |  | }); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | test('should work with default export', async ({ runInlineTest }) => { | 
					
						
							|  |  |  |  |   const result = await runInlineTest({ | 
					
						
							|  |  |  |  |     'file.spec.ts': `
 | 
					
						
							| 
									
										
										
										
											2021-10-11 22:52:17 +08:00
										 |  |  |  |       import t from '@playwright/test'; | 
					
						
							| 
									
										
										
										
											2021-06-07 08:09:53 +08:00
										 |  |  |  |       t('passed', () => { | 
					
						
							|  |  |  |  |         t.expect(1 + 1).toBe(2); | 
					
						
							|  |  |  |  |       }); | 
					
						
							|  |  |  |  |     `
 | 
					
						
							|  |  |  |  |   }); | 
					
						
							|  |  |  |  |   expect(result.exitCode).toBe(0); | 
					
						
							|  |  |  |  |   expect(result.passed).toBe(1); | 
					
						
							|  |  |  |  |   expect(result.failed).toBe(0); | 
					
						
							|  |  |  |  | }); | 
					
						
							| 
									
										
										
										
											2021-06-22 02:25:15 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | test('should work with test wrapper', async ({ runInlineTest }) => { | 
					
						
							|  |  |  |  |   const result = await runInlineTest({ | 
					
						
							|  |  |  |  |     'helper.js': `
 | 
					
						
							| 
									
										
										
										
											2023-02-15 11:20:56 +08:00
										 |  |  |  |       const { test, expect } = require('@playwright/test'); | 
					
						
							| 
									
										
										
										
											2021-06-22 02:25:15 +08:00
										 |  |  |  |       console.log('%%helper'); | 
					
						
							|  |  |  |  |       exports.wrap = (title, fn) => { | 
					
						
							| 
									
										
										
										
											2023-02-15 11:20:56 +08:00
										 |  |  |  |         test(title, fn); | 
					
						
							| 
									
										
										
										
											2021-06-22 02:25:15 +08:00
										 |  |  |  |       }; | 
					
						
							|  |  |  |  |     `,
 | 
					
						
							| 
									
										
										
										
											2023-02-15 11:20:56 +08:00
										 |  |  |  |     'a.spec.ts': `
 | 
					
						
							|  |  |  |  |       import { test, expect } from '@playwright/test'; | 
					
						
							| 
									
										
										
										
											2021-06-22 02:25:15 +08:00
										 |  |  |  |       console.log('%%a.spec'); | 
					
						
							|  |  |  |  |       const { wrap } = require('./helper'); | 
					
						
							|  |  |  |  |       wrap('test1', () => { | 
					
						
							|  |  |  |  |         console.log('%%test1'); | 
					
						
							|  |  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2023-02-15 11:20:56 +08:00
										 |  |  |  |       test.describe('suite1', () => { | 
					
						
							| 
									
										
										
										
											2021-06-22 02:25:15 +08:00
										 |  |  |  |         wrap('suite1.test1', () => { | 
					
						
							|  |  |  |  |           console.log('%%suite1.test1'); | 
					
						
							|  |  |  |  |         }); | 
					
						
							|  |  |  |  |       }); | 
					
						
							|  |  |  |  |     `,
 | 
					
						
							| 
									
										
										
										
											2023-02-15 11:20:56 +08:00
										 |  |  |  |     'b.spec.ts': `
 | 
					
						
							|  |  |  |  |       import { test, expect } from '@playwright/test'; | 
					
						
							| 
									
										
										
										
											2021-06-22 02:25:15 +08:00
										 |  |  |  |       console.log('%%b.spec'); | 
					
						
							|  |  |  |  |       const { wrap } = require('./helper'); | 
					
						
							|  |  |  |  |       wrap('test2', () => { | 
					
						
							|  |  |  |  |         console.log('%%test2'); | 
					
						
							|  |  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2023-02-15 11:20:56 +08:00
										 |  |  |  |       test.describe('suite2', () => { | 
					
						
							| 
									
										
										
										
											2021-06-22 02:25:15 +08:00
										 |  |  |  |         wrap('suite2.test2', () => { | 
					
						
							|  |  |  |  |           console.log('%%suite2.test2'); | 
					
						
							|  |  |  |  |         }); | 
					
						
							|  |  |  |  |       }); | 
					
						
							|  |  |  |  |     `,
 | 
					
						
							|  |  |  |  |   }, { workers: 1, reporter: 'line' }); | 
					
						
							|  |  |  |  |   expect(result.passed).toBe(4); | 
					
						
							|  |  |  |  |   expect(result.exitCode).toBe(0); | 
					
						
							| 
									
										
										
										
											2023-02-08 07:11:44 +08:00
										 |  |  |  |   expect(result.outputLines).toEqual([ | 
					
						
							|  |  |  |  |     'a.spec', | 
					
						
							|  |  |  |  |     'helper', | 
					
						
							|  |  |  |  |     'b.spec', | 
					
						
							|  |  |  |  |     'a.spec', | 
					
						
							|  |  |  |  |     'helper', | 
					
						
							|  |  |  |  |     'test1', | 
					
						
							|  |  |  |  |     'suite1.test1', | 
					
						
							|  |  |  |  |     'b.spec', | 
					
						
							|  |  |  |  |     'test2', | 
					
						
							|  |  |  |  |     'suite2.test2', | 
					
						
							| 
									
										
										
										
											2021-06-22 02:25:15 +08:00
										 |  |  |  |   ]); | 
					
						
							|  |  |  |  | }); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | test('should work with test helper', async ({ runInlineTest }) => { | 
					
						
							|  |  |  |  |   const result = await runInlineTest({ | 
					
						
							| 
									
										
										
										
											2023-02-15 11:20:56 +08:00
										 |  |  |  |     'helper-a.ts': `
 | 
					
						
							|  |  |  |  |       import { test, expect } from '@playwright/test'; | 
					
						
							| 
									
										
										
										
											2021-06-22 02:25:15 +08:00
										 |  |  |  |       console.log('%%helper-a'); | 
					
						
							| 
									
										
										
										
											2023-02-15 11:20:56 +08:00
										 |  |  |  |       test('test1', () => { | 
					
						
							| 
									
										
										
										
											2021-06-22 02:25:15 +08:00
										 |  |  |  |         console.log('%%test1'); | 
					
						
							|  |  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2023-02-15 11:20:56 +08:00
										 |  |  |  |       test.describe('suite1', () => { | 
					
						
							|  |  |  |  |         test('suite1.test1', () => { | 
					
						
							| 
									
										
										
										
											2021-06-22 02:25:15 +08:00
										 |  |  |  |           console.log('%%suite1.test1'); | 
					
						
							|  |  |  |  |         }); | 
					
						
							|  |  |  |  |       }); | 
					
						
							|  |  |  |  |     `,
 | 
					
						
							| 
									
										
										
										
											2023-02-15 11:20:56 +08:00
										 |  |  |  |     'a.spec.ts': `
 | 
					
						
							| 
									
										
										
										
											2021-06-22 02:25:15 +08:00
										 |  |  |  |       console.log('%%a.spec'); | 
					
						
							|  |  |  |  |       require('./helper-a'); | 
					
						
							|  |  |  |  |     `,
 | 
					
						
							| 
									
										
										
										
											2023-02-15 11:20:56 +08:00
										 |  |  |  |     'helper-b.ts': `
 | 
					
						
							|  |  |  |  |       import { test, expect } from '@playwright/test'; | 
					
						
							| 
									
										
										
										
											2021-06-22 02:25:15 +08:00
										 |  |  |  |       console.log('%%helper-b'); | 
					
						
							| 
									
										
										
										
											2023-02-15 11:20:56 +08:00
										 |  |  |  |       test('test1', () => { | 
					
						
							| 
									
										
										
										
											2021-06-22 02:25:15 +08:00
										 |  |  |  |         console.log('%%test2'); | 
					
						
							|  |  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2023-02-15 11:20:56 +08:00
										 |  |  |  |       test.describe('suite2', () => { | 
					
						
							|  |  |  |  |         test('suite2.test2', () => { | 
					
						
							| 
									
										
										
										
											2021-06-22 02:25:15 +08:00
										 |  |  |  |           console.log('%%suite2.test2'); | 
					
						
							|  |  |  |  |         }); | 
					
						
							|  |  |  |  |       }); | 
					
						
							|  |  |  |  |     `,
 | 
					
						
							| 
									
										
										
										
											2023-02-15 11:20:56 +08:00
										 |  |  |  |     'b.spec.ts': `
 | 
					
						
							| 
									
										
										
										
											2021-06-22 02:25:15 +08:00
										 |  |  |  |       console.log('%%b.spec'); | 
					
						
							|  |  |  |  |       require('./helper-b'); | 
					
						
							|  |  |  |  |     `,
 | 
					
						
							|  |  |  |  |   }, { workers: 1, reporter: 'line' }); | 
					
						
							|  |  |  |  |   expect(result.passed).toBe(4); | 
					
						
							|  |  |  |  |   expect(result.exitCode).toBe(0); | 
					
						
							| 
									
										
										
										
											2023-02-08 07:11:44 +08:00
										 |  |  |  |   expect(result.outputLines).toEqual([ | 
					
						
							|  |  |  |  |     'a.spec', | 
					
						
							|  |  |  |  |     'helper-a', | 
					
						
							|  |  |  |  |     'b.spec', | 
					
						
							|  |  |  |  |     'helper-b', | 
					
						
							|  |  |  |  |     'a.spec', | 
					
						
							|  |  |  |  |     'helper-a', | 
					
						
							|  |  |  |  |     'test1', | 
					
						
							|  |  |  |  |     'suite1.test1', | 
					
						
							|  |  |  |  |     'b.spec', | 
					
						
							|  |  |  |  |     'helper-b', | 
					
						
							|  |  |  |  |     'test2', | 
					
						
							|  |  |  |  |     'suite2.test2', | 
					
						
							| 
									
										
										
										
											2021-06-22 02:25:15 +08:00
										 |  |  |  |   ]); | 
					
						
							|  |  |  |  | }); | 
					
						
							| 
									
										
										
										
											2021-07-23 03:34:37 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-07 04:54:11 +08:00
										 |  |  |  | test('should support describe() without a title', async ({ runInlineTest }) => { | 
					
						
							| 
									
										
										
										
											2021-07-23 03:34:37 +08:00
										 |  |  |  |   const result = await runInlineTest({ | 
					
						
							| 
									
										
										
										
											2023-02-15 11:20:56 +08:00
										 |  |  |  |     'a.spec.ts': `
 | 
					
						
							|  |  |  |  |       import { test, expect } from '@playwright/test'; | 
					
						
							|  |  |  |  |       test.describe('suite1', () => { | 
					
						
							|  |  |  |  |         test.describe(() => { | 
					
						
							|  |  |  |  |           test.describe('suite2', () => { | 
					
						
							|  |  |  |  |             test('my test', () => {}); | 
					
						
							| 
									
										
										
										
											2022-07-07 04:54:11 +08:00
										 |  |  |  |           }); | 
					
						
							|  |  |  |  |         }); | 
					
						
							|  |  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2021-07-23 03:34:37 +08:00
										 |  |  |  |     `,
 | 
					
						
							| 
									
										
										
										
											2022-07-07 04:54:11 +08:00
										 |  |  |  |   }, { reporter: 'list' }); | 
					
						
							|  |  |  |  |   expect(result.exitCode).toBe(0); | 
					
						
							|  |  |  |  |   expect(result.passed).toBe(1); | 
					
						
							| 
									
										
										
										
											2023-02-15 11:20:56 +08:00
										 |  |  |  |   expect(result.output).toContain('a.spec.ts:6:17 › suite1 › suite2 › my test'); | 
					
						
							| 
									
										
										
										
											2021-07-23 03:34:37 +08:00
										 |  |  |  | }); | 
					
						
							| 
									
										
										
										
											2021-07-30 05:33:37 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-20 03:40:40 +08:00
										 |  |  |  | test('test.{skip,fixme} should define a skipped test', async ({ runInlineTest }) => { | 
					
						
							| 
									
										
										
										
											2021-07-30 05:33:37 +08:00
										 |  |  |  |   const result = await runInlineTest({ | 
					
						
							|  |  |  |  |     'a.test.ts': `
 | 
					
						
							| 
									
										
										
										
											2023-02-15 11:20:56 +08:00
										 |  |  |  |       import { test, expect } from '@playwright/test'; | 
					
						
							| 
									
										
										
										
											2021-07-30 05:33:37 +08:00
										 |  |  |  |       const logs = []; | 
					
						
							|  |  |  |  |       test.skip('foo', () => { | 
					
						
							|  |  |  |  |         console.log('%%dontseethis'); | 
					
						
							|  |  |  |  |         throw new Error('foo'); | 
					
						
							|  |  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2021-11-20 03:40:40 +08:00
										 |  |  |  |       test.fixme('bar', () => { | 
					
						
							|  |  |  |  |         console.log('%%dontseethis'); | 
					
						
							|  |  |  |  |         throw new Error('bar'); | 
					
						
							|  |  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2021-07-30 05:33:37 +08:00
										 |  |  |  |     `,
 | 
					
						
							|  |  |  |  |   }); | 
					
						
							|  |  |  |  |   expect(result.exitCode).toBe(0); | 
					
						
							| 
									
										
										
										
											2021-11-20 03:40:40 +08:00
										 |  |  |  |   expect(result.skipped).toBe(2); | 
					
						
							| 
									
										
										
										
											2021-07-30 05:33:37 +08:00
										 |  |  |  |   expect(result.output).not.toContain('%%dontseethis'); | 
					
						
							|  |  |  |  | }); | 
					
						
							| 
									
										
										
										
											2021-09-01 01:50:30 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-25 06:03:49 +08:00
										 |  |  |  | test('should report unhandled error during test and not report timeout', async ({ runInlineTest }) => { | 
					
						
							|  |  |  |  |   const result = await runInlineTest({ | 
					
						
							|  |  |  |  |     'a.test.ts': `
 | 
					
						
							|  |  |  |  |       import { test, expect } from '@playwright/test'; | 
					
						
							|  |  |  |  |       test('unhandled rejection', async () => { | 
					
						
							|  |  |  |  |         setTimeout(() => { | 
					
						
							|  |  |  |  |           throw new Error('Unhandled'); | 
					
						
							|  |  |  |  |         }, 0); | 
					
						
							|  |  |  |  |         await new Promise(f => setTimeout(f, 100)); | 
					
						
							|  |  |  |  |       }); | 
					
						
							|  |  |  |  |     `,
 | 
					
						
							|  |  |  |  |   }); | 
					
						
							|  |  |  |  |   expect(result.exitCode).toBe(1); | 
					
						
							|  |  |  |  |   expect(result.failed).toBe(1); | 
					
						
							|  |  |  |  |   expect(result.output).toContain('Error: Unhandled'); | 
					
						
							|  |  |  |  |   expect(result.output).not.toContain('Test timeout of 30000ms exceeded'); | 
					
						
							|  |  |  |  | }); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-01 01:50:30 +08:00
										 |  |  |  | test('should report unhandled rejection during worker shutdown', async ({ runInlineTest }) => { | 
					
						
							|  |  |  |  |   const result = await runInlineTest({ | 
					
						
							|  |  |  |  |     'a.test.ts': `
 | 
					
						
							| 
									
										
										
										
											2023-02-15 11:20:56 +08:00
										 |  |  |  |       import { test, expect } from '@playwright/test'; | 
					
						
							| 
									
										
										
										
											2021-09-01 01:50:30 +08:00
										 |  |  |  |       test('unhandled rejection', async () => { | 
					
						
							|  |  |  |  |         new Promise((f, r) => r(new Error('Unhandled'))); | 
					
						
							|  |  |  |  |       }); | 
					
						
							|  |  |  |  |     `,
 | 
					
						
							|  |  |  |  |   }); | 
					
						
							|  |  |  |  |   expect(result.exitCode).toBe(1); | 
					
						
							|  |  |  |  |   expect(result.passed).toBe(1); | 
					
						
							|  |  |  |  |   expect(result.output).toContain('Error: Unhandled'); | 
					
						
							| 
									
										
										
										
											2023-02-15 11:20:56 +08:00
										 |  |  |  |   expect(result.output).toContain('a.test.ts:4:33'); | 
					
						
							| 
									
										
										
										
											2021-09-01 01:50:30 +08:00
										 |  |  |  | }); | 
					
						
							| 
									
										
										
										
											2021-10-30 04:36:12 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | test('should not reuse worker after unhandled rejection in test.fail', async ({ runInlineTest }) => { | 
					
						
							|  |  |  |  |   const result = await runInlineTest({ | 
					
						
							|  |  |  |  |     'a.spec.ts': `
 | 
					
						
							| 
									
										
										
										
											2023-02-15 11:20:56 +08:00
										 |  |  |  |       import { test as base, expect } from '@playwright/test'; | 
					
						
							|  |  |  |  |       const test = base.extend({ | 
					
						
							| 
									
										
										
										
											2021-10-30 04:36:12 +08:00
										 |  |  |  |         needsCleanup: async ({}, use) => { | 
					
						
							|  |  |  |  |           await use(); | 
					
						
							|  |  |  |  |           await new Promise(f => setTimeout(f, 3000)); | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |       }); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |       test('failing', async ({ needsCleanup }) => { | 
					
						
							|  |  |  |  |         test.fail(); | 
					
						
							|  |  |  |  |         new Promise(() => { throw new Error('Oh my!') }); | 
					
						
							|  |  |  |  |       }); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |       test('passing', async () => { | 
					
						
							|  |  |  |  |       }); | 
					
						
							|  |  |  |  |     `
 | 
					
						
							|  |  |  |  |   }, { workers: 1 }); | 
					
						
							| 
									
										
										
										
											2023-10-24 00:14:31 +08:00
										 |  |  |  |   expect(result.exitCode).toBe(0); | 
					
						
							|  |  |  |  |   expect(result.failed).toBe(0); | 
					
						
							|  |  |  |  |   expect(result.passed).toBe(2); | 
					
						
							|  |  |  |  |   expect(result.output).not.toContain(`Oh my!`); | 
					
						
							| 
									
										
										
										
											2021-10-30 04:36:12 +08:00
										 |  |  |  |   expect(result.output).not.toContain(`Did not teardown test scope`); | 
					
						
							|  |  |  |  | }); | 
					
						
							| 
									
										
										
										
											2022-02-04 09:14:12 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | test('should allow unhandled expects in test.fail', async ({ runInlineTest }) => { | 
					
						
							|  |  |  |  |   const result = await runInlineTest({ | 
					
						
							|  |  |  |  |     'a.spec.ts': `
 | 
					
						
							| 
									
										
										
										
											2023-02-15 11:20:56 +08:00
										 |  |  |  |       import { test, expect } from '@playwright/test'; | 
					
						
							| 
									
										
										
										
											2022-02-04 09:14:12 +08:00
										 |  |  |  |       test('failing1', async ({}) => { | 
					
						
							|  |  |  |  |         test.fail(); | 
					
						
							|  |  |  |  |         Promise.resolve().then(() => expect(1).toBe(2)); | 
					
						
							|  |  |  |  |         await new Promise(f => setTimeout(f, 100)); | 
					
						
							|  |  |  |  |       }); | 
					
						
							|  |  |  |  |     `
 | 
					
						
							|  |  |  |  |   }); | 
					
						
							|  |  |  |  |   expect(result.exitCode).toBe(0); | 
					
						
							|  |  |  |  |   expect(result.passed).toBe(1); | 
					
						
							|  |  |  |  |   expect(result.output).not.toContain(`Error: expect`); | 
					
						
							|  |  |  |  | }); | 
					
						
							| 
									
										
										
										
											2022-03-19 07:07:11 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-24 23:32:14 +08:00
										 |  |  |  | test('should not skip tests after test.fail', async ({ runInlineTest, server }) => { | 
					
						
							|  |  |  |  |   const result = await runInlineTest({ | 
					
						
							|  |  |  |  |     'a.spec.ts': `
 | 
					
						
							|  |  |  |  |       import { test, expect } from '@playwright/test'; | 
					
						
							|  |  |  |  |       test('failing', async ({}) => { | 
					
						
							|  |  |  |  |         test.fail(); | 
					
						
							|  |  |  |  |         expect(Promise.resolve('a')).resolves.toBe('b'); | 
					
						
							|  |  |  |  |         await new Promise(f => setTimeout(f, 1000)); | 
					
						
							|  |  |  |  |       }); | 
					
						
							|  |  |  |  |     `,
 | 
					
						
							|  |  |  |  |     'b.spec.ts': `
 | 
					
						
							|  |  |  |  |       import { test, expect } from '@playwright/test'; | 
					
						
							|  |  |  |  |       test('passing', async ({}) => { | 
					
						
							|  |  |  |  |         console.log('b-passing'); | 
					
						
							|  |  |  |  |       }); | 
					
						
							|  |  |  |  |     `,
 | 
					
						
							|  |  |  |  |     'c.spec.ts': `
 | 
					
						
							|  |  |  |  |       import { test, expect } from '@playwright/test'; | 
					
						
							|  |  |  |  |       test('passing', async ({}) => { | 
					
						
							|  |  |  |  |         console.log('c-passing'); | 
					
						
							|  |  |  |  |       }); | 
					
						
							|  |  |  |  |     `,
 | 
					
						
							|  |  |  |  |   }, { workers: '1' }); | 
					
						
							|  |  |  |  |   expect(result.exitCode).toBe(0); | 
					
						
							|  |  |  |  |   expect(result.passed).toBe(3); | 
					
						
							|  |  |  |  |   expect(result.output).toContain('b-passing'); | 
					
						
							|  |  |  |  |   expect(result.output).toContain('c-passing'); | 
					
						
							|  |  |  |  | }); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-19 07:07:11 +08:00
										 |  |  |  | test('should support describe.skip', async ({ runInlineTest }) => { | 
					
						
							|  |  |  |  |   const result = await runInlineTest({ | 
					
						
							| 
									
										
										
										
											2023-02-15 11:20:56 +08:00
										 |  |  |  |     'nested-skip.spec.ts': `
 | 
					
						
							|  |  |  |  |       import { test, expect } from '@playwright/test'; | 
					
						
							| 
									
										
										
										
											2022-03-19 07:07:11 +08:00
										 |  |  |  |       test.describe.skip('skipped', () => { | 
					
						
							|  |  |  |  |         test.describe('nested', () => { | 
					
						
							|  |  |  |  |           test('test1', () => {}); | 
					
						
							|  |  |  |  |         }); | 
					
						
							|  |  |  |  |         test('test2', () => {}); | 
					
						
							|  |  |  |  |       }); | 
					
						
							|  |  |  |  |       test.describe('not skipped', () => { | 
					
						
							|  |  |  |  |         test.describe.skip('skipped', () => { | 
					
						
							|  |  |  |  |           test('test4', () => {}); | 
					
						
							|  |  |  |  |         }); | 
					
						
							|  |  |  |  |         test('test4', () => { | 
					
						
							|  |  |  |  |           console.log('heytest4'); | 
					
						
							|  |  |  |  |         }); | 
					
						
							|  |  |  |  |       }); | 
					
						
							|  |  |  |  |     `
 | 
					
						
							|  |  |  |  |   }); | 
					
						
							|  |  |  |  |   expect(result.exitCode).toBe(0); | 
					
						
							|  |  |  |  |   expect(result.passed).toBe(1); | 
					
						
							|  |  |  |  |   expect(result.skipped).toBe(3); | 
					
						
							|  |  |  |  |   expect(result.output).toContain('heytest4'); | 
					
						
							|  |  |  |  | }); | 
					
						
							| 
									
										
										
										
											2022-07-30 03:44:22 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | test('should support describe.fixme', async ({ runInlineTest }) => { | 
					
						
							|  |  |  |  |   const result = await runInlineTest({ | 
					
						
							| 
									
										
										
										
											2023-02-15 11:20:56 +08:00
										 |  |  |  |     'nested-skip.spec.ts': `
 | 
					
						
							|  |  |  |  |       import { test, expect } from '@playwright/test'; | 
					
						
							| 
									
										
										
										
											2022-07-30 03:44:22 +08:00
										 |  |  |  |       test.describe.fixme('skipped', () => { | 
					
						
							|  |  |  |  |         test.describe('nested', () => { | 
					
						
							|  |  |  |  |           test('test1', () => {}); | 
					
						
							|  |  |  |  |         }); | 
					
						
							|  |  |  |  |         test('test2', () => {}); | 
					
						
							|  |  |  |  |       }); | 
					
						
							|  |  |  |  |       test.describe('not skipped', () => { | 
					
						
							|  |  |  |  |         test.describe.fixme('skipped', () => { | 
					
						
							|  |  |  |  |           test('test4', () => {}); | 
					
						
							|  |  |  |  |         }); | 
					
						
							|  |  |  |  |         test('test4', () => { | 
					
						
							|  |  |  |  |           console.log('heytest4'); | 
					
						
							|  |  |  |  |         }); | 
					
						
							|  |  |  |  |       }); | 
					
						
							|  |  |  |  |     `
 | 
					
						
							|  |  |  |  |   }); | 
					
						
							|  |  |  |  |   expect(result.exitCode).toBe(0); | 
					
						
							|  |  |  |  |   expect(result.passed).toBe(1); | 
					
						
							|  |  |  |  |   expect(result.skipped).toBe(3); | 
					
						
							|  |  |  |  |   expect(result.output).toContain('heytest4'); | 
					
						
							|  |  |  |  | }); | 
					
						
							| 
									
										
										
										
											2024-10-16 21:47:23 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | test('should fail when test.fail.only passes unexpectedly', async ({ runInlineTest }) => { | 
					
						
							|  |  |  |  |   const result = await runInlineTest({ | 
					
						
							|  |  |  |  |     'fail-only-pass.spec.ts': `
 | 
					
						
							|  |  |  |  |       import { test, expect } from '@playwright/test'; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |       test('test1', () => { | 
					
						
							|  |  |  |  |         console.log('test1 should not run'); | 
					
						
							|  |  |  |  |         expect(1 + 1).toBe(2); | 
					
						
							|  |  |  |  |       }); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |       test.fail.only('test2', () => { | 
					
						
							|  |  |  |  |         console.log('test2 should run and pass unexpectedly'); | 
					
						
							|  |  |  |  |         expect(1 + 1).toBe(2); | 
					
						
							|  |  |  |  |       }); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |       test('test3', () => { | 
					
						
							|  |  |  |  |         console.log('test3 should not run'); | 
					
						
							|  |  |  |  |         expect(1 + 1).toBe(2); | 
					
						
							|  |  |  |  |       }); | 
					
						
							|  |  |  |  |     `,
 | 
					
						
							|  |  |  |  |   }); | 
					
						
							|  |  |  |  |   expect(result.exitCode).toBe(1); | 
					
						
							|  |  |  |  |   expect(result.passed).toBe(0); | 
					
						
							|  |  |  |  |   expect(result.failed).toBe(1); | 
					
						
							|  |  |  |  |   expect(result.skipped).toBe(0); | 
					
						
							|  |  |  |  |   expect(result.output).toContain('should run and pass unexpectedly'); | 
					
						
							|  |  |  |  |   expect(result.output).not.toContain('test1 should not run'); | 
					
						
							|  |  |  |  |   expect(result.output).not.toContain('test3 should not run'); | 
					
						
							|  |  |  |  | }); | 
					
						
							| 
									
										
										
										
											2025-04-11 05:39:33 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | test('should serialize circular objects', async ({ runInlineTest }) => { | 
					
						
							|  |  |  |  |   const result = await runInlineTest({ | 
					
						
							|  |  |  |  |     'one-failure.spec.ts': `
 | 
					
						
							|  |  |  |  |       import { test, expect } from '@playwright/test'; | 
					
						
							|  |  |  |  |       test('circular dependency', () => { | 
					
						
							|  |  |  |  |         const a = {}; | 
					
						
							|  |  |  |  |         a.b = a; | 
					
						
							|  |  |  |  |         expect(1).toEqual(a); | 
					
						
							|  |  |  |  |       }); | 
					
						
							|  |  |  |  |     `
 | 
					
						
							|  |  |  |  |   }); | 
					
						
							|  |  |  |  |   expect(result.exitCode).toBe(1); | 
					
						
							|  |  |  |  |   expect(result.passed).toBe(0); | 
					
						
							|  |  |  |  |   expect(result.failed).toBe(1); | 
					
						
							|  |  |  |  |   expect(result.output).toContain('Expected: {"b": [Circular]}'); | 
					
						
							|  |  |  |  | }); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | test('should serialize BigInt', async ({ runInlineTest }) => { | 
					
						
							|  |  |  |  |   const result = await runInlineTest({ | 
					
						
							|  |  |  |  |     'one-failure.spec.ts': `
 | 
					
						
							|  |  |  |  |       import { test, expect } from '@playwright/test'; | 
					
						
							|  |  |  |  |       test('BigInt', () => { | 
					
						
							|  |  |  |  |         expect(1).toEqual(1n); | 
					
						
							|  |  |  |  |       }); | 
					
						
							|  |  |  |  |     `
 | 
					
						
							|  |  |  |  |   }); | 
					
						
							|  |  |  |  |   expect(result.exitCode).toBe(1); | 
					
						
							|  |  |  |  |   expect(result.failed).toBe(1); | 
					
						
							|  |  |  |  |   expect(result.output).toContain('Expected: 1n'); | 
					
						
							|  |  |  |  | }); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | test('should report serialization error', async ({ runInlineTest }) => { | 
					
						
							|  |  |  |  |   const result = await runInlineTest({ | 
					
						
							|  |  |  |  |     'one-failure.spec.ts': `
 | 
					
						
							|  |  |  |  |       import { test, expect } from '@playwright/test'; | 
					
						
							|  |  |  |  |       test('function', () => { | 
					
						
							|  |  |  |  |         expect(1).toEqual({ a: () => {} }); | 
					
						
							|  |  |  |  |       }); | 
					
						
							|  |  |  |  |     `
 | 
					
						
							|  |  |  |  |   }); | 
					
						
							|  |  |  |  |   expect(result.exitCode).toBe(1); | 
					
						
							|  |  |  |  |   expect(result.passed).toBe(0); | 
					
						
							|  |  |  |  |   expect(result.output).toContain('Expected: {\"a\": [Function a]}'); | 
					
						
							|  |  |  |  | }); |