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
12 changes: 8 additions & 4 deletions docs/release-note.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@

🚀 Highlight Features

- Improved the as-test performances.
- Introduce new features `isolated: false` to significantly reduce test execution time in large projects. ([#73](https://github.com/wasm-ecosystem/assemblyscript-unittest-framework/pull/73))
- Introduced new features `isolated: false` to significantly reduce test execution time in large projects. ([#73](https://github.com/wasm-ecosystem/assemblyscript-unittest-framework/pull/73))
- Introduce setup and teardown API. ([#77](https://github.com/wasm-ecosystem/assemblyscript-unittest-framework/pull/77))

🛠️ Improvements

- Improved the as-test performances.
- Improved the error messages when test case assert failed.

## 1.3.1

🚀 Highlight Features
Expand All @@ -18,7 +22,7 @@
- `2` means invalid AS file.
- `>2` means configuration error.

🚀 Improvements
🛠️ Improvements

- Proper handling of situations where AS files are not invalid.

Expand All @@ -35,7 +39,7 @@
- Expose the framework's `log` function in the configuration file, and the logs redirected to this function will be appended to the final test report.
- Support test crashes and provide good call stack information.

🚀 Improvements
🛠️ Improvements

- Code coverage calculation.
- Skip type definitions.
Expand Down
2 changes: 1 addition & 1 deletion src/core/execute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ async function nodeExecutor(
const binaryBuffer = await readFile(instrumentResult.instrumentedWasm);
const binary = binaryBuffer.buffer.slice(binaryBuffer.byteOffset, binaryBuffer.byteOffset + binaryBuffer.byteLength);
const importFuncList = parseImportFunctionInfo(binary as ArrayBuffer);
supplyDefaultFunction(importFuncList, importObject);
supplyDefaultFunction(importFuncList, importObject, importsArg);
const ins = await instantiate(binary, importObject);
importsArg.module = ins.module;
importsArg.instance = ins.instance;
Expand Down
34 changes: 26 additions & 8 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Imports as ASImports } from "@assemblyscript/loader";
import { ImportFunctionInfo } from "../interface.js";
import { ImportFunctionInfo, ImportsArgument } from "../interface.js";
import { TypeKind } from "wasmparser/dist/cjs/WasmParser.js";

export function json2map<V>(json: Record<string, V>): Map<string, V> {
Expand Down Expand Up @@ -45,16 +45,34 @@ export function checkGenerics(functionName: string): string | undefined {
return undefined;
}

export function supplyDefaultFunction(infos: ImportFunctionInfo[], importObject: ASImports) {
export function supplyDefaultFunction(
infos: ImportFunctionInfo[],
importObject: ASImports,
importsArg: ImportsArgument
) {
for (const info of infos) {
const module = info.module;
const name = info.name;
if (importObject[module]?.[name] === undefined) {
if (importObject[module] === undefined) {
importObject[module] = {};
}
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any, @typescript-eslint/no-unused-vars
(importObject[module] as any)[name] = (..._args: unknown[]): unknown => {
const importObjectModule = importObject[module] ?? {};
importObject[module] = importObjectModule;
if (importObjectModule[name] !== undefined) {
continue;
}
if (module === "env" && name === "abort") {
importObjectModule[name] = (msg: number, file: number, line: number, col: number) => {
const exports = importsArg.exports!;
throw new WebAssembly.RuntimeError(
`abort: ${exports.__getString(msg)} at ${exports.__getString(file)}:${line}:${col}`
);
};
} else if (module === "env" && name === "trace") {
importObjectModule[name] = (msg: number, n: number, ...args: number[]) => {
const exports = importsArg.exports!;
importsArg.framework.log(`trace: ${exports.__getString(msg)}${n > 0 ? " " : ""}${args.slice(0, n).join(", ")}`);
};
} else {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
importObjectModule[name] = (..._args: unknown[]): unknown => {
return info.return?.kind === TypeKind.i64 ? BigInt(0) : 0;
};
}
Expand Down
5 changes: 2 additions & 3 deletions tests/e2e/assertFailed/assertOnTest.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { test, expect } from "../../../assembly";
import { log } from "./env";

test("assert on test", () => {
log("This test will fail due to an assertion error");
assert(false, "This assertion is expected to fail");
trace("this test will fail due to an assertion error");
assert(false, "this assertion is expected to fail");
});
1 change: 0 additions & 1 deletion tests/e2e/assertFailed/env.ts

This file was deleted.

12 changes: 6 additions & 6 deletions tests/e2e/assertFailed/stdout.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ test case: 0/2 (success/total)
Error Message:
assert on test:
Test Crashed!
This test will fail due to an assertion error
Reason: unreachable
at start:tests/e2e/assertFailed/assertOnTest.test~anonymous|0 (tests/e2e/assertFailed/assertOnTest.test.ts:6:2)
at executeTestFunction (tests/e2e/assertFailed/tmp/assertOnTest.test.instrumented.wasm:1:649)
trace: this test will fail due to an assertion error
Reason: abort: this assertion is expected to fail at tests/e2e/assertFailed/assertOnTest.test.ts:5:3
at start:tests/e2e/assertFailed/assertOnTest.test~anonymous|0 (tests/e2e/assertFailed/assertOnTest.test.ts:5:2)
at executeTestFunction (tests/e2e/assertFailed/tmp/assertOnTest.test.instrumented.wasm:1:780)

tests/e2e/assertFailed/tmp/assertOnInit.test - init:
Test Crashed!
Reason: unreachable
Reason: abort: null at tests/e2e/assertFailed/assertOnInit.test.ts:1:1
at start:tests/e2e/assertFailed/assertOnInit.test (tests/e2e/assertFailed/assertOnInit.test.ts:1:0)
at ~start (tests/e2e/assertFailed/tmp/assertOnInit.test.instrumented.wasm:1:265)
at ~start (tests/e2e/assertFailed/tmp/assertOnInit.test.instrumented.wasm:1:289)

2 changes: 1 addition & 1 deletion tests/e2e/setup-teardown/stdout.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ test case: 18/19 (success/total)
Error Message:
tests/e2e/setup-teardown/tmp/setup_out_of_block.test - init:
Test Crashed!
Reason: unreachable
Reason: abort: register setup function failed at assembly/implement.ts:20:3
at assembly/implement/beforeEachImpl (assembly/implement.ts:20:2)
at assembly/index/beforeEach (assembly/index.ts:47:2)
at start:tests/e2e/setup-teardown/setup_out_of_block.test (tests/e2e/setup-teardown/tmp/setup_out_of_block.test.instrumented.wasm:1:547)
Expand Down