Skip to content

Resolve "Add frontend vitest unit tests to ci and fix broken tests" - #397

Merged
nick-greenwald merged 11 commits into
mainfrom
389-add-frontend-vitest-unit-tests-to-ci-and-fix-broken-tests
Aug 26, 2026
Merged

nick-greenwald merged 11 commits into
mainfrom
389-add-frontend-vitest-unit-tests-to-ci-and-fix-broken-tests

Conversation

@nick-greenwald

Copy link
Copy Markdown
Contributor

Fixes broken skeleton unit tests for various components and adds a unit test CI job.

@nick-greenwald nick-greenwald self-assigned this Aug 19, 2026
@nick-greenwald
nick-greenwald requested a review from a team as a code owner August 19, 2026 19:40
@nick-greenwald nick-greenwald added the sustainment Long-term sustainment activities and technical debt removal label Aug 19, 2026
@nick-greenwald nick-greenwald linked an issue Aug 19, 2026 that may be closed by this pull request
@github-project-automation github-project-automation Bot moved this to Todo in ANMS Aug 19, 2026
Comment thread .github/workflows/build-test.yaml Fixed
Comment thread .github/workflows/build-test.yaml Fixed
Comment thread .github/workflows/build-test.yaml Fixed
@BrianSipos BrianSipos added this to the ANMS v3.0.0 milestone Aug 21, 2026

@d-linko d-linko left a comment

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.

Attempting running the testing locally
got

 Test Files  25 passed (25)
      Tests  62 passed (62)
     Errors  1 error

with the error HttpErrorResponse: Http failure response for http://localhost:3000/api/core/adms: 401 Unauthorized

and also in the logs im seeing

Failed to load ARIs HttpErrorResponse {
  headers: HttpHeaders {
    headers: undefined,
    normalizedNames: Map(0) {},
    lazyInit: [Function (anonymous)],
    lazyUpdate: null
  },
  status: 401,
  statusText: 'Unauthorized',
  url: 'http://localhost:3000/api/build/ari/all',
  ok: false,
  type: undefined,
  redirected: undefined,
  responseType: undefined,
  name: 'HttpErrorResponse',
  message: 'Http failure response for http://localhost:3000/api/build/ari/all: 401 Unauthorized',
  error: {
    extra: null,
    message: 'Unauthorized',
    messageId: 'auth.unauthorized',
    statusCode: 401,
    traceID: ''
  }
}

looks like its trying a different port is that different in the CI

@nick-greenwald

Copy link
Copy Markdown
Contributor Author

@d-linko #397 (review)

The latest changes I made should fix this. I believe the issue was that the Angular dev server that vitest runs against tries to bind to port 3000, and if you have the docker containers up and running then the grafana container is already bound to that port. There were some unhandled HTTP requests being thrown out by component dependencies that should have been mocked, so that is likely why you were getting 401 unauthorized errors, as the HTTP requests being thrown out by the dev server tests were hitting running containers. The latest changes mock the dependencies that were sending out the unhandled HTTP requests so this should hopefully not be an issue anymore, but you can try to test with the ANMS containers up and down to see if you see a difference in test behavior.

@d-linko

d-linko commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

#397 (comment)

The test now pass when containers are up or down
Im still seeing errors

stderr | src/app/features/status/status.spec.ts
update status error HttpErrorResponse {
  headers: HttpHeaders {
    headers: Map(0) {},
    normalizedNames: Map(0) {},
    lazyInit: undefined,
    lazyUpdate: null
  },
  status: 0,
  statusText: 'Unknown Error',
  url: '/api/core/service_status',
  ok: false,
  type: undefined,
  redirected: undefined,
  responseType: undefined,
  name: 'HttpErrorResponse',
  message: 'Http failure response for /api/core/service_status: 0 Unknown Error',
  error: ProgressEvent { isTrusted: [Getter] }
}
Error fetching service status: HttpErrorResponse {
  headers: HttpHeaders {
    headers: Map(0) {},
    normalizedNames: Map(0) {},
    lazyInit: undefined,
    lazyUpdate: null
  },
  status: 0,
  statusText: 'Unknown Error',
  url: '/api/core/service_status',
  ok: false,
  type: undefined,
  redirected: undefined,
  responseType: undefined,
  name: 'HttpErrorResponse',
  message: 'Http failure response for /api/core/service_status: 0 Unknown Error',
  error: ProgressEvent { isTrusted: [Getter] }
}

in either case

@d-linko
d-linko self-requested a review August 25, 2026 14:36
@sonarqubecloud

Copy link
Copy Markdown

@nick-greenwald

Copy link
Copy Markdown
Contributor Author

#397 (comment) @d-linko

There was still some usage of the Http Client, which was not the correct way to mock HTTP requests. I've updated everything and those unknown HTTP errors in the test output should not longer be present. I also found that the way I stubbed some of the service dependencies for previous tests wasn't very conducive to expanding the tests in the future, so I fixed those.

I also made an update that suppresses that error properly by spying on the output, as it is an expected error. I also fixed a sonarqube warning that exposed a lack of any real assertions in that status test as well, so the PR should be in a good state now.

@d-linko

d-linko commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

#397 (comment)
Just tried locally and everything passed without an of the errors seen before!

@nick-greenwald
nick-greenwald merged commit a0dff6d into main Aug 26, 2026
16 checks passed
@nick-greenwald
nick-greenwald deleted the 389-add-frontend-vitest-unit-tests-to-ci-and-fix-broken-tests branch August 26, 2026 17:52
@github-project-automation github-project-automation Bot moved this from Todo to Done in ANMS Aug 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

sustainment Long-term sustainment activities and technical debt removal

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Add frontend vitest unit tests to CI and fix broken tests

5 participants