npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

rs-jest

v1.1.0

Published

Jest preprocessor/transformer for Rust

Readme

npm size npm deps tests

rs-jest

tl;dr -- see examples

This is a jest transformer that loads Rust code so it can be interop with Javascript base project. Currently, the Rust code will be compiled as:

  • [x] WebAssembly module/instance
  • [ ] Node.js addon/ffi

Requirements

rustup default 1.28.0
rustup target add wasm32-unknown-unknown

Getting Started

To begin, you'll need to install rs-jest:

npm install rs-jest --save-dev

Then configure Jest to make rs-jest to transform the Rust (*.rs) file. For example:

jest.config.js

module.exports = {
  transform: {
    "^.+\\.rs$": "rs-jest"
  }
};

or if you prefer to put the config in package.json

  "jest": {
    "transform": {
      "^.+\\.rs$": "rs-jest"
    }
  }

lib.rs

#[no_mangle]
pub fn add(a: i32, b: i32) -> i32 {
    a + b
}

index.js

import wasm from "lib.rs";

export async function increment(a) {
  const { instance } = await wasm;
  return instance.exports.add(1, a);
}

And run jest via your preferred method.

Options

Pretty much like ts-jest, you can configure rs-jest by using global variables under the "rs-jest" key:

How wasm code would be exported. This options is identical with option export in webassembly-loader. (see examples)

{
  "globals": {
    "rs-jest": {
      "export": "instance"
    }
  },
  "transform": {
    "^.+\\.rs$": "rs-jest"
  }
}

The Rust target to use. Currently it only support wasm related target

{
  "globals": {
    "rs-jest": {
      "target": "wasm32-unknown-emscripten"
    }
  },
  "transform": {
    "^.+\\.rs$": "rs-jest"
  }
}
  • Type: Boolean
  • Default: true

Whether to compile the Rust code in debug or release mode.

{
  "globals": {
    "rs-jest": {
      "release": false
    }
  },
  "transform": {
    "^.+\\.rs$": "rs-jest"
  }
}

Examples

See the test cases and example projects in fixtures and examples for more insight.

Given this Rust code

lib.rs

#[no_mangle]
pub fn add(a: i32, b: i32) -> i32 {
    a + b
}

Cargo.toml

[package]
name = "adder"
version = "0.1.0"
authors = ["Full Name <[email protected]>"]

[lib]
crate-type = ["cdylib"]
path = "lib.rs"

With options

{export: 'buffer'}

import wasmCode from "./lib.rs";

WebAssembly.compile(wasmCode).then(module => {
  const instance = new WebAssembly.Instance(module);
  console(instance.exports.add(1, 2)); // 3
});

{export: 'module'}

import wasmModule from "./lib.rs";

const instance = new WebAssembly.Instance(wasmModule);
console(instance.exports.add(1, 2)); // 3

{export: 'instance'}

import wasm from "./lib.rs";

console(wasm.exports.add(1, 2)); // 3

{export: 'async'}

extern {
    fn hook(c: i32);
}

#[no_mangle]
pub fn add(a: i32, b: i32) -> i32 {
    hook(a + b)
}
import wasmInstantiate from "./lib.rs";

wasmInstantiate(importObject | undefined).then(({ instance, module }) => {
  console(instance.exports.add(1, 2)); // 3

  // create different instance, extra will be called in different environment
  const differentInstance = new WebAssembly.Instance(module, {
    env: {
      hook: result => result * 2
    }
  });
  console(differentInstance.exports.add(1, 2)); // 6
});

{export: 'async-instance'}

import wasmInstantiate from "./lib.rs";

wasmInstantiate(importObject | undefined).then(instance => {
  console(instance.exports.add(1, 2)); // 3
});

{export: 'async-module'}

import wasmInstantiate from "./lib.rs";

wasmCompile(importObject | undefined).then(module => {
  const differentInstance = new WebAssembly.Instance(module);
  console(differentInstance.exports.add(1, 2)); // 3
});

Who use this?

Contributing

Credits


License

FOSSA Status