Skip to content

[YUNIKORN-3254] Migrate unit tests from Karma to Vitest#271

Closed
mitdesai wants to merge 2 commits into
apache:masterfrom
mitdesai:YUNIKORN-3254
Closed

[YUNIKORN-3254] Migrate unit tests from Karma to Vitest#271
mitdesai wants to merge 2 commits into
apache:masterfrom
mitdesai:YUNIKORN-3254

Conversation

@mitdesai
Copy link
Copy Markdown
Contributor

What is this PR for?

Migrate the unit test infrastructure from the deprecated Karma + Jasmine stack to Vitest, using Angular's built-in @angular/build:unit-test builder. Karma is no longer maintained and Vitest becomes the official Angular test runner default in Angular 21. This migration removes 12 Karma/Jasmine devDependencies, eliminates the Puppeteer/Chrome requirement, and runs tests under jsdom instead of a headless browser.

What type of PR is it?

  • - Bug Fix
  • - Improvement
  • - Feature
  • - Documentation
  • - Hot Fix
  • - Refactoring

What is the Jira issue?

https://issues.apache.org/jira/browse/YUNIKORN-3254

How should this be tested?

Run make test — all 24 test files (50 tests) should pass.
No behavioral changes to the application code; only test infrastructure and spec files are modified.

Screenshots (if appropriate)

N/A

Questions:

  • - The licenses files need update. (Apache headers added to no new source files; deleted files only)
  • - There is breaking changes for older versions.
  • - It needs documentation.

@mitdesai mitdesai requested a review from wilfred-s April 16, 2026 02:24
@mitdesai mitdesai self-assigned this Apr 16, 2026
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 16, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 41.66%. Comparing base (d4beecb) to head (bb2635e).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #271      +/-   ##
==========================================
+ Coverage   38.77%   41.66%   +2.89%     
==========================================
  Files           2       61      +59     
  Lines          49     2328    +2279     
  Branches        0      383     +383     
==========================================
+ Hits           19      970     +951     
- Misses         27     1165    +1138     
- Partials        3      193     +190     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Contributor

@akhilpb001 akhilpb001 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we are in angular v20, vitest support is available from v21 onwards. Why don't you upgrade angular to 21 along with unit tests? Is there any breaking changes from 20 to 21? Also can you check the config files with newly generated angular 21 sample app and verify the config files side by side?

Comment thread package.json Outdated
"build:prod": "ng build --configuration production",
"start:srv": "json-server --watch json-db.json",
"test:coverage": "ng test --code-coverage --karma-config=./karma.conf.ci.js --watch=false",
"test:coverage": "ng test --watch=false",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In angular 21, coverage is supported by --coverage flag, add it for test:coverage command.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

@mitdesai
Copy link
Copy Markdown
Contributor Author

Thanks for reviewing @akhilpb001. I will work on these changes and update the PR

- Upgrade all @angular/* packages to ^21.2.0 and TypeScript to ~5.9.2
- Add provideZoneChangeDetection() to AppModule (required by Angular 21)
- Add null guard for queueSelect ViewChild in apps-view component
  (Angular 21 TestBed rethrows errors previously swallowed)
- Fix queue-v2 spec: prevent D3 visualization from running under jsdom
- Fix test:coverage script to use --coverage flag (Angular 21 stable)
@mitdesai
Copy link
Copy Markdown
Contributor Author

Angular 20 → 21 Upgrade

Package upgrades

  • All @angular/* packages: ^20.x^21.2.0
  • TypeScript: 5.8.35.9.2 (required by @angular/build@21)

src/app/components/apps-view/apps-view.component.ts

This is a production code fix surfaced by the Angular 21 upgrade. The openQueueSelection() method calls this.queueSelect.open(), where queueSelect is a @ViewChild with static: false. During ngOnInit, a route param subscription fires clearQueueSelection() → openQueueSelection() before ngAfterViewInit resolves the ViewChild, so queueSelect is undefined. Under Angular 20, this error was silently swallowed. Angular 21's TestBed now correctly rethrows application errors (documented breaking change). The fix: this.queueSelect?.open().

src/app/components/queue-v2/queues-v2.component.spec.ts

Two changes to prevent D3 visualization from crashing under jsdom:

  1. Removed fixture.detectChanges() from beforeEach — prevents ngOnInit from triggering the D3 SVG rendering pipeline
  2. Changed the service spy to mockReturnValue(of({} as any)) (no rootQueue) — the second test now verifies the service call chain (spinner.show → fetchSchedulerQueues → spinner.hide) without entering the queueVisualization() code path that requires real SVG/canvas APIs

src/app/app.module.ts

Added provideZoneChangeDetection({ eventCoalescing: true }) to AppModule.providers. Angular 21 no longer provides a ZoneJS change detection scheduler by default — this must now be explicitly configured.

package.json

  • Angular and TypeScript version bumps
  • test:coverage script updated to use --coverage flag (supported in Angular 21's stable @angular/build:unit-test builder; was broken under Angular 20's experimental builder)

@mitdesai mitdesai requested a review from akhilpb001 April 16, 2026 16:06
@wilfred-s
Copy link
Copy Markdown
Contributor

The changes look good from my side.
I will need to rebase the CVE fixes on top of what you have done here.
@akhilpb001 any further remarks? Looks like everything is covered and the build is working generating the same UI as before the change.

Copy link
Copy Markdown
Contributor

@wilfred-s wilfred-s left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@manirajv06 manirajv06 closed this in b14dbf5 May 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants