From 359edf9c0f0ec89d260017b9bc41938e70bf39e8 Mon Sep 17 00:00:00 2001 From: Simon Knott Date: Wed, 17 Jul 2024 16:04:12 +0200 Subject: [PATCH] treat edge case of calling it in subdirectory --- packages/playwright/src/util.ts | 5 +++-- tests/playwright-test/only-changed.spec.ts | 24 ++++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/packages/playwright/src/util.ts b/packages/playwright/src/util.ts index 4102f446b8..a0e8e278c4 100644 --- a/packages/playwright/src/util.ts +++ b/packages/playwright/src/util.ts @@ -87,7 +87,7 @@ export async function detectChangedFiles(baseCommit: string): Promise return childProcess.execSync( `git ${command}`, { encoding: 'utf-8', stdio: 'pipe' } - ).split('\n').filter(Boolean).map(file => path.resolve(file)); + ).split('\n').filter(Boolean); } catch (_error) { const error = _error as childProcess.SpawnSyncReturns; throw new Error([ @@ -107,8 +107,9 @@ 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 filesWithChanges = [...untrackedFiles, ...trackedFilesWithChanges]; + const filesWithChanges = [...untrackedFiles, ...trackedFilesWithChanges].map(file => path.join(gitRoot, file)); return [ ...filesWithChanges, ...affectedTestFiles(filesWithChanges), diff --git a/tests/playwright-test/only-changed.spec.ts b/tests/playwright-test/only-changed.spec.ts index 7201d4f947..672c3a6794 100644 --- a/tests/playwright-test/only-changed.spec.ts +++ b/tests/playwright-test/only-changed.spec.ts @@ -240,3 +240,27 @@ test('should suppport component tests', async ({ runInlineTest, setupRepository, expect(result2.output).toContain('button2.test.tsx'); 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(); + + 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'); +}); \ No newline at end of file