Thanks to visit codestin.com
Credit goes to github.com

Skip to content

@angular/build:karma does not include scripts in the output #30534

Closed
@Tucos

Description

@Tucos

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

Don't known / other

Is this a regression?

No

Description

The @angular/build:karma builder - used by default for new projects - has support for the scripts option. This is the same as for the @angular-devkit/build-angular:karma builder.

This option should result in the specified script being included in the generated output that hosts the test, but it is not.

In the provided reproduction, the application has a declaration for some global data. This data is output by the application. The repository has 2 branches, karma-new and karma-old. Running npx ng serve shows the expected output with the new builder; running npx ng test fails with the new builder. Running npx ng test with the old builder works fine.

Please provide a link to a minimal reproduction of the bug

https://github.com/Tucos/angular-karma-builder-scripts-bug

Please provide the exception or error you saw

ReferenceError: someglobalobject is not defined
            at App2.get data [as data] (src/app/app.ts:10:5)
            at App2_Template (ng:///App2.js:12:55)
            at executeTemplate (node_modules/@angular/core/fesm2022/debug_node-JnOYh9kg.mjs:7140:9)
            at refreshView (node_modules/@angular/core/fesm2022/debug_node-JnOYh9kg.mjs:8888:13)
            at detectChangesInView (node_modules/@angular/core/fesm2022/debug_node-JnOYh9kg.mjs:9108:9)
            at detectChangesInViewIfAttached (node_modules/@angular/core/fesm2022/debug_node-JnOYh9kg.mjs:9068:5)
            at detectChangesInComponent (node_modules/@angular/core/fesm2022/debug_node-JnOYh9kg.mjs:9056:5)
            at detectChangesInChildComponents (node_modules/@angular/core/fesm2022/debug_node-JnOYh9kg.mjs:9134:9)
            at refreshView (node_modules/@angular/core/fesm2022/debug_node-JnOYh9kg.mjs:8943:13)
            at detectChangesInView (node_modules/@angular/core/fesm2022/debug_node-JnOYh9kg.mjs:9108:9)
Chrome 137.0.0.0 (Windows 10): Executed 2 of 2 (1 FAILED) (0.283 secs / 0.277 secs)

Please provide the environment you discovered this bug in (run ng version)

Angular CLI: 20.0.2
Node: 20.19.2
Package Manager: npm 10.8.2
OS: win32 x64

Angular: 20.0.3
... common, compiler, compiler-cli, core, forms
... platform-browser, router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.2000.2
@angular-devkit/build-angular   20.0.2
@angular-devkit/core            20.0.2
@angular-devkit/schematics      20.0.2
@angular/build                  20.0.2
@angular/cli                    20.0.2
@schematics/angular             20.0.2
rxjs                            7.8.2
typescript                      5.8.3
zone.js                         0.15.1

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions