Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 39 additions & 13 deletions .github/workflows/js-wasm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,37 +51,63 @@ jobs:
echo "test=$test" >> "$GITHUB_OUTPUT"
echo "gate=$gate" >> "$GITHUB_OUTPUT"

lint:
name: JS/WASM Lints
needs: [plan]
if: needs.plan.outputs.test == 'true'
runs-on: ubuntu-24.04
defaults:
run:
working-directory: bindings/js

steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6
with:
node-version: 24
cache: npm
cache-dependency-path: bindings/js/package-lock.json

- name: Install dependencies
run: npm ci

- name: Run linter
run: npm run lint

test:
name: JS/WASM Tests
needs: [plan]
if: needs.plan.outputs.test == 'true'
runs-on: ubuntu-24.04
env:
WASM_BINDGEN_USE_BROWSER: 1
defaults:
run:
working-directory: bindings/js

steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6
with:
node-version: 24
cache: npm
cache-dependency-path: bindings/js/package-lock.json
- uses: Swatinem/rust-cache@e18b497796c12c097a38f9edb9d0641fb99eee32 # v2

- name: Install wasm-pack
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh

- name: Test in Firefox
run: |
cd bindings/js
export WASM_BINDGEN_USE_BROWSER=1
wasm-pack test --headless --firefox
run: wasm-pack test --headless --firefox

- name: Test in Chrome
run: |
cd bindings/js
export WASM_BINDGEN_USE_BROWSER=1
wasm-pack test --headless --chrome
run: wasm-pack test --headless --chrome

- name: Build for Node.js and test
run: |
cd bindings/js
npm install
npm run test:browser
- name: Install Node.js dependencies
run: npm ci

- name: Test with Node.js
run: npm run test:browser

ci-gate:
name: JS/WASM CI Gate
Expand Down
12 changes: 12 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ repos:
.*\.lock
)$

# Lint: javascript
- repo: https://github.com/pre-commit/mirrors-eslint
rev: v10.1.0
hooks:
- id: eslint
files: ^bindings/js/
types: [javascript]
additional_dependencies:
- eslint@^10.1.0
- "@eslint/js@^10.0.1"
- globals@^17.4.0

# Autoformat: rust
- repo: local
hooks:
Expand Down
2 changes: 2 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"recommendations": [
"davidanson.vscode-markdownlint",
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode",
"gruntfuggly.todo-tree",
"ms-python.python",
"rust-lang.rust-analyzer",
Expand Down
4 changes: 3 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"cSpell.words": [
"clippy",
"kerml",
"kpar",
"mdbook",
Expand All @@ -17,5 +18,6 @@
"thiserror",
"werr",
"wrapfs"
]
],
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
31 changes: 29 additions & 2 deletions bindings/js/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# WASM bindings

## Building and running tests
## Setup

Requirements:

Expand All @@ -9,6 +9,16 @@ Requirements:
- [wasm-pack](https://github.com/drager/wasm-pack) (can be installed with e. g.
`cargo install wasm-pack`)

### VS Code

If using VS Code (or other compatible editor like e.g. Codium or Cursor) then
base support for JavaScript should come without any need for extensions. We use
ESlint and Prettier for linting and formatting respectively, and both come with
official extensions [ESLint](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint)
and [Prettier](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode).

## Building and running tests

Build:

```sh
Expand All @@ -29,11 +39,28 @@ See [wasm-bindgen
documentation](https://wasm-bindgen.github.io/wasm-bindgen/wasm-bindgen-test/browsers.html)
for how to run in other browsers, in Node, etc. It is also worth looking into
[`.github/workflows/js-wasm.yml`](https://github.com/sensmetry/sysand/blob/main/.github/workflows/js-wasm.yml)
to see which versions of the tools are tested in CI and, therefore, expected to work.
to see which versions of the tools are tested in CI and, therefore, expected to
work.

To run the Jasmine tests, install the dependencies and run `test:browser` target:

```sh
npm install
npm run test:browser
```

## Formatting and linting

Format Rust code and run linters for Rust and JavaScript:

```sh
./scripts/run_chores.sh
```

You can also run the lint for JavaScript separately with

```sh
npm run lint
```

assuming you have already installed the dependencies with `npm install`.
18 changes: 18 additions & 0 deletions bindings/js/eslint.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const js = require("@eslint/js");
const globals = require("globals");

module.exports = [
{
files: ["**/*.{js,mjs,cjs}"],
ignores: [
"**/browser_dist/**/*.js",
"**/browser_pkg/**/*.js",
"**/browser_test_dist/**/*.js",
],
plugins: { js },
...js.configs.recommended,
languageOptions: {
globals: { ...globals.browser, ...globals.jasmine, ...globals.node },
},
},
];
Loading
Loading