-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
992 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
node_modules/ | ||
dist/ | ||
typings/ | ||
/test-results/ | ||
/playwright-report/ | ||
/playwright/.cache/ | ||
|
||
wasmtime/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<html> | ||
<head> | ||
<title>Test Harness</title> | ||
</head> | ||
<h1>Status: <span id=status data-testid=status>Not started</span></h1> | ||
<h2>Check console for details</h2> | ||
<script src="harness.js" type="module"></script> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { WASI, File, PreopenDirectory } from "../dist/index.js"; | ||
|
||
const stdio = { | ||
stdin: undefined, | ||
stdout: new File(), | ||
stderr: new File(), | ||
}; | ||
|
||
const WASI_ENVS = { | ||
DEFAULT: [ | ||
stdio.stdin, | ||
stdio.stdout, | ||
stdio.stderr, | ||
new PreopenDirectory("/", {}), | ||
], | ||
}; | ||
|
||
async function main(options) { | ||
const wasmReq = await fetch(options.file); | ||
|
||
const args = [options.file]; | ||
args.push(...(options.args || [])); | ||
|
||
const wasi = new WASI( | ||
args, | ||
(options.env || "").split(","), | ||
WASI_ENVS[options.wasi_env] || WASI_ENVS.DEFAULT, | ||
{ | ||
debug: true, | ||
}, | ||
); | ||
const module = await WebAssembly.compileStreaming(wasmReq); | ||
|
||
const instance = await WebAssembly.instantiate(module, { | ||
wasi_snapshot_preview1: wasi.wasiImport, | ||
}); | ||
|
||
const status = document.getElementById("status"); | ||
try { | ||
if (options.reactor) { | ||
wasi.initialize(instance); | ||
} | ||
if (options.command) { | ||
wasi.start(instance); | ||
} | ||
printBuffer(stdio, "stdout", "log"); | ||
printBuffer(stdio, "stderr", "log"); | ||
status.innerText = "success"; | ||
} catch (e) { | ||
printBuffer(stdio, "stdout", "log"); | ||
printBuffer(stdio, "stderr", "error"); | ||
status.innerText = "failure"; | ||
throw e; | ||
} | ||
} | ||
|
||
function printBuffer(stdio, type, logger) { | ||
const output = new TextDecoder().decode(stdio[type].data); | ||
if (output.trim().length > 0) { | ||
console[logger](`${type}`, output); | ||
} | ||
} | ||
|
||
main(JSON.parse(decodeURI(location.search.slice(1)))) | ||
.then(() => { | ||
console.log("done"); | ||
}) | ||
.catch((e) => { | ||
console.error(e); | ||
throw e; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { test, expect } from "@playwright/test"; | ||
|
||
const URL = "http://127.0.0.1:3000/e2e/harness.html"; | ||
const WASMDIR = "../wasmtime/artifacts"; | ||
|
||
const tests = [ | ||
{ | ||
file: `${WASMDIR}/preview1_path_open_read_write.wasm`, | ||
command: true, | ||
args: ["/"], | ||
}, | ||
]; | ||
|
||
for (const testDef of tests) { | ||
test(`first ${testDef.file}`, async ({ page }) => { | ||
await page.goto(`${URL}?${JSON.stringify(testDef)}`); | ||
await page.waitForFunction( | ||
() => document.getElementById("status")?.textContent !== "Not started", | ||
); | ||
expect(await await page.getByTestId("status").textContent()).toBe( | ||
"success", | ||
); | ||
}); | ||
} |
Oops, something went wrong.