Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/schematics/angular/web-worker/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { parseName } from '../utility/parse-name';
import { relativePathToWorkspaceRoot } from '../utility/paths';
import { createProjectSchematic } from '../utility/project';
import { buildDefaultPath, updateWorkspace } from '../utility/workspace';
import { Builders } from '../utility/workspace-models';
import { Schema as WebWorkerOptions } from './schema';

function addSnippet(options: WebWorkerOptions): Rule {
Expand Down Expand Up @@ -115,7 +116,8 @@ const webWorkerSchematic: RuleFactory<WebWorkerOptions> = createProjectSchematic

const workerConfigPath = join(root, 'tsconfig.worker.json');
(buildTarget.options ??= {}).webWorkerTsConfig ??= workerConfigPath;
if (testTarget) {
// The unit-test builder has no `webWorkerTsConfig` option and reads it from the build target.
if (testTarget && testTarget.builder !== Builders.BuildUnitTest) {
(testTarget.options ??= {}).webWorkerTsConfig ??= workerConfigPath;
}
}),
Expand Down
20 changes: 20 additions & 0 deletions packages/schematics/angular/web-worker/index_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import { SchematicTestRunner, UnitTestTree } from '@angular-devkit/schematics/testing';
import { parse as parseJson } from 'jsonc-parser';
import { Schema as ApplicationOptions } from '../application/schema';
import { Builders } from '../utility/workspace-models';
import { Schema as WorkspaceOptions } from '../workspace/schema';
import { Schema as WebWorkerOptions } from './schema';

Expand Down Expand Up @@ -68,6 +69,25 @@ describe('Web Worker Schematic', () => {
);
});

it('should not add the webWorkerTsConfig option to a unit-test builder test target', async () => {
const tree = await schematicRunner.runSchematic('web-worker', defaultOptions, appTree);
const { projects } = JSON.parse(tree.readContent('/angular.json'));
expect(projects.bar.architect.test.builder).toBe(Builders.BuildUnitTest);
expect(projects.bar.architect.test.options?.webWorkerTsConfig).toBeUndefined();
});

it('should add the webWorkerTsConfig option to a karma builder test target', async () => {
const config = JSON.parse(appTree.readContent('/angular.json'));
config.projects.bar.architect.test = { builder: Builders.BuildKarma, options: {} };
appTree.overwrite('/angular.json', JSON.stringify(config, undefined, 2));

const tree = await schematicRunner.runSchematic('web-worker', defaultOptions, appTree);
const { projects } = JSON.parse(tree.readContent('/angular.json'));
expect(projects.bar.architect.test.options.webWorkerTsConfig).toBe(
'projects/bar/tsconfig.worker.json',
);
});

it('should add snippet to sibling file', async () => {
const tree = await schematicRunner.runSchematic('web-worker', defaultOptions, appTree);
const appComponent = tree.readContent('/projects/bar/src/app/app.ts');
Expand Down
Loading