Skip to content

Commit

Permalink
chore: enable WASM support (#430)
Browse files Browse the repository at this point in the history
* chore: enable WASM support

* chore: add docs and changeset
  • Loading branch information
mdjastrzebski committed Dec 5, 2023
1 parent 1205605 commit 8ca46a4
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .changeset/nasty-cars-attack.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@callstack/reassure-cli': patch
'reassure': patch
---

feat: Experimental options to enable WebAssembly (--enable-wasm)
18 changes: 18 additions & 0 deletions docusaurus/docs/troubleshooting.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
title: Troubleshooting
sidebar_position: 5
---

### Handling `ReferenceError: WebAssembly is not defined`

Reassure, by default, uses Node.js's `--jitless` flag to disable its optimizing compiler to increase test stability. This flag prevents WebAssembly (WASM) from running because of internal Node.js architecture. In some cases, you might still allow your tests to include code depending on WASM, e.g., the `fetch` method is implemented using WASM.

In such cases, pass the `--enable-wasm` flag to Reassure CLI:

```sh
$ reassure --enable-wasm
```

This option will replace the Node.js `--jitless` flag with alternative flags to achieve a similar stabilizing effect.

Note that this option is experimental and may negatively affect the stability of your tests.
7 changes: 6 additions & 1 deletion packages/reassure-cli/src/commands/check-stability.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ export const command: CommandModule<{}, CommonOptions> = {
command: 'check-stability',
describe: 'Checks how stable is the current machine by running measurements twice for the same code',
builder: (yargs) => {
return applyCommonOptions(yargs);
return applyCommonOptions(yargs).option('enable-wasm', {
type: 'boolean',
default: false,
describe:
'(experimental) Enables WebAssembly support in tests by modifying Node flags. This may affect test stability.',
});
},
handler: (args) => run(args),
};
12 changes: 10 additions & 2 deletions packages/reassure-cli/src/commands/measure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface MeasureOptions extends CommonOptions {
branch?: string;
commitHash?: string;
testMatch?: string;
enableWasm?: boolean;
}

export async function run(options: MeasureOptions) {
Expand Down Expand Up @@ -64,15 +65,16 @@ export async function run(options: MeasureOptions) {
const testRunnerArgs = process.env.TEST_RUNNER_ARGS ?? defaultArgs;

const nodeArgs = [
'--jitless',
// Use less restrictive flags to allow running WASM code (e.g. `fetch`) in tests.
options.enableWasm ? '--no-opt --no-sparkplug' : '--jitless',
'--expose-gc',
'--no-concurrent-sweeping',
'--max-old-space-size=4096',
testRunnerPath,
testRunnerArgs,
];
logger.verbose('Running tests using command:');
logger.verbose(`$ node ${nodeArgs.join(' \\\n ')}\n`);
logger.verbose(`$ node \\\n ${nodeArgs.join(' \\\n ')}\n`);

const spawnInfo = spawnSync('node', nodeArgs, {
shell: true,
Expand Down Expand Up @@ -145,6 +147,12 @@ export const command: CommandModule<{}, MeasureOptions> = {
type: 'string',
default: undefined,
describe: 'Run performance tests for a specific test file',
})
.option('enable-wasm', {
type: 'boolean',
default: false,
describe:
'(experimental) Enables WebAssembly support in tests by modifying Node flags. This may affect test stability.',
});
},
handler: (args) => run(args),
Expand Down

0 comments on commit 8ca46a4

Please sign in to comment.