Skip to content

Commit eea19bf

Browse files
committed
Add CLI testing suite foundation
1 parent 49d7f83 commit eea19bf

19 files changed

Lines changed: 209 additions & 37 deletions

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,16 @@
88
"prepare": "npx husky",
99
"debug": "npm run debug -ws",
1010
"build": "npm run build -ws",
11-
"lint": "npx eslint ./packages/*/src/*.ts",
12-
"lint:fix": "npx eslint --fix ./packages/*/src/*.ts",
13-
"format": "npx prettier --check ./packages/*/src/*.ts",
11+
"lint": "npx eslint ./packages/*/src/**/*.ts",
12+
"lint:fix": "npx eslint --fix ./packages/*/src/**/*.ts",
13+
"format": "npx prettier --check ./packages/*/src/**/*.ts",
1414
"format:fix": "npx prettier --write ./packages/*/src/**/*.ts",
1515
"metatest": "./scripts/metatest.sh",
1616
"metatest:unit": "npm run metatest -w @rapidjs.org/testing-unit",
1717
"metatest:http": "npm run metatest -w @rapidjs.org/testing-http",
1818
"test": "npm run build && npm run metatest",
19-
"generate:suite": "node ./packages/test/build/cli/cli.gen.js suite --path ./packages/ --name @__generated",
19+
"bin": "./bin.sh",
20+
"generate:suite": "npm run bin -- gen template --path ./packages/ --name @__generated",
2021
"validate-examples": "./scripts/validate-examples.sh"
2122
},
2223
"devDependencies": {

packages/@cli/README.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# [rJS Testing](https://github.com/rapidjs-org/testing) CLITest `cli`
2+
3+
rJS Testing CLI testing suite (`CLITest`): Test command line interfaces based on stdout and -err.
4+
5+
``` cli
6+
npm i -D @rapidjs.org/testing-cli
7+
```
8+
9+
``` cli
10+
npx rjs-test cli <tests-path>
11+
```
12+
13+
> Integrated in [`rapidjs-org/testing`](https://github.com/rapidjs-org/testing).
14+
15+
## Test Anatomy
16+
17+
### Expressions
18+
19+
(#### Actual)
20+
21+
``` ts
22+
.actual(expression: any)
23+
.expected(expression: any)
24+
```
25+
26+
(#### Expected)
27+
28+
### Value-based Assertion
29+
30+
``` ts
31+
new <Suite>Test("Example label")
32+
.actual(<expression>)
33+
.expected(<expression>);
34+
```
35+
36+
### Error-based Assertion
37+
38+
``` ts
39+
new <Suite>Test("Example label")
40+
.actual(<expression>)
41+
.error("<error-message>", <ErrorConstructor>);
42+
```
43+
44+
## Comparison Strategy
45+
46+
...
47+
48+
**&thinsp; SUCCESS**
49+
50+
``` js
51+
.actual(<expression>)
52+
.expected(<expression>)
53+
```
54+
55+
**&thinsp; FAILURE**
56+
57+
``` js
58+
.actual(<expression>)
59+
.expected(<expression>)
60+
```
61+
62+
##
63+
64+
<sub>&copy; Thassilo Martin Schiepanski</sub>

packages/@cli/package.json

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"name": "@rapidjs.org/testing-cli",
3+
"version": "0.1.0",
4+
"description": "rJS Testing – CLI testing suite.",
5+
"author": "Thassilo Martin Schiepanski",
6+
"homepage": "https://github.com/rapidjs-org/testing/tree/master/packages/@cli",
7+
"repository": {
8+
"type": "git",
9+
"url": "git+https://github.com/rapidjs-org/testing.git"
10+
},
11+
"bugs": {
12+
"url": "https://github.com/rapidjs-org/testing/issues"
13+
},
14+
"main": "./build/api.js",
15+
"types": "./types/api.d.ts",
16+
"files": [
17+
"./build/",
18+
"./types/"
19+
],
20+
"scripts": {
21+
"debug": "npx tsc --project ./tsconfig.debug.json",
22+
"debug:watch": "npm run debug -- --watch",
23+
"build": "rm -rf ./build/ && rm -rf ./types/ && npx tsc --project ./tsconfig.build.json",
24+
"metatest:single-file": "../../bin.sh http ./metatest/http-1.test.js",
25+
"metatest": "../../bin.sh http ./metatest/",
26+
"test": "npm run build && npm run metatest && npm run metatest:single-file",
27+
"release:minor": "npm run test && npx release --minor",
28+
"release:patch": "npm run test && npx release --patch"
29+
},
30+
"devDependencies": {
31+
"@t-ski/gh-npm-release": "github:t-ski/gh-npm-release",
32+
"@types/node": "^20.10.6",
33+
"typescript": "^5.3.3"
34+
},
35+
"dependencies": {
36+
"@rapidjs.org/testing": "^0.1.0"
37+
}
38+
}

packages/@cli/src/CLITest.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { Test } from "@rapidjs.org/testing";
2+
3+
import { TColor } from "../../common.types";
4+
5+
interface IObject {
6+
[key: string]: string | number | boolean | IObject;
7+
}
8+
9+
export class CLITest extends Test<IObject> {
10+
public static readonly suiteTitle: string = "CLI";
11+
public static readonly suiteColor: TColor = [73, 220, 177]; // 108, 55, 55
12+
13+
constructor(title: string) {
14+
super(title);
15+
}
16+
17+
protected evalActualExpression(obj: IObject): Promise<IObject> {
18+
return new Promise((resolve) => {
19+
resolve(
20+
Object.fromEntries(
21+
Object.entries(obj).map((entry: [string, unknown]) => [entry[0].toLowerCase(), entry[1]])
22+
) as IObject
23+
);
24+
});
25+
}
26+
27+
protected isEqual(actual: IObject, expected: IObject): boolean {
28+
return !Object.keys(this.filterComparedValues(actual, expected).actual).length;
29+
}
30+
31+
protected filterComparedValues(actual: IObject, expected: IObject) {
32+
return {
33+
actual: actual,
34+
expected: expected
35+
};
36+
}
37+
}

packages/@cli/src/api.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { CLITest } from "./CLITest";

packages/@cli/tsconfig.build.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"compilerOptions": {
4+
"removeComments": true
5+
}
6+
}

packages/@cli/tsconfig.debug.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"compilerOptions": {
4+
"sourceMap": true
5+
}
6+
}

packages/@cli/tsconfig.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"compilerOptions": {
3+
"module": "CommonJS",
4+
"target": "es2017",
5+
"moduleResolution": "node",
6+
"esModuleInterop": true,
7+
"noImplicitAny": true,
8+
"resolveJsonModule": true,
9+
"noEmitOnError": true,
10+
"allowJs": true,
11+
"declaration": true,
12+
"declarationDir": "./types/",
13+
"rootDir": "./src/",
14+
"outDir": "./build/"
15+
},
16+
"include": [
17+
"./src/**/*.ts",
18+
"./src/**/*.json"
19+
]
20+
}

packages/@http/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# [rJS Testing](https://github.com/rapidjs-org/testing) HTTPTest `http`
22

3-
rJS Testing unit testing suite (`HTTPTest`): Test HTTP(S) endpoints based on expectation filtered responses.
3+
rJS Testing HTTP(S) testing suite (`HTTPTest`): Test endpoints based on expectation filtered responses.
44

55
``` cli
66
npm i -D @rapidjs.org/testing-http
@@ -10,7 +10,7 @@ npm i -D @rapidjs.org/testing-http
1010
npx rjs-test http <tests-path>
1111
```
1212

13-
> Integrated in [`rapidjs-org/testing`](https://github.com/rapidjs-org/testing)
13+
> Integrated in [`rapidjs-org/testing`](https://github.com/rapidjs-org/testing).
1414
1515
## Configuration
1616

0 commit comments

Comments
 (0)