angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

Angular 12 tests cannot construct Web Workers

Open ryankugel opened this issue 5 years ago • 2 comments

Which @angular/* package(s) are the source of the bug?

Don't known / other

Is this a regression?

Yes

Description

Web Workers are unable to be constructed in tests in Angular 12, which causes the following error: SecurityError: Failed to construct 'Worker': Script at 'file:///C:/Users/rkugel/Projects/webworker-test-angular-12/src/app/test.worker' cannot be accessed from origin 'http://localhost:9876'

This worked with previous versions of Angular, but fails on Angular 12. This failure can be seen in my example project by running ng test.

Please provide a link to a minimal reproduction of the bug

https://github.com/ryankugel/webworker-test-angular-12

Please provide the exception or error you saw

SecurityError: Failed to construct 'Worker': Script at 'file:///C:/Users/rkugel/Projects/webworker-test-angular-12/src/app/test.worker' cannot be accessed from origin 'http://localhost:9876'

Please provide the environment you discovered this bug in

Angular CLI: 12.2.4
Node: 14.17.5
Package Manager: npm 6.14.14
OS: win32 x64

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

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1202.4
@angular-devkit/build-angular   12.2.4
@angular-devkit/core            12.2.4
@angular-devkit/schematics      12.2.4
@schematics/angular             12.2.4
rxjs                            6.6.7
typescript                      4.3.5

Anything else?

No response

ryankugel avatar Sep 01 '21 22:09 ryankugel

The webWorkerTsConfig option needs to be added in the test builder.

"test": {
  "builder": "@angular-devkit/build-angular:karma",
  "options": {
    "main": "src/test.ts",
    "polyfills": "src/polyfills.ts",
+   "webWorkerTsConfig": "tsconfig.worker.ts",
    "tsConfig": "tsconfig.spec.json",
    "karmaConfig": "karma.conf.js",
    "styles": [
      "src/styles.scss"
    ],
    "scripts": []
  }

alan-agius4 avatar Sep 02 '21 11:09 alan-agius4

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.