Skip to content

Commit 63e5501

Browse files
committed
address pr comments
1 parent 00e67ef commit 63e5501

File tree

3 files changed

+37
-33
lines changed

3 files changed

+37
-33
lines changed

src/utils/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ export function supplyDefaultFunction(importList: WebAssembly.ModuleImportDescri
6262
if (imp.kind === "function") {
6363
const moduleName = imp.module;
6464
const funcName = imp.name;
65-
if (!importObject[moduleName]?.[funcName]) {
66-
if (!importObject[moduleName]) {
65+
if (importObject[moduleName]?.[funcName] === undefined) {
66+
if (importObject[moduleName] === undefined) {
6767
importObject[moduleName] = {};
6868
}
6969
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any

tests/ts/test/utils/index.test.ts

Lines changed: 0 additions & 30 deletions
This file was deleted.

tests/ts/test/utils/utils.test.ts

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
import fs from "fs-extra";
22
import { join } from "node:path";
3+
import { Imports as ASImports } from "@assemblyscript/loader";
34
import { fileURLToPath, URL } from "node:url";
45
import { DebugInfo, CovDebugInfo } from "../../../../src/interface.js";
5-
import { isIncluded, json2map, checkFunctionName, checkGenerics } from "../../../../src/utils/index.js";
6+
import {
7+
isIncluded,
8+
json2map,
9+
checkFunctionName,
10+
checkGenerics,
11+
supplyDefaultFunction,
12+
} from "../../../../src/utils/index.js";
613

714
const __dirname = fileURLToPath(new URL(".", import.meta.url));
815

@@ -65,3 +72,30 @@ test("checkGenerics", () => {
6572
expect(checkGenerics("func<")).toEqual(undefined);
6673
expect(checkGenerics("fun>a")).toEqual(undefined);
6774
});
75+
76+
describe("supplyDefaultFunction", () => {
77+
test("supplyTest", () => {
78+
const mockImportList: WebAssembly.ModuleImportDescriptor[] = [
79+
{ kind: "function", module: "myenv", name: "processEvent" },
80+
{ kind: "function", module: "externalMath", name: "add" },
81+
{ kind: "function", module: "system", name: "getStatus" },
82+
{ kind: "function", module: "logger", name: "logWarning" },
83+
{ kind: "function", module: "customOps", name: "combineValues" },
84+
];
85+
86+
const mockImportObject: ASImports = {
87+
myenv: {},
88+
externalMath: {},
89+
system: {},
90+
logger: {},
91+
customOps: {},
92+
};
93+
94+
supplyDefaultFunction(mockImportList, mockImportObject);
95+
96+
expect(typeof mockImportObject["myenv"]?.["processEvent"]).toBe("function");
97+
expect(typeof mockImportObject["system"]?.["getStatus"]).toBe("function");
98+
expect(typeof mockImportObject["logger"]?.["logWarning"]).toBe("function");
99+
expect(typeof mockImportObject["customOps"]?.["combineValues"]).toBe("function");
100+
});
101+
});

0 commit comments

Comments
 (0)