Introducing rs-jest. A Jest preprocessor for transforming Rust code into Javascript module

in #utopian-io6 years ago (edited)

Repository

RepositoryLink
rs-jesthttps://github.com/DrSensor/rs-jest
Examplehttps://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.

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).

current ecosystem

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 😆.

CI workflow

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:

my plans to improve the ecosystem

  • 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 😅


GitHub Account

https://github.com/DrSensor


Sort:  
  • Great post, you have a very deep knowledge of rust.
  • I would love to see a real life example of its use. That would help the rest of us who have not yet oxidised.
  • There is a lot of details in your commits, you are used to work in teams right? Also it does look you're having a lot of fun with emojis, again. ;-)

Your contribution has been evaluated according to Utopian policies and guidelines, as well as a predefined set of questions pertaining to the category.

To view those questions and the relevant answers related to your post, click here.


Need help? Write a ticket on https://support.utopian.io/.
Chat with us on Discord.
[utopian-moderator]

Thankyou @helo, glad that you like it :). Some quick replies:

Great post, you have a very deep knowledge of rust.

I actually can't consider myself as an expert in Rust because I never published any crates (Rust package) yet ヽ(ツ)ノ. I just have some knowledge of build tools in general.

I would love to see a real-life example of its use. That would help the rest of us who have not yet oxidized.

Yeah, glad that someone takes interest (▀̿Ĺ̯▀̿*). Seems the fixtures and smoke-test that I provide are little bit shallow :D. The real advantage to use Rust in Javascript base project is the very minimal bundle size you can produce (see my tutorials) which are suitable to replace some implementation that requires complex abstraction level. Another benefit is performance, it doesn't guarantee that it has better execution speed over Javascript but at least you can have predictable performance (see here). I actually plan to make some webcomponent with Rust and Stenciljs to simulate a hardware device.

There is a lot of details in your commits, you are used to working in teams right? Also, it does look you're having a lot of fun with emojis, again. ;-)

Sort of, in the past ⎝ᵔᴥᵔ⎠
At least I don't use Lennyface as the bullet list ヽ(܍╭͜ʖ╮܍)ノ

Thank you for your review, @helo!

So far this week you've reviewed 2 contributions. Keep up the good work!

Hello! Your post has been resteemed and upvoted by @ilovecoding because we love coding! Keep up good work! Consider upvoting this comment to support the @ilovecoding and increase your future rewards! ^_^ Steem On!

Reply !stop to disable the comment. Thanks!

Hi @drsensor!

Your post was upvoted by @steem-ua, new Steem dApp, using UserAuthority for algorithmic post curation!
Your post is eligible for our upvote, thanks to our collaboration with @utopian-io!
Feel free to join our @steem-ua Discord server

Hey, @drsensor!

Thanks for contributing on Utopian.
We’re already looking forward to your next contribution!

Get higher incentives and support Utopian.io!
Simply set @utopian.pay as a 5% (or higher) payout beneficiary on your contribution post (via SteemPlus or Steeditor).

Want to chat? Join us on Discord https://discord.gg/h52nFrV.

Vote for Utopian Witness!

Coin Marketplace

STEEM 0.20
TRX 0.25
JST 0.038
BTC 96907.08
ETH 3380.66
USDT 1.00
SBD 3.23