-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #347 from wasmerio/api-tweaks
[SDK-3] Finalise the public API
- Loading branch information
Showing
10 changed files
with
126 additions
and
23 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 |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
*.md | ||
node_modules/ | ||
dist/ | ||
docs/ |
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
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
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
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,7 +1,7 @@ | ||
import { expect } from "@esm-bundle/chai"; | ||
import { | ||
Runtime, | ||
run, | ||
runWasix, | ||
wat2wasm, | ||
Wasmer, | ||
init, | ||
|
@@ -32,7 +32,7 @@ describe("run", function () { | |
const wasm = wat2wasm(noop); | ||
const module = await WebAssembly.compile(wasm); | ||
|
||
const instance = await run(module, { program: "noop", runtime }); | ||
const instance = await runWasix(module, { program: "noop", runtime }); | ||
const output = await instance.wait(); | ||
|
||
expect(output.ok).to.be.true; | ||
|
@@ -44,7 +44,7 @@ describe("run", function () { | |
const quickjs = pkg.commands["quickjs"].binary(); | ||
const module = await WebAssembly.compile(quickjs); | ||
|
||
const instance = await run(module, { | ||
const instance = await runWasix(module, { | ||
program: "quickjs", | ||
args: ["--eval", "console.log('Hello, World!')"], | ||
runtime, | ||
|
@@ -64,7 +64,7 @@ describe("run", function () { | |
const quickjs = pkg.commands["quickjs"].binary(); | ||
const module = await WebAssembly.compile(quickjs); | ||
|
||
const instance = await run(module, { | ||
const instance = await runWasix(module, { | ||
program: "quickjs", | ||
args: [ | ||
"--std", | ||
|
@@ -91,7 +91,7 @@ describe("run", function () { | |
const quickjs = pkg.commands["quickjs"].binary(); | ||
const module = await WebAssembly.compile(quickjs); | ||
|
||
const instance = await run(module, { | ||
const instance = await runWasix(module, { | ||
program: "quickjs", | ||
args: [ | ||
"--std", | ||
|
@@ -111,6 +111,33 @@ describe("run", function () { | |
expect(decoder.decode(output.stderr)).to.be.empty; | ||
}); | ||
|
||
it("can read files mounted using DirectoryInit", async () => { | ||
const pkg = await Wasmer.fromRegistry("saghul/[email protected]"); | ||
const quickjs = pkg.commands["quickjs"].binary(); | ||
const module = await WebAssembly.compile(quickjs); | ||
|
||
const instance = await runWasix(module, { | ||
program: "quickjs", | ||
args: [ | ||
"--std", | ||
"--eval", | ||
`console.log(std.open('/tmp/file.txt', "r").readAsString())`, | ||
], | ||
runtime, | ||
mount: { | ||
"/tmp": { | ||
"file.txt": "Hello, World!" | ||
}, | ||
}, | ||
}); | ||
const output = await instance.wait(); | ||
|
||
expect(output.ok).to.be.true; | ||
expect(output.code).to.equal(0); | ||
expect(decoder.decode(output.stdout)).to.equal("Hello, World!\n"); | ||
expect(decoder.decode(output.stderr)).to.be.empty; | ||
}); | ||
|
||
it("can write files", async () => { | ||
const dir = new Directory(); | ||
const pkg = await Wasmer.fromRegistry("saghul/[email protected]"); | ||
|
@@ -122,7 +149,7 @@ describe("run", function () { | |
f.close(); | ||
`; | ||
|
||
const instance = await run(module, { | ||
const instance = await runWasix(module, { | ||
program: "quickjs", | ||
args: ["--std", "--eval", script], | ||
runtime, | ||
|