@@ -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