summaryrefslogtreecommitdiff
path: root/std/wasi/snapshot_preview1_test.ts
diff options
context:
space:
mode:
authorCasper Beyer <caspervonb@pm.me>2020-11-03 01:50:45 +0800
committerGitHub <noreply@github.com>2020-11-02 18:50:45 +0100
commitc5611636fb03ce71f50a9bca958c79d23b55be00 (patch)
treed9e5e3c9fbae15c7e0d636bd823e618d6a2cffef /std/wasi/snapshot_preview1_test.ts
parenta8ca9fe7bb93d031af865ffcf45fb265395f1e1b (diff)
feat(std/wasi): add start method to Context (#8141)
This adds a start method to the Context to make starting a command less tedious and yield consistent errors. Manually setting the memory is still valid for more complex scenarios, just undocumented for the time being.
Diffstat (limited to 'std/wasi/snapshot_preview1_test.ts')
-rw-r--r--std/wasi/snapshot_preview1_test.ts45
1 files changed, 44 insertions, 1 deletions
diff --git a/std/wasi/snapshot_preview1_test.ts b/std/wasi/snapshot_preview1_test.ts
index 0ea57e089..44877117c 100644
--- a/std/wasi/snapshot_preview1_test.ts
+++ b/std/wasi/snapshot_preview1_test.ts
@@ -1,5 +1,6 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
-import { assertEquals } from "../testing/asserts.ts";
+import Context from "./snapshot_preview1.ts";
+import { assertEquals, assertThrows } from "../testing/asserts.ts";
import { copy } from "../fs/mod.ts";
import * as path from "../path/mod.ts";
@@ -137,3 +138,45 @@ for (const pathname of tests) {
},
});
}
+
+Deno.test("context_start", function () {
+ assertThrows(
+ () => {
+ const context = new Context({});
+ context.start({
+ exports: {
+ _start() {},
+ },
+ });
+ },
+ TypeError,
+ "must provide a memory export",
+ );
+
+ assertThrows(
+ () => {
+ const context = new Context({});
+ context.start({
+ exports: {
+ _initialize() {},
+ memory: new WebAssembly.Memory({ initial: 1 }),
+ },
+ });
+ },
+ TypeError,
+ "export _initialize must not be a function",
+ );
+
+ assertThrows(
+ () => {
+ const context = new Context({});
+ context.start({
+ exports: {
+ memory: new WebAssembly.Memory({ initial: 1 }),
+ },
+ });
+ },
+ TypeError,
+ "export _start must be a function",
+ );
+});