Skip to content

Commit 88f860d

Browse files
fix(testing): warn and default if sourceRoot isn't set for ng CT (#13940)
1 parent 3a2721b commit 88f860d

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

packages/angular/plugins/component-testing.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,11 +231,20 @@ function normalizeBuildTargetOptions(
231231
buildOptions.scripts = [];
232232
buildOptions.stylePreprocessorOptions = { includePaths: [] };
233233
}
234-
const { root, sourceRoot } =
234+
235+
const config =
235236
buildContext.projectGraph.nodes[buildContext.projectName]?.data;
237+
238+
if (!config.sourceRoot) {
239+
logger.warn(stripIndents`Unable to find the 'sourceRoot' in the project configuration.
240+
Will set 'sourceRoot' to '${config.root}/src'
241+
Note: this may fail, setting the correct 'sourceRoot' for ${buildContext.projectName} in the project.json file will ensure the correct value is used.`);
242+
config.sourceRoot = joinPathFragments(config.root, 'src');
243+
}
244+
236245
return {
237-
root: joinPathFragments(offset, root),
238-
sourceRoot: joinPathFragments(offset, sourceRoot),
246+
root: joinPathFragments(offset, config.root),
247+
sourceRoot: joinPathFragments(offset, config.sourceRoot),
239248
buildOptions,
240249
};
241250
}

0 commit comments

Comments
 (0)