mirror of
https://github.com/angular/angular-cli.git
synced 2025-05-16 02:24:10 +08:00
fix(@schematics/angular): properly log data received in web worker snippet
The generated snippet was: worker.onmessage = ({ data }) => { console.log('page got message: $\{data\}'); }; which doesn't use a template string and so does not log `data`. Fixes the generated snippet to be `console.log(`page got message: ${data}`);`. Also adds a newline at the end of the web worker template to not fail the default TSLint rules if the schematic is used.
This commit is contained in:
parent
0edc095cd3
commit
fcbe988d10
@ -150,12 +150,13 @@ function addSnippet(options: WebWorkerOptions): Rule {
|
||||
}
|
||||
|
||||
const siblingModulePath = `${options.path}/${siblingModules[0]}`;
|
||||
const logMessage = 'console.log(`page got message: ${data}`);';
|
||||
const workerCreationSnippet = tags.stripIndent`
|
||||
if (typeof Worker !== 'undefined') {
|
||||
// Create a new
|
||||
const worker = new Worker('./${options.name}.worker', { type: 'module' });
|
||||
worker.onmessage = ({ data }) => {
|
||||
console.log('page got message: $\{data\}');
|
||||
${logMessage}
|
||||
};
|
||||
worker.postMessage('hello');
|
||||
} else {
|
||||
|
@ -81,5 +81,6 @@ describe('Service Worker Schematic', () => {
|
||||
const tree = schematicRunner.runSchematic('web-worker', defaultOptions, appTree);
|
||||
const appComponent = tree.readContent('/projects/bar/src/app/app.component.ts');
|
||||
expect(appComponent).toContain(`new Worker('./${defaultOptions.name}.worker`);
|
||||
expect(appComponent).toContain('console.log(`page got message: ${data}`)');
|
||||
});
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user