diff --git a/example/as-test.config.cjs b/example/as-test.config.cjs index cc1f4f6..83a8fa3 100644 --- a/example/as-test.config.cjs +++ b/example/as-test.config.cjs @@ -1,6 +1,6 @@ /** @type {import("assemblyscript-unittest-framework/config.d.ts").Config} */ module.exports = { - include: ["tests"], + include: ["tests", "assembly"], exclude: ["lib"], flags: "", diff --git a/example/as-test.config.js b/example/as-test.config.js index 5d72d65..05a6e61 100644 --- a/example/as-test.config.js +++ b/example/as-test.config.js @@ -1,6 +1,6 @@ /** @type {import("assemblyscript-unittest-framework/config.d.ts").Config} */ export default { - include: ["tests"], + include: ["tests", "assembly"], exclude: ["lib"], flags: "", diff --git a/src/executionResult.ts b/src/executionResult.ts index b98f085..b8e611b 100644 --- a/src/executionResult.ts +++ b/src/executionResult.ts @@ -11,6 +11,7 @@ import { FailedLogMessages, } from "./interface.js"; import chalk from "chalk"; +import assert from "node:assert"; const { readFile, writeFile } = promises; @@ -32,12 +33,13 @@ export class ExecutionResultSummary { return failedInfo; } - #processAssertInfo(failedInfo: AssertFailMessage, expectInfo: ExpectInfo) { + #processAssertInfo(failedInfo: AssertFailMessage, expectInfo: ExpectInfo | null) { for (const [testcaseName, value] of json2map(failedInfo)) { const errorMsgs: string[] = []; for (const msg of value) { - const [index, actualValue, expectValue] = msg; - const debugLocation = expectInfo[index]; + const [expectInfoIndex, actualValue, expectValue] = msg; + assert(expectInfo !== null && "missing expect info!"); + const debugLocation = expectInfo[expectInfoIndex]; let errorMsg = `${debugLocation ?? ""} value: ${actualValue} expect: ${expectValue}`; if (errorMsg.length > 160) { errorMsg = `${debugLocation ?? ""}\nvalue: \n ${actualValue}\nexpect: \n ${expectValue}`; @@ -72,7 +74,7 @@ export class ExecutionResultSummary { if (result.fail > 0) { try { const expectContent = await readFile(expectInfoFilePath, { encoding: "utf8" }); - const expectInfo = JSON.parse(expectContent) as ExpectInfo; + const expectInfo = JSON.parse(expectContent) as ExpectInfo | null; this.#processAssertInfo(result.failedInfo, expectInfo); this.#processCrashInfo(result.crashInfo); this.#processLogMessages(result.failedLogMessages);