Skip to content

Commit 54d652a

Browse files
authored
chore: better error message when instrumentation failed (#89)
1 parent fe0f695 commit 54d652a

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

example/as-test.config.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/** @type {import("assemblyscript-unittest-framework/config.d.ts").Config} */
22
module.exports = {
3-
include: ["tests"],
3+
include: ["tests", "assembly"],
44
exclude: ["lib"],
55

66
flags: "",

example/as-test.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/** @type {import("assemblyscript-unittest-framework/config.d.ts").Config} */
22
export default {
3-
include: ["tests"],
3+
include: ["tests", "assembly"],
44
exclude: ["lib"],
55

66
flags: "",

src/executionResult.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
FailedLogMessages,
1212
} from "./interface.js";
1313
import chalk from "chalk";
14+
import assert from "node:assert";
1415

1516
const { readFile, writeFile } = promises;
1617

@@ -32,12 +33,13 @@ export class ExecutionResultSummary {
3233
return failedInfo;
3334
}
3435

35-
#processAssertInfo(failedInfo: AssertFailMessage, expectInfo: ExpectInfo) {
36+
#processAssertInfo(failedInfo: AssertFailMessage, expectInfo: ExpectInfo | null) {
3637
for (const [testcaseName, value] of json2map<AssertMessage[]>(failedInfo)) {
3738
const errorMsgs: string[] = [];
3839
for (const msg of value) {
39-
const [index, actualValue, expectValue] = msg;
40-
const debugLocation = expectInfo[index];
40+
const [expectInfoIndex, actualValue, expectValue] = msg;
41+
assert(expectInfo !== null && "missing expect info!");
42+
const debugLocation = expectInfo[expectInfoIndex];
4143
let errorMsg = `${debugLocation ?? ""} value: ${actualValue} expect: ${expectValue}`;
4244
if (errorMsg.length > 160) {
4345
errorMsg = `${debugLocation ?? ""}\nvalue: \n ${actualValue}\nexpect: \n ${expectValue}`;
@@ -72,7 +74,7 @@ export class ExecutionResultSummary {
7274
if (result.fail > 0) {
7375
try {
7476
const expectContent = await readFile(expectInfoFilePath, { encoding: "utf8" });
75-
const expectInfo = JSON.parse(expectContent) as ExpectInfo;
77+
const expectInfo = JSON.parse(expectContent) as ExpectInfo | null;
7678
this.#processAssertInfo(result.failedInfo, expectInfo);
7779
this.#processCrashInfo(result.crashInfo);
7880
this.#processLogMessages(result.failedLogMessages);

0 commit comments

Comments
 (0)