Skip to content

Commit 0d1f298

Browse files
committed
refactor(@schematics/angular): support parsing plain template literals in karma config analyzer
Updates the AST analyzer to accept static backtick strings that do not contain runtime expressions. Previously, even simple template literals resulted in a fallback warning flag, triggering manual migration overrides unnecessarily.
1 parent aed407d commit 0d1f298

2 files changed

Lines changed: 31 additions & 1 deletion

File tree

packages/schematics/angular/migrations/migrate-karma-to-vitest/karma-config-analyzer.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ export function analyzeKarmaConfig(content: string): KarmaConfigAnalysis {
8080
function extractValue(node: ts.Expression): KarmaConfigValue {
8181
switch (node.kind) {
8282
case ts.SyntaxKind.StringLiteral:
83-
return (node as ts.StringLiteral).text;
83+
case ts.SyntaxKind.NoSubstitutionTemplateLiteral:
84+
return (node as ts.StringLiteral | ts.NoSubstitutionTemplateLiteral).text;
8485
case ts.SyntaxKind.NumericLiteral:
8586
return Number((node as ts.NumericLiteral).text);
8687
case ts.SyntaxKind.TrueKeyword:

packages/schematics/angular/migrations/migrate-karma-to-vitest/karma-config-analyzer_spec.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,4 +293,33 @@ describe('Karma Config Analyzer', () => {
293293
expect(settings.size).toBe(0);
294294
expect(hasUnsupportedValues).toBe(true);
295295
});
296+
297+
it('should parse plain template literal strings without substitution', () => {
298+
const karmaConf = `
299+
module.exports = function (config) {
300+
config.set({
301+
basePath: \`some/path\`,
302+
});
303+
};
304+
`;
305+
const { settings, hasUnsupportedValues } = analyzeKarmaConfig(karmaConf);
306+
307+
expect(settings.get('basePath') as unknown).toBe('some/path');
308+
expect(hasUnsupportedValues).toBe(false);
309+
});
310+
311+
it('should flag template literals with substitution as unsupported', () => {
312+
const karmaConf = `
313+
const relativePath = './coverage';
314+
module.exports = function (config) {
315+
config.set({
316+
basePath: \`\${relativePath}/test\`,
317+
});
318+
};
319+
`;
320+
const { settings, hasUnsupportedValues } = analyzeKarmaConfig(karmaConf);
321+
322+
expect(settings.get('basePath')).toBeUndefined();
323+
expect(hasUnsupportedValues).toBe(true);
324+
});
296325
});

0 commit comments

Comments
 (0)