
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
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:
rustup default 1.28.0
rustup target add wasm32-unknown-unknown
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.
Pretty much like ts-jest, you can configure rs-jest by using global variables under the "rs-jest" key:
exportHow 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"
}
}
targetStringwasm32-unknown-unknownThe Rust target to use. Currently it only support wasm related target
{
"globals": {
"rs-jest": {
"target": "wasm32-unknown-emscripten"
}
},
"transform": {
"^.+\\.rs$": "rs-jest"
}
}
releaseBooleantrueWhether to compile the Rust code in debug or release mode.
{
"globals": {
"rs-jest": {
"release": false
}
},
"transform": {
"^.+\\.rs$": "rs-jest"
}
}
See the test cases and example projects in fixtures and examples for more insight.
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@site.domain>"]
[lib]
crate-type = ["cdylib"]
path = "lib.rs"
{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
});
FAQs
Jest preprocessor/transformer for Rust
We found that rs-jest demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.