Skip to content

using BuilderContext from @angular-devkit/architect to run angular unit test converts undefined to default type value #32652

Description

@BharathSubu

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

Don't known / other

Is this a regression?

Yes

Description

i have multiple libs so for each lib the unit test is running using @angular/build:unit-test in jsdom , like this

"test": { "builder": "@angular/build:unit-test", "options": { "tsConfig": "libs/mylib/tsconfig.spec.json", "runnerConfig": "libs/mylib/vitest.config.ts", "watch": false } },

to run all utest of all libs im using

"test-all": { "builder": "dist:build-all", "options": { "targets": [ mylib:test , mylib1:test ] } },

this dist:build-all uses BuilderContext from @angular-devkit/architect

await this.context.scheduleTarget(target, overrides);

issue is when running mylib:test the test run fines , but when running project:test-all

angular unit test fails with list of supported browser not specified

the issue

when running mylib:test the parameter passed to @angular/build:unit-test is browser = undefined
but when running project:test-all the parameter passed to @angular/build:unit-test is browser = []

coz internally await this.context.scheduleTarget(target, overrides); convert undefined to default value i guess here it is []

so is there any way i can make sure this conversion doesnt happen , or specify @angular/build:unit-test to not run the test in browser

Image

this issue also happend when coverageIncludes is not specified , when ran using @angular/build:unit-test
coverageIncludes is undefined , but when ran using await this.context.scheduleTarget(target, overrides); the value passed is [] and coverage is not reported

Please provide a link to a minimal reproduction of the bug

No response

Please provide the exception or error you saw


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


Angular CLI       : 21.1.0
Angular           : 21.1.0
Node.js           : 22.18.0
Package Manager   : yarn 1.22.22
Operating System  : win32 x64

┌───────────────────────────────────┬───────────────────┬───────────────────┐
│ Package                           │ Installed Version │ Requested Version │
├───────────────────────────────────┼───────────────────┼───────────────────┤
│ @angular-devkit/architect         │ 0.2101.0          │ 0.2101.0          │
│ @angular-devkit/build-angular     │ 21.1.0            │ 21.1.0            │
│ @angular-devkit/core              │ 21.1.0            │ 21.1.0            │
│ @angular-devkit/schematics        │ 21.1.0            │ 21.1.0            │
│ @angular-devkit/schematics-cli    │ 21.1.0            │ 21.1.0            │
│ @angular/animations               │ 21.1.0            │ 21.1.0            │
│ @angular/build                    │ 21.1.0            │ 21.1.0            │
│ @angular/cdk                      │ 21.1.0            │ 21.1.0            │
│ @angular/cli                      │ 21.1.0            │ 21.1.0            │
│ @angular/common                   │ 21.1.0            │ 21.1.0            │
│ @angular/compiler                 │ 21.1.0            │ 21.1.0            │
│ @angular/compiler-cli             │ 21.1.0            │ 21.1.0            │
│ @angular/core                     │ 21.1.0            │ 21.1.0            │
│ @angular/elements                 │ 21.1.0            │ 21.1.0            │
│ @angular/forms                    │ 21.1.0            │ 21.1.0            │
│ @angular/language-service         │ 21.1.0            │ 21.1.0            │
│ @angular/localize                 │ 21.1.0            │ 21.1.0            │
│ @angular/material                 │ 21.1.0            │ 21.1.0            │
│ @angular/platform-browser         │ 21.1.0            │ 21.1.0            │
│ @angular/platform-browser-dynamic │ 21.1.0            │ 21.1.0            │
│ @angular/router                   │ 21.1.0            │ 21.1.0            │
│ @angular/service-worker           │ 21.1.0            │ 21.1.0            │
│ ng-packagr                        │ 21.1.0            │ 21.1.0            │
│ rxjs                              │ 7.8.2             │ 7.8.2             │
│ typescript                        │ 5.9.3             │ 5.9.3             │
│ vitest                            │ 4.0.18            │ 4.0.18            │
│ webpack                           │ 5.105.0           │ 5.105.0           │
│ zone.js                           │ 0.16.0            │ 0.16.0            │

Anything else?

No response

