◐ Shell
clean mode source ↗

esm: js-string Wasm builtins in ESM Integration · nodejs/node@71bb6cd

@@ -403,4 +403,95 @@ describe('ESM: WASM modules', { concurrency: !process.env.TEST_PARALLEL }, () =>

403403

strictEqual(stdout, '');

404404

notStrictEqual(code, 0);

405405

});

406+407+

it('should reject wasm: import names', async () => {

408+

const { code, stderr, stdout } = await spawnPromisified(execPath, [

409+

'--no-warnings',

410+

'--experimental-wasm-modules',

411+

'--input-type=module',

412+

'--eval',

413+

`import(${JSON.stringify(fixtures.fileURL('es-modules/invalid-import-name.wasm'))})`,

414+

]);

415+416+

match(stderr, /Invalid Wasm import name/);

417+

strictEqual(stdout, '');

418+

notStrictEqual(code, 0);

419+

});

420+421+

it('should reject wasm-js: import names', async () => {

422+

const { code, stderr, stdout } = await spawnPromisified(execPath, [

423+

'--no-warnings',

424+

'--experimental-wasm-modules',

425+

'--input-type=module',

426+

'--eval',

427+

`import(${JSON.stringify(fixtures.fileURL('es-modules/invalid-import-name-wasm-js.wasm'))})`,

428+

]);

429+430+

match(stderr, /Invalid Wasm import name/);

431+

strictEqual(stdout, '');

432+

notStrictEqual(code, 0);

433+

});

434+435+

it('should reject wasm-js: import module names', async () => {

436+

const { code, stderr, stdout } = await spawnPromisified(execPath, [

437+

'--no-warnings',

438+

'--experimental-wasm-modules',

439+

'--input-type=module',

440+

'--eval',

441+

`import(${JSON.stringify(fixtures.fileURL('es-modules/invalid-import-module.wasm'))})`,

442+

]);

443+444+

match(stderr, /Invalid Wasm import/);

445+

strictEqual(stdout, '');

446+

notStrictEqual(code, 0);

447+

});

448+449+

it('should reject wasm: export names', async () => {

450+

const { code, stderr, stdout } = await spawnPromisified(execPath, [

451+

'--no-warnings',

452+

'--experimental-wasm-modules',

453+

'--input-type=module',

454+

'--eval',

455+

`import(${JSON.stringify(fixtures.fileURL('es-modules/invalid-export-name.wasm'))})`,

456+

]);

457+458+

match(stderr, /Invalid Wasm export/);

459+

strictEqual(stdout, '');

460+

notStrictEqual(code, 0);

461+

});

462+463+

it('should reject wasm-js: export names', async () => {

464+

const { code, stderr, stdout } = await spawnPromisified(execPath, [

465+

'--no-warnings',

466+

'--experimental-wasm-modules',

467+

'--input-type=module',

468+

'--eval',

469+

`import(${JSON.stringify(fixtures.fileURL('es-modules/invalid-export-name-wasm-js.wasm'))})`,

470+

]);

471+472+

match(stderr, /Invalid Wasm export/);

473+

strictEqual(stdout, '');

474+

notStrictEqual(code, 0);

475+

});

476+477+

it('should support js-string builtins', async () => {

478+

const { code, stderr, stdout } = await spawnPromisified(execPath, [

479+

'--no-warnings',

480+

'--experimental-wasm-modules',

481+

'--input-type=module',

482+

'--eval',

483+

[

484+

'import { strictEqual } from "node:assert";',

485+

`import * as wasmExports from ${JSON.stringify(fixtures.fileURL('es-modules/js-string-builtins.wasm'))};`,

486+

'strictEqual(wasmExports.getLength("hello"), 5);',

487+

'strictEqual(wasmExports.concatStrings("hello", " world"), "hello world");',

488+

'strictEqual(wasmExports.compareStrings("test", "test"), 1);',

489+

'strictEqual(wasmExports.compareStrings("test", "different"), 0);',

490+

].join('\n'),

491+

]);

492+493+

strictEqual(stderr, '');

494+

strictEqual(stdout, '');

495+

strictEqual(code, 0);

496+

});

406497

});