Skip to content

Commit

Permalink
fix: parse test errors from mocha@^10.0.0
Browse files Browse the repository at this point in the history
Closes #73
  • Loading branch information
dsanders11 committed Nov 12, 2024
1 parent dccca06 commit 091d3f3
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 14 deletions.
11 changes: 10 additions & 1 deletion electron/mocha-reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,19 @@ function Reporter(runner: Runner) {

runner.on("fail", (test, err) => {
const output = clean(test);
// Manually destructure as err can't be JSON stringified
const { actual, expected, message } = err;
writeToSocket(
JSON.stringify({
stream: "mocha-test-results",
data: ["fail", { ...output, err, stack: err.stack || null }],
data: [
"fail",
{
...output,
error: { actual, expected, message },
stack: err.stack || null,
},
],
}),
);
});
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@
"@types/eslint__js": "^8.42.3",
"@types/markdown-it": "^10.0.2",
"@types/markdown-it-emoji": "^1.4.0",
"@types/mocha": "^5.2.0",
"@types/mocha": "^10.0.9",
"@types/node": "^22.8.6",
"@types/uuid": "^8.3.0",
"@types/vscode": "1.71.0",
Expand Down
19 changes: 11 additions & 8 deletions src/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,20 @@ interface MochaTestEvent {
fullTitle: string;
duration: number;
currentRetry?: number;
err?: {
}

interface MochaTestFailEvent extends MochaTestEvent {
error: {
message: string;
actual?: string;
expected?: string;
};
stack?: string;
stack: string;
}

type MochaEvent =
| ["pass", MochaTestEvent]
| ["fail", MochaTestEvent]
| ["fail", MochaTestFailEvent]
| ["pending", MochaTestEvent]
| ["test-start", MochaTestEvent];

Expand Down Expand Up @@ -186,18 +189,18 @@ export function createTestController(

let testMessage: vscode.TestMessage;

if (details.err) {
testMessage = new vscode.TestMessage(details.err.message);
testMessage.actualOutput = details.err.actual;
testMessage.expectedOutput = details.err.expected;
if (details.error) {
testMessage = new vscode.TestMessage(details.error.message);
testMessage.actualOutput = details.error.actual;
testMessage.expectedOutput = details.error.expected;
} else {
testMessage = new vscode.TestMessage(
"Couldn't parse failure output",
);
}

// Pull file position details if they're available
if (test.uri && details.err && details.stack) {
if (test.uri && details.error && details.stack) {
const failureDetails = /^.*\((.*):(\d+):(\d+)\)\s*$/m.exec(
details.stack,
);
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1155,10 +1155,10 @@
resolved "https://registry.yarnpkg.com/@types/mdurl/-/mdurl-1.0.2.tgz#e2ce9d83a613bacf284c7be7d491945e39e1f8e9"
integrity sha512-eC4U9MlIcu2q0KQmXszyn5Akca/0jrQmwDRgpAMJai7qBWq4amIQhZyNau4VYGtCeALvW1/NtjzJJ567aZxfKA==

"@types/mocha@^5.2.0":
version "5.2.7"
resolved "https://registry.yarnpkg.com/@types/mocha/-/mocha-5.2.7.tgz#315d570ccb56c53452ff8638738df60726d5b6ea"
integrity sha512-NYrtPht0wGzhwe9+/idPaBB+TqkY9AhTvOLMkThm0IoEfLaiVQZwBwyJ5puCkO3AUCWrmcoePjp2mbFocKy4SQ==
"@types/mocha@^10.0.9":
version "10.0.9"
resolved "https://registry.yarnpkg.com/@types/mocha/-/mocha-10.0.9.tgz#101e9da88d2c02e5ac8952982c23b224524d662a"
integrity sha512-sicdRoWtYevwxjOHNMPTl3vSfJM6oyW8o1wXeI7uww6b6xHg8eBznQDNSGBCDJmsE8UMxP05JgZRtsKbTqt//Q==

"@types/node@*":
version "14.14.7"
Expand Down

0 comments on commit 091d3f3

Please sign in to comment.