Skip to content

Commit 7410b3a

Browse files
fix(runner): preserve quoted paths in only-changed detection (#43726)
Co-authored-by: microsoft-playwright-automation[bot] <203992400+microsoft-playwright-automation[bot]@users.noreply.github.com>
1 parent 018adb5 commit 7410b3a

2 files changed

Lines changed: 28 additions & 5 deletions

File tree

‎packages/playwright/src/runner/vcs.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ import path from 'path';
2020
import { cc } from '../common';
2121

2222
export async function detectChangedTestFiles(baseCommit: string, configDir: string): Promise<Set<string>> {
23-
function gitFileList(args: string[]) {
23+
function gitFileList(args: string[], separator = '\n') {
2424
try {
2525
return childProcess.execFileSync(
2626
'git', args,
2727
{ encoding: 'utf-8', stdio: 'pipe', cwd: configDir }
28-
).split('\n').filter(Boolean);
28+
).split(separator).filter(Boolean);
2929
} catch (_error) {
3030
const error = _error as childProcess.SpawnSyncReturns<string>;
3131

@@ -49,10 +49,10 @@ export async function detectChangedTestFiles(baseCommit: string, configDir: stri
4949
}
5050
}
5151

52-
const untrackedFiles = gitFileList(['ls-files', '--others', '--exclude-standard']).map(file => path.join(configDir, file));
52+
const untrackedFiles = gitFileList(['ls-files', '--others', '--exclude-standard', '-z'], '\0').map(file => path.join(configDir, file));
5353

5454
const [gitRoot] = gitFileList(['rev-parse', '--show-toplevel']);
55-
const trackedFilesWithChanges = gitFileList(['diff', baseCommit, '--name-only']).map(file => path.join(gitRoot, file));
55+
const trackedFilesWithChanges = gitFileList(['diff', baseCommit, '--name-only', '-z'], '\0').map(file => path.join(gitRoot, file));
5656

5757
return new Set(cc.affectedTestFiles([...untrackedFiles, ...trackedFilesWithChanges]));
5858
}

‎tests/playwright-test/only-changed.spec.ts‎

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,18 +288,38 @@ test('should run project dependencies of changed tests', {
288288
expect(result.output).toContain('setup test is executed');
289289
});
290290

291-
test('should work with list mode', async ({ runInlineTest, git, writeFiles }) => {
291+
test('should work with list mode', {
292+
annotation: { type: 'issue', description: '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/microsoft/playwright/issues/43661' },
293+
}, async ({ runInlineTest, git, writeFiles }) => {
292294
await writeFiles({
293295
'a.spec.ts': `
294296
import { test, expect } from '@playwright/test';
295297
test('fails', () => { expect(1).toBe(2); });
296298
`,
299+
'cadastro-usuário.spec.ts': `
300+
import { test } from '@playwright/test';
301+
test('tracked', () => {});
302+
`,
297303
});
298304

299305
git(`add .`);
300306
git(`commit -m init`);
301307

302308
const result = await runInlineTest({
309+
'cadastro-usuário.spec.ts': `
310+
import { test } from '@playwright/test';
311+
test('modified', () => {});
312+
`,
313+
'ação.spec.ts': `
314+
import { test } from '@playwright/test';
315+
test('untracked', () => {});
316+
`,
317+
...(process.platform === 'win32' ? {} : {
318+
'quoted "ação"\t\n.spec.ts': `
319+
import { test } from '@playwright/test';
320+
test('quoted', () => {});
321+
`,
322+
}),
303323
'b.spec.ts': `
304324
import { test, expect } from '@playwright/test';
305325
test('fails', () => { expect(1).toBe(2); });
@@ -309,6 +329,9 @@ test('should work with list mode', async ({ runInlineTest, git, writeFiles }) =>
309329
expect(result.exitCode).toBe(0);
310330
expect(result.output).toContain('b.spec.ts');
311331
expect(result.output).not.toContain('a.spec.ts');
332+
expect(result.output).toContain('cadastro-usuário.spec.ts');
333+
expect(result.output).toContain('ação.spec.ts');
334+
expect(result.output).toContain(`Total: ${process.platform === 'win32' ? 3 : 4} tests in ${process.platform === 'win32' ? 3 : 4} files`);
312335
});
313336

314337
test('exits successfully if there are no changes', async ({ runInlineTest, git, writeFiles }) => {

0 commit comments

Comments
 (0)