Skip to content

Commit 1ed50f5

Browse files
authored
feat: update to new syntest-core api (#175)
Removes "_conditionAST" everywhere Passes the entire error object from failing tests instead of just the message Renames some functions
1 parent 938dc62 commit 1ed50f5

21 files changed

+359
-547
lines changed

libraries/analysis-javascript/lib/cfg/ControlFlowGraphVisitor.ts

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,10 @@ import {
2828
Node,
2929
NodeType,
3030
} from "@syntest/cfg";
31-
import { getLogger } from "@syntest/logging";
31+
import { Logger, getLogger } from "@syntest/logging";
3232

3333
export class ControlFlowGraphVisitor extends AbstractSyntaxTreeVisitor {
34-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
35-
protected static override LOGGER: any;
34+
protected static override LOGGER: Logger;
3635

3736
private _nodesList: Node[];
3837
private _nodes: Map<string, Node>;
@@ -300,29 +299,6 @@ export class ControlFlowGraphVisitor extends AbstractSyntaxTreeVisitor {
300299
return node;
301300
}
302301

303-
// private _isSpecial(path: NodePath): boolean {
304-
// return (
305-
// path.isFunction() ||
306-
// path.isClass() ||
307-
// path.isConditional() ||
308-
// path.isLoop() ||
309-
// path.isBlock() ||
310-
// // terminating statements
311-
// path.isBreakStatement() ||
312-
// path.isContinueStatement() ||
313-
// path.isReturnStatement() ||
314-
// path.isThrowStatement() ||
315-
// // exports
316-
// path.isExportAllDeclaration() ||
317-
// path.isExportDeclaration() ||
318-
// path.isExportDefaultDeclaration() ||
319-
// path.isExportDefaultSpecifier() ||
320-
// path.isExportNamedDeclaration() ||
321-
// path.isExportNamespaceSpecifier() ||
322-
// path.isExportSpecifier()
323-
// );
324-
// }
325-
326302
private _createEdge(
327303
source: Node,
328304
target: Node,

libraries/instrumentation-javascript/lib/instrumentation/VisitState.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -367,10 +367,6 @@ export class VisitState {
367367
const metaTracker = T.callExpression(T.identifier(this.metaVarName), [
368368
T.stringLiteral(`${branchName}`),
369369
T.objectExpression([
370-
T.objectProperty(
371-
T.stringLiteral("condition_ast"),
372-
T.stringLiteral("TODO we should remove the condition asts entirely")
373-
),
374370
T.objectProperty(
375371
T.stringLiteral("condition"),
376372
T.stringLiteral(testAsCode)

libraries/instrumentation-javascript/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@
4646
"test:watch": "mocha --config ../../.mocharc.json --watch"
4747
},
4848
"dependencies": {
49+
"@syntest/analysis-javascript": "^0.1.0-beta.20",
4950
"@babel/core": "7.20.12",
5051
"@babel/traverse": "7.20.12",
5152
"@istanbuljs/schema": "^0.1.3",
52-
"@syntest/analysis-javascript": "^0.1.0-beta.20",
5353
"@syntest/ast-visitor-javascript": "*",
5454
"@syntest/storage": "*",
5555
"istanbul-lib-coverage": "^3.2.0"

libraries/search-javascript/lib/criterion/BranchDistance.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ export class BranchDistance extends CoreBranchDistance {
3838
}
3939

4040
calculate(
41-
_conditionAST: string, // deprecated
4241
condition: string,
4342
variables: Record<string, unknown>,
4443
trueOrFalse: boolean

libraries/search-javascript/lib/search/JavaScriptExecutionResult.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* limitations under the License.
1717
*/
1818

19-
import { Datapoint, ExecutionResult } from "@syntest/search";
19+
import { Trace, ExecutionResult } from "@syntest/search";
2020

2121
export enum JavaScriptExecutionStatus {
2222
PASSED,
@@ -42,7 +42,7 @@ export class JavaScriptExecutionResult implements ExecutionResult {
4242
* ARRAY of traces of the execution.
4343
* @protected
4444
*/
45-
protected _traces: Datapoint[];
45+
protected _traces: Trace[];
4646

4747
/**
4848
* Duration of the execution.
@@ -51,10 +51,10 @@ export class JavaScriptExecutionResult implements ExecutionResult {
5151
protected _duration: number;
5252

5353
/**
54-
* Exception of execution.
54+
* Error of execution.
5555
* @protected
5656
*/
57-
protected _exception: string;
57+
protected _error: Error | undefined;
5858

5959
/**
6060
* Constructor.
@@ -66,14 +66,14 @@ export class JavaScriptExecutionResult implements ExecutionResult {
6666
*/
6767
public constructor(
6868
status: JavaScriptExecutionStatus,
69-
traces: Datapoint[],
69+
traces: Trace[],
7070
duration: number,
71-
exception?: string | undefined
71+
error?: Error | undefined
7272
) {
7373
this._status = status;
7474
this._traces = traces;
7575
this._duration = duration;
76-
this._exception = exception;
76+
this._error = error;
7777
}
7878

7979
/**
@@ -132,22 +132,22 @@ export class JavaScriptExecutionResult implements ExecutionResult {
132132
/**
133133
* @inheritDoc
134134
*/
135-
public getExceptions(): string {
136-
return this._exception;
135+
public getError(): Error {
136+
return this._error;
137137
}
138138

139139
/**
140140
* @inheritDoc
141141
*/
142-
public getTraces(): Datapoint[] {
142+
public getTraces(): Trace[] {
143143
return this._traces;
144144
}
145145

146146
/**
147147
* @inheritDoc
148148
*/
149-
public hasExceptions(): boolean {
150-
return this._exception !== null && this._exception !== undefined;
149+
public hasError(): boolean {
150+
return this._error !== null && this._error !== undefined;
151151
}
152152

153153
/**

libraries/search-javascript/lib/testcase/execution/ExecutionInformationIntegrator.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@ export class ExecutionInformationIntegrator {
4242
const children = root.getChildren();
4343

4444
for (const child of children) {
45-
if (testResult.exception && testResult.exception.includes(child.name)) {
45+
if (
46+
testResult.error &&
47+
testResult.error.message &&
48+
testResult.error.message.includes(child.name)
49+
) {
4650
this._typeModel.addExecutionScore(
4751
child.variableIdentifier,
4852
child.typeIdentifier,

libraries/search-javascript/lib/testcase/execution/JavaScriptRunner.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
import * as path from "node:path";
2020

21-
import { Datapoint, EncodingRunner, ExecutionResult } from "@syntest/search";
21+
import { Trace, EncodingRunner, ExecutionResult } from "@syntest/search";
2222
import { getLogger, Logger } from "@syntest/logging";
2323

2424
import {
@@ -112,7 +112,6 @@ export class JavaScriptRunner implements EncodingRunner<JavaScriptTestCase> {
112112
if (data.message === "done") {
113113
childProcess.removeAllListeners();
114114
clearTimeout(timeout);
115-
116115
if (!data.instrumentationData) {
117116
return reject("no instrumentation data found");
118117
}
@@ -161,7 +160,7 @@ export class JavaScriptRunner implements EncodingRunner<JavaScriptTestCase> {
161160
// If one of the executions failed, log it
162161
this.executionInformationIntegrator.process(testCase, test, stats);
163162

164-
const traces: Datapoint[] = this._extractTraces(
163+
const traces: Trace[] = this._extractTraces(
165164
instrumentationData,
166165
metaData
167166
);
@@ -171,7 +170,7 @@ export class JavaScriptRunner implements EncodingRunner<JavaScriptTestCase> {
171170
test.status,
172171
traces,
173172
test.duration,
174-
test.exception
173+
test.error
175174
);
176175
} catch (error) {
177176
if (error === "timeout") {
@@ -201,8 +200,8 @@ export class JavaScriptRunner implements EncodingRunner<JavaScriptTestCase> {
201200
private _extractTraces(
202201
instrumentationData: InstrumentationData,
203202
metaData: MetaData
204-
): Datapoint[] {
205-
const traces: Datapoint[] = [];
203+
): Trace[] {
204+
const traces: Trace[] = [];
206205

207206
for (const key of Object.keys(instrumentationData)) {
208207
for (const functionKey of Object.keys(instrumentationData[key].fnMap)) {
@@ -254,7 +253,6 @@ export class JavaScriptRunner implements EncodingRunner<JavaScriptTestCase> {
254253

255254
hits: hits[0],
256255

257-
condition_ast: meta?.condition_ast,
258256
condition: meta?.condition,
259257
variables: meta?.variables,
260258
});
@@ -273,7 +271,6 @@ export class JavaScriptRunner implements EncodingRunner<JavaScriptTestCase> {
273271

274272
hits: hits[index],
275273

276-
condition_ast: meta?.condition_ast,
277274
condition: meta?.condition,
278275
variables: meta?.variables,
279276
});
@@ -289,7 +286,6 @@ export class JavaScriptRunner implements EncodingRunner<JavaScriptTestCase> {
289286

290287
hits: hits[1],
291288

292-
condition_ast: meta?.condition_ast,
293289
condition: meta?.condition,
294290
variables: meta?.variables,
295291
});
@@ -306,7 +302,6 @@ export class JavaScriptRunner implements EncodingRunner<JavaScriptTestCase> {
306302

307303
hits: hits[0] ? 0 : 1,
308304

309-
condition_ast: meta?.condition_ast,
310305
condition: meta?.condition,
311306
variables: meta?.variables,
312307
});

libraries/search-javascript/lib/testcase/execution/TestExecutor.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export type Suite = {
5050

5151
export type Test = {
5252
status: JavaScriptExecutionStatus;
53-
exception?: string;
53+
error?: Error | undefined;
5454
duration: number;
5555
};
5656

@@ -118,11 +118,16 @@ async function runMocha(silent: boolean, paths: string[], timeout: number) {
118118
} else {
119119
status = JavaScriptExecutionStatus.FAILED;
120120
}
121+
121122
return {
122123
status: status,
123-
exception:
124+
error:
124125
status === JavaScriptExecutionStatus.FAILED
125-
? test.err.message
126+
? {
127+
name: test.err.name,
128+
message: test.err.message,
129+
stack: test.err.stack,
130+
}
126131
: undefined,
127132
duration: test.duration,
128133
};

0 commit comments

Comments
 (0)