Skip to content

Commit 6fe727b

Browse files
committed
fix(@angular/build): support extra test setup files with unit-test vitest runner
1 parent 4161ea8 commit 6fe727b

5 files changed

Lines changed: 42 additions & 3 deletions

File tree

packages/angular/build/src/builders/unit-test/builder.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,11 @@ export async function* execute(
193193
}
194194

195195
// Add setup file entries for TestBed initialization and project polyfills
196-
const setupFiles = ['init-testbed.js'];
196+
const setupFiles = ['init-testbed.js', ...normalizedOptions.setupFiles];
197197
if (buildTargetOptions?.polyfills?.length) {
198-
setupFiles.push('polyfills.js');
198+
// Placed first as polyfills may be required by the Testbed initialization
199+
// or other project provided setup files (e.g., zone.js, ECMAScript polyfills).
200+
setupFiles.unshift('polyfills.js');
199201
}
200202
const debugOptions = normalizedOptions.debug
201203
? {

packages/angular/build/src/builders/unit-test/karma-bridge.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ export async function useKarmaBuilder(
2121
);
2222
}
2323

24+
if (unitTestOptions.setupFiles.length) {
25+
context.logger.warn(
26+
'The "karma" test runner does not support the "setupFiles" option. The option will be ignored.',
27+
);
28+
}
29+
2430
const buildTargetOptions = (await context.validateOptions(
2531
await context.getTargetOptions(unitTestOptions.buildTarget),
2632
await context.getBuilderNameForTarget(unitTestOptions.buildTarget),

packages/angular/build/src/builders/unit-test/options.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ export async function normalizeOptions(
6262
watch: options.watch ?? isTTY(),
6363
debug: options.debug ?? false,
6464
providersFile: options.providersFile && path.join(workspaceRoot, options.providersFile),
65+
setupFiles: options.setupFiles
66+
? options.setupFiles.map((setupFile) => path.join(workspaceRoot, setupFile))
67+
: [],
6568
};
6669
}
6770

packages/angular/build/src/builders/unit-test/schema.json

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,14 @@
7676
"type": "array",
7777
"minItems": 1,
7878
"maxItems": 2,
79-
"items": [{ "$ref": "#/definitions/coverage-reporters" }, { "type": "object" }]
79+
"items": [
80+
{
81+
"$ref": "#/definitions/coverage-reporters"
82+
},
83+
{
84+
"type": "object"
85+
}
86+
]
8087
}
8188
]
8289
}
@@ -92,6 +99,13 @@
9299
"type": "string",
93100
"description": "TypeScript file that exports an array of Angular providers to use during test execution. The array must be a default export.",
94101
"minLength": 1
102+
},
103+
"setupFiles": {
104+
"type": "array",
105+
"items": {
106+
"type": "string"
107+
},
108+
"description": "A list of global setup and configuration files that are included before the test files. The application's polyfills are always included before these files. The Angular Testbed is also initialized prior to the execution of these files."
95109
}
96110
},
97111
"additionalProperties": false,

packages/angular/cli/src/commands/mcp/mcp-server.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,5 +76,19 @@ export async function createMcpServer(context: {
7676
},
7777
);
7878

79+
server.registerTool(
80+
'generate_component',
81+
{
82+
description: '',
83+
inputSchema: {},
84+
annotations: {},
85+
},
86+
() => {
87+
return {
88+
content: [],
89+
};
90+
},
91+
);
92+
7993
return server;
8094
}

0 commit comments

Comments
 (0)