untracked and tracked files need to be treated differently

This commit is contained in:
Simon Knott 2024-07-17 16:06:56 +02:00
parent 359edf9c0f
commit ab05bbf9c8
No known key found for this signature in database
GPG key ID: 8CEDC00028084AEC
2 changed files with 43 additions and 23 deletions

View file

@ -105,11 +105,12 @@ export async function detectChangedFiles(baseCommit: string): Promise<string[]>
} }
} }
const untrackedFiles = gitFileList(`ls-files --others --exclude-standard`); const untrackedFiles = gitFileList(`ls-files --others --exclude-standard`).map(file => path.join(process.cwd(), file));
const trackedFilesWithChanges = gitFileList(`diff ${baseCommit} --name-only`);
const [gitRoot] = gitFileList('rev-parse --show-toplevel');
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 [ return [
...filesWithChanges, ...filesWithChanges,
...affectedTestFiles(filesWithChanges), ...affectedTestFiles(filesWithChanges),

View file

@ -241,26 +241,45 @@ test('should suppport component tests', async ({ runInlineTest, setupRepository,
expect(result2.output).not.toContain('button.test.tsx'); expect(result2.output).not.toContain('button.test.tsx');
}); });
test('should work the same if being called in subdirectory', async ({ runInlineTest, setupRepository, writeFiles }) => { test.describe('should work the same if being called in subdirectory', () => {
const git = await setupRepository(); test('tracked file', async ({ runInlineTest, setupRepository, writeFiles }) => {
const git = await setupRepository();
await writeFiles({ await writeFiles({
'tests/c.spec.ts': ` 'tests/c.spec.ts': `
import { test, expect } from '@playwright/test'; import { test, expect } from '@playwright/test';
test('fails', () => { expect(1).toBe(2); }); 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({ test('untracked file', async ({ runInlineTest, setupRepository }) => {
'tests/c.spec.ts': ` await setupRepository();
import { test, expect } from '@playwright/test';
test('fails', () => { expect(1).toBe(3); });
`
}, { 'only-changed': true }, {}, { cwd: 'tests' });
expect(result.exitCode).toBe(1); const result = await runInlineTest({
expect(result.failed).toBe(1); 'tests/c.spec.ts': `
expect(result.output).toContain('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');
});
}); });