Skip to content

Commit

Permalink
fix: improve errors and results from test executor (#209)
Browse files Browse the repository at this point in the history
  • Loading branch information
dstallenberg authored Dec 11, 2023
1 parent 8bbb66d commit 4cdc920
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,14 @@ export class JavaScriptRunner implements EncodingRunner<JavaScriptTestCase> {
childProcess.on("message", (data: Message) => {
if (typeof data !== "object") {
return reject(
new TypeError("Invalid data received from child process")
new ImplementationError(
"Invalid data received from child process",
{
context: {
data: data,
},
}
)
);
}

Expand Down
25 changes: 21 additions & 4 deletions libraries/search-javascript/lib/testcase/execution/TestExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,9 @@ async function runMocha(silent: boolean, paths: string[], timeout: number) {
error:
status === JavaScriptExecutionStatus.FAILED
? {
name: test.err.name,
message: test.err.message,
stack: test.err.stack,
name: test.err ? test.err.name : "",
message: test.err ? test.err.message : "",
stack: test.err ? test.err.stack : "",
}
: undefined,
duration: test.duration,
Expand All @@ -153,7 +153,24 @@ async function runMocha(silent: boolean, paths: string[], timeout: number) {
resetInstrumentationData();
(<GlobalType>(<unknown>global)).__meta__ = undefined;
(<GlobalType>(<unknown>global)).__assertion__ = undefined;
process.send(result);

const cache = new Set();

// This is to prevent circular references
// TODO this actually removes all repeating values which is not good
process.send(
JSON.parse(
JSON.stringify(result, (_, value) => {
if (typeof value === "object" && value !== null) {
if (cache.has(value)) return;

cache.add(value);
}
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return value;
})
)
);

mocha.dispose();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/

import { Export, TypeEnum } from "@syntest/analysis-javascript";
import { ImplementationError } from "@syntest/diagnostics";
import { prng } from "@syntest/prng";

import { ContextBuilder } from "../../../testbuilding/ContextBuilder";
Expand Down Expand Up @@ -59,6 +60,11 @@ export class ConstructorCall extends ActionStatement {
arguments_,
export_
);
if (!export_) {
throw new ImplementationError(
"Export of constructor call cannot be undefined"
);
}
this._classIdentifier = classIdentifier;
}

Expand Down

0 comments on commit 4cdc920

Please sign in to comment.