| 
									
										
										
										
											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. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import { test, expect } from './playwright-test-fixtures'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test('should access error in fixture', async ({ runInlineTest }) => { | 
					
						
							|  |  |  |   const result = await runInlineTest({ | 
					
						
							|  |  |  |     'test-error-visible-in-env.spec.ts': `
 | 
					
						
							| 
									
										
										
										
											2021-06-06 22:07:07 -07:00
										 |  |  |       const test = pwt.test.extend({ | 
					
						
							| 
									
										
										
										
											2021-06-06 17:09:53 -07:00
										 |  |  |         foo: [async ({}, run, testInfo) => { | 
					
						
							|  |  |  |           await run(); | 
					
						
							|  |  |  |           console.log('ERROR[[[' + JSON.stringify(testInfo.error, undefined, 2) + ']]]'); | 
					
						
							|  |  |  |         }, { auto: true }], | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       test('ensure env handles test error', async ({}) => { | 
					
						
							|  |  |  |         expect(true).toBe(false); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     `
 | 
					
						
							|  |  |  |   }, {}); | 
					
						
							|  |  |  |   expect(result.exitCode).toBe(1); | 
					
						
							|  |  |  |   const start = result.output.indexOf('ERROR[[[') + 8; | 
					
						
							|  |  |  |   const end = result.output.indexOf(']]]'); | 
					
						
							|  |  |  |   const data = JSON.parse(result.output.substring(start, end)); | 
					
						
							|  |  |  |   expect(data.message).toContain('Object.is equality'); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test('should access annotations in fixture', async ({ runInlineTest }) => { | 
					
						
							|  |  |  |   const { exitCode, report } = await runInlineTest({ | 
					
						
							|  |  |  |     'test-data-visible-in-env.spec.ts': `
 | 
					
						
							| 
									
										
										
										
											2021-06-06 22:07:07 -07:00
										 |  |  |       const test = pwt.test.extend({ | 
					
						
							| 
									
										
										
										
											2021-06-06 17:09:53 -07:00
										 |  |  |         foo: [async ({}, run, testInfo) => { | 
					
						
							|  |  |  |           await run(); | 
					
						
							|  |  |  |           testInfo.annotations.push({ type: 'myname', description: 'hello' }); | 
					
						
							|  |  |  |         }, { auto: true }], | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       test('ensure env can set data', async ({}, testInfo) => { | 
					
						
							|  |  |  |         test.slow(true, 'just slow'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         console.log('console.log'); | 
					
						
							|  |  |  |         console.error('console.error'); | 
					
						
							|  |  |  |         expect(testInfo.config.rootDir).toBeTruthy(); | 
					
						
							|  |  |  |         expect(testInfo.file).toContain('test-data-visible-in-env'); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     `
 | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  |   expect(exitCode).toBe(0); | 
					
						
							|  |  |  |   const test = report.suites[0].specs[0].tests[0]; | 
					
						
							| 
									
										
										
										
											2022-08-18 20:12:33 +02:00
										 |  |  |   expect(test.annotations).toEqual([{ type: 'slow', description: 'just slow' }, { type: 'myname', description: 'hello' }]); | 
					
						
							| 
									
										
										
										
											2021-06-06 17:09:53 -07:00
										 |  |  |   expect(test.results[0].stdout).toEqual([{ text: 'console.log\n' }]); | 
					
						
							|  |  |  |   expect(test.results[0].stderr).toEqual([{ text: 'console.error\n' }]); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test('should report projectName in result', async ({ runInlineTest }) => { | 
					
						
							|  |  |  |   const { exitCode, report } = await runInlineTest({ | 
					
						
							|  |  |  |     'playwright.config.ts': `
 | 
					
						
							|  |  |  |       module.exports = { | 
					
						
							|  |  |  |         projects: [ | 
					
						
							|  |  |  |           { name: 'foo' }, | 
					
						
							|  |  |  |           {}, | 
					
						
							|  |  |  |         ], | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  |     `,
 | 
					
						
							|  |  |  |     'test-data-visible-in-env.spec.ts': `
 | 
					
						
							| 
									
										
										
										
											2021-06-06 22:07:07 -07:00
										 |  |  |       pwt.test('some test', async ({}, testInfo) => { | 
					
						
							| 
									
										
										
										
											2021-06-06 17:09:53 -07:00
										 |  |  |       }); | 
					
						
							|  |  |  |     `
 | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  |   expect(report.suites[0].specs[0].tests[0].projectName).toBe('foo'); | 
					
						
							|  |  |  |   expect(report.suites[0].specs[0].tests[1].projectName).toBe(''); | 
					
						
							|  |  |  |   expect(exitCode).toBe(0); | 
					
						
							|  |  |  | }); | 
					
						
							| 
									
										
										
										
											2021-07-08 17:16:36 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-16 13:48:37 -07:00
										 |  |  | test('should access testInfo.attachments in fixture', async ({ runInlineTest }) => { | 
					
						
							| 
									
										
										
										
											2021-07-08 17:16:36 -07:00
										 |  |  |   const { exitCode, report } = await runInlineTest({ | 
					
						
							|  |  |  |     'test-data-visible-in-env.spec.ts': `
 | 
					
						
							|  |  |  |       const test = pwt.test.extend({ | 
					
						
							|  |  |  |         foo: async ({}, run, testInfo) => { | 
					
						
							|  |  |  |           await run(); | 
					
						
							| 
									
										
										
										
											2021-07-16 13:48:37 -07:00
										 |  |  |           testInfo.attachments.push({ name: 'foo', body: Buffer.from([1, 2, 3]), contentType: 'application/octet-stream' }); | 
					
						
							| 
									
										
										
										
											2021-07-08 17:16:36 -07:00
										 |  |  |         }, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       test('ensure fixture can set data', async ({ foo }) => { | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     `
 | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  |   expect(exitCode).toBe(0); | 
					
						
							|  |  |  |   const test = report.suites[0].specs[0].tests[0]; | 
					
						
							| 
									
										
										
										
											2021-07-16 13:48:37 -07:00
										 |  |  |   expect(test.results[0].attachments[0]).toEqual({ name: 'foo', body: 'AQID', contentType: 'application/octet-stream' }); | 
					
						
							| 
									
										
										
										
											2021-07-08 17:16:36 -07:00
										 |  |  | }); |