Activity

  1. added
    area: build & ciRelated the build and CI infrastructure of the project
    gemini-triagedLabel noting that an issue has been triaged by gemini
    on Mar 3, 2026
  2. added this to the needsTriage milestone on Mar 3, 2026
  3. added
    area: build & ciRelated the build and CI infrastructure of the project
    gemini-triagedLabel noting that an issue has been triaged by gemini
    on Mar 3, 2026
  4. transferred this issue fromangular/angularon Mar 3, 2026
  5. removed
    area: build & ciRelated the build and CI infrastructure of the project
    gemini-triagedLabel noting that an issue has been triaged by gemini
    on Mar 3, 2026
  6. alan-agius4 commented on Mar 3, 2026

    @alan-agius4
    Collaborator

    Since ng test already handles the full project suite, could you clarify the specific need for a separate builder in this case? Without a runnable reproduction, it’s difficult to diagnose the issue you're seeing with your custom builder.

    Regarding the logic: the conversion from undefined to [] is intentional, and there is currently no configuration to disable this behavior

  7. BharathSubu commented on Mar 3, 2026

    @BharathSubu
    Author

    We’re using a custom builder as an orchestration layer over ng test because we need to override certain parameters when running the full project suite — for example, enabling coverage (and additional suite-specific options) only during full-suite execution, while keeping individual library test runs lightweight. different lib with different config when ran for entire project suite.

    any other builder i can use that would allow me to perform this and not have this undefined to [] and still override the options

  8. alan-agius4 commented on Mar 3, 2026

    @alan-agius4
    Collaborator

    We'd require a minimal reproduction to investigate.

    You can read here why this is needed. A good way to make a minimal repro is to create a new app via ng new repro-app and adding the minimum possible code to show the problem. Then you can push this repository to github and link it here.

    This might be related to your directory structure so its really important to get an accurate repro to diagnose this.

  9. BharathSubu commented on Mar 4, 2026

    @BharathSubu
    Author

    @alan-agius4 https://github.com/BharathSubu/angular-build-issue-repo

    after setup try running ng run mylib:test and ng run repro-app:test-all

    ng run my-lib:test                              
    Initial chunk files  | Names             |  Raw size
    chunk-CGZBV6BD.js    | -                 |   4.07 kB | 
    spec-lib-my-lib.js   | spec-lib-my-lib   |   1.66 kB | 
    init-testbed.js      | init-testbed      |   1.21 kB | 
    vitest-mock-patch.js | vitest-mock-patch | 481 bytes |                    
    
                         | Initial total     |   7.42 kB
    
    Application bundle generation complete. [2.079 seconds] - 2026-03-04T10:22:31.802Z
    
    Watch mode enabled. Watching for file changes...
    
     DEV  v4.0.18 D:/Personal/repro-app
    
     ✓  my-lib  projects/my-lib/src/lib/my-lib.spec.ts (1 test) 33ms
       ✓ MyLib (1)
         ✓ should create 32ms
    
     Test Files  1 passed (1)
          Tests  1 passed (1)
       Start at  15:52:32
       Duration  1.83s (transform 87ms, setup 432ms, import 22ms, tests 33ms, environment 1.12s)
    
    ng run repro-app:test-all
    Running target "my-lib:test"...
    Initial chunk files  | Names             |  Raw size
    chunk-CGZBV6BD.js    | -                 |   4.07 kB | 
    spec-lib-my-lib.js   | spec-lib-my-lib   |   1.66 kB | 
    init-testbed.js      | init-testbed      |   1.21 kB | 
    vitest-mock-patch.js | vitest-mock-patch | 481 bytes | 
    
                         | Initial total     |   7.42 kB
    
    Application bundle generation complete. [1.249 seconds] - 2026-03-04T10:21:21.658Z
    
    Watch mode enabled. Watching for file changes...
    An exception occurred during test execution:
    Error: The "browsers" option requires either "playwright" or "webdriverio" to be installed within the project. Please install one of these packages and rerun the test command.
    
  10. alan-agius4 commented on Mar 4, 2026

    @alan-agius4
    Collaborator

    In the reproduction provided I am only seeing a single project and no custom builders.

  11. BharathSubu commented on Mar 4, 2026

    @BharathSubu
    Author

    @alan-agius4 sry , i missed to push the changes, could you check now pls

  12. added a commit that references this issue on Mar 4, 2026
    1a16a26
  13. added a commit that references this issue on Mar 4, 2026
    584f6a2
  14. alan-agius4 commented on Mar 4, 2026

    @alan-agius4
    Collaborator

    Actually I just realized that there other properties with this issue

  15. added a commit that references this issue on Mar 4, 2026
    f17ed30
  16. self-assigned this
    on Mar 4, 2026
  17. BharathSubu commented on Mar 4, 2026

    @BharathSubu
    Author

    true , i observed this with coverageIncludes too , guess anything undefined need to be handled when passing thru the builder

  18. alan-agius4 commented on Mar 5, 2026

    @alan-agius4
    Collaborator

    I’ve investigated the behavior, and it appears that coverageIncludes remains unaffected. Both undefined and empty arrays are currently handled identically within the logic.

  19. angular-automatic-lock-bot commented on Apr 5, 2026

    @angular-automatic-lock-bot

    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.

  20. locked and limited conversation to collaborators on Apr 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions