Skip to content

Commit 8a9fa18

Browse files
committed
fixup! fix(@angular/build): resolve Vitest artifacts when workspace root is aliased
1 parent c1d06f3 commit 8a9fa18

2 files changed

Lines changed: 19 additions & 9 deletions

File tree

‎packages/angular/build/src/builders/unit-test/runners/vitest/executor.ts‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
updateExternalMetadata,
2020
} from '../../../../tools/vite/utils';
2121
import { assertIsError } from '../../../../utils/error';
22+
import { toPosixPath } from '../../../../utils/path';
2223
import {
2324
type FullResult,
2425
type IncrementalResult,
@@ -377,11 +378,15 @@ export class VitestExecutor implements TestExecutor {
377378
// Filter internal entries and setup files from the include list
378379
const internalEntries = ['angular:'];
379380
const setupFileSet = new Set(testSetupFiles);
380-
const include = [...this.testFileToEntryPoint.keys()].filter((entry) => {
381-
return (
382-
!internalEntries.some((internal) => entry.startsWith(internal)) && !setupFileSet.has(entry)
383-
);
384-
});
381+
const include: string[] = [];
382+
for (const entry of this.testFileToEntryPoint.keys()) {
383+
if (
384+
!internalEntries.some((internal) => entry.startsWith(internal)) &&
385+
!setupFileSet.has(entry)
386+
) {
387+
include.push(toPosixPath(path.relative(workspaceRoot, entry)));
388+
}
389+
}
385390
this.debugLog(DebugLogLevel.Verbose, 'Included test files (after filtering):', include);
386391

387392
const vitestConfig = {

‎packages/angular/build/src/builders/unit-test/runners/vitest/plugins_spec.ts‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,13 @@
77
*/
88

99
import path from 'node:path';
10-
import type { VitestPluginContext } from 'vitest/node';
1110
import { BuildOutputFileType } from '../../../../tools/esbuild/bundler-files';
1211
import { toPosixPath } from '../../../../utils/path';
1312
import type { ResultFile } from '../../../application/results';
1413
import { createVitestPlugins } from './plugins';
1514

1615
describe('createVitestPlugins', () => {
17-
it('resolves and loads setup files when vitestConfig.root differs from workspaceRoot (e.g., symlink or subst drive)', async () => {
16+
it('resolves and loads setup and spec files when vitestConfig.root differs from workspaceRoot', async () => {
1817
const workspaceRoot = path.resolve('/logical-workspace/test-project');
1918
const physicalRoot = toPosixPath(path.resolve('/physical-disk/tmp/test-project'));
2019
const specFile = toPosixPath(path.join(workspaceRoot, 'src/app/app.spec.ts'));
@@ -57,14 +56,14 @@ describe('createVitestPlugins', () => {
5756
expect(inMemoryPlugin).toBeDefined();
5857

5958
const configureVitest = inMemoryPlugin?.configureVitest as
60-
((context: VitestPluginContext) => void) | undefined;
59+
((context: { vitest: { config: { root: string } } }) => void) | undefined;
6160
configureVitest?.({
6261
vitest: {
6362
config: {
6463
root: physicalRoot,
6564
},
6665
},
67-
} as unknown as VitestPluginContext);
66+
});
6867

6968
const resolveId = inMemoryPlugin?.resolveId as (
7069
id: string,
@@ -80,5 +79,11 @@ describe('createVitestPlugins', () => {
8079

8180
const loadedSetup = await load(expectedSetupId);
8281
expect(loadedSetup?.code).toBe('console.log("init-compiler");');
82+
83+
const resolvedSpecId = resolveId(`${physicalRoot}/src/app/app.spec.ts`, undefined);
84+
expect(resolvedSpecId).toBe(specFile);
85+
86+
const loadedSpec = await load(specFile);
87+
expect(loadedSpec?.code).toBe('console.log("spec");');
8388
});
8489
});

0 commit comments

Comments
 (0)