chore: remove output dir before each test (#23380)
This commit is contained in:
		
							parent
							
								
									7638b4bb76
								
							
						
					
					
						commit
						7ad03027fb
					
				|  | @ -30,7 +30,6 @@ import { InternalReporter } from '../reporters/internalReporter'; | |||
| type ProjectConfigWithFiles = { | ||||
|   name: string; | ||||
|   testDir: string; | ||||
|   outputDir: string; | ||||
|   use: { testIdAttribute?: string }; | ||||
|   files: string[]; | ||||
| }; | ||||
|  | @ -55,7 +54,6 @@ export class Runner { | |||
|       report.projects.push({ | ||||
|         name: project.project.name, | ||||
|         testDir: project.project.testDir, | ||||
|         outputDir: project.project.outputDir, | ||||
|         use: { testIdAttribute: project.project.use.testIdAttribute }, | ||||
|         files: await collectFilesForProject(project) | ||||
|       }); | ||||
|  |  | |||
|  | @ -146,6 +146,8 @@ function createGlobalSetupTask(): Task<TestRun> { | |||
| 
 | ||||
| function createRemoveOutputDirsTask(): Task<TestRun> { | ||||
|   return async ({ config }) => { | ||||
|     if (process.env.PW_TEST_NO_REMOVE_OUTPUT_DIRS) | ||||
|       return; | ||||
|     const outputDirs = new Set<string>(); | ||||
|     for (const p of config.projects) { | ||||
|       if (!config.cliProjectFilter || config.cliProjectFilter.includes(p.project.name)) | ||||
|  |  | |||
|  | @ -318,6 +318,8 @@ export class WorkerMain extends ProcessRunner { | |||
|         return; | ||||
|       } | ||||
| 
 | ||||
|       await removeFolderAsync(testInfo.outputDir).catch(() => {}); | ||||
| 
 | ||||
|       let testFunctionParams: object | null = null; | ||||
|       await testInfo._runAsStep({ category: 'hook', title: 'Before Hooks' }, async step => { | ||||
|         testInfo._beforeHooksStep = step; | ||||
|  | @ -471,7 +473,7 @@ export class WorkerMain extends ProcessRunner { | |||
|     const preserveOutput = this._config.config.preserveOutput === 'always' || | ||||
|       (this._config.config.preserveOutput === 'failures-only' && testInfo._isFailure()); | ||||
|     if (!preserveOutput) | ||||
|       await removeFolderAsync(testInfo.outputDir).catch(e => {}); | ||||
|       await removeFolderAsync(testInfo.outputDir).catch(() => {}); | ||||
|   } | ||||
| 
 | ||||
|   private async _runModifiersForSuite(suite: Suite, testInfo: TestInfoImpl, scope: 'worker' | 'test', timeSlot: TimeSlot | undefined, extraAnnotations?: Annotation[]) { | ||||
|  |  | |||
|  | @ -14,7 +14,6 @@ | |||
|  * limitations under the License. | ||||
|  */ | ||||
| 
 | ||||
| import path from 'path'; | ||||
| import { test, expect } from './playwright-test-fixtures'; | ||||
| 
 | ||||
| test('should list files', async ({ runListFiles }) => { | ||||
|  | @ -32,7 +31,6 @@ test('should list files', async ({ runListFiles }) => { | |||
|       { | ||||
|         name: 'foo', | ||||
|         testDir: expect.stringContaining('list-files-should-list-files-playwright-test'), | ||||
|         outputDir: expect.stringContaining(path.join('list-files-should-list-files-playwright-test', 'test-results')), | ||||
|         use: {}, | ||||
|         files: [ | ||||
|           expect.stringContaining('a.test.js') | ||||
|  | @ -41,7 +39,6 @@ test('should list files', async ({ runListFiles }) => { | |||
|       { | ||||
|         name: 'bar', | ||||
|         testDir: expect.stringContaining('list-files-should-list-files-playwright-test'), | ||||
|         outputDir: expect.stringContaining(path.join('list-files-should-list-files-playwright-test', 'test-results')), | ||||
|         use: {}, | ||||
|         files: [ | ||||
|           expect.stringContaining('a.test.js') | ||||
|  | @ -68,7 +65,6 @@ test('should include testIdAttribute', async ({ runListFiles }) => { | |||
|       { | ||||
|         name: '', | ||||
|         testDir: expect.stringContaining('list-files-should-include-testIdAttribute-playwright-test'), | ||||
|         outputDir: expect.stringContaining(path.join('list-files-should-include-testIdAttribute-playwright-test', 'test-results')), | ||||
|         use: { | ||||
|           testIdAttribute: 'myid' | ||||
|         }, | ||||
|  |  | |||
|  | @ -360,3 +360,37 @@ test('should ignore repeatEach', async ({ runUITest }) => { | |||
| 
 | ||||
|   await expect(page.getByTestId('status-line')).toHaveText('1/1 passed (100%)'); | ||||
| }); | ||||
| 
 | ||||
| test('should remove output folder before test run', async ({ runUITest }) => { | ||||
|   const { page } = await runUITest({ | ||||
|     'playwright.config.ts': ` | ||||
|       import { defineConfig } from '@playwright/test'; | ||||
|     `,
 | ||||
|     'a.test.ts': ` | ||||
|       import fs from 'fs'; | ||||
|       import { test, expect } from '@playwright/test'; | ||||
|       test('should pass', () => { | ||||
|         const path = test.info().outputPath('a.txt'); | ||||
|         expect(fs.existsSync(path)).toBe(false); | ||||
|         fs.writeFileSync(path, 'dirty'); | ||||
|       }); | ||||
|     `,
 | ||||
|   }); | ||||
|   await expect.poll(dumpTestTree(page)).toContain(` | ||||
|     ▼ ◯ a.test.ts | ||||
|   `);
 | ||||
| 
 | ||||
|   await page.getByTitle('Run all').click(); | ||||
|   await expect.poll(dumpTestTree(page)).toBe(` | ||||
|     ▼ ✅ a.test.ts | ||||
|         ✅ should pass | ||||
|   `);
 | ||||
|   await expect(page.getByTestId('status-line')).toHaveText('1/1 passed (100%)'); | ||||
| 
 | ||||
|   await page.getByTitle('Run all').click(); | ||||
|   await expect.poll(dumpTestTree(page)).toBe(` | ||||
|     ▼ ✅ a.test.ts | ||||
|         ✅ should pass | ||||
|   `);
 | ||||
|   await expect(page.getByTestId('status-line')).toHaveText('1/1 passed (100%)'); | ||||
| }); | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue