Add client unit testing #74

Manually merged
luca0N merged 17 commits from dev_client_tests into dev 2026-07-23 23:04:03 +00:00
Owner

Add unit testing to the web app client using Vitest.

Add unit testing to the web app client using Vitest.
luca0N self-assigned this 2026-05-20 23:45:40 +00:00
Switch to `vitest' for unit testing in the web app project, the default
unit test package provided for new Angular projects.
Add missing `@angular/localize' reference that caused issues when
running unit tests in the web app Angular project.
luca0N changed title from Add client unit testing to WIP: Add client unit testing 2026-06-05 11:19:16 +00:00
Add workflow for running client unit tests
Some checks failed
/ Test client (push) Failing after 48s
7cc850cec4
Create CI workflow to run unit testing for the web app client.
Update Node.js package in client workflow
Some checks failed
/ Test client (push) Failing after 58s
0b5ab62c39
Use the `nodejs-current' Alpine Linux package as opposed to `nodejs', as
Angular requires a minimum version of Node.js that is not available in
the latter.
Fix web app unit testing
Some checks failed
/ Test client (push) Has been cancelled
ab7dbb44fe
Fix the web app client unit testing by making `ConfigManager.ts'
@Injectable (and move it to the `services/' subdirectory), and perform
some minor code refactoring (to reflect these changes in files that use
ConfigManager).
luca0N force-pushed dev_client_tests from ab7dbb44fe
Some checks failed
/ Test client (push) Has been cancelled
to edf4cc9aac
Some checks failed
/ Test client (push) Failing after 55s
2026-06-16 22:29:25 +00:00
Compare
luca0N force-pushed dev_client_tests from edf4cc9aac
Some checks failed
/ Test client (push) Failing after 55s
to 28eff1a35e
All checks were successful
/ Test client (push) Successful in 58s
2026-06-16 22:34:14 +00:00
Compare
luca0N force-pushed dev_client_tests from 28eff1a35e
All checks were successful
/ Test client (push) Successful in 58s
to 38e60eb4e8 2026-06-16 22:39:11 +00:00
Compare
Author
Owner
  • Force-push from ab7dbb44fe to edf4cc9aac was made to revert an erroneous change in the workflow
  • Force-push from edf4cc9aac to 28eff1a35e was made to fix an outdated source file which referenced the old path for ConfigManager
  • Force-push from 28eff1a35e to 38e60eb4e8 was made to change the commit message, detailing that partial support for HttpClient was added.

HttpClient will replace the direct fetch API used in the web app client because it has unit test support built-in, making it much easier to run this workflow.

- Force-push from ab7dbb44fe to edf4cc9aac was made to revert an erroneous change in the workflow - Force-push from edf4cc9aac to 28eff1a35e was made to fix an outdated source file which referenced the old path for ConfigManager - Force-push from 28eff1a35e to 38e60eb4e8 was made to change the commit message, detailing that partial support for HttpClient was added. HttpClient will replace the direct fetch API used in the web app client because it has unit test support built-in, making it much easier to run this workflow.
Use HttpClient in ServerComms
Some checks failed
/ Test client (push) Failing after 55s
ece2380978
Replace the fetch API with HttpClient in the ServerComms class, as part
of the ongoing migration intended to introduce unit testing in the web
app client.
luca0N force-pushed dev_client_tests from ece2380978
Some checks failed
/ Test client (push) Failing after 55s
to 20841f9290
Some checks failed
/ Test client (push) Failing after 55s
2026-06-21 20:06:21 +00:00
Compare
luca0N force-pushed dev_client_tests from 20841f9290
Some checks failed
/ Test client (push) Failing after 55s
to 3bce136eea
All checks were successful
/ Test client (push) Successful in 1m0s
2026-06-21 20:09:14 +00:00
Compare
Author
Owner

The previous force-push operations (from ece2380978 to 20841f9290, and from 20841f9290 to 3bce136eea) were made to fix syntax errors in the code, and to remove WIP code that is not ready to be committed.

