| 
									
										
										
										
											2021-06-06 17:09:53 -07: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-07 15:11:44 -08:00
										 |  |  | import { test, expect } from './playwright-test-fixtures'; | 
					
						
							| 
									
										
										
										
											2021-06-06 17:09:53 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | test('should run fixture teardown on timeout', async ({ runInlineTest }) => { | 
					
						
							|  |  |  |   const result = await runInlineTest({ | 
					
						
							|  |  |  |     'helper.ts': `
 | 
					
						
							| 
									
										
										
										
											2023-02-14 19:20:56 -08:00
										 |  |  |       import { test as base, expect } from '@playwright/test'; | 
					
						
							|  |  |  |       export const test = base.extend({ | 
					
						
							| 
									
										
										
										
											2021-06-06 17:09:53 -07:00
										 |  |  |         foo: async ({}, run, testInfo) => { | 
					
						
							|  |  |  |           await run(); | 
					
						
							|  |  |  |           console.log('STATUS:' + testInfo.status); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     `,
 | 
					
						
							|  |  |  |     'c.spec.ts': `
 | 
					
						
							|  |  |  |       import { test } from './helper'; | 
					
						
							|  |  |  |       test('works', async ({ foo }) => { | 
					
						
							|  |  |  |         await new Promise(f => setTimeout(f, 100000)); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     `
 | 
					
						
							|  |  |  |   }, { timeout: 1000 }); | 
					
						
							|  |  |  |   expect(result.exitCode).toBe(1); | 
					
						
							|  |  |  |   expect(result.failed).toBe(1); | 
					
						
							|  |  |  |   expect(result.output).toContain('STATUS:timedOut'); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test('should respect test.setTimeout', async ({ runInlineTest }) => { | 
					
						
							|  |  |  |   const result = await runInlineTest({ | 
					
						
							|  |  |  |     'a.spec.ts': `
 | 
					
						
							| 
									
										
										
										
											2023-02-14 19:20:56 -08:00
										 |  |  |       import { test, expect } from '@playwright/test'; | 
					
						
							| 
									
										
										
										
											2021-06-06 17:09:53 -07:00
										 |  |  |       test('fails', async ({}) => { | 
					
						
							|  |  |  |         await new Promise(f => setTimeout(f, 1500)); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       test('passes', async ({}) => { | 
					
						
							|  |  |  |         await new Promise(f => setTimeout(f, 500)); | 
					
						
							|  |  |  |         test.setTimeout(2000); | 
					
						
							|  |  |  |         await new Promise(f => setTimeout(f, 1000)); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       test.describe('suite', () => { | 
					
						
							|  |  |  |         test.beforeEach(() => { | 
					
						
							|  |  |  |           test.setTimeout(2000); | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |         test('passes2', async ({}, testInfo) => { | 
					
						
							|  |  |  |           expect(testInfo.timeout).toBe(2000); | 
					
						
							|  |  |  |           await new Promise(f => setTimeout(f, 1500)); | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     `
 | 
					
						
							|  |  |  |   }, { timeout: 1000 }); | 
					
						
							|  |  |  |   expect(result.exitCode).toBe(1); | 
					
						
							|  |  |  |   expect(result.failed).toBe(1); | 
					
						
							|  |  |  |   expect(result.passed).toBe(2); | 
					
						
							| 
									
										
										
										
											2022-06-30 17:05:08 -07:00
										 |  |  |   expect(result.output).toContain('Test timeout of 1000ms exceeded.'); | 
					
						
							| 
									
										
										
										
											2021-06-06 17:09:53 -07:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-29 13:33:13 -07:00
										 |  |  | test('should respect test.setTimeout outside of the test', async ({ runInlineTest }) => { | 
					
						
							|  |  |  |   const result = await runInlineTest({ | 
					
						
							|  |  |  |     'a.spec.ts': `
 | 
					
						
							| 
									
										
										
										
											2023-02-14 19:20:56 -08:00
										 |  |  |       import { test, expect } from '@playwright/test'; | 
					
						
							| 
									
										
										
										
											2021-06-29 13:33:13 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-22 17:31:02 -08:00
										 |  |  |       test.setTimeout(1000); | 
					
						
							| 
									
										
										
										
											2021-06-29 13:33:13 -07:00
										 |  |  |       test('fails', async ({}) => { | 
					
						
							| 
									
										
										
										
											2023-02-09 08:49:51 -08:00
										 |  |  |         await new Promise(f => setTimeout(f, 1100)); | 
					
						
							| 
									
										
										
										
											2021-06-29 13:33:13 -07:00
										 |  |  |       }); | 
					
						
							|  |  |  |       test('passes', async ({}) => { | 
					
						
							|  |  |  |         await new Promise(f => setTimeout(f, 100)); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       test.describe('suite', () => { | 
					
						
							| 
									
										
										
										
											2023-02-09 08:49:51 -08:00
										 |  |  |         test.setTimeout(500); | 
					
						
							| 
									
										
										
										
											2021-06-29 13:33:13 -07:00
										 |  |  |         test('fails', async ({}) => { | 
					
						
							| 
									
										
										
										
											2023-02-09 08:49:51 -08:00
										 |  |  |           await new Promise(f => setTimeout(f, 600)); | 
					
						
							| 
									
										
										
										
											2021-06-29 13:33:13 -07:00
										 |  |  |         }); | 
					
						
							|  |  |  |         test('passes', async ({}) => { | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     `
 | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  |   expect(result.exitCode).toBe(1); | 
					
						
							|  |  |  |   expect(result.failed).toBe(2); | 
					
						
							|  |  |  |   expect(result.passed).toBe(2); | 
					
						
							| 
									
										
										
										
											2022-12-22 17:31:02 -08:00
										 |  |  |   expect(result.output).toContain('Test timeout of 1000ms exceeded.'); | 
					
						
							| 
									
										
										
										
											2023-02-09 08:49:51 -08:00
										 |  |  |   expect(result.output).toContain('Test timeout of 500ms exceeded.'); | 
					
						
							| 
									
										
										
										
											2021-06-29 13:33:13 -07:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-06 17:09:53 -07:00
										 |  |  | test('should timeout when calling test.setTimeout too late', async ({ runInlineTest }) => { | 
					
						
							|  |  |  |   const result = await runInlineTest({ | 
					
						
							|  |  |  |     'a.spec.ts': `
 | 
					
						
							| 
									
										
										
										
											2023-02-14 19:20:56 -08:00
										 |  |  |       import { test, expect } from '@playwright/test'; | 
					
						
							| 
									
										
										
										
											2021-06-06 17:09:53 -07:00
										 |  |  |       test('fails', async ({}) => { | 
					
						
							|  |  |  |         await new Promise(f => setTimeout(f, 500)); | 
					
						
							|  |  |  |         test.setTimeout(100); | 
					
						
							|  |  |  |         await new Promise(f => setTimeout(f, 1)); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     `
 | 
					
						
							|  |  |  |   }, { timeout: 1000 }); | 
					
						
							|  |  |  |   expect(result.exitCode).toBe(1); | 
					
						
							|  |  |  |   expect(result.failed).toBe(1); | 
					
						
							|  |  |  |   expect(result.passed).toBe(0); | 
					
						
							| 
									
										
										
										
											2022-06-30 17:05:08 -07:00
										 |  |  |   expect(result.output).toContain('Test timeout of 100ms exceeded.'); | 
					
						
							| 
									
										
										
										
											2021-06-06 17:09:53 -07:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test('should respect test.slow', async ({ runInlineTest }) => { | 
					
						
							|  |  |  |   const result = await runInlineTest({ | 
					
						
							|  |  |  |     'a.spec.ts': `
 | 
					
						
							| 
									
										
										
										
											2023-02-14 19:20:56 -08:00
										 |  |  |       import { test, expect } from '@playwright/test'; | 
					
						
							| 
									
										
										
										
											2021-06-06 17:09:53 -07:00
										 |  |  |       test('fails', async ({}) => { | 
					
						
							|  |  |  |         await new Promise(f => setTimeout(f, 1500)); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       test('passes', async ({}) => { | 
					
						
							|  |  |  |         test.slow(); | 
					
						
							|  |  |  |         await new Promise(f => setTimeout(f, 1500)); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       test.describe('suite', () => { | 
					
						
							|  |  |  |         test.slow(); | 
					
						
							|  |  |  |         test('passes2', async ({}, testInfo) => { | 
					
						
							|  |  |  |           expect(testInfo.timeout).toBe(3000); | 
					
						
							|  |  |  |           await new Promise(f => setTimeout(f, 1500)); | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     `
 | 
					
						
							|  |  |  |   }, { timeout: 1000 }); | 
					
						
							|  |  |  |   expect(result.exitCode).toBe(1); | 
					
						
							|  |  |  |   expect(result.failed).toBe(1); | 
					
						
							|  |  |  |   expect(result.passed).toBe(2); | 
					
						
							| 
									
										
										
										
											2022-06-30 17:05:08 -07:00
										 |  |  |   expect(result.output).toContain('Test timeout of 1000ms exceeded.'); | 
					
						
							| 
									
										
										
										
											2021-06-06 17:09:53 -07:00
										 |  |  | }); | 
					
						
							| 
									
										
										
										
											2021-12-17 15:17:48 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | test('should ignore test.setTimeout when debugging', async ({ runInlineTest }) => { | 
					
						
							|  |  |  |   const result = await runInlineTest({ | 
					
						
							|  |  |  |     'a.spec.ts': `
 | 
					
						
							| 
									
										
										
										
											2023-02-14 19:20:56 -08:00
										 |  |  |       import { test as base, expect } from '@playwright/test'; | 
					
						
							|  |  |  |       const test = base.extend({ | 
					
						
							| 
									
										
										
										
											2022-03-17 09:36:03 -07:00
										 |  |  |         fixture: async ({}, use) => { | 
					
						
							|  |  |  |           test.setTimeout(100); | 
					
						
							|  |  |  |           await new Promise(f => setTimeout(f, 200)); | 
					
						
							|  |  |  |           await use('hey'); | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       test('my test', async ({ fixture }) => { | 
					
						
							| 
									
										
										
										
											2021-12-17 15:17:48 -08:00
										 |  |  |         test.setTimeout(1000); | 
					
						
							|  |  |  |         await new Promise(f => setTimeout(f, 2000)); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     `
 | 
					
						
							|  |  |  |   }, { timeout: 0 }); | 
					
						
							|  |  |  |   expect(result.exitCode).toBe(0); | 
					
						
							|  |  |  |   expect(result.passed).toBe(1); | 
					
						
							|  |  |  | }); | 
					
						
							| 
									
										
										
										
											2022-03-17 09:36:03 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | test('should respect fixture timeout', async ({ runInlineTest }) => { | 
					
						
							|  |  |  |   const result = await runInlineTest({ | 
					
						
							|  |  |  |     'a.spec.ts': `
 | 
					
						
							| 
									
										
										
										
											2023-02-14 19:20:56 -08:00
										 |  |  |       import { test as base, expect } from '@playwright/test'; | 
					
						
							|  |  |  |       const test = base.extend({ | 
					
						
							| 
									
										
										
										
											2022-03-17 09:36:03 -07:00
										 |  |  |         fixture: [async ({}, use) => { | 
					
						
							|  |  |  |           await new Promise(f => setTimeout(f, 300)); | 
					
						
							|  |  |  |           await use('hey'); | 
					
						
							|  |  |  |           await new Promise(f => setTimeout(f, 300)); | 
					
						
							|  |  |  |         }, { timeout: 1000 }], | 
					
						
							|  |  |  |         noTimeout: [async ({}, use) => { | 
					
						
							|  |  |  |           await new Promise(f => setTimeout(f, 300)); | 
					
						
							|  |  |  |           await use('hey'); | 
					
						
							|  |  |  |           await new Promise(f => setTimeout(f, 300)); | 
					
						
							|  |  |  |         }, { timeout: 0 }], | 
					
						
							|  |  |  |         slowSetup: [async ({}, use) => { | 
					
						
							|  |  |  |           await new Promise(f => setTimeout(f, 2000)); | 
					
						
							|  |  |  |           await use('hey'); | 
					
						
							| 
									
										
										
										
											2022-04-13 15:13:31 -07:00
										 |  |  |         }, { timeout: 500, _title: 'custom title' }], | 
					
						
							| 
									
										
										
										
											2022-03-17 09:36:03 -07:00
										 |  |  |         slowTeardown: [async ({}, use) => { | 
					
						
							|  |  |  |           await use('hey'); | 
					
						
							|  |  |  |           await new Promise(f => setTimeout(f, 2000)); | 
					
						
							|  |  |  |         }, { timeout: 400 }], | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       test('test ok', async ({ fixture, noTimeout }) => { | 
					
						
							|  |  |  |         await new Promise(f => setTimeout(f, 1000)); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       test('test setup', async ({ slowSetup }) => { | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       test('test teardown', async ({ slowTeardown }) => { | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     `
 | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  |   expect(result.exitCode).toBe(1); | 
					
						
							|  |  |  |   expect(result.passed).toBe(1); | 
					
						
							|  |  |  |   expect(result.failed).toBe(2); | 
					
						
							| 
									
										
										
										
											2023-03-10 13:45:47 -08:00
										 |  |  |   expect(result.output).toContain('Fixture "custom title" timeout of 500ms exceeded during setup.'); | 
					
						
							|  |  |  |   expect(result.output).toContain('Fixture "slowTeardown" timeout of 400ms exceeded during teardown.'); | 
					
						
							| 
									
										
										
										
											2023-02-14 19:20:56 -08:00
										 |  |  |   expect(result.output).toContain('> 3 |       const test = base.extend({'); | 
					
						
							| 
									
										
										
										
											2022-03-17 09:36:03 -07:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test('should respect test.setTimeout in the worker fixture', async ({ runInlineTest }) => { | 
					
						
							|  |  |  |   const result = await runInlineTest({ | 
					
						
							|  |  |  |     'a.spec.ts': `
 | 
					
						
							| 
									
										
										
										
											2023-02-14 19:20:56 -08:00
										 |  |  |       import { test as base, expect } from '@playwright/test'; | 
					
						
							|  |  |  |       const test = base.extend({ | 
					
						
							| 
									
										
										
										
											2022-03-17 09:36:03 -07:00
										 |  |  |         fixture: [async ({}, use) => { | 
					
						
							|  |  |  |           await new Promise(f => setTimeout(f, 300)); | 
					
						
							|  |  |  |           await use('hey'); | 
					
						
							|  |  |  |           await new Promise(f => setTimeout(f, 300)); | 
					
						
							|  |  |  |         }, { scope: 'worker', timeout: 1000 }], | 
					
						
							|  |  |  |         noTimeout: [async ({}, use) => { | 
					
						
							|  |  |  |           await new Promise(f => setTimeout(f, 300)); | 
					
						
							|  |  |  |           await use('hey'); | 
					
						
							|  |  |  |           await new Promise(f => setTimeout(f, 300)); | 
					
						
							|  |  |  |         }, { scope: 'worker', timeout: 0 }], | 
					
						
							|  |  |  |         slowSetup: [async ({}, use) => { | 
					
						
							|  |  |  |           await new Promise(f => setTimeout(f, 2000)); | 
					
						
							|  |  |  |           await use('hey'); | 
					
						
							|  |  |  |         }, { scope: 'worker', timeout: 500 }], | 
					
						
							|  |  |  |         slowTeardown: [async ({}, use) => { | 
					
						
							|  |  |  |           await use('hey'); | 
					
						
							|  |  |  |           await new Promise(f => setTimeout(f, 2000)); | 
					
						
							| 
									
										
										
										
											2022-04-13 15:13:31 -07:00
										 |  |  |         }, { scope: 'worker', timeout: 400, _title: 'custom title' }], | 
					
						
							| 
									
										
										
										
											2022-03-17 09:36:03 -07:00
										 |  |  |       }); | 
					
						
							|  |  |  |       test('test ok', async ({ fixture, noTimeout }) => { | 
					
						
							|  |  |  |         await new Promise(f => setTimeout(f, 1000)); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       test('test setup', async ({ slowSetup }) => { | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       test('test teardown', async ({ slowTeardown }) => { | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     `
 | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  |   expect(result.exitCode).toBe(1); | 
					
						
							|  |  |  |   expect(result.passed).toBe(2); | 
					
						
							|  |  |  |   expect(result.failed).toBe(1); | 
					
						
							| 
									
										
										
										
											2023-03-10 13:45:47 -08:00
										 |  |  |   expect(result.output).toContain('Fixture "slowSetup" timeout of 500ms exceeded during setup.'); | 
					
						
							|  |  |  |   expect(result.output).toContain('Fixture "custom title" timeout of 400ms exceeded during teardown.'); | 
					
						
							| 
									
										
										
										
											2022-03-17 09:36:03 -07:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test('fixture time in beforeAll hook should not affect test', async ({ runInlineTest }) => { | 
					
						
							|  |  |  |   const result = await runInlineTest({ | 
					
						
							|  |  |  |     'a.spec.ts': `
 | 
					
						
							| 
									
										
										
										
											2023-02-14 19:20:56 -08:00
										 |  |  |       import { test as base, expect } from '@playwright/test'; | 
					
						
							|  |  |  |       const test = base.extend({ | 
					
						
							| 
									
										
										
										
											2022-03-17 09:36:03 -07:00
										 |  |  |         fixture: async ({}, use) => { | 
					
						
							|  |  |  |           await new Promise(f => setTimeout(f, 500)); | 
					
						
							|  |  |  |           await use('hey'); | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       test.beforeAll(async ({ fixture }) => { | 
					
						
							|  |  |  |         // Nothing to see here.
 | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       test('test ok', async ({}) => { | 
					
						
							|  |  |  |         test.setTimeout(1000); | 
					
						
							|  |  |  |         await new Promise(f => setTimeout(f, 800)); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     `
 | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  |   expect(result.exitCode).toBe(0); | 
					
						
							|  |  |  |   expect(result.passed).toBe(1); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test('fixture timeout in beforeAll hook should not affect test', async ({ runInlineTest }) => { | 
					
						
							|  |  |  |   const result = await runInlineTest({ | 
					
						
							|  |  |  |     'a.spec.ts': `
 | 
					
						
							| 
									
										
										
										
											2023-02-14 19:20:56 -08:00
										 |  |  |       import { test as base, expect } from '@playwright/test'; | 
					
						
							|  |  |  |       const test = base.extend({ | 
					
						
							| 
									
										
										
										
											2022-03-17 09:36:03 -07:00
										 |  |  |         fixture: [async ({}, use) => { | 
					
						
							|  |  |  |           await new Promise(f => setTimeout(f, 500)); | 
					
						
							|  |  |  |           await use('hey'); | 
					
						
							|  |  |  |         }, { timeout: 800 }], | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       test.beforeAll(async ({ fixture }) => { | 
					
						
							|  |  |  |         // Nothing to see here.
 | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       test('test ok', async ({}) => { | 
					
						
							|  |  |  |         test.setTimeout(1000); | 
					
						
							|  |  |  |         await new Promise(f => setTimeout(f, 800)); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     `
 | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  |   expect(result.exitCode).toBe(0); | 
					
						
							|  |  |  |   expect(result.passed).toBe(1); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test('fixture time in beforeEach hook should affect test', async ({ runInlineTest }) => { | 
					
						
							|  |  |  |   const result = await runInlineTest({ | 
					
						
							|  |  |  |     'a.spec.ts': `
 | 
					
						
							| 
									
										
										
										
											2023-02-14 19:20:56 -08:00
										 |  |  |       import { test as base, expect } from '@playwright/test'; | 
					
						
							|  |  |  |       const test = base.extend({ | 
					
						
							| 
									
										
										
										
											2022-03-17 09:36:03 -07:00
										 |  |  |         fixture: async ({}, use) => { | 
					
						
							|  |  |  |           await new Promise(f => setTimeout(f, 500)); | 
					
						
							|  |  |  |           await use('hey'); | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       test.beforeEach(async ({ fixture }) => { | 
					
						
							|  |  |  |         // Nothing to see here.
 | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       test('test ok', async ({}) => { | 
					
						
							|  |  |  |         test.setTimeout(1000); | 
					
						
							|  |  |  |         await new Promise(f => setTimeout(f, 800)); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     `
 | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  |   expect(result.exitCode).toBe(1); | 
					
						
							|  |  |  |   expect(result.failed).toBe(1); | 
					
						
							| 
									
										
										
										
											2022-06-30 17:05:08 -07:00
										 |  |  |   expect(result.output).toContain('Test timeout of 1000ms exceeded.'); | 
					
						
							| 
									
										
										
										
											2022-03-17 09:36:03 -07:00
										 |  |  | }); | 
					
						
							| 
									
										
										
										
											2022-05-09 20:38:20 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | test('test timeout should still run hooks before fixtures teardown', async ({ runInlineTest }) => { | 
					
						
							|  |  |  |   const result = await runInlineTest({ | 
					
						
							|  |  |  |     'a.spec.ts': `
 | 
					
						
							| 
									
										
										
										
											2023-02-14 19:20:56 -08:00
										 |  |  |       import { test as base, expect } from '@playwright/test'; | 
					
						
							|  |  |  |       const test = base.extend({ | 
					
						
							| 
									
										
										
										
											2022-05-09 20:38:20 +01:00
										 |  |  |         auto: [async ({}, use) => { | 
					
						
							|  |  |  |           console.log('\\n%%before-auto'); | 
					
						
							|  |  |  |           await use('hey'); | 
					
						
							|  |  |  |           console.log('\\n%%after-auto'); | 
					
						
							|  |  |  |         }, { auto: true }] | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       test.afterAll(async () => { | 
					
						
							|  |  |  |         console.log('\\n%%afterAll-1'); | 
					
						
							|  |  |  |         await new Promise(f => setTimeout(f, 500)); | 
					
						
							|  |  |  |         console.log('\\n%%afterAll-2'); | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2023-05-02 11:04:51 -07:00
										 |  |  |       test.afterEach(async () => { | 
					
						
							|  |  |  |         console.log('\\n%%afterEach'); | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2022-05-09 20:38:20 +01:00
										 |  |  |       test('test fail', async ({}) => { | 
					
						
							|  |  |  |         test.setTimeout(100); | 
					
						
							|  |  |  |         console.log('\\n%%test'); | 
					
						
							|  |  |  |         await new Promise(f => setTimeout(f, 800)); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     `
 | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  |   expect(result.exitCode).toBe(1); | 
					
						
							|  |  |  |   expect(result.failed).toBe(1); | 
					
						
							| 
									
										
										
										
											2022-06-30 17:05:08 -07:00
										 |  |  |   expect(result.output).toContain('Test timeout of 100ms exceeded.'); | 
					
						
							| 
									
										
										
										
											2023-02-07 15:11:44 -08:00
										 |  |  |   expect(result.outputLines).toEqual([ | 
					
						
							|  |  |  |     'before-auto', | 
					
						
							|  |  |  |     'test', | 
					
						
							| 
									
										
										
										
											2023-05-02 11:04:51 -07:00
										 |  |  |     'afterEach', | 
					
						
							|  |  |  |     'after-auto', | 
					
						
							| 
									
										
										
										
											2023-02-07 15:11:44 -08:00
										 |  |  |     'afterAll-1', | 
					
						
							|  |  |  |     'afterAll-2', | 
					
						
							| 
									
										
										
										
											2022-05-09 20:38:20 +01:00
										 |  |  |   ]); | 
					
						
							|  |  |  | }); | 
					
						
							| 
									
										
										
										
											2022-07-08 11:45:44 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | test('should not include fixtures with own timeout and beforeAll in test duration', async ({ runInlineTest }) => { | 
					
						
							|  |  |  |   const result = await runInlineTest({ | 
					
						
							|  |  |  |     'c.spec.ts': `
 | 
					
						
							| 
									
										
										
										
											2023-02-14 19:20:56 -08:00
										 |  |  |       import { test as base, expect } from '@playwright/test'; | 
					
						
							|  |  |  |       const test = base.extend({ | 
					
						
							| 
									
										
										
										
											2022-07-08 11:45:44 -07:00
										 |  |  |         foo: [async ({}, use) => { | 
					
						
							|  |  |  |           await new Promise(f => setTimeout(f, 1000)); | 
					
						
							|  |  |  |           await use('foo'); | 
					
						
							|  |  |  |         }, { timeout: 0 }], | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         bar: async ({}, use) => { | 
					
						
							|  |  |  |           await new Promise(f => setTimeout(f, 300)); | 
					
						
							|  |  |  |           await use('bar'); | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       test.beforeAll(async () => { | 
					
						
							|  |  |  |         await new Promise(f => setTimeout(f, 1000)); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       test.beforeEach(async () => { | 
					
						
							|  |  |  |         await new Promise(f => setTimeout(f, 300)); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       test.afterEach(async () => { | 
					
						
							|  |  |  |         await new Promise(f => setTimeout(f, 300)); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       test('works', async ({ foo, bar }) => { | 
					
						
							|  |  |  |         await new Promise(f => setTimeout(f, 300)); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     `
 | 
					
						
							|  |  |  |   }, { timeout: 5000 }); | 
					
						
							|  |  |  |   expect(result.exitCode).toBe(0); | 
					
						
							|  |  |  |   const duration = result.results[0].duration; | 
					
						
							|  |  |  |   expect(duration).toBeGreaterThanOrEqual(300 * 4);  // Includes test, beforeEach, afterEach and bar.
 | 
					
						
							|  |  |  |   expect(duration).toBeLessThan(300 * 4 + 1000);  // Does not include beforeAll and foo.
 | 
					
						
							|  |  |  | }); | 
					
						
							| 
									
										
										
										
											2022-10-25 12:34:15 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | test('should run fixture teardowns after timeout with soft expect error', async ({ runInlineTest }) => { | 
					
						
							|  |  |  |   const result = await runInlineTest({ | 
					
						
							|  |  |  |     'helper.ts': `
 | 
					
						
							| 
									
										
										
										
											2023-02-14 19:20:56 -08:00
										 |  |  |       import { test as base, expect } from '@playwright/test'; | 
					
						
							|  |  |  |       export const test = base.extend({ | 
					
						
							| 
									
										
										
										
											2022-10-25 12:34:15 -07:00
										 |  |  |         foo: async ({}, run, testInfo) => { | 
					
						
							|  |  |  |           await run(); | 
					
						
							|  |  |  |           await new Promise(f => setTimeout(f, 500)); | 
					
						
							|  |  |  |           testInfo.attachments.push({ name: 'foo', contentType: 'text/plain', body: Buffer.from('foo') }); | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |         bar: async ({ foo }, run, testInfo) => { | 
					
						
							|  |  |  |           await run(foo); | 
					
						
							|  |  |  |           await new Promise(f => setTimeout(f, 500)); | 
					
						
							|  |  |  |           testInfo.attachments.push({ name: 'bar', contentType: 'text/plain', body: Buffer.from('bar') }); | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     `,
 | 
					
						
							|  |  |  |     'c.spec.ts': `
 | 
					
						
							|  |  |  |       import { test } from './helper'; | 
					
						
							|  |  |  |       test('works', async ({ bar }) => { | 
					
						
							|  |  |  |         expect.soft(1).toBe(2); | 
					
						
							|  |  |  |         await new Promise(f => setTimeout(f, 5000)); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     `
 | 
					
						
							|  |  |  |   }, { timeout: 2000 }); | 
					
						
							|  |  |  |   expect(result.exitCode).toBe(1); | 
					
						
							|  |  |  |   expect(result.failed).toBe(1); | 
					
						
							|  |  |  |   const test = result.report.suites[0].specs[0].tests[0]; | 
					
						
							|  |  |  |   expect(test.results[0].attachments[0]).toEqual({ | 
					
						
							|  |  |  |     name: 'bar', | 
					
						
							|  |  |  |     body: 'YmFy', | 
					
						
							|  |  |  |     contentType: 'text/plain', | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  |   expect(test.results[0].attachments[1]).toEqual({ | 
					
						
							|  |  |  |     name: 'foo', | 
					
						
							|  |  |  |     body: 'Zm9v', | 
					
						
							|  |  |  |     contentType: 'text/plain', | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | }); | 
					
						
							| 
									
										
										
										
											2022-10-27 15:53:27 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | test('should respect test.describe.configure', async ({ runInlineTest }) => { | 
					
						
							|  |  |  |   const result = await runInlineTest({ | 
					
						
							|  |  |  |     'a.spec.ts': `
 | 
					
						
							| 
									
										
										
										
											2023-02-14 19:20:56 -08:00
										 |  |  |       import { test, expect } from '@playwright/test'; | 
					
						
							| 
									
										
										
										
											2022-10-27 15:53:27 -07:00
										 |  |  |       test.describe.configure({ timeout: 1000 }); | 
					
						
							|  |  |  |       test('test1', async ({}) => { | 
					
						
							|  |  |  |         console.log('test1-' + test.info().timeout); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       test.describe(() => { | 
					
						
							|  |  |  |         test.describe.configure({ timeout: 2000 }); | 
					
						
							|  |  |  |         test.describe(() => { | 
					
						
							|  |  |  |           test('test2', async ({}) => { | 
					
						
							|  |  |  |             console.log('test2-' + test.info().timeout); | 
					
						
							|  |  |  |           }); | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     `
 | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  |   expect(result.exitCode).toBe(0); | 
					
						
							|  |  |  |   expect(result.passed).toBe(2); | 
					
						
							|  |  |  |   expect(result.output).toContain('test1-1000'); | 
					
						
							|  |  |  |   expect(result.output).toContain('test2-2000'); | 
					
						
							|  |  |  | }); |