Skip to content

Commit 8ba1155

Browse files
committed
wip
1 parent 2a7a4e8 commit 8ba1155

File tree

5 files changed

+24
-7
lines changed

5 files changed

+24
-7
lines changed

assembly/env.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ export namespace assertResult {
88
export declare function removeDescription(): void;
99

1010

11+
@external("__unittest_framework_env","registerTestFunction")
12+
export declare function registerTestFunction(index: u32): void;
13+
14+
1115
@external("__unittest_framework_env","collectCheckResult")
1216
export declare function collectCheckResult(
1317
result: bool,

assembly/implement.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export function describeImpl(
1111
}
1212
export function testImpl(description: string, testFunction: () => void): void {
1313
assertResult.addDescription(description);
14-
testFunction();
14+
assertResult.registerTestFunction(testFunction.index);
1515
assertResult.removeDescription();
1616
mockFunctionStatus.clear();
1717
}

bin/cli.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ const excludes = config.exclude || [];
4040
validatArgument(includes, excludes);
4141

4242
// if enabled testcase or testNamePattern, disable collectCoverage by default
43-
const collectCoverage = Boolean(options.collectCoverage) || config.collectCoverage || (!options.testcase && !options.testNamePattern);
43+
const collectCoverage =
44+
Boolean(options.collectCoverage) || config.collectCoverage || (!options.testcase && !options.testNamePattern);
4445

4546
const testOption = {
4647
includes,
@@ -57,7 +58,7 @@ const testOption = {
5758
mode: options.mode || config.mode || "table",
5859
warnLimit: Number(options.coverageLimit?.at(1)),
5960
errorLimit: Number(options.coverageLimit?.at(0)),
60-
}
61+
};
6162

6263
start_unit_test(testOption)
6364
.then((success) => {

src/core/executionRecorder.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export class ExecutionRecorder implements IAssertResult {
44
total: number = 0;
55
fail: number = 0;
66
failed_info: AssertFailMessage = {};
7+
registerFunctions: [string, number][] = [];
78
_currentTestDescriptions: string[] = [];
89

910
_addDescription(description: string): void {
@@ -12,6 +13,10 @@ export class ExecutionRecorder implements IAssertResult {
1213
_removeDescription(): void {
1314
this._currentTestDescriptions.pop();
1415
}
16+
registerTestFunction(fncIndex: number): void {
17+
const testCaseFullName = this._currentTestDescriptions.join(" - ");
18+
this.registerFunctions.push([testCaseFullName, fncIndex]);
19+
}
1520
collectCheckResult(result: boolean, codeInfoIndex: number, actualValue: string, expectValue: string): void {
1621
this.total++;
1722
if (!result) {
@@ -32,6 +37,9 @@ export class ExecutionRecorder implements IAssertResult {
3237
removeDescription: (): void => {
3338
this._removeDescription();
3439
},
40+
registerTestFunction: (index: number): void => {
41+
this.registerTestFunction(index);
42+
},
3543
collectCheckResult: (result: number, codeInfoIndex: number, actualValue: number, expectValue: number): void => {
3644
this.collectCheckResult(
3745
result !== 0,

tests/ts/test/core/precompile.test.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
import { join } from "node:path";
21
import { precompile } from "../../../../src/core/precompile.js";
3-
import { projectRoot } from "../../../../src/utils/projectRoot.js";
42

53
test("listFunction transform", async () => {
6-
const transformFunction = join(projectRoot, "transform", "listFunctions.mjs");
7-
const unittestPackages = await precompile(["tests/ts/fixture/transformFunction.ts"], [], [], "", transformFunction);
4+
const unittestPackages = await precompile(
5+
["tests/ts/fixture/transformFunction.ts"],
6+
[],
7+
undefined,
8+
undefined,
9+
false,
10+
""
11+
);
812
expect(unittestPackages.testCodePaths).toEqual([]);
913
expect(unittestPackages.sourceFunctions).toMatchSnapshot();
1014
});

0 commit comments

Comments
 (0)