support changed files

This commit is contained in:
Simon Knott 2024-07-17 10:45:41 +02:00
parent da65da5d79
commit 30447b14f4
No known key found for this signature in database
GPG key ID: 8CEDC00028084AEC
2 changed files with 33 additions and 2 deletions

View file

@ -83,7 +83,9 @@ export type TestFileFilter = {
export async function createFileFiltersFromArguments(args: string[], onlyChanged: boolean): Promise<TestFileFilter[]> {
if (onlyChanged) {
const untrackedFiles = childProcess.execSync('git ls-files --others --exclude-standard', { encoding: 'utf-8' }).split('\n').filter(Boolean);
args = untrackedFiles;
const changedFiles = childProcess.execSync('git diff --name-only', { encoding: 'utf-8' }).split('\n').filter(Boolean);
args = [...untrackedFiles, ...changedFiles];
}
return args.map(arg => {

View file

@ -19,7 +19,7 @@ import { execSync } from 'node:child_process';
import { writeFile } from 'node:fs/promises';
import { join } from 'node:path';
test('should filter by file name', async ({ runInlineTest }) => {
test('should detect untracked files', async ({ runInlineTest }) => {
const result = await runInlineTest({
'a.spec.ts': `
import { test, expect } from '@playwright/test';
@ -45,3 +45,32 @@ test('should filter by file name', async ({ runInlineTest }) => {
expect(result.failed).toBe(1);
expect(result.output).toContain('c.spec.ts');
});
test('should detect changed files', async ({ runInlineTest }) => {
const result = await runInlineTest({
'a.spec.ts': `
import { test, expect } from '@playwright/test';
test('fails', () => { expect(1).toBe(2); });
`,
'b.spec.ts': `
import { test, expect } from '@playwright/test';
test('fails', () => { expect(1).toBe(2); });
`,
async [magicFileCreationSymbol](baseDir) {
execSync(`git init --initial-branch=main`, { cwd: baseDir });
execSync(`git add .`, { cwd: baseDir });
execSync(`git commit -m init`, { cwd: baseDir });
await writeFile(join(baseDir, 'b.spec.ts'), `
import { test, expect } from '@playwright/test';
test('fails', () => { expect(1).toBe(3); });
`);
}
}, { 'only-changed': true });
expect(result.exitCode).toBe(1);
expect(result.failed).toBe(1);
expect(result.output).toContain('b.spec.ts');
});