Skip to content

Commit c5331a9

Browse files
committed
fixup! fix(@schematics/angular): avoid adding web worker snippet to server configuration files
1 parent 68d986a commit c5331a9

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

‎packages/schematics/angular/web-worker/index.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ function addSnippet(options: WebWorkerOptions): Rule {
3737
return;
3838
}
3939

40-
const fileRegExp = new RegExp(`^${options.name}.*\\.ts`);
40+
const fileRegExp = new RegExp(`^${options.name}(?:\\..+)?\\.ts$`);
4141
const siblingModules = host
4242
.getDir(options.path)
4343
.subfiles // Find all files that start with the same name, are ts files,

‎packages/schematics/angular/web-worker/index_spec.ts‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ describe('Web Worker Schematic', () => {
9696
});
9797

9898
it('should add snippet to the component file and not a server configuration file', async () => {
99-
const serverAppTree = await schematicRunner.runSchematic('server', { project: 'bar' }, appTree);
100-
const tree = await schematicRunner.runSchematic('web-worker', defaultOptions, serverAppTree);
99+
appTree.create('/projects/bar/src/app/app.config.server.ts', 'export const config = {};\n');
100+
const tree = await schematicRunner.runSchematic('web-worker', defaultOptions, appTree);
101101

102102
const appComponent = tree.readContent('/projects/bar/src/app/app.ts');
103103
expect(appComponent).toContain(`new Worker(new URL('./${defaultOptions.name}.worker`);
@@ -115,6 +115,16 @@ describe('Web Worker Schematic', () => {
115115
expect(content).toContain(`new Worker(new URL('./observer.worker`);
116116
});
117117

118+
it('should not add snippet to a file whose name only starts with the worker name', async () => {
119+
appTree.create('/projects/bar/src/app/app-header.ts', 'export class AppHeader {}\n');
120+
const tree = await schematicRunner.runSchematic('web-worker', defaultOptions, appTree);
121+
122+
expect(tree.readContent('/projects/bar/src/app/app-header.ts')).not.toContain('new Worker');
123+
expect(tree.readContent('/projects/bar/src/app/app.ts')).toContain(
124+
`new Worker(new URL('./${defaultOptions.name}.worker`,
125+
);
126+
});
127+
118128
it('should not add snippet to a declaration file', async () => {
119129
appTree.create('/projects/bar/src/app/app.d.ts', 'declare const foo: string;\n');
120130
const tree = await schematicRunner.runSchematic('web-worker', defaultOptions, appTree);

0 commit comments

Comments
 (0)