Repository
Repository | Link |
---|---|
rs-jest | https://github.com/DrSensor/rs-jest |
Example | https://github.com/DrSensor/example-stencil-rust |
About rs-jest
rs-jest is a Jest preprocessor for transforming Rust code so that Jest can test a project that incorporate Rust on it.
Current features
Well, the feature are same as rollup-plugin-rust.
- 🗸 compile as WebAssembly
- 🗴 compile as Node Addon (probably will implement this using neon)
Technology Stack
The technology stack are pretty much the same as rollup-plugin-rust (see this post) with the difference in CI workflow and the linter + static-type-checker that I use.
Main Dependencies
Unlike rollup-plugin-rust, there is no main dependencies for this project. I actually want to make rust-native-wasm-loader as the main dependencies just like rollup-plugin-rust but I can't do that because Jest only support synchronous transformation and doesn't have intention to support asynchronous transformation. This is why I rewrote some functions of cargo.js in rust-native-wasm-loader to became synchronous one (see cargo.ts file).

CI and Build tools
The CI workflow with the build tools itself are almost the same as rollup-plugin-rust with the exception that I don't need to move smoke-test for stencil into TravisCI 😆.

Linter and Static type-checker
Since I had bad experience with Flow because it keep eating my RAM unpolitely 😂, I use Typescript as replacement. Typescript has their own linter called TSLint which mean I don't need ESLint that I setup in rollup-plugin-rust.
Test Framework/Approach
The test framework I used for this project is of course Jest running on Nodejs v8 or higher. The reason the minimum Nodejs is not v6 because the WebAssembly support begins in Nodejs v8. For the approach, I implement 2 kinds of test: unit-tests and smoke-tests. The unit-tests use Jest which automatically confirms that the generated code can be run in Nodejs ≥8.x. The smoke-tests itself written as example-stencil-rust (linked as git submodule) which automatically confirm that it can be used in the real project. There is weird setup for the unit-tests itself because I want to test the edge case just like how ts-jest approach it. I rely the test-cases pretty much on the fixtures which cause the number the test cases are pretty minimum. At this moment the test-cases are only one but it testing 6 fixtures 🤔.
Future Plans
To make maintaining rollup-plugin-rust and rs-jest easier and both of them are compatible within each release, I plan to add additional library as shown below:

- webassembly-loader : I need to create another wasm-loader alike because rs-jest and rollup-plugin-rust can export wasm into javascript module in various mode while wasm-loader don't have that feature. This make issue #11 to be moved in
webassembly-loader
. - cargo-cli-wrapper : Since most functions inside cargo.js in rust-native-wasm-loader are asynchronous functions while Jest don't support asynchronous transformation, I need to create wrapper that export both synchronous and asynchronous function (pretty much like fs-extra). Maybe I can make the function much simpler and have additional features and controls.
- Seems I need to get in touch with the maintainer of rust-native-wasm-loader after the
cargo-cli-wrapper
was released and see if he also want to maintain or use it.
How to contribute?
Just DM's me, make a Github issue or writes a comment below if interested. For guidelines, see Contributing section (contribution is always welcome so don't be afraid to make mistakes 🙂).
References/Credits
Reminder for myself! When you want to place comment of some code refences from Github, use copy permalink instead of copy line. This is what I found in most ts-jest codebase 😂
Parting words: by the way, where can I get
supported by utopian.io
badges 😅