support changed files
This commit is contained in:
parent
da65da5d79
commit
30447b14f4
|
|
@ -83,7 +83,9 @@ export type TestFileFilter = {
|
||||||
export async function createFileFiltersFromArguments(args: string[], onlyChanged: boolean): Promise<TestFileFilter[]> {
|
export async function createFileFiltersFromArguments(args: string[], onlyChanged: boolean): Promise<TestFileFilter[]> {
|
||||||
if (onlyChanged) {
|
if (onlyChanged) {
|
||||||
const untrackedFiles = childProcess.execSync('git ls-files --others --exclude-standard', { encoding: 'utf-8' }).split('\n').filter(Boolean);
|
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 => {
|
return args.map(arg => {
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ import { execSync } from 'node:child_process';
|
||||||
import { writeFile } from 'node:fs/promises';
|
import { writeFile } from 'node:fs/promises';
|
||||||
import { join } from 'node:path';
|
import { join } from 'node:path';
|
||||||
|
|
||||||
test('should filter by file name', async ({ runInlineTest }) => {
|
test('should detect untracked files', async ({ runInlineTest }) => {
|
||||||
const result = await runInlineTest({
|
const result = await runInlineTest({
|
||||||
'a.spec.ts': `
|
'a.spec.ts': `
|
||||||
import { test, expect } from '@playwright/test';
|
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.failed).toBe(1);
|
||||||
expect(result.output).toContain('c.spec.ts');
|
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');
|
||||||
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue