|
6 | 6 | * found in the LICENSE file at https://angular.dev/license |
7 | 7 | */ |
8 | 8 |
|
| 9 | +import { promises as fs } from 'node:fs'; |
| 10 | +import os from 'node:os'; |
| 11 | +import { join } from 'node:path'; |
9 | 12 | import { initializeHash } from '../../utils/hash'; |
10 | | -import { generateNameFromPath, getTestEntrypoints } from './test-discovery'; |
| 13 | +import { toPosixPath } from '../../utils/path'; |
| 14 | +import { findTests, generateNameFromPath, getTestEntrypoints } from './test-discovery'; |
| 15 | + |
| 16 | +describe('findTests', () => { |
| 17 | + let projectSourceRoot: string; |
| 18 | + |
| 19 | + beforeEach(async () => { |
| 20 | + projectSourceRoot = await fs.mkdtemp(join(os.tmpdir(), 'angular-find-tests-')); |
| 21 | + }); |
| 22 | + |
| 23 | + afterEach(async () => { |
| 24 | + await fs.rm(projectSourceRoot, { recursive: true, force: true }); |
| 25 | + }); |
| 26 | + |
| 27 | + it('should return the test files sorted, regardless of the crawl order', async () => { |
| 28 | + const files = ['z/z.spec.ts', 'a/b/c.spec.ts', 'm.spec.ts', 'a/a.spec.ts', 'b/x/y.spec.ts']; |
| 29 | + for (const file of files) { |
| 30 | + const path = join(projectSourceRoot, file); |
| 31 | + await fs.mkdir(join(path, '..'), { recursive: true }); |
| 32 | + await fs.writeFile(path, ''); |
| 33 | + } |
| 34 | + |
| 35 | + const result = await findTests(['**/*.spec.ts'], [], projectSourceRoot, projectSourceRoot); |
| 36 | + |
| 37 | + const expected = files.map((file) => toPosixPath(join(projectSourceRoot, file))).sort(); |
| 38 | + expect(result).toEqual(expected); |
| 39 | + }); |
| 40 | +}); |
11 | 41 |
|
12 | 42 | describe('getTestEntrypoints', () => { |
13 | 43 | beforeAll(async () => { |
|
0 commit comments