@w-lfpup/jackrabbit 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/{build_and_test.yml → tests.yml} +3 -3
- package/README.md +111 -8
- package/cli/dist/config.js +1 -22
- package/cli/src/config.ts +1 -28
- package/core/dist/jackrabbit_types.d.ts +1 -1
- package/core/src/jackrabbit_types.ts +1 -1
- package/package.json +4 -3
- package/test_guide.md +0 -114
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
name:
|
|
1
|
+
name: Tests
|
|
2
2
|
|
|
3
3
|
on:
|
|
4
4
|
push:
|
|
@@ -10,8 +10,8 @@ jobs:
|
|
|
10
10
|
build_and_test:
|
|
11
11
|
runs-on: ubuntu-latest
|
|
12
12
|
steps:
|
|
13
|
-
- uses: actions/checkout@
|
|
14
|
-
- uses: actions/setup-node@
|
|
13
|
+
- uses: actions/checkout@v6
|
|
14
|
+
- uses: actions/setup-node@v6
|
|
15
15
|
- name: Install
|
|
16
16
|
run: npm ci
|
|
17
17
|
- name: Test
|
package/README.md
CHANGED
|
@@ -2,13 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
Write tests without dependencies (including jackrabbit itself).
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
Read [this guide](./test_guide.md) to create jackrabbit tests.
|
|
8
|
-
|
|
9
|
-
## Nodejs
|
|
5
|
+
[](https://github.com/w-lfpup/jackrabbit-js/actions/workflows/tests.yml)
|
|
10
6
|
|
|
11
|
-
|
|
7
|
+
## Install
|
|
12
8
|
|
|
13
9
|
Install jackrabbit with npm.
|
|
14
10
|
|
|
@@ -22,10 +18,117 @@ Or Install jackrabbit directly from github.
|
|
|
22
18
|
npm install --save-dev https://github.com/w-lfpup/jackrabbit-js
|
|
23
19
|
```
|
|
24
20
|
|
|
25
|
-
|
|
21
|
+
# Tests
|
|
22
|
+
|
|
23
|
+
For a quick visual reference, please refer to the [examples](./examples/).
|
|
24
|
+
|
|
25
|
+
Developers with javascript experience can immediately start testing with basically zero overhead.
|
|
26
|
+
|
|
27
|
+
## Tests
|
|
28
|
+
|
|
29
|
+
Tests are functions or promises that return assertions.
|
|
30
|
+
|
|
31
|
+
Tests `pass` when they return the `undefined` primitive or an empty array `[]`.
|
|
32
|
+
|
|
33
|
+
```TS
|
|
34
|
+
// my.tests.ts
|
|
35
|
+
|
|
36
|
+
function testStuffAndPass() {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function testMoreStuffAndPass() {
|
|
41
|
+
return [];
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Any other value will cause a test to `fail`.
|
|
46
|
+
|
|
47
|
+
So tests that `fail` look like:
|
|
48
|
+
|
|
49
|
+
```TS
|
|
50
|
+
// my.tests.ts
|
|
51
|
+
|
|
52
|
+
function testStuffAndFail() {
|
|
53
|
+
return "this test failed!";
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function testMoreStuffAndFail() {
|
|
57
|
+
return ["this test also failed!"];
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Test Modules
|
|
62
|
+
|
|
63
|
+
Test Modules are javascript `modules` that export two values: `tests` and `options`.
|
|
64
|
+
|
|
65
|
+
### Export Tests
|
|
66
|
+
|
|
67
|
+
Test Modules export their tests in an array called `tests`.
|
|
68
|
+
|
|
69
|
+
```TS
|
|
70
|
+
// my.tests.ts
|
|
71
|
+
|
|
72
|
+
export const tests = [
|
|
73
|
+
testStuffAndPass,
|
|
74
|
+
testMoreStuffAndPass,
|
|
75
|
+
testStuffAndFail,
|
|
76
|
+
testMoreStuffAndFail,
|
|
77
|
+
];
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### Export Options
|
|
81
|
+
|
|
82
|
+
Export a parameter object named `options` to affect test behaviors in the current module:
|
|
83
|
+
|
|
84
|
+
```TS
|
|
85
|
+
// my.tests.ts
|
|
86
|
+
|
|
87
|
+
interface Options {
|
|
88
|
+
runAsynchronously?: boolean;
|
|
89
|
+
timeoutMs?: number;
|
|
90
|
+
title?: string;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
...
|
|
94
|
+
|
|
95
|
+
export const options = {
|
|
96
|
+
runAsyncronously: true,
|
|
97
|
+
timeoutMs: 3000,
|
|
98
|
+
title: import.meta.url,
|
|
99
|
+
}
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
All properties are optional and exporting an `options` pojo is not required.
|
|
103
|
+
|
|
104
|
+
Tests run sequentially unless the `runAsyncronously` property is set to `true`.
|
|
105
|
+
|
|
106
|
+
## Test Collections
|
|
107
|
+
|
|
108
|
+
A `test collection` is a javascript module that exports a list test modules called `testModules`.
|
|
109
|
+
|
|
110
|
+
```TS
|
|
111
|
+
// mod.test.ts
|
|
112
|
+
|
|
113
|
+
import * as MyTests from "./my.tests.ts";
|
|
114
|
+
|
|
115
|
+
export const testModules = [
|
|
116
|
+
MyTests
|
|
117
|
+
];
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
## Run Test Collections
|
|
121
|
+
|
|
122
|
+
Run the following command and to log the results of a test collection.
|
|
123
|
+
|
|
124
|
+
```sh
|
|
125
|
+
npx jackrabbit ./mod.tests.ts
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
To run multiple test collections, add more filepaths as commandline arguments:
|
|
26
129
|
|
|
27
130
|
```sh
|
|
28
|
-
npx jackrabbit
|
|
131
|
+
npx jackrabbit ./mod.tests.ts ./another_mod.tests.ts
|
|
29
132
|
```
|
|
30
133
|
|
|
31
134
|
## License
|
package/cli/dist/config.js
CHANGED
|
@@ -1,27 +1,6 @@
|
|
|
1
|
-
const reactions = {
|
|
2
|
-
"--file": fileConfig,
|
|
3
|
-
"-f": fileConfig,
|
|
4
|
-
};
|
|
5
|
-
function fileConfig(config, file) {
|
|
6
|
-
if (file === undefined)
|
|
7
|
-
return;
|
|
8
|
-
config.files.push(file);
|
|
9
|
-
}
|
|
10
|
-
function iterateArgs(config, args) {
|
|
11
|
-
let index = 0;
|
|
12
|
-
while (index < args.length) {
|
|
13
|
-
const flag = args[index];
|
|
14
|
-
const reaction = reactions[flag];
|
|
15
|
-
if (reaction === undefined) {
|
|
16
|
-
throw new Error(`unrecognized argument: ${flag}`);
|
|
17
|
-
}
|
|
18
|
-
reaction(config, args[index + 1]);
|
|
19
|
-
index += 2;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
1
|
export class Config {
|
|
23
2
|
files = [];
|
|
24
3
|
constructor(args) {
|
|
25
|
-
|
|
4
|
+
this.files = args;
|
|
26
5
|
}
|
|
27
6
|
}
|
package/cli/src/config.ts
CHANGED
|
@@ -1,36 +1,9 @@
|
|
|
1
1
|
import type { ConfigInterface } from "./cli_types.ts";
|
|
2
2
|
|
|
3
|
-
type Reaction = (config: ConfigInterface, value?: string) => void;
|
|
4
|
-
type Reactions = Record<string, Reaction>;
|
|
5
|
-
|
|
6
|
-
const reactions: Reactions = {
|
|
7
|
-
"--file": fileConfig,
|
|
8
|
-
"-f": fileConfig,
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
function fileConfig(config: ConfigInterface, file?: string) {
|
|
12
|
-
if (file === undefined) return;
|
|
13
|
-
config.files.push(file);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
function iterateArgs(config: ConfigInterface, args: string[]) {
|
|
17
|
-
let index = 0;
|
|
18
|
-
while (index < args.length) {
|
|
19
|
-
const flag = args[index];
|
|
20
|
-
const reaction = reactions[flag];
|
|
21
|
-
if (reaction === undefined) {
|
|
22
|
-
throw new Error(`unrecognized argument: ${flag}`);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
reaction(config, args[index + 1]);
|
|
26
|
-
index += 2;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
3
|
export class Config implements ConfigInterface {
|
|
31
4
|
files: string[] = [];
|
|
32
5
|
|
|
33
6
|
constructor(args: string[]) {
|
|
34
|
-
|
|
7
|
+
this.files = args;
|
|
35
8
|
}
|
|
36
9
|
}
|
|
@@ -6,9 +6,9 @@ type SyncTest = () => Assertions;
|
|
|
6
6
|
type AsyncTest = () => Promise<Assertions>;
|
|
7
7
|
export type Test = SyncTest | AsyncTest;
|
|
8
8
|
export interface Options {
|
|
9
|
-
title?: string;
|
|
10
9
|
runAsynchronously?: boolean;
|
|
11
10
|
timeoutMs?: number;
|
|
11
|
+
title?: string;
|
|
12
12
|
}
|
|
13
13
|
export interface TestModule {
|
|
14
14
|
tests: Test[];
|
package/package.json
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@w-lfpup/jackrabbit",
|
|
3
3
|
"description": "A test runner without dependencies",
|
|
4
|
+
"version": "0.2.0",
|
|
5
|
+
"license": "BSD-3-Clause",
|
|
4
6
|
"workspaces": [
|
|
5
7
|
"core",
|
|
6
8
|
"tests",
|
|
@@ -14,12 +16,11 @@
|
|
|
14
16
|
"prepare": "npm run build",
|
|
15
17
|
"build": "npm run --workspaces build",
|
|
16
18
|
"format": "npx prettier --write ./",
|
|
17
|
-
"test": "npx jackrabbit
|
|
19
|
+
"test": "npx jackrabbit ./tests/dist/mod.js"
|
|
18
20
|
},
|
|
19
|
-
"version": "0.1.0",
|
|
20
21
|
"repository": {
|
|
21
22
|
"type": "git",
|
|
22
|
-
"url": "git+https://github.com/w-lfpup/
|
|
23
|
+
"url": "git+https://github.com/w-lfpup/jackrabbit-js.git"
|
|
23
24
|
},
|
|
24
25
|
"devDependencies": {
|
|
25
26
|
"@types/node": "^22.5.5",
|
package/test_guide.md
DELETED
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
# Jackrabbit Tests
|
|
2
|
-
|
|
3
|
-
For a quick visual reference, please refer to the [examples](./examples/).
|
|
4
|
-
|
|
5
|
-
`Jackrabbit` leverages esmodules for a flat, concise testing experience. There are no assertion libraries, there are no wild BDD functions. Developers with javascript experience can immediately start testing with basically zero overhead.
|
|
6
|
-
|
|
7
|
-
## Tests
|
|
8
|
-
|
|
9
|
-
Tests are functions that return assertions.
|
|
10
|
-
|
|
11
|
-
Tests `pass` when they return the `undefined` primitive or an empty array `[]`.
|
|
12
|
-
|
|
13
|
-
```TS
|
|
14
|
-
// my_library.tests.ts
|
|
15
|
-
|
|
16
|
-
function testStuffAndPass() {
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
async function testMoreStuffAndPass() {
|
|
21
|
-
return [];
|
|
22
|
-
}
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
Any other value will cause a test to `fail`.
|
|
26
|
-
|
|
27
|
-
So tests that `fail` look like:
|
|
28
|
-
|
|
29
|
-
```TS
|
|
30
|
-
// my_library.tests.ts
|
|
31
|
-
|
|
32
|
-
function testStuffAndFail() {
|
|
33
|
-
return "this test failed!";
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function testMoreStuffAndFail() {
|
|
37
|
-
return ["this test also failed!"];
|
|
38
|
-
}
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
## Test Modules
|
|
42
|
-
|
|
43
|
-
Test Modules are javascript `modules` that contain tests.
|
|
44
|
-
|
|
45
|
-
### Export Tests
|
|
46
|
-
|
|
47
|
-
Test Modules export their tests in an array called `tests`.
|
|
48
|
-
|
|
49
|
-
```TS
|
|
50
|
-
// my_library.tests.ts
|
|
51
|
-
|
|
52
|
-
export const tests = [
|
|
53
|
-
testStuffAndPass,
|
|
54
|
-
testMoreStuffAndPass,
|
|
55
|
-
testStuffAndFail,
|
|
56
|
-
testMoreStuffAndFail,
|
|
57
|
-
];
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
### Export Options
|
|
61
|
-
|
|
62
|
-
Exporting an `options` pojo is not required.
|
|
63
|
-
|
|
64
|
-
But exporting an `options` pojo with the following properties will affect test behavior:
|
|
65
|
-
|
|
66
|
-
```TS
|
|
67
|
-
export const options = {
|
|
68
|
-
title: import.meta.url,
|
|
69
|
-
runAsyncronously: true,
|
|
70
|
-
timeoutMs: 3000,
|
|
71
|
-
}
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
All properteis are optional.
|
|
75
|
-
|
|
76
|
-
Tests run sequentially unless the `runAsyncronously` property is set to `true`.
|
|
77
|
-
|
|
78
|
-
```TS
|
|
79
|
-
// my_library.tests.ts
|
|
80
|
-
|
|
81
|
-
interface Options {
|
|
82
|
-
title?: string;
|
|
83
|
-
runAsynchronously?: boolean;
|
|
84
|
-
timeoutMs?: number;
|
|
85
|
-
}
|
|
86
|
-
```
|
|
87
|
-
|
|
88
|
-
## Test Collections
|
|
89
|
-
|
|
90
|
-
A `test collection` is a javascript module that exports a list test modules called `testModules`.
|
|
91
|
-
|
|
92
|
-
```TS
|
|
93
|
-
// mod.test.ts
|
|
94
|
-
|
|
95
|
-
import * as MyTests from "./my_library.tests.ts";
|
|
96
|
-
|
|
97
|
-
export const testModules = [
|
|
98
|
-
MyTests
|
|
99
|
-
];
|
|
100
|
-
```
|
|
101
|
-
|
|
102
|
-
This gathers all tests into a single explicit location.
|
|
103
|
-
|
|
104
|
-
## Run Test Collections
|
|
105
|
-
|
|
106
|
-
Run the following command and Jackrabbit will log the results of `test collections`.
|
|
107
|
-
|
|
108
|
-
```sh
|
|
109
|
-
npx jackrabbit --file ./mod.test.ts
|
|
110
|
-
```
|
|
111
|
-
|
|
112
|
-
## License
|
|
113
|
-
|
|
114
|
-
BSD 3-Clause License
|