Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,10 @@ export async function findTests(
}
}

// 3. Combine and de-duplicate results
return [...resolvedTestFiles];
// 3. Combine, de-duplicate and sort the results. The glob crawls directories asynchronously and
// returns matches in a varying order; the order feeds the build entry points, so an unsorted list
// makes the output (chunk contents and names) differ between two builds of the same sources.
return [...resolvedTestFiles].sort();
Comment thread
jv3n marked this conversation as resolved.
}

interface TestEntrypointsOptions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,40 @@
* found in the LICENSE file at https://angular.dev/license
*/

import assert from 'node:assert';
import { promises as fs } from 'node:fs';
import { join } from 'node:path';
import { initializeHash } from '../../utils/hash';
import { generateNameFromPath, getTestEntrypoints } from './test-discovery';
import { toPosixPath } from '../../utils/path';
import { findTests, generateNameFromPath, getTestEntrypoints } from './test-discovery';

describe('findTests', () => {
let projectSourceRoot: string;

beforeEach(async () => {
const baseTmpDir = process.env['TEST_TMPDIR'];
assert(baseTmpDir, 'TEST_TMPDIR is not set');
projectSourceRoot = await fs.mkdtemp(join(baseTmpDir, 'angular-find-tests-'));
});
Comment thread
jv3n marked this conversation as resolved.

afterEach(async () => {
await fs.rm(projectSourceRoot, { recursive: true, force: true });
});

it('should return the test files sorted, regardless of the crawl order', async () => {
const files = ['z/z.spec.ts', 'a/b/c.spec.ts', 'm.spec.ts', 'a/a.spec.ts', 'b/x/y.spec.ts'];
for (const file of files) {
const path = join(projectSourceRoot, file);
await fs.mkdir(join(path, '..'), { recursive: true });
await fs.writeFile(path, '');
}

const result = await findTests(['**/*.spec.ts'], [], projectSourceRoot, projectSourceRoot);

const expected = files.map((file) => toPosixPath(join(projectSourceRoot, file))).sort();
expect(result).toEqual(expected);
});
});

describe('getTestEntrypoints', () => {
beforeAll(async () => {
Expand Down
Loading