Skip to content

Conversation

@naoNao89
Copy link
Contributor

Implements WebAssembly unit tests as requested in #73. Adds 20 WASM browser tests running in headless Chrome, 10 native error handling tests with mock FFI, and CI automation.

fixes #73

@naoNao89 naoNao89 force-pushed the feat/wasm-unit-tests-issue-73 branch 7 times, most recently from 9b879db to 006e78e Compare December 16, 2025 01:41
- name: Run WASM tests in headless browser
run: |
cd whoami
wasm-pack test --headless --chrome --all-features
Copy link
Member

Choose a reason for hiding this comment

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

Would it be possible to use wasmtime instead?

@AldaronLau
Copy link
Member

@naoNao89 Thanks for the PR! I think a number of changes will be needed before merging, but it's pretty cool as-is. I think mostly it seems like the platform specific code wouldn't be compiled when running the wasm tests since it's gated on not(target_arch = "wasm"), and I think it needs an extra condition, that way it can override that condition if the mock_ffi feature is enabled (or maybe a custom cfg, like for the existing daku cfg, would be better).

- Add 20 WASM integration tests running in headless Chrome
- Add 10 native Unix error handling tests with mock FFI
- Add Windows error handling test infrastructure
- Add CI job for automated WASM testing
- Add wasm-bindgen-test dev dependency
@naoNao89 naoNao89 force-pushed the feat/wasm-unit-tests-issue-73 branch from 006e78e to f38d13d Compare December 21, 2025 12:47
@naoNao89
Copy link
Contributor Author

naoNao89 commented Dec 21, 2025

Done, removed the redundant console dep and dead test code.

Added a big TODO about potentially switching to wasmtime instead of Chrome for CI. Would eliminate browser dependencies and speed up tests, worth discussing for a future PR.

@naoNao89 naoNao89 requested a review from AldaronLau December 21, 2025 18:40
@AldaronLau
Copy link
Member

@naoNao89 I'm still not quite sure how this PR all comes together. As far as I can tell unix_test and windows_test modules under the os modules aren't being included anywhere. I'm finding it too difficult for me to review as well as I'd like to. I think it has a lot of components needed to resolve #73, but I also think it's missing some pieces. It would also be easier for me to review if it was broken up into smaller PRs (like having the wasm, windows, and unix pieces up separately, and having running wasm in CI working first). I think I'll break up #73 into smaller issues. I'd also like if some of the FFI types didn't need to be duplicated in their definitions for these tests (for example UtsName, MockUtsName). I don't want to merge this all together, or with a dependency on chrome in C/I. I do appreciate this PR, though!

My eventual vision, (that I didn't fully write out) should contain something like this:

   {

       mock_set_pass_wd(PassWd { .. });
       mock_set_getpwuid_r(Ok(()));
       let res = whoami::username();
       assert!(res, Ok("mock_username"));

       mock_set_errno(EIO);
       mock_set_getpwuid_r(Err(()));
       let res = whoami::username();
       assert!(res, Err(..));
   }

I think for a next step, if you could split part of this (probably targeting a specific platform to wasm) into a smaller PR, that would be really helpful for me. Thank you!

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.

WebAssembly Unit Tests

2 participants