Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 26 additions & 26 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
"url": "https://github.com/AssemblyScript/node/issues"
},
"devDependencies": {
"@as-pect/core": "^3.1.0-beta.3",
"assemblyscript": "0.9.3",
"@as-pect/core": "^3.2.2",
"assemblyscript": "0.10.0",
"glob": "^7.1.6"
},
"scripts": {
"test": "node --experimental-wasi-unstable-preview1 tests/node"
"test": "node --experimental-wasi-unstable-preview1 --experimental-wasm-bigint tests/node"
},
"dependencies": {}
}
3 changes: 3 additions & 0 deletions tests/fs.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
test("an empty test", () => {

});
7 changes: 7 additions & 0 deletions tests/fs.spec.wasi.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
env: process.env,
argv: process.argv,
preopens: {
"./tests/sandbox": "./tests/sandbox"
}
};
43 changes: 33 additions & 10 deletions tests/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ const { instantiateSync } = require("assemblyscript/lib/loader");
const { main } = require("assemblyscript/cli/asc");
const { parse } = require("assemblyscript/cli/util/options");
const path = require("path");
const fs = require("fs").promises;
const fssync = require("fs");
const fs = fssync.promises;
const { WASI } = require("wasi");

const promises = [];
Expand All @@ -21,13 +22,29 @@ const options = parse(process.argv.slice(2), {
"type": "b",
"alias": "u"
},
"preopens": {
"description": "A set of preopened directories for wasi. Ex. ./dir=./dir",
"type": "S",
"alias": "p",
"default": [],
},
});

if (options.unknown.length > 1) {
console.error("Unknown options arguments: " + options.unknown.join(" "));
process.exit(1);
}

// calculate default preopens from cli
const preopens = options.options.preopens.reduce(
(obj, value) => {
const [_, dir1, dir2] = /([^=])*=(.*)/.exec(value);
obj[dir1] = dir2;
return obj;
},
{}
);

const reporter = new VerboseReporter();
reporter.stderr = process.stderr;
reporter.stdout = process.stdout;
Expand All @@ -40,7 +57,6 @@ const ascOptions = [
relativeFromCwd(require.resolve("@as-pect/assembly/assembly/index.ts")),
"--use", "ASC_RTRACE=1",
"--explicitStart",
"--validate",
"--measure",
"--lib", "assembly",
"--transform", require.resolve("@as-pect/core/lib/transform/index.js"),
Expand Down Expand Up @@ -117,29 +133,36 @@ function runTest(fileName, type, binary, wat) {
const basename = path.basename(fileName, ".ts");
const fullName = path.join(dirname, basename)
const watPath = `${fullName}.${type}.wat`;
const wasiPath = `${fullName}.wasi.js`;
const fileNamePath = `${fullName}.${type}.ts`;

// use either a custom wasi configuration, or the default one
const wasiOptions = fssync.existsSync(wasiPath)
? require(path.resolve(wasiPath))
: {
args: process.argv,
env: process.env,
preopens,
};

// should not block testing
promises.push(fs.writeFile(watPath, wat));

const wasi = new WASI(wasiOptions);

const context = new TestContext({
fileName: fileNamePath, // set the fileName
reporter, // use verbose reporter
binary, // pass the binary to get function names
wasi,
});
const wasi = new WASI({
args: [],
env: {},
preopens: {
// '/sandbox': '/some/real/path/that/wasm/can/access'
}
});

const imports = context.createImports({
wasi_snapshot_preview1: wasi.wasiImport,
});

const instance = instantiateSync(binary, imports);
// TODO: wasi.start(instance);

process.stdout.write("\n");
context.run(instance);

Expand Down
Empty file added tests/sandbox/test.txt
Empty file.