Skip to content
File

Blob: src/workerd/tests/module-imports-test.js

javascript48 lines
1// Copyright (c) 2025 Cloudflare, Inc.
2// Licensed under the Apache 2.0 license found in the LICENSE file or at:
3// https://opensource.org/licenses/Apache-2.0
4import { rejects, ok } from 'node:assert';
5 
6export const test = {
7 async test() {
8 await rejects(import('node:crypto'), {
9 message: /^No such module/,
10 });
11 await rejects(import('node:buffer'), {
12 message: /^No such module/,
13 });
14 },
15};
16 
17import source wasmSource from 'wasm';
18export const wasmSourcePhaseTest = {
19 async test() {
20 ok(wasmSource instanceof WebAssembly.Module);
21 await WebAssembly.instantiate(wasmSource, {});
22 },
23};
24 
25export const wasmModuleTest = {
26 async test() {
27 const { default: wasm } = await import('wasm');
28 ok(wasm instanceof WebAssembly.Module);
29 await WebAssembly.instantiate(wasm, {});
30 },
31};
32 
33export const dynamicWasmSourcePhaseTest = {
34 async test() {
35 await rejects(import.source('wasm'), {
36 message: /Not supported/,
37 });
38 },
39};
40 
41export const dynamicSourcePhaseErrorTest = {
42 async test() {
43 await rejects(import.source('worker'), {
44 message: /Not supported/,
45 });
46 },
47};