Skip to content

Commit 955a87e

Browse files
committed
Add examples
1 parent 187e90b commit 955a87e

File tree

5 files changed

+85
-3
lines changed

5 files changed

+85
-3
lines changed

Diff for: README.md

+60
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,63 @@ TST: TypeScript Tester
22
======================
33

44
Simple testing tool to run and test TypeScript code in combination with assertion libraries.
5+
6+
7+
8+
Command Line Arguments
9+
----------------------
10+
11+
* \[options] : Optional flags explained in the section below.
12+
13+
* \[source] : Source folder with TypeScript tests.
14+
15+
16+
17+
Command Line Options
18+
--------------------
19+
20+
* --help, -h : Prints this help text.
21+
22+
* --only [path] : Runs a single test in [source].
23+
24+
* --verbose : Prints this help text.
25+
26+
* --version, -v : Prints the version string.
27+
28+
29+
30+
Examples
31+
--------
32+
33+
Import the default test function in the following pattern. If you like to use a
34+
custom assert library, you can ignore the assert argument.
35+
36+
```ts
37+
import test from '@typescriptlibs/tst';
38+
39+
test('Test the answer to the ultimate question.', (assert: test.Assert) => {
40+
assert.strictEqual(
41+
42,
42+
Math.cbrt(74088),
43+
'The answer to the ultimate question should be the cube root of 74088.'
44+
);
45+
});
46+
47+
test('Test the timeout function.', async (assert: test.Assert) => {
48+
const time = Date.now();
49+
50+
await new Promise((resolve) => setTimeout(resolve, 100));
51+
52+
const delta = Date.now() - time;
53+
54+
assert.ok(
55+
delta > 100,
56+
`The timeout should fire after 100 milliseconds. (${delta})`
57+
);
58+
});
59+
```
60+
61+
Compiles, loads and runs assertion tests in the "tests" folder.
62+
```sh
63+
$ tst tests/
64+
```

Diff for: tst/CLI.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import test, { CLI, System } from '@typescriptlibs/tst';
1212
*
1313
* */
1414

15-
test('CLI tests', function (assert: test.Assert) {
15+
test('CLI tests', (assert: test.Assert) => {
1616
assert.strictEqual(
1717
CLI.VERSION,
1818
`Version ${System.VERSION}`,

Diff for: tst/Examples.ts

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import test from '@typescriptlibs/tst';
2+
3+
test('Test the answer to the ultimate question.', (assert: test.Assert) => {
4+
assert.strictEqual(
5+
42,
6+
Math.cbrt(74088),
7+
'The answer to the ultimate question should be the cube root of 74088.'
8+
);
9+
});
10+
11+
test('Test the timeout function.', async (assert: test.Assert) => {
12+
const time = Date.now();
13+
14+
await new Promise((resolve) => setTimeout(resolve, 100));
15+
16+
const delta = Date.now() - time;
17+
18+
assert.ok(
19+
delta > 100,
20+
`The timeout should fire after 100 milliseconds. (${delta})`
21+
);
22+
});

Diff for: tst/System.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import test, { System } from '@typescriptlibs/tst';
1212
*
1313
* */
1414

15-
test('System tests', function (assert: test.Assert) {
15+
test('System tests', (assert: test.Assert) => {
1616
assert.ok(
1717
System.VERSION.match(/^\d+\.\d+\.\d+$/),
1818
'System.VERSION should be a version string.'

Diff for: tst/Tester.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import test, { Tester } from '@typescriptlibs/tst';
1212
*
1313
* */
1414

15-
test('Tester tests', function (assert: test.Assert) {
15+
test('Tester tests', (assert: test.Assert) => {
1616
assert.ok(
1717
typeof Tester === 'function',
1818
'Tester should be a class constructor.'

0 commit comments

Comments
 (0)