Skip to content

Commit c2989de

Browse files
committed
add test case for OriginalSourceFile api
Signed-off-by: karthik2804 <karthik.ganeshram@fermyon.com>
1 parent d6657f1 commit c2989de

File tree

2 files changed

+51
-4
lines changed

2 files changed

+51
-4
lines changed

test/api/index.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { now } from 'wasi:clocks/wall-clock@0.2.3';
2+
import { getRandomBytes } from 'wasi:random/random@0.2.3';
3+
4+
let result;
5+
export const run = {
6+
run() {
7+
result = `NOW: ${now().seconds}, RANDOM: ${getRandomBytes(2n)}`;
8+
}
9+
};
10+
11+
export const getResult = () => result;

test/test.js

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,9 @@ suite('Builtins', () => {
109109
reject(
110110
new Error(
111111
'test timed out with output:\n' +
112-
stdout +
113-
'\n\nstderr:\n' +
114-
stderr
112+
stdout +
113+
'\n\nstderr:\n' +
114+
stderr
115115
)
116116
);
117117
}, 10_000);
@@ -254,7 +254,7 @@ suite('Bindings', () => {
254254
});
255255

256256
suite('WASI', () => {
257-
test('basic app', async () => {
257+
test('basic app (old API)', async () => {
258258
const { component } = await componentize(
259259
`
260260
import { now } from 'wasi:clocks/wall-clock@0.2.3';
@@ -301,4 +301,40 @@ suite('WASI', () => {
301301
strictEqual(result.slice(0, 10), `NOW: ${String(Date.now()).slice(0, 5)}`);
302302
strictEqual(result.split(',').length, 3);
303303
});
304+
305+
test('basic app (OriginalSourceFile API)', async () => {
306+
const { component } = await componentize(
307+
{
308+
sourcePath: "./test/api/index.js",
309+
witPath: fileURLToPath(new URL('./wit', import.meta.url)),
310+
worldName: 'test1',
311+
enableAot,
312+
debugBuild,
313+
}
314+
);
315+
316+
await writeFile(
317+
new URL(`./output/wasi.component.wasm`, import.meta.url),
318+
component
319+
);
320+
321+
const { files } = await transpile(component, { tracing: DEBUG_TRACING });
322+
323+
await mkdir(new URL(`./output/wasi/interfaces`, import.meta.url), {
324+
recursive: true,
325+
});
326+
327+
for (const file of Object.keys(files)) {
328+
await writeFile(
329+
new URL(`./output/wasi/${file}`, import.meta.url),
330+
files[file]
331+
);
332+
}
333+
334+
var instance = await import(`./output/wasi/component.js`);
335+
instance.run.run();
336+
const result = instance.getResult();
337+
strictEqual(result.slice(0, 10), `NOW: ${String(Date.now()).slice(0, 5)}`);
338+
strictEqual(result.split(',').length, 3);
339+
});
304340
});

0 commit comments

Comments
 (0)