diff --git a/IntegrationTests/TestSuites/Sources/PrimaryTests/main.swift b/IntegrationTests/TestSuites/Sources/PrimaryTests/main.swift index a9d12710..71615103 100644 --- a/IntegrationTests/TestSuites/Sources/PrimaryTests/main.swift +++ b/IntegrationTests/TestSuites/Sources/PrimaryTests/main.swift @@ -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) diff --git a/IntegrationTests/bin/benchmark-tests.js b/IntegrationTests/bin/benchmark-tests.js index 424ce819..0d8b5410 100644 --- a/IntegrationTests/bin/benchmark-tests.js +++ b/IntegrationTests/bin/benchmark-tests.js @@ -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 diff --git a/IntegrationTests/bin/concurrency-tests.js b/IntegrationTests/bin/concurrency-tests.js index 47ef4abd..02489c95 100644 --- a/IntegrationTests/bin/concurrency-tests.js +++ b/IntegrationTests/bin/concurrency-tests.js @@ -1,4 +1,4 @@ -const { startWasiTask } = require("../lib"); +import { startWasiTask } from "../lib.js"; Error.stackTraceLimit = Infinity; diff --git a/IntegrationTests/bin/primary-tests.js b/IntegrationTests/bin/primary-tests.js index 50532cea..36ac6581 100644 --- a/IntegrationTests/bin/primary-tests.js +++ b/IntegrationTests/bin/primary-tests.js @@ -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); diff --git a/IntegrationTests/lib.js b/IntegrationTests/lib.js index 71570bfe..2ed9a918 100644 --- a/IntegrationTests/lib.js +++ b/IntegrationTests/lib.js @@ -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 }) => { @@ -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 @@ -74,5 +71,3 @@ const startWasiTask = async (wasmPath, wasiConstructor = selectWASIBackend()) => // Start the WebAssembly WASI instance! wasi.start(instance, swift); }; - -module.exports = { startWasiTask, WASI }; diff --git a/IntegrationTests/package.json b/IntegrationTests/package.json index 29a3597c..8491e91f 100644 --- a/IntegrationTests/package.json +++ b/IntegrationTests/package.json @@ -1,5 +1,6 @@ { "private": true, + "type": "module", "dependencies": { "uwasi": "^1.2.0", "javascript-kit-swift": "file:.." diff --git a/Makefile b/Makefile index 35530b26..e71734a5 100644 --- a/Makefile +++ b/Makefile @@ -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: diff --git a/scripts/test-harness.js b/scripts/test-harness.mjs similarity index 84% rename from scripts/test-harness.js rename to scripts/test-harness.mjs index 27f9e93a..b0384d4d 100644 --- a/scripts/test-harness.js +++ b/scripts/test-harness.mjs @@ -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.");