Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🔥 NG generate web worker breaks unit tests in Angular 12 #21108

Closed
rustygreen opened this issue Jun 10, 2021 · 3 comments · Fixed by #21109
Closed

🔥 NG generate web worker breaks unit tests in Angular 12 #21108

rustygreen opened this issue Jun 10, 2021 · 3 comments · Fixed by #21109

Comments

@rustygreen
Copy link

🐞 Bug Report

Affected Package

The issue involves the generator for service workers when using Angular 12.

Is this a regression?

The issue was not present in previous versions of Angular. It only started happening for Angular 12.

Description

When adding a web worker in Angular12 (now required to use the import.meta.url due to webpack 5 - as the Angular docs describe), unit tests will not run:

image

Minimal Reproduction

  1. Create a new Angular 12 application using the CLI
    npx -p @angular/cli ng new worker-test --style=scss --routing
    cd new worker-test
  2. Generate a web worker using the CLI
    npm run ng -- generate web-worker my-test-worker
  3. Add web worker usage in app.component.ts
  ngOnInit():void{
    // NOTE: using new URL('', import.meta.url) breaks unit test compilation in v12.
    const worker = new Worker(new URL('./my-test-worker.worker', import.meta.url));
    worker.onmessage = ({ data }) => {
      console.log(`page got message: ${data}`);
    };

    worker.postMessage('hello');
  }
  1. Run npm run test

Exception or Error

image

Your Environment

Angular Version:


Angular CLI: 12.0.3
Node: 14.17.0
Package Manager: npm 6.14.13
OS: win32 x64

Angular: 12.0.4
... animations, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1200.3
@angular-devkit/build-angular   12.0.3
@angular-devkit/core            12.0.3
@angular-devkit/schematics      12.0.3
@angular/cli                    12.0.3
@schematics/angular             12.0.3
rxjs                            6.6.7
typescript                      4.2.4
@JoostK JoostK transferred this issue from angular/angular Jun 10, 2021
@alan-agius4
Copy link
Collaborator

For new projects this is fixed via #21057.

For existing projects, in angular.json you need to specify the web-worker tsconfig path in using the webWorkerTsConfigoption under the test builder.

@rustygreen
Copy link
Author

That did it. Thanks, @alan-agius4!

clydin pushed a commit that referenced this issue Jun 11, 2021
…hen `webWorkerTsConfig` is not defined in karma builder

This is to retain version 11 behaviour.

Closes #21108
clydin pushed a commit that referenced this issue Jun 11, 2021
…hen `webWorkerTsConfig` is not defined in karma builder

This is to retain version 11 behaviour.

Closes #21108

(cherry picked from commit 071c8d1)
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Jul 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
2 participants