Skip to content

Commit

Permalink
Migrate to ESM
Browse files Browse the repository at this point in the history
  • Loading branch information
kateinoigakukun committed May 8, 2024
1 parent cbd2074 commit 36408f5
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ try test("Call Function With This") {
let setName = try expectFunction(getJSValue(this: cat1, name: "setName"))

// Direct call without this
try expectEqual(getIsCat(), .undefined)
_ = try expectThrow(try getIsCat.throws())

// Call with this
let gotIsCat = getIsCat(this: cat1)
Expand Down
4 changes: 2 additions & 2 deletions IntegrationTests/bin/benchmark-tests.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { startWasiTask } = require("../lib");
const { performance } = require("perf_hooks");
import { startWasiTask } from "../lib.js";
import { performance } from "perf_hooks";

const SAMPLE_ITERATION = 1000000

Expand Down
2 changes: 1 addition & 1 deletion IntegrationTests/bin/concurrency-tests.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { startWasiTask } = require("../lib");
import { startWasiTask } from "../lib.js";

Error.stackTraceLimit = Infinity;

Expand Down
2 changes: 1 addition & 1 deletion IntegrationTests/bin/primary-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ global.objectDecodingTest = {
bi: BigInt(3)
};

const { startWasiTask, WASI } = require("../lib");
import { startWasiTask } from "../lib.js";

startWasiTask("./dist/PrimaryTests.wasm").catch((err) => {
console.log(err);
Expand Down
17 changes: 6 additions & 11 deletions IntegrationTests/lib.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
const SwiftRuntime = require("javascript-kit-swift").SwiftRuntime;
const NodeWASI = require("wasi").WASI;
const { WASI: MicroWASI, useAll } = require("uwasi");

const promisify = require("util").promisify;
const fs = require("fs");
const readFile = promisify(fs.readFile);
import { SwiftRuntime } from "javascript-kit-swift"
import { WASI as NodeWASI } from "wasi"
import { WASI as MicroWASI, useAll } from "uwasi"
import * as fs from "fs/promises"

const WASI = {
MicroWASI: ({ programName }) => {
Expand Down Expand Up @@ -54,10 +51,10 @@ const selectWASIBackend = () => {
return WASI.Node;
};

const startWasiTask = async (wasmPath, wasiConstructor = selectWASIBackend()) => {
export const startWasiTask = async (wasmPath, wasiConstructor = selectWASIBackend()) => {
const swift = new SwiftRuntime();
// Fetch our Wasm File
const wasmBinary = await readFile(wasmPath);
const wasmBinary = await fs.readFile(wasmPath);
const wasi = wasiConstructor({ programName: wasmPath });

// Instantiate the WebAssembly file
Expand All @@ -74,5 +71,3 @@ const startWasiTask = async (wasmPath, wasiConstructor = selectWASIBackend()) =>
// Start the WebAssembly WASI instance!
wasi.start(instance, swift);
};

module.exports = { startWasiTask, WASI };
1 change: 1 addition & 0 deletions IntegrationTests/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"private": true,
"type": "module",
"dependencies": {
"uwasi": "^1.2.0",
"javascript-kit-swift": "file:.."
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ test:
unittest:
@echo Running unit tests
swift build --build-tests --triple wasm32-unknown-wasi -Xswiftc -Xclang-linker -Xswiftc -mexec-model=reactor -Xlinker --export-if-defined=main -Xlinker --export-if-defined=__main_argc_argv --static-swift-stdlib -Xswiftc -static-stdlib
node --experimental-wasi-unstable-preview1 scripts/test-harness.js ./.build/wasm32-unknown-wasi/debug/JavaScriptKitPackageTests.wasm
node --experimental-wasi-unstable-preview1 scripts/test-harness.mjs ./.build/wasm32-unknown-wasi/debug/JavaScriptKitPackageTests.wasm

.PHONY: benchmark_setup
benchmark_setup:
Expand Down
2 changes: 1 addition & 1 deletion scripts/test-harness.js → scripts/test-harness.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Error.stackTraceLimit = Infinity;

const { startWasiTask } = require("../IntegrationTests/lib");
import { startWasiTask } from "../IntegrationTests/lib.js";

if (process.env["JAVASCRIPTKIT_WASI_BACKEND"] === "MicroWASI") {
console.log("Skipping XCTest tests for MicroWASI because it is not supported yet.");
Expand Down

0 comments on commit 36408f5

Please sign in to comment.