diff --git a/packages/schematics/angular/web-worker/index.ts b/packages/schematics/angular/web-worker/index.ts index 8283ab9e72f5..e1437ecc17c9 100644 --- a/packages/schematics/angular/web-worker/index.ts +++ b/packages/schematics/angular/web-worker/index.ts @@ -105,7 +105,6 @@ function addSnippet(options: WebWorkerOptions): Rule { export default function (options: WebWorkerOptions): Rule { return async (host: Tree) => { const workspace = await getWorkspace(host); - if (!options.project) { throw new SchematicsException('Option "project" is required.'); } @@ -142,6 +141,18 @@ export default function (options: WebWorkerOptions): Rule { projectTargetOptions.webWorkerTsConfig = workerConfigPath; } + const projectTestTarget = project.targets.get('test'); + if (projectTestTarget) { + const projectTestTargetOptions = ((projectTestTarget.options || + {}) as unknown) as BrowserBuilderOptions; + + const needWebWorkerConfig = !projectTestTargetOptions.webWorkerTsConfig; + if (needWebWorkerConfig) { + const workerConfigPath = join(normalize(root), 'tsconfig.worker.json'); + projectTestTargetOptions.webWorkerTsConfig = workerConfigPath; + } + } + const templateSource = apply(url('./files/worker'), [ applyTemplates({ ...options, ...strings }), move(parsedPath.path),