Skip to content

Commit b680810

Browse files
committed
update docs
1 parent 31a00c0 commit b680810

File tree

11 files changed

+71
-40
lines changed

11 files changed

+71
-40
lines changed

assembly/implement.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ export function describeImpl(
99
testsFunction();
1010
assertResult.removeDescription();
1111
}
12-
export function testImpl(description: string, testFunction: () => void): void {
13-
assertResult.addDescription(description);
12+
export function testImpl(name: string, testFunction: () => void): void {
13+
assertResult.addDescription(name);
1414
assertResult.registerTestFunction(testFunction.index);
1515
assertResult.removeDescription();
1616
}

assembly/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ export function describe(description: string, testsFunction: () => void): void {
2020

2121
/**
2222
* run a test
23-
* @param description test description
23+
* @param name test name
2424
* @param testFunction main function of test
2525
*/
26-
export function test(description: string, testFunction: () => void): void {
27-
testImpl(description, testFunction);
26+
export function test(name: string, testFunction: () => void): void {
27+
testImpl(name, testFunction);
2828
}
2929

3030
/**

bin/cli.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ import { validatArgument, start_unit_test } from "../dist/index.js";
1212
const program = new Command();
1313
program
1414
.option("--config <config file>", "path of config file", "as-test.config.js")
15-
.option("--testcase <testcases...>", "run only specified test cases")
1615
.option("--temp <path>", "test template file folder")
1716
.option("--output <path>", "coverage report output folder")
1817
.option("--mode <output mode>", "coverage report output format")
1918
.option("--coverageLimit [error warning...]", "set warn(yellow) and error(red) upper limit in coverage report")
19+
.option("--testcase <testcases...>", "run only specified test cases")
2020
.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");
2222

docs/api-documents.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ A comprehensive AssemblyScript testing solution, offering developers a robust su
22

33
- Function Mocking
44
- Coverage statistics
5-
- Expectations
5+
- Matchers

docs/api-documents/mock-function.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ test("getTime error handle", () => {
3131
expect(getTime()).equal(false); // success
3232
expect(fn.calls).equal(1); // success
3333
});
34-
endTest();
3534
```
3635

3736
mock API can temporary change the behavior of function, effective scope is each test.

docs/api-documents/options.md

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ There are several ways to run partial test cases:
3333

3434
#### Partial Test Files
3535

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

3838
::: tip
3939
`--testcase` can accept multiple file paths.
@@ -57,20 +57,49 @@ run `as-test --testcase a.test.ts b.test.ts` will match all tests in `a.test.ts`
5757

5858
#### Partial Tests
5959

60-
Providing regex which can match targeted test name to `--testNamePattern`. it can specify a certain group of tests for testing.
60+
Providing regex which can match targeted test name to `--testNamePattern`, it can specify a certain group of tests for testing.
6161

6262
::: details
6363

6464
```
65-
- a.test.ts
66-
|- case_1
67-
|- case_2
68-
- b.test.ts
69-
|- case_A
70-
- c.test.ts
71-
|- case_4
65+
describe("groupA", () => {
66+
test("case_1", () => {
67+
...
68+
});
69+
test("case_2", () => {
70+
...
71+
});
72+
test("case_3", () => {
73+
...
74+
});
75+
});
76+
77+
describe("groupB", () => {
78+
test("case_A", () => {
79+
...
80+
});
81+
test("case_B", () => {
82+
...
83+
});
84+
test("case_C", () => {
85+
...
86+
});
87+
});
7288
```
7389

74-
run `as-test --testNamePattern "case_\d"` will match `case 1`, `case 2`, `case 4`
90+
run `as-test --testNamePattern "groupA case_\d"` will run `case_1`, `case_2`, `case_3`.
91+
92+
::: tip
93+
The framework join `DescriptionName` and `TestName` with `" "` by default, e.g. `groupA case_1` is the fullTestCaseName of `case_1`.
7594

7695
:::
96+
97+
### Whether collect coverage information
98+
99+
```
100+
--collectCoverage <boolean> whether to collect coverage information and report
101+
```
102+
103+
The framework collects coverage and generates reports by default, but it will be disablea while running partial test cases by `--testcase` or `--testNamePattern`.
104+
105+
You can control the coverage collection manually with `--collectCoverage` option.

docs/quick-start.md

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,13 @@ export function add(a: i32, b: i32): i32 {
1919
Then, create a file named `tests/sum.test.ts`. This will contain our actual test:
2020

2121
```Typescript
22-
import { test, expect, endTest } from "assemblyscript-unittest-framework/assembly";
22+
import { test, expect } from "assemblyscript-unittest-framework/assembly";
2323
import { add } from "../source/sum";
2424

2525
test("sum", () => {
2626
expect(add(1, 2)).equal(3);
2727
expect(add(1, 1)).equal(3);
2828
});
29-
endTest(); // Don't forget it!
3029
```
3130

3231
Create a config file in project root `as-test.config.js`:
@@ -60,16 +59,29 @@ Add the following section to your `package.json`
6059
Finally, run `npm run test` and as-test will print this message:
6160

6261
```
63-
transform source/sum.ts => build/source/sum.ts.cov
64-
transform build/source/sum.ts.cov => build/source/sum.ts
65-
transform tests/sum.test.ts => build/tests/sum.test.ts
66-
(node:489815) ExperimentalWarning: WASI is an experimental feature. This feature could change at any time
62+
63+
> as-test
64+
65+
(node:144985) ExperimentalWarning: WASI is an experimental feature and might change at any time
66+
(Use `node --trace-warnings ...` to show where the warning was created)
67+
code analysis: OK
68+
compile testcases: OK
69+
instrument: OK
70+
execute testcases: OK
6771
6872
test case: 1/2 (success/total)
6973
70-
Error Message:
71-
sum:
72-
tests/sum.test.ts:6:3 (6:3, 6:29)
74+
Error Message:
75+
sum:
76+
tests/sum.test.ts:6:2 value: 2 expect: = 3
77+
---------|---------|----------|---------|--------
78+
File | % Stmts | % Branch | % Funcs | % Lines
79+
---------|---------|----------|---------|--------
80+
source | 100 | 100 | 100 | 100
81+
sum.ts | 100 | 100 | 100 | 100
82+
---------|---------|----------|---------|--------
83+
84+
Test Failed
7385
```
7486

7587
You can also use `npx as-test -h` for more information to control detail configurations

tests/as/comparison.test.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { describe, endTest, expect, test } from "../../assembly";
1+
import { describe, expect, test } from "../../assembly";
22

33
describe("base type equal", () => {
44
test("i32", () => {
@@ -177,7 +177,6 @@ describe("single level container type equal", () => {
177177
});
178178
test("nullable equal normal", () => {});
179179
});
180-
// end test
181180
});
182181

183182
describe("mutli-level container type equal", () => {
@@ -209,5 +208,3 @@ describe("mutli-level container type equal", () => {
209208
expect(arr).equal(arr2);
210209
});
211210
});
212-
213-
endTest();

tests/as/expect.test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { describe, endTest, expect, test } from "../../assembly";
1+
import { describe, expect, test } from "../../assembly";
22

33
describe("expect", () => {
44
test("< = >", () => {
@@ -14,5 +14,3 @@ describe("expect", () => {
1414
expect<string | null>("test").notNull();
1515
});
1616
});
17-
18-
endTest();

tests/as/format.test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { describe, endTest, expect, test } from "../../assembly";
1+
import { describe, expect, test } from "../../assembly";
22
import { toJson } from "../../assembly/formatPrint";
33

44
class A {}
@@ -57,5 +57,3 @@ describe("print", () => {
5757
expect(toJson(new A())).equal("[Object A]");
5858
});
5959
});
60-
61-
endTest();

0 commit comments

Comments
 (0)