Skip to content

Commit 02bd788

Browse files
committed
fix: align naming for test case and test file
1 parent 5fcd957 commit 02bd788

File tree

18 files changed

+144
-72
lines changed

18 files changed

+144
-72
lines changed

bin/cli.js

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,22 @@ import { resolve } from "node:path";
77
import { Command } from "commander";
88
import { pathToFileURL } from "node:url";
99

10-
import { validatArgument, start_unit_test } from "../dist/index.js";
10+
import { validateArgument, start_unit_test } from "../dist/index.js";
1111

1212
const program = new Command();
1313
program
1414
.option("--config <config file>", "path of config file", "as-test.config.js")
15+
1516
.option("--temp <path>", "test template file folder")
1617
.option("--output <path>", "coverage report output folder")
1718
.option("--mode <output mode>", "coverage report output format")
19+
1820
.option("--coverageLimit [error warning...]", "set warn(yellow) and error(red) upper limit in coverage report")
19-
.option("--testcase <testcases...>", "run only specified test cases")
20-
.option("--testNamePattern <test name pattern>", "run only tests with a name that matches the regex pattern")
2121
.option("--collectCoverage <boolean>", "whether to collect coverage information and report")
22+
23+
.option("--testcase <testcases...>", "run only specified test cases deprecated, use --testFiles instead")
24+
.option("--testFiles <testFiles...>", "run only specified test files")
25+
.option("--testNamePattern <test name pattern>", "run only tests with a name that matches the regex pattern")
2226
.option("--onlyFailures", "Run tests that failed in the previous");
2327

2428
program.parse(process.argv);
@@ -38,20 +42,29 @@ if (includes === undefined) {
3842
exit(-1);
3943
}
4044
const excludes = config.exclude || [];
41-
validatArgument(includes, excludes);
45+
validateArgument(includes, excludes);
46+
47+
if (options.testcase !== undefined) {
48+
console.log(
49+
chalk.yellowBright(
50+
"Warning: --testcase is deprecated, please use --testFiles instead, --testcase will be removed in next versions"
51+
)
52+
);
53+
}
54+
const testFiles = options.testFiles || options.testcase;
4255

4356
const onlyFailures = options.onlyFailures || false;
4457

4558
// if enabled testcase or testNamePattern or onlyFailures, disable collectCoverage by default
4659
const collectCoverage =
4760
Boolean(options.collectCoverage) ||
4861
config.collectCoverage ||
49-
(!options.testcase && !options.testNamePattern && !onlyFailures);
62+
(testFiles !== undefined && options.testNamePattern !== undefined && !onlyFailures);
5063

5164
const testOption = {
5265
includes,
5366
excludes,
54-
testcases: options.testcase,
67+
testFiles,
5568
testNamePattern: options.testNamePattern,
5669
collectCoverage,
5770
onlyFailures,
@@ -74,6 +87,9 @@ start_unit_test(testOption)
7487
}
7588
})
7689
.catch((e) => {
77-
console.error(chalk.redBright(" Test crash, error message: ") + chalk.yellowBright(`${e.stack}`) + "\n");
90+
console.error(chalk.redBright("framework crash, error message: ") + chalk.yellowBright(`${e.stack}`) + "\n");
91+
console.error(
92+
"please submit an issue at https://github.com/wasm-ecosystem/assemblyscript-unittest-framework/issues"
93+
);
7894
exit(255);
7995
});

docs/api-documents/options.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ There are command line options which can override the configuration in `as-test.
2525
### Run partial test cases
2626

2727
```
28-
--testcase <testcases...> only run specified test cases
28+
--testFiles <test files...> only run specified test cases
2929
--testNamePattern <test name pattern> run only tests with a name that matches the regex pattern
3030
--onlyFailures Run tests that failed in the previous
3131
```
@@ -34,10 +34,10 @@ There are several ways to run partial test cases:
3434

3535
#### Run specified test files
3636

37-
Providing file path to `--testcase`, it can specify a certain group of files for testing.
37+
Providing file path to `--testFiles`, it can specify a certain group of files for testing.
3838

3939
::: tip
40-
`--testcase` can accept multiple file paths.
40+
`--testFiles` can accept multiple file paths.
4141
:::
4242

4343
::: details
@@ -52,7 +52,7 @@ Providing file path to `--testcase`, it can specify a certain group of files for
5252
|- case_4
5353
```
5454

55-
run `as-test --testcase a.test.ts b.test.ts` will match all tests in `a.test.ts` and `b.test.ts`
55+
run `as-test --testFiles a.test.ts b.test.ts` will match all tests in `a.test.ts` and `b.test.ts`
5656

5757
:::
5858

