Skip to content

Commit 36af1cb

Browse files
Migrate to ESM
1 parent 09bc778 commit 36af1cb

File tree

8 files changed

+14
-18
lines changed

8 files changed

+14
-18
lines changed

IntegrationTests/TestSuites/Sources/PrimaryTests/main.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ try test("Call Function With This") {
400400
let setName = try expectFunction(getJSValue(this: cat1, name: "setName"))
401401

402402
// Direct call without this
403-
try expectEqual(getIsCat(), .undefined)
403+
_ = try expectThrow(try getIsCat.throws())
404404

405405
// Call with this
406406
let gotIsCat = getIsCat(this: cat1)

IntegrationTests/bin/benchmark-tests.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const { startWasiTask } = require("../lib");
2-
const { performance } = require("perf_hooks");
1+
import { startWasiTask } from "../lib.js";
2+
import { performance } from "perf_hooks";
33

44
const SAMPLE_ITERATION = 1000000
55

IntegrationTests/bin/concurrency-tests.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { startWasiTask } = require("../lib");
1+
import { startWasiTask } from "../lib.js";
22

33
Error.stackTraceLimit = Infinity;
44

IntegrationTests/bin/primary-tests.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ global.objectDecodingTest = {
102102
bi: BigInt(3)
103103
};
104104

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

107107
startWasiTask("./dist/PrimaryTests.wasm").catch((err) => {
108108
console.log(err);

IntegrationTests/lib.js

+6-11
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
const SwiftRuntime = require("javascript-kit-swift").SwiftRuntime;
2-
const NodeWASI = require("wasi").WASI;
3-
const { WASI: MicroWASI, useAll } = require("uwasi");
4-
5-
const promisify = require("util").promisify;
6-
const fs = require("fs");
7-
const readFile = promisify(fs.readFile);
1+
import { SwiftRuntime } from "javascript-kit-swift"
2+
import { WASI as NodeWASI } from "wasi"
3+
import { WASI as MicroWASI, useAll } from "uwasi"
4+
import * as fs from "fs/promises"
85

96
const WASI = {
107
MicroWASI: ({ programName }) => {
@@ -54,10 +51,10 @@ const selectWASIBackend = () => {
5451
return WASI.Node;
5552
};
5653

57-
const startWasiTask = async (wasmPath, wasiConstructor = selectWASIBackend()) => {
54+
export const startWasiTask = async (wasmPath, wasiConstructor = selectWASIBackend()) => {
5855
const swift = new SwiftRuntime();
5956
// Fetch our Wasm File
60-
const wasmBinary = await readFile(wasmPath);
57+
const wasmBinary = await fs.readFile(wasmPath);
6158
const wasi = wasiConstructor({ programName: wasmPath });
6259

6360
// Instantiate the WebAssembly file
@@ -74,5 +71,3 @@ const startWasiTask = async (wasmPath, wasiConstructor = selectWASIBackend()) =>
7471
// Start the WebAssembly WASI instance!
7572
wasi.start(instance, swift);
7673
};
77-
78-
module.exports = { startWasiTask, WASI };

IntegrationTests/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"private": true,
3+
"type": "module",
34
"dependencies": {
45
"uwasi": "^1.2.0",
56
"javascript-kit-swift": "file:.."

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ test:
2222
unittest:
2323
@echo Running unit tests
2424
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
25-
node --experimental-wasi-unstable-preview1 scripts/test-harness.js ./.build/wasm32-unknown-wasi/debug/JavaScriptKitPackageTests.wasm
25+
node --experimental-wasi-unstable-preview1 scripts/test-harness.mjs ./.build/wasm32-unknown-wasi/debug/JavaScriptKitPackageTests.wasm
2626

2727
.PHONY: benchmark_setup
2828
benchmark_setup:

scripts/test-harness.js renamed to scripts/test-harness.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Error.stackTraceLimit = Infinity;
22

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

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

0 commit comments

Comments
 (0)