From ab05bbf9c8345bd5e0b6d8197d7d0ed682a44e5c Mon Sep 17 00:00:00 2001 From: Simon Knott Date: Wed, 17 Jul 2024 16:06:56 +0200 Subject: [PATCH] untracked and tracked files need to be treated differently --- packages/playwright/src/util.ts | 9 ++-- tests/playwright-test/only-changed.spec.ts | 57 ++++++++++++++-------- 2 files changed, 43 insertions(+), 23 deletions(-) diff --git a/packages/playwright/src/util.ts b/packages/playwright/src/util.ts index a0e8e278c4..bc58bd9dd6 100644 --- a/packages/playwright/src/util.ts +++ b/packages/playwright/src/util.ts @@ -105,11 +105,12 @@ export async function detectChangedFiles(baseCommit: string): Promise } } - const untrackedFiles = gitFileList(`ls-files --others --exclude-standard`); - const trackedFilesWithChanges = gitFileList(`diff ${baseCommit} --name-only`); - const [gitRoot] = gitFileList('rev-parse --show-toplevel'); + const untrackedFiles = gitFileList(`ls-files --others --exclude-standard`).map(file => path.join(process.cwd(), file)); - const filesWithChanges = [...untrackedFiles, ...trackedFilesWithChanges].map(file => path.join(gitRoot, file)); + const [gitRoot] = gitFileList('rev-parse --show-toplevel'); + const trackedFilesWithChanges = gitFileList(`diff ${baseCommit} --name-only`).map(file => path.join(gitRoot, file)); + + const filesWithChanges = [...untrackedFiles, ...trackedFilesWithChanges]; return [ ...filesWithChanges, ...affectedTestFiles(filesWithChanges), diff --git a/tests/playwright-test/only-changed.spec.ts b/tests/playwright-test/only-changed.spec.ts index 672c3a6794..283756294c 100644 --- a/tests/playwright-test/only-changed.spec.ts +++ b/tests/playwright-test/only-changed.spec.ts @@ -241,26 +241,45 @@ test('should suppport component tests', async ({ runInlineTest, setupRepository, expect(result2.output).not.toContain('button.test.tsx'); }); -test('should work the same if being called in subdirectory', async ({ runInlineTest, setupRepository, writeFiles }) => { - const git = await setupRepository(); +test.describe('should work the same if being called in subdirectory', () => { + test('tracked file', async ({ runInlineTest, setupRepository, writeFiles }) => { + const git = await setupRepository(); - await writeFiles({ - 'tests/c.spec.ts': ` - import { test, expect } from '@playwright/test'; - test('fails', () => { expect(1).toBe(2); }); - ` + await writeFiles({ + 'tests/c.spec.ts': ` + import { test, expect } from '@playwright/test'; + test('fails', () => { expect(1).toBe(2); }); + ` + }); + git('add .'); + git('commit -a -m "add test"'); + + const result = await runInlineTest({ + 'tests/c.spec.ts': ` + import { test, expect } from '@playwright/test'; + test('fails', () => { expect(1).toBe(3); }); + ` + }, { 'only-changed': true }, {}, { cwd: 'tests' }); + + expect(result.exitCode).toBe(1); + expect(result.failed).toBe(1); + expect(result.output).toContain('c.spec.ts'); }); - git('add .'); - git('commit -a -m "add test"'); - const result = await runInlineTest({ - 'tests/c.spec.ts': ` - import { test, expect } from '@playwright/test'; - test('fails', () => { expect(1).toBe(3); }); - ` - }, { 'only-changed': true }, {}, { cwd: 'tests' }); + test('untracked file', async ({ runInlineTest, setupRepository }) => { + await setupRepository(); + + const result = await runInlineTest({ + 'tests/c.spec.ts': ` + import { test, expect } from '@playwright/test'; + test('fails', () => { expect(1).toBe(3); }); + ` + }, { 'only-changed': true }, {}, { cwd: 'tests' }); + + expect(result.exitCode).toBe(1); + expect(result.failed).toBe(1); + expect(result.output).toContain('c.spec.ts'); + }); +}); + - expect(result.exitCode).toBe(1); - expect(result.failed).toBe(1); - expect(result.output).toContain('c.spec.ts'); -}); \ No newline at end of file