The previous force-push operations (from ece2380978 to 20841f9290, and from 20841f9290 to 3bce136eea) were made to fix syntax errors in the code, and to remove WIP code that is not ready to be committed.
In the web app client, replace the unused Jasmine types with Vitest's in
`tsconfig.spec.ts'.  This will be required in a future commit where
Vitest types will be used, and are implicitly required.
Add unit testing for web app `ServerComms'
All checks were successful
/ Test client (push) Successful in 1m0s
2fa1ff8830
Add unit tests for the `ServerComms' class in the web app client, and
use `reject' in the `authenticate' function, as required to get the
combination of HttpClient and Vitest's `rejects.toThrow' to work.
Add unit testing for `ConfigManager'
All checks were successful
/ Test client (push) Successful in 1m1s
2e4bcbe413
Add unit tests for the `ConfigManager' class.  This new unit testing
source file checks for two of the public functions in the
`ConfigManager' class, which return the server configuration.  The unit
test checks to see if both return the configuration that matches that of
the mocked response.
Move and refactor LiveConnection class
All checks were successful
/ Test client (push) Successful in 1m1s
f76c24e3aa
Perform some minor code refactoring by moving the @Injectable
LiveConnection class to the `services/' subdirectory, which contains
other @Injectable classes used in the project, and create a new
@Injectable class for handling WebSocket connections, which will be used
in a future commit to mock WebSocket connections in unit tests.
Add initial WebSocket mocking support
All checks were successful
/ Test client (push) Successful in 55s
9704a5c78d
Create initial `WebSocketConnectionMock' class for mocking WebSocket
servers during unit testing in the client web app.  The base
`WebSocketConnection' class was slightly changed to allow replacing
during `TestBed' injection.
Add initial LiveConnection unit testing
All checks were successful
/ Test client (push) Successful in 57s
3b695edf92
Add initial unit testing for the LiveConnection web app client source
file, using the newly created WebSocketConnectionMock class.  At this
time, the unit testing is very limited, as the only thing that is being
testing is whether LiveConnection is indeed attempting to establish a
WebSocket connection.
Test incoming WebSocket data in unit tests
All checks were successful
/ Test client (push) Successful in 56s
2f5261e333
Add support for mocking incoming data (client-to-server) in the
`WebSocketConnectionMock' source file, and use it in the
`LiveConnection' unit testing source file to test whether the class is
indeed sending expected data right after connecting to the mocked
WebSocket server.
Test outgoing data from `LiveConnection'
All checks were successful
/ Test client (push) Successful in 58s
9897acaa4a
Test outgoing data from `LiveConnection' to the mock WebSocket server,
and add support for testing client data in `WebSocketConnectionMock'.
Test live connection events
All checks were successful
/ Test client (push) Successful in 58s
3a1fa0fd04
Modify the `LiveConnection.spec.ts' source file to test whether
LiveConnection is correctly receiving and parsing the EVENT_HOST_FOUND
event.
Author
Owner

The web app client set of tests are almost complete, and the remaining classes/source files that haven't had their unit testing counterpart added are the ones that are out of scope (like PreferencesManager.ts, which deals with browser cookies and is very simple, not too much complexity that can introduce bugs).

I am currently evaluating whether I will add unit testing for components in this pull request. Lanbassador does not have any custom components to test: all components used in the web app come from Material Angular.

The web app client set of tests are almost complete, and the remaining classes/source files that haven't had their unit testing counterpart added are the ones that are out of scope (like PreferencesManager.ts, which deals with browser cookies and is very simple, not too much complexity that can introduce bugs). I am currently evaluating whether I will add unit testing for components in this pull request. Lanbassador does not have any custom components to test: all components used in the web app come from Material Angular.
Await call to `expect' in the `should receive host detection events'
LiveConnection test, per Vitest documentation.
Add more `LiveConnection' tests
All checks were successful
/ Test client (push) Successful in 59s
6a8e328de3
Create the following unit tests for the LiveConnection class:

   1. should connect: tests if the LiveConnection class is able to
      connect to the mock WebSocket server.

   2. should not connect on protocol version mismatch: tests whether the
      onConnectionError event is called on protocol mismatch.  If the
      server indicates that the protocol version announced by the client
      during the initial handshake is unsupported, then connection
      should fail, and the test shall pass.

   3. should receive host history: tests whether LiveConnection can
      correctly receive the list of previously detected hosts (those in
      the history queue, which are hosts that have been detected prior
      to the current connection).

In order to accomplish item no. 2 above, LiveConnection had to be
slightly modified so that it calls the onConnectionError event, as
opposed to throwing an Error.
Author
Owner

I am currently satisfied with the unit testing in Lanbassador, so this means that the time of merging this pull request is almost here.

I am currently satisfied with the unit testing in Lanbassador, so this means that the time of merging this pull request is almost here.
luca0N changed title from WIP: Add client unit testing to Add client unit testing 2026-07-23 22:52:46 +00:00
Author
Owner

As laid out in the commit 6a8e328de3 message, I had to change LiveConnection slightly so that it would call the onConnectionError event instead of throwing Errors on unsuccessful return actions. I have also modified the signature for that event so that it could provide more information about the connection error, instead of it just being a callback with no parameters.

The reason behind this decision is that I was unsuccessful at my attempts of getting Vitest to detect those errors being thrown, supposedly due to the fact that they were thrown inside the Subscriber. This pull request has already been dragged out for way too long, so these changes will suffice at this time.

As laid out in the commit 6a8e328de3 message, I had to change `LiveConnection` slightly so that it would call the `onConnectionError` event instead of throwing `Error`s on unsuccessful return actions. I have also modified the signature for that event so that it could provide more information about the connection error, instead of it just being a callback with no parameters. The reason behind this decision is that I was unsuccessful at my attempts of getting Vitest to detect those errors being thrown, supposedly due to the fact that [they were thrown inside the Subscriber](https://git.luca0n.com/luca0N/lanbassador/src/commit/b1eaf61d96/client/src/app/services/LiveConnection.ts#L297). This pull request has already been dragged out for way too long, so these changes will suffice at this time.
luca0N manually merged commit 276dfb9505 into dev 2026-07-23 23:04:03 +00:00
luca0N deleted branch dev_client_tests 2026-07-23 23:04:15 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Blocks
#11 Add tests
luca0N/lanbassador
Reference
luca0N/lanbassador!74
No description provided.