@@ -91,7 +91,7 @@ describe("groupB", () => {
9191
run `as-test --testNamePattern "groupA case_\d"` will run `case_1`, `case_2`, `case_3`.
9292

9393
::: tip
94-
The framework join `DescriptionName` and `TestName` with `" "` by default, e.g. `groupA case_1` is the fullTestCaseName of `case_1`.
94+
The framework join `DescriptionName` and `TestName` with `" "` by default, e.g. `groupA case_1` is the full test case name of `case_1`.
9595

9696
:::
9797

@@ -105,6 +105,6 @@ Provides `--onlyFailures` command line option to run the test cases that failed
105105
--collectCoverage <boolean> whether to collect coverage information and report
106106
```
107107

108-
The framework collects coverage and generates reports by default, but it will be disablea while running partial test cases by `--testcase` or `--testNamePattern`.
108+
The framework collects coverage and generates reports by default, but it will be disablea while running partial test cases by `--testFiles` or `--testNamePattern`.
109109

110110
You can control the coverage collection manually with `--collectCoverage` option.

docs/quick-start.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ Finally, run `npm run test` and as-test will print this message:
6565
(node:144985) ExperimentalWarning: WASI is an experimental feature and might change at any time
6666
(Use `node --trace-warnings ...` to show where the warning was created)
6767
code analysis: OK
68-
compile testcases: OK
68+
compile test files: OK
6969
instrument: OK
70-
execute testcases: OK
70+
execute test files: OK
7171
7272
test case: 1/2 (success/total)
7373

src/core/precompile.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ import assert from "node:assert";
1414
export async function precompile(
1515
includes: string[],
1616
excludes: string[],
17-
testcases: string[] | undefined, // this field specifed test file names
17+
testFiles: string[] | undefined, // this field specifed test file names
1818
testNamePattern: string | undefined,
1919
failedTestNames: string[],
2020
collectCoverage: boolean,
2121
flags: string
2222
): Promise<UnittestPackage> {
23-
// if specify testcases, use testcases for unittest
24-
// otherwise, get testcases(*.test.ts) in includes directory
25-
const testCodePaths = testcases ?? getRelatedFiles(includes, excludes, (path: string) => path.endsWith(".test.ts"));
23+
// if specify testFiles, use testFiles for unittest
24+
// otherwise, get testFiles(*.test.ts) in includes directory
25+
const testCodePaths = testFiles ?? getRelatedFiles(includes, excludes, (path: string) => path.endsWith(".test.ts"));
2626
const matchedTestFiles = new Set<string>();
2727
let matchedTestNames: string[] = [];
2828

src/executionResult.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,9 @@ export class ExecutionResultSummary {
9494
(this.fail === 0 ? chalk.greenBright(this.total) : chalk.redBright(this.total - this.fail)) +
9595
"/" +
9696
this.total.toString();
97-
log(`\ntest case: ${rate} (success/total)\n`);
97+
log(`\ntest case: ${rate} (success/total)`);
9898
if (this.fail !== 0) {
99+
log("");
99100
this.#printErrorMessage(log);
100101
}
101102
}

src/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { join } from "node:path";
1111

1212
const { readFileSync, emptydirSync } = pkg;
1313

14-
export function validatArgument(includes: unknown, excludes: unknown) {
14+
export function validateArgument(includes: unknown, excludes: unknown) {
1515
if (!Array.isArray(includes)) {
1616
throw new TypeError("include section illegal");
1717
}
@@ -53,7 +53,7 @@ export async function start_unit_test(options: TestOption): Promise<boolean> {
5353
const unittestPackage = await precompile(
5454
options.includes,
5555
options.excludes,
56-
options.testcases,
56+
options.testFiles,
5757
options.testNamePattern,
5858
failedTestCases,
5959
options.collectCoverage,
@@ -62,7 +62,7 @@ export async function start_unit_test(options: TestOption): Promise<boolean> {
6262
console.log(chalk.blueBright("code analysis: ") + chalk.bold.greenBright("OK"));
6363

6464
const wasmPaths = await compile(unittestPackage.testCodePaths, options.tempFolder, options.flags);
65-
console.log(chalk.blueBright("compile testcases: ") + chalk.bold.greenBright("OK"));
65+
console.log(chalk.blueBright("compile test files: ") + chalk.bold.greenBright("OK"));
6666

6767
const sourcePaths = unittestPackage.sourceFunctions ? Array.from(unittestPackage.sourceFunctions.keys()) : [];
6868
const instrumentResult = await instrument(wasmPaths, sourcePaths, options.collectCoverage);
@@ -74,7 +74,7 @@ export async function start_unit_test(options: TestOption): Promise<boolean> {
7474
unittestPackage.matchedTestNames,
7575
options.imports
7676
);
77-
console.log(chalk.blueBright("execute testcases: ") + chalk.bold.greenBright("OK"));
77+
console.log(chalk.blueBright("execute test files: ") + chalk.bold.greenBright("OK"));
7878

7979
await executedResult.writeFailures(failurePath);
8080
executedResult.print(console.log);

src/interface.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ export type Imports = ((arg: ImportsArgument) => Record<string, unknown>) | null
200200
export interface TestOption {
201201
includes: string[];
202202
excludes: string[];
203-
testcases?: string[];
203+
testFiles?: string[];
204204
testNamePattern?: string;
205205
collectCoverage: boolean;
206206
onlyFailures: boolean;

tests/e2e/assertFailed/stdout.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
code analysis: OK
2-
compile testcases: OK
2+
compile test files: OK
33
instrument: OK
4-
execute testcases: OK
4+
execute test files: OK
55

66
test case: 0/2 (success/total)
77

@@ -11,11 +11,11 @@ Error Message:
1111
This test will fail due to an assertion error
1212
Reason: unreachable
1313
at start:tests/e2e/assertFailed/assertOnTest.test~anonymous|0 (tests/e2e/assertFailed/assertOnTest.test.ts:6:2)
14-
at executeTestFunction (tests/e2e/assertFailed/tmp/assertOnTest.test.instrumented.wasm:1:675)
14+
at executeTestFunction (tests/e2e/assertFailed/tmp/assertOnTest.test.instrumented.wasm:1:637)
1515

1616
tests/e2e/assertFailed/tmp/assertOnInit.test - init:
1717
Test Crashed!
1818
Reason: unreachable
1919
at start:tests/e2e/assertFailed/assertOnInit.test (tests/e2e/assertFailed/assertOnInit.test.ts:1:0)
20-
at ~start (tests/e2e/assertFailed/tmp/assertOnInit.test.instrumented.wasm:1:244)
20+
at ~start (tests/e2e/assertFailed/tmp/assertOnInit.test.instrumented.wasm:1:206)
2121

tests/e2e/printLogInFailedInfo/stdout.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
code analysis: OK
2-
compile testcases: OK
2+
compile test files: OK
33
instrument: OK
4-
execute testcases: OK
4+
execute test files: OK
55

66
test case: 1/2 (success/total)
77

tests/e2e/run.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,7 @@ import { argv } from "node:process";
66
import { readFileSync } from "node:fs";
77

88
function getDiff(s1, s2) {
9-
const handleEscape = (c) =>
10-
c
11-
.split("\n")
12-
.map((l) => (l.length === 0 ? "\xB6" : l))
13-
.join("\n");
9+
const handleEscape = (c) => (/^\n*$/.test(c) ? c.replaceAll("\n", "\xB6\n") : c);
1410
return diffLines(s1, s2)
1511
.map((part) => {
1612
if (part.added) {
@@ -32,10 +28,10 @@ function isEnabled(name) {
3228
return enabledTests.includes(name);
3329
}
3430

35-
function runEndToEndTest(name, handle) {
31+
function runEndToEndTest(name, flags, handle) {
3632
if (isEnabled(name)) {
3733
console.log(`Running e2e test: ${name}`);
38-
exec(`node ./bin/as-test.js --config tests/e2e/${name}/as-test.config.js`, (error, stdout, stderr) => {
34+
exec(`node ./bin/as-test.js --config tests/e2e/${name}/as-test.config.js ${flags}`, (error, stdout, stderr) => {
3935
// standard check
4036
const expectStdOut = readFileSync(`tests/e2e/${name}/stdout.txt`, "utf-8");
4137
if (expectStdOut !== stdout) {
@@ -51,10 +47,18 @@ function runEndToEndTest(name, handle) {
5147
}
5248
}
5349

54-
runEndToEndTest("printLogInFailedInfo", (error, stdout, stderr) => {
50+
runEndToEndTest("printLogInFailedInfo", "", (error, stdout, stderr) => {
5551
assert(error.code === 255);
5652
});
5753

58-
runEndToEndTest("assertFailed", (error, stdout, stderr) => {
54+
runEndToEndTest("assertFailed", "", (error, stdout, stderr) => {
5955
assert(error.code === 255);
6056
});
57+
58+
runEndToEndTest(
59+
"testFiles",
60+
"--testFiles tests/e2e/testFiles/succeed_0.test.ts tests/e2e/testFiles/succeed_1.test.ts",
61+
(error, stdout, stderr) => {
62+
assert(error === null);
63+
}
64+
);

0 commit comments

Comments
 (0)