| 
									
										
										
										
											2021-09-09 14:17:18 -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 fs from 'fs'; | 
					
						
							| 
									
										
										
										
											2021-09-13 20:34:46 -07:00
										 |  |  | import path from 'path'; | 
					
						
							| 
									
										
										
										
											2021-09-09 14:17:18 -07:00
										 |  |  | import { test, expect } from './playwright-test-fixtures'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-11 10:52:17 -04:00
										 |  |  | const kRawReporterPath = path.join(__dirname, '..', '..', 'packages', 'playwright-test', 'lib', 'reporters', 'raw.js'); | 
					
						
							| 
									
										
										
										
											2021-09-13 20:34:46 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-09 14:17:18 -07:00
										 |  |  | test('should generate raw report', async ({ runInlineTest }, testInfo) => { | 
					
						
							|  |  |  |   const result = await runInlineTest({ | 
					
						
							|  |  |  |     'a.test.js': `
 | 
					
						
							|  |  |  |       const { test } = pwt; | 
					
						
							|  |  |  |       test('passes', async ({ page }, testInfo) => {}); | 
					
						
							|  |  |  |     `,
 | 
					
						
							| 
									
										
										
										
											2021-09-20 17:17:12 -07:00
										 |  |  |   }, { reporter: 'dot,' + kRawReporterPath }, {}, { usesCustomOutputDir: true }); | 
					
						
							| 
									
										
										
										
											2021-09-09 14:17:18 -07:00
										 |  |  |   const json = JSON.parse(fs.readFileSync(testInfo.outputPath('test-results', 'report', 'project.report'), 'utf-8')); | 
					
						
							|  |  |  |   expect(json.config).toBeTruthy(); | 
					
						
							|  |  |  |   expect(json.project).toBeTruthy(); | 
					
						
							|  |  |  |   expect(result.exitCode).toBe(0); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test('should use project name', async ({ runInlineTest }, testInfo) => { | 
					
						
							|  |  |  |   const result = await runInlineTest({ | 
					
						
							|  |  |  |     'playwright.config.ts': `
 | 
					
						
							|  |  |  |       module.exports = { | 
					
						
							|  |  |  |         projects: [{ | 
					
						
							|  |  |  |           name: 'project-name', | 
					
						
							|  |  |  |           outputDir: 'output' | 
					
						
							|  |  |  |         }] | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     `,
 | 
					
						
							|  |  |  |     'a.test.js': `
 | 
					
						
							|  |  |  |       const { test } = pwt; | 
					
						
							|  |  |  |       test('passes', async ({ page }, testInfo) => {}); | 
					
						
							|  |  |  |     `,
 | 
					
						
							| 
									
										
										
										
											2021-09-20 17:17:12 -07:00
										 |  |  |   }, { reporter: 'dot,' + kRawReporterPath }, {}, { usesCustomOutputDir: true }); | 
					
						
							| 
									
										
										
										
											2021-09-09 14:17:18 -07:00
										 |  |  |   const json = JSON.parse(fs.readFileSync(testInfo.outputPath('output', 'report', 'project-name.report'), 'utf-8')); | 
					
						
							|  |  |  |   expect(json.project.name).toBe('project-name'); | 
					
						
							|  |  |  |   expect(result.exitCode).toBe(0); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test('should save stdio', async ({ runInlineTest }, testInfo) => { | 
					
						
							|  |  |  |   await runInlineTest({ | 
					
						
							|  |  |  |     'a.test.js': `
 | 
					
						
							|  |  |  |       const { test } = pwt; | 
					
						
							|  |  |  |       test('passes', async ({ page }, testInfo) => { | 
					
						
							|  |  |  |         console.log('STDOUT'); | 
					
						
							| 
									
										
										
										
											2021-09-09 17:35:31 -07:00
										 |  |  |         process.stdout.write(Buffer.from([1, 2, 3])); | 
					
						
							| 
									
										
										
										
											2021-09-09 14:17:18 -07:00
										 |  |  |         console.error('STDERR'); | 
					
						
							| 
									
										
										
										
											2021-09-09 17:35:31 -07:00
										 |  |  |         process.stderr.write(Buffer.from([4, 5, 6])); | 
					
						
							| 
									
										
										
										
											2021-09-09 14:17:18 -07:00
										 |  |  |       }); | 
					
						
							|  |  |  |     `,
 | 
					
						
							| 
									
										
										
										
											2021-09-20 17:17:12 -07:00
										 |  |  |   }, { reporter: 'dot,' + kRawReporterPath }, {}, { usesCustomOutputDir: true }); | 
					
						
							| 
									
										
										
										
											2021-09-09 14:17:18 -07:00
										 |  |  |   const json = JSON.parse(fs.readFileSync(testInfo.outputPath('test-results', 'report', 'project.report'), 'utf-8')); | 
					
						
							|  |  |  |   const result = json.suites[0].tests[0].results[0]; | 
					
						
							| 
									
										
										
										
											2021-09-09 17:35:31 -07:00
										 |  |  |   expect(result.attachments).toEqual([ | 
					
						
							|  |  |  |     { name: 'stdout', contentType: 'text/plain', body: 'STDOUT\n' }, | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       name: 'stdout', | 
					
						
							|  |  |  |       contentType: 'application/octet-stream', | 
					
						
							| 
									
										
										
										
											2021-12-08 08:51:44 -08:00
										 |  |  |       body: { data: [1, 2, 3], type: 'Buffer' } | 
					
						
							| 
									
										
										
										
											2021-09-09 17:35:31 -07:00
										 |  |  |     }, | 
					
						
							|  |  |  |     { name: 'stderr', contentType: 'text/plain', body: 'STDERR\n' }, | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       name: 'stderr', | 
					
						
							|  |  |  |       contentType: 'application/octet-stream', | 
					
						
							| 
									
										
										
										
											2021-12-08 08:51:44 -08:00
										 |  |  |       body: { data: [4, 5, 6], type: 'Buffer' } | 
					
						
							| 
									
										
										
										
											2021-09-09 17:35:31 -07:00
										 |  |  |     } | 
					
						
							|  |  |  |   ]); | 
					
						
							| 
									
										
										
										
											2021-09-09 14:17:18 -07:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test('should save attachments', async ({ runInlineTest }, testInfo) => { | 
					
						
							|  |  |  |   await runInlineTest({ | 
					
						
							|  |  |  |     'a.test.js': `
 | 
					
						
							|  |  |  |       const { test } = pwt; | 
					
						
							|  |  |  |       test('passes', async ({ page }, testInfo) => { | 
					
						
							|  |  |  |         testInfo.attachments.push({ | 
					
						
							|  |  |  |           name: 'binary', | 
					
						
							|  |  |  |           contentType: 'application/octet-stream', | 
					
						
							|  |  |  |           body: Buffer.from([1,2,3]) | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |         testInfo.attachments.push({ | 
					
						
							|  |  |  |           name: 'text', | 
					
						
							|  |  |  |           contentType: 'text/plain', | 
					
						
							|  |  |  |           path: 'dummy-path' | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     `,
 | 
					
						
							| 
									
										
										
										
											2021-09-20 17:17:12 -07:00
										 |  |  |   }, { reporter: 'dot,' + kRawReporterPath }, {}, { usesCustomOutputDir: true }); | 
					
						
							| 
									
										
										
										
											2021-09-09 14:17:18 -07:00
										 |  |  |   const json = JSON.parse(fs.readFileSync(testInfo.outputPath('test-results', 'report', 'project.report'), 'utf-8')); | 
					
						
							|  |  |  |   const result = json.suites[0].tests[0].results[0]; | 
					
						
							|  |  |  |   expect(result.attachments[0].name).toBe('binary'); | 
					
						
							| 
									
										
										
										
											2021-09-09 17:35:31 -07:00
										 |  |  |   expect(Buffer.from(result.attachments[0].body, 'base64')).toEqual(Buffer.from([1,2,3])); | 
					
						
							| 
									
										
										
										
											2021-09-09 14:17:18 -07:00
										 |  |  |   expect(result.attachments[1].name).toBe('text'); | 
					
						
							|  |  |  |   const path2 = result.attachments[1].path; | 
					
						
							|  |  |  |   expect(path2).toBe('dummy-path'); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-23 09:30:53 -08:00
										 |  |  | test(`testInfo.attach should save attachments via path`, async ({ runInlineTest }, testInfo) => { | 
					
						
							|  |  |  |   await runInlineTest({ | 
					
						
							|  |  |  |     'a.test.js': `
 | 
					
						
							|  |  |  |       const path = require('path'); | 
					
						
							|  |  |  |       const fs = require('fs'); | 
					
						
							|  |  |  |       const { test } = pwt; | 
					
						
							|  |  |  |       test('infer contentType from path', async ({}, testInfo) => { | 
					
						
							|  |  |  |         const tmpPath = testInfo.outputPath('example.json'); | 
					
						
							|  |  |  |         await fs.promises.writeFile(tmpPath, 'We <3 Playwright!'); | 
					
						
							| 
									
										
										
										
											2022-01-05 16:39:33 -08:00
										 |  |  |         await testInfo.attach('foo', { path: tmpPath }); | 
					
						
							| 
									
										
										
										
											2021-11-23 09:30:53 -08:00
										 |  |  |         // Forcibly remove the tmp file to ensure attach is actually automagically copying it
 | 
					
						
							|  |  |  |         await fs.promises.unlink(tmpPath); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       test('explicit contentType (over extension)', async ({}, testInfo) => { | 
					
						
							|  |  |  |         const tmpPath = testInfo.outputPath('example.json'); | 
					
						
							|  |  |  |         await fs.promises.writeFile(tmpPath, 'We <3 Playwright!'); | 
					
						
							| 
									
										
										
										
											2022-01-05 16:39:33 -08:00
										 |  |  |         await testInfo.attach('foo', { path: tmpPath, contentType: 'image/png' }); | 
					
						
							| 
									
										
										
										
											2021-11-23 09:30:53 -08:00
										 |  |  |         // Forcibly remove the tmp file to ensure attach is actually automagically copying it
 | 
					
						
							|  |  |  |         await fs.promises.unlink(tmpPath); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       test('explicit contentType (over extension and name)', async ({}, testInfo) => { | 
					
						
							|  |  |  |         const tmpPath = testInfo.outputPath('example.json'); | 
					
						
							|  |  |  |         await fs.promises.writeFile(tmpPath, 'We <3 Playwright!'); | 
					
						
							| 
									
										
										
										
											2022-01-05 16:39:33 -08:00
										 |  |  |         await testInfo.attach('example.png', { path: tmpPath, contentType: 'x-playwright/custom' }); | 
					
						
							| 
									
										
										
										
											2021-11-23 09:30:53 -08:00
										 |  |  |         // Forcibly remove the tmp file to ensure attach is actually automagically copying it
 | 
					
						
							|  |  |  |         await fs.promises.unlink(tmpPath); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       test('fallback contentType', async ({}, testInfo) => { | 
					
						
							| 
									
										
										
										
											2022-01-05 16:39:33 -08:00
										 |  |  |         const tmpPath = testInfo.outputPath('example.this-extension-better-not-map-to-an-actual-mimetype'); | 
					
						
							| 
									
										
										
										
											2021-11-23 09:30:53 -08:00
										 |  |  |         await fs.promises.writeFile(tmpPath, 'We <3 Playwright!'); | 
					
						
							| 
									
										
										
										
											2022-01-05 16:39:33 -08:00
										 |  |  |         await testInfo.attach('foo', { path: tmpPath }); | 
					
						
							| 
									
										
										
										
											2021-11-23 09:30:53 -08:00
										 |  |  |         // Forcibly remove the tmp file to ensure attach is actually automagically copying it
 | 
					
						
							|  |  |  |         await fs.promises.unlink(tmpPath); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     `,
 | 
					
						
							|  |  |  |   }, { reporter: 'dot,' + kRawReporterPath, workers: 1 }, {}, { usesCustomOutputDir: true }); | 
					
						
							|  |  |  |   const json = JSON.parse(fs.readFileSync(testInfo.outputPath('test-results', 'report', 'project.report'), 'utf-8')); | 
					
						
							|  |  |  |   { | 
					
						
							|  |  |  |     const result = json.suites[0].tests[0].results[0]; | 
					
						
							| 
									
										
										
										
											2022-01-05 16:39:33 -08:00
										 |  |  |     expect(result.attachments[0].name).toBe('foo'); | 
					
						
							| 
									
										
										
										
											2021-11-23 09:30:53 -08:00
										 |  |  |     expect(result.attachments[0].contentType).toBe('application/json'); | 
					
						
							|  |  |  |     const p = result.attachments[0].path; | 
					
						
							| 
									
										
										
										
											2022-01-13 10:38:47 -08:00
										 |  |  |     expect(p).toMatch(/[/\\]attachments[/\\][0-9a-f]+\.json$/); | 
					
						
							| 
									
										
										
										
											2021-11-23 09:30:53 -08:00
										 |  |  |     const contents = fs.readFileSync(p); | 
					
						
							|  |  |  |     expect(contents.toString()).toBe('We <3 Playwright!'); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   { | 
					
						
							|  |  |  |     const result = json.suites[0].tests[1].results[0]; | 
					
						
							| 
									
										
										
										
											2022-01-05 16:39:33 -08:00
										 |  |  |     expect(result.attachments[0].name).toBe('foo'); | 
					
						
							| 
									
										
										
										
											2021-11-23 09:30:53 -08:00
										 |  |  |     expect(result.attachments[0].contentType).toBe('image/png'); | 
					
						
							|  |  |  |     const p = result.attachments[0].path; | 
					
						
							| 
									
										
										
										
											2022-01-13 10:38:47 -08:00
										 |  |  |     expect(p).toMatch(/[/\\]attachments[/\\][0-9a-f]+\.json$/); | 
					
						
							| 
									
										
										
										
											2021-11-23 09:30:53 -08:00
										 |  |  |     const contents = fs.readFileSync(p); | 
					
						
							|  |  |  |     expect(contents.toString()).toBe('We <3 Playwright!'); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   { | 
					
						
							|  |  |  |     const result = json.suites[0].tests[2].results[0]; | 
					
						
							|  |  |  |     expect(result.attachments[0].name).toBe('example.png'); | 
					
						
							|  |  |  |     expect(result.attachments[0].contentType).toBe('x-playwright/custom'); | 
					
						
							|  |  |  |     const p = result.attachments[0].path; | 
					
						
							| 
									
										
										
										
											2022-01-13 10:38:47 -08:00
										 |  |  |     expect(p).toMatch(/[/\\]attachments[/\\][0-9a-f]+\.json$/); | 
					
						
							| 
									
										
										
										
											2021-11-23 09:30:53 -08:00
										 |  |  |     const contents = fs.readFileSync(p); | 
					
						
							|  |  |  |     expect(contents.toString()).toBe('We <3 Playwright!'); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   { | 
					
						
							| 
									
										
										
										
											2022-01-05 16:39:33 -08:00
										 |  |  |     const result = json.suites[0].tests[3].results[0]; | 
					
						
							|  |  |  |     expect(result.attachments[0].name).toBe('foo'); | 
					
						
							| 
									
										
										
										
											2021-11-23 09:30:53 -08:00
										 |  |  |     expect(result.attachments[0].contentType).toBe('application/octet-stream'); | 
					
						
							|  |  |  |     const p = result.attachments[0].path; | 
					
						
							| 
									
										
										
										
											2022-01-13 10:38:47 -08:00
										 |  |  |     expect(p).toMatch(/[/\\]attachments[/\\][0-9a-f]+\.this-extension-better-not-map-to-an-actual-mimetype$/); | 
					
						
							| 
									
										
										
										
											2021-11-23 09:30:53 -08:00
										 |  |  |     const contents = fs.readFileSync(p); | 
					
						
							|  |  |  |     expect(contents.toString()).toBe('We <3 Playwright!'); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test(`testInfo.attach should save attachments via inline attachment`, async ({ runInlineTest }, testInfo) => { | 
					
						
							|  |  |  |   await runInlineTest({ | 
					
						
							|  |  |  |     'a.test.js': `
 | 
					
						
							|  |  |  |       const path = require('path'); | 
					
						
							|  |  |  |       const fs = require('fs'); | 
					
						
							|  |  |  |       const { test } = pwt; | 
					
						
							| 
									
										
										
										
											2022-01-05 16:39:33 -08:00
										 |  |  |       test('default contentType - string', async ({}, testInfo) => { | 
					
						
							|  |  |  |         await testInfo.attach('example.json', { body: 'We <3 Playwright!' }); | 
					
						
							| 
									
										
										
										
											2021-11-23 09:30:53 -08:00
										 |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-05 16:39:33 -08:00
										 |  |  |       test('default contentType - Buffer', async ({}, testInfo) => { | 
					
						
							|  |  |  |         await testInfo.attach('example.json', { body: Buffer.from('We <3 Playwright!') }); | 
					
						
							| 
									
										
										
										
											2021-11-23 09:30:53 -08:00
										 |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       test('explicit contentType - string', async ({}, testInfo) => { | 
					
						
							| 
									
										
										
										
											2022-01-05 16:39:33 -08:00
										 |  |  |         await testInfo.attach('example.json', { body: 'We <3 Playwright!', contentType: 'x-playwright/custom' }); | 
					
						
							| 
									
										
										
										
											2021-11-23 09:30:53 -08:00
										 |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       test('explicit contentType - Buffer', async ({}, testInfo) => { | 
					
						
							| 
									
										
										
										
											2022-01-05 16:39:33 -08:00
										 |  |  |         await testInfo.attach('example.json', { body: Buffer.from('We <3 Playwright!'), contentType: 'x-playwright/custom' }); | 
					
						
							| 
									
										
										
										
											2021-11-23 09:30:53 -08:00
										 |  |  |       }); | 
					
						
							|  |  |  |   `,
 | 
					
						
							|  |  |  |   }, { reporter: 'dot,' + kRawReporterPath, workers: 1 }, {}, { usesCustomOutputDir: true }); | 
					
						
							|  |  |  |   const json = JSON.parse(fs.readFileSync(testInfo.outputPath('test-results', 'report', 'project.report'), 'utf-8')); | 
					
						
							|  |  |  |   { | 
					
						
							|  |  |  |     const result = json.suites[0].tests[0].results[0]; | 
					
						
							|  |  |  |     expect(result.attachments[0].name).toBe('example.json'); | 
					
						
							| 
									
										
										
										
											2022-01-05 16:39:33 -08:00
										 |  |  |     expect(result.attachments[0].contentType).toBe('text/plain'); | 
					
						
							| 
									
										
										
										
											2021-11-23 09:30:53 -08:00
										 |  |  |     expect(Buffer.from(result.attachments[0].body, 'base64')).toEqual(Buffer.from('We <3 Playwright!')); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   { | 
					
						
							|  |  |  |     const result = json.suites[0].tests[1].results[0]; | 
					
						
							|  |  |  |     expect(result.attachments[0].name).toBe('example.json'); | 
					
						
							|  |  |  |     expect(result.attachments[0].contentType).toBe('application/octet-stream'); | 
					
						
							|  |  |  |     expect(Buffer.from(result.attachments[0].body, 'base64')).toEqual(Buffer.from('We <3 Playwright!')); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   { | 
					
						
							| 
									
										
										
										
											2022-01-05 16:39:33 -08:00
										 |  |  |     const result = json.suites[0].tests[2].results[0]; | 
					
						
							| 
									
										
										
										
											2021-11-23 09:30:53 -08:00
										 |  |  |     expect(result.attachments[0].name).toBe('example.json'); | 
					
						
							|  |  |  |     expect(result.attachments[0].contentType).toBe('x-playwright/custom'); | 
					
						
							|  |  |  |     expect(Buffer.from(result.attachments[0].body, 'base64')).toEqual(Buffer.from('We <3 Playwright!')); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   { | 
					
						
							| 
									
										
										
										
											2022-01-05 16:39:33 -08:00
										 |  |  |     const result = json.suites[0].tests[3].results[0]; | 
					
						
							| 
									
										
										
										
											2021-11-23 09:30:53 -08:00
										 |  |  |     expect(result.attachments[0].name).toBe('example.json'); | 
					
						
							|  |  |  |     expect(result.attachments[0].contentType).toBe('x-playwright/custom'); | 
					
						
							|  |  |  |     expect(Buffer.from(result.attachments[0].body, 'base64')).toEqual(Buffer.from('We <3 Playwright!')); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-08 13:22:14 -07:00
										 |  |  | test(`GlobalInfo.attach works`, async ({ runInlineTest }, testInfo) => { | 
					
						
							|  |  |  |   const result = await runInlineTest({ | 
					
						
							|  |  |  |     'globalSetup.ts': `
 | 
					
						
							|  |  |  |       import fs from 'fs'; | 
					
						
							|  |  |  |       import { FullConfig, GlobalInfo } from '@playwright/test'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       async function globalSetup(config: FullConfig, globalInfo: GlobalInfo) { | 
					
						
							| 
									
										
										
										
											2022-04-08 17:48:01 -07:00
										 |  |  |         const external = 'external.txt'; | 
					
						
							| 
									
										
										
										
											2022-04-08 13:22:14 -07:00
										 |  |  |         await fs.promises.writeFile(external, 'external'); | 
					
						
							|  |  |  |         await globalInfo.attach('inline.txt', { body: Buffer.from('inline'), contentType: 'text/plain' }); | 
					
						
							|  |  |  |         await globalInfo.attach('external.txt', { path: external, contentType: 'text/plain' }); | 
					
						
							|  |  |  |         // The attach call above should have saved it to a safe place
 | 
					
						
							|  |  |  |         await fs.promises.unlink(external); | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       export default globalSetup; | 
					
						
							|  |  |  |     `,
 | 
					
						
							|  |  |  |     'playwright.config.ts': `
 | 
					
						
							|  |  |  |       import path from 'path'; | 
					
						
							|  |  |  |       const config = { | 
					
						
							|  |  |  |         globalSetup: path.join(__dirname, './globalSetup'), | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       export default config; | 
					
						
							|  |  |  |     `,
 | 
					
						
							|  |  |  |     'example.spec.ts': `
 | 
					
						
							|  |  |  |       const { test } = pwt; | 
					
						
							|  |  |  |       test('sample', async ({}) => { expect(2).toBe(2); }); | 
					
						
							|  |  |  |     `,
 | 
					
						
							|  |  |  |   }, { reporter: 'dot,' + kRawReporterPath, workers: 1 }, {}, { usesCustomOutputDir: true }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   expect(result.exitCode).toBe(0); | 
					
						
							|  |  |  |   const outputPath = testInfo.outputPath('test-results', 'report', 'project.report'); | 
					
						
							|  |  |  |   const json = JSON.parse(fs.readFileSync(outputPath, 'utf-8')); | 
					
						
							|  |  |  |   { | 
					
						
							|  |  |  |     const attachment = json.attachments[0]; | 
					
						
							|  |  |  |     expect(attachment.name).toBe('inline.txt'); | 
					
						
							|  |  |  |     expect(attachment.contentType).toBe('text/plain'); | 
					
						
							|  |  |  |     expect(attachment.path).toBeUndefined(); | 
					
						
							|  |  |  |     expect(Buffer.from(attachment.body, 'base64').toString()).toEqual('inline'); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   { | 
					
						
							|  |  |  |     const attachment = json.attachments[1]; | 
					
						
							|  |  |  |     expect(attachment.name).toBe('external.txt'); | 
					
						
							|  |  |  |     expect(attachment.contentType).toBe('text/plain'); | 
					
						
							|  |  |  |     const contents = fs.readFileSync(attachment.path); | 
					
						
							|  |  |  |     expect(attachment.path.startsWith(path.join(testInfo.outputDir, 'attachments')), 'Attachment should be in our output directory.').toBeTruthy(); | 
					
						
							|  |  |  |     expect(contents.toString()).toEqual('external'); | 
					
						
							|  |  |  |     expect(attachment.body).toBeUndefined(); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-09 14:17:18 -07:00
										 |  |  | test('dupe project names', async ({ runInlineTest }, testInfo) => { | 
					
						
							|  |  |  |   await runInlineTest({ | 
					
						
							|  |  |  |     'playwright.config.ts': `
 | 
					
						
							|  |  |  |       module.exports = { | 
					
						
							|  |  |  |         projects: [ | 
					
						
							|  |  |  |           { name: 'project-name' }, | 
					
						
							|  |  |  |           { name: 'project-name' }, | 
					
						
							|  |  |  |           { name: 'project-name' }, | 
					
						
							|  |  |  |         ] | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     `,
 | 
					
						
							|  |  |  |     'a.test.js': `
 | 
					
						
							|  |  |  |       const { test } = pwt; | 
					
						
							|  |  |  |       test('passes', async ({ page }, testInfo) => {}); | 
					
						
							|  |  |  |     `,
 | 
					
						
							| 
									
										
										
										
											2021-09-20 17:17:12 -07:00
										 |  |  |   }, { reporter: 'dot,' + kRawReporterPath }, {}, { usesCustomOutputDir: true }); | 
					
						
							| 
									
										
										
										
											2021-09-09 14:17:18 -07:00
										 |  |  |   const files = fs.readdirSync(testInfo.outputPath('test-results', 'report')); | 
					
						
							|  |  |  |   expect(new Set(files)).toEqual(new Set(['project-name.report', 'project-name-1.report', 'project-name-2.report'])); | 
					
						
							|  |  |  | }); |