api-tuner 0.3.3 → 0.4.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/README.md +14 -24
- package/bin/tuner.sh +2 -7
- package/index.js +3 -5
- package/package.json +6 -5
- package/rules/curl-body.n3 +1 -1
- package/rules/formula.n3 +11 -0
- package/rules/headers.n3 +8 -0
- package/rules/http-helpers.n3 +85 -0
- package/rules/queryParams.n3 +8 -0
- package/rules/requests.n3 +11 -5
package/README.md
CHANGED
|
@@ -43,40 +43,30 @@ Create a test case file `test.n3`:
|
|
|
43
43
|
|
|
44
44
|
```turtle
|
|
45
45
|
# test.n3
|
|
46
|
-
PREFIX : <http://example.com/>
|
|
47
46
|
PREFIX earl: <http://www.w3.org/ns/earl#>
|
|
48
47
|
PREFIX tuner: <https://api-tuner.described.at/>
|
|
48
|
+
prefix resource: <https://api-tuner.described.at/resource#>
|
|
49
49
|
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
|
|
50
|
-
PREFIX log: <http://www.w3.org/2000/10/swap/log#>
|
|
51
50
|
PREFIX string: <http://www.w3.org/2000/10/swap/string#>
|
|
52
51
|
|
|
53
52
|
<#getExampleDotCom>
|
|
54
53
|
a earl:TestCase ;
|
|
55
54
|
rdfs:label "Simple GET test" ;
|
|
55
|
+
tuner:formula {
|
|
56
|
+
# Execute the request and capture its response
|
|
57
|
+
( <http://localhost:1080/example.com> ?res ) resource:getIn [] .
|
|
58
|
+
|
|
59
|
+
# Check the response status code and content type
|
|
60
|
+
?res tuner:http_code 200 ;
|
|
61
|
+
tuner:header ( "content-type" "text/html" ) ;
|
|
62
|
+
.
|
|
63
|
+
|
|
64
|
+
# Check the body contains the work "Example"
|
|
65
|
+
?res tuner:body ?body .
|
|
66
|
+
?body string:contains "Example Domain" .
|
|
67
|
+
} ;
|
|
56
68
|
.
|
|
57
69
|
|
|
58
|
-
# Configure a request
|
|
59
|
-
_:req
|
|
60
|
-
a tuner:Request ;
|
|
61
|
-
tuner:url <http://localhost:1080/example.com> ;
|
|
62
|
-
tuner:method "GET" ;
|
|
63
|
-
.
|
|
64
|
-
|
|
65
|
-
{
|
|
66
|
-
# Execute the request and capture its response
|
|
67
|
-
_:req tuner:response ?res .
|
|
68
|
-
|
|
69
|
-
# Check the response status code and content type
|
|
70
|
-
?res tuner:http_code 200 ;
|
|
71
|
-
tuner:header ( "content-type" "text/html" ) ;
|
|
72
|
-
.
|
|
73
|
-
|
|
74
|
-
# Check the body contains the work "Example"
|
|
75
|
-
?res!tuner:body string:contains "Example Domain" .
|
|
76
|
-
} => {
|
|
77
|
-
# Use te EARL vocabulary to assert the test passed
|
|
78
|
-
<#getExampleDotCom> earl:outcome earl:passed .
|
|
79
|
-
} .
|
|
80
70
|
```
|
|
81
71
|
|
|
82
72
|
Execute the test case:
|
package/bin/tuner.sh
CHANGED
|
@@ -1,14 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
|
6
|
-
cd "$SCRIPT_DIR" || exit
|
|
3
|
+
SCRIPT_DIR=$(cd "$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")" && pwd)
|
|
7
4
|
|
|
8
5
|
# find JS entrypoint
|
|
9
|
-
tuner
|
|
10
|
-
|
|
11
|
-
cd "$WORKING_DIR" || exit
|
|
6
|
+
tuner="$SCRIPT_DIR/index.js"
|
|
12
7
|
|
|
13
8
|
# if tsx exists in path
|
|
14
9
|
if command -v tsx > /dev/null 2>&1
|
package/index.js
CHANGED
|
@@ -37,10 +37,8 @@ if (options.debug) {
|
|
|
37
37
|
const debugN3Path = url.fileURLToPath(new URL('logging/debug.n3', import.meta.url));
|
|
38
38
|
eyeArgs.push(debugN3Path);
|
|
39
39
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
eyeArgs.push(infoN3Path);
|
|
43
|
-
}
|
|
40
|
+
const infoN3Path = url.fileURLToPath(new URL('logging/info.n3', import.meta.url));
|
|
41
|
+
eyeArgs.push(infoN3Path);
|
|
44
42
|
const rulesPath = url.fileURLToPath(new URL('rules/*.n3', import.meta.url));
|
|
45
43
|
const levelIcon = {
|
|
46
44
|
INFO: 'ℹ️',
|
|
@@ -94,7 +92,7 @@ const testSuites = program.args.map(async (path) => {
|
|
|
94
92
|
};
|
|
95
93
|
}
|
|
96
94
|
let summary = `\n🔎 SUITE <file://${absolutePath}>\n`;
|
|
97
|
-
if (!validationResult.success) {
|
|
95
|
+
if (!validationResult.success || !options.silent) {
|
|
98
96
|
const stderr = await getStream(result.stderr);
|
|
99
97
|
summary += stderr.replace(/"([^"]*)" TRACE ("([^"]*)")?/gm, (_, level, quoted, text) => {
|
|
100
98
|
return `${levelIcon[level]} ${text || ''}`;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "api-tuner",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -8,12 +8,13 @@
|
|
|
8
8
|
"api-tuner": "./bin/tuner.sh"
|
|
9
9
|
},
|
|
10
10
|
"scripts": {
|
|
11
|
-
"download-eye": "EYE_VERSION=11.
|
|
11
|
+
"download-eye": "EYE_VERSION=11.16.4 ./lib/download-eye.sh",
|
|
12
12
|
"postinstall": "([ -d eye ] || npm run download-eye) && eye/install.sh --prefix=eye",
|
|
13
13
|
"prepare": "husky",
|
|
14
14
|
"lint": "eslint . --quiet --ignore-path .gitignore",
|
|
15
|
-
"
|
|
16
|
-
"
|
|
15
|
+
"pre_test": "docker compose up -d",
|
|
16
|
+
"_test": "./bin/tuner.sh --base-iri http://localhost:1080/",
|
|
17
|
+
"test": "npm run _test -- tests/*.n3 tests/**/*.n3",
|
|
17
18
|
"prepack": "tsc",
|
|
18
19
|
"release": "changeset publish"
|
|
19
20
|
},
|
|
@@ -27,7 +28,7 @@
|
|
|
27
28
|
"rules"
|
|
28
29
|
],
|
|
29
30
|
"dependencies": {
|
|
30
|
-
"@changesets/cli": "^2.
|
|
31
|
+
"@changesets/cli": "^2.29.7",
|
|
31
32
|
"@jeswr/pretty-turtle": "^1.5.0",
|
|
32
33
|
"@zazuko/env-node": "^2.1.4",
|
|
33
34
|
"commander": "^13.1.0",
|
package/rules/curl-body.n3
CHANGED
|
@@ -54,7 +54,7 @@ prefix math: <http://www.w3.org/2000/10/swap/math#>
|
|
|
54
54
|
} <= {
|
|
55
55
|
{
|
|
56
56
|
?value log:rawType log:Literal .
|
|
57
|
-
( " -F " ?name "=" ?value ) string:concatenation ?formField .
|
|
57
|
+
( " -F " ?name "='" ?value "'" ) string:concatenation ?formField .
|
|
58
58
|
} log:callWithCut true .
|
|
59
59
|
} .
|
|
60
60
|
|
package/rules/formula.n3
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
prefix earl: <http://www.w3.org/ns/earl#>
|
|
2
|
+
prefix log: <http://www.w3.org/2000/10/swap/log#>
|
|
3
|
+
prefix tuner: <https://api-tuner.described.at/>
|
|
4
|
+
prefix graph: <http://www.w3.org/2000/10/swap/graph#>
|
|
5
|
+
|
|
6
|
+
{
|
|
7
|
+
?test a earl:TestCase ; tuner:formula ?formula .
|
|
8
|
+
?formula log:call true .
|
|
9
|
+
} => {
|
|
10
|
+
?test earl:outcome earl:passed .
|
|
11
|
+
} .
|
package/rules/headers.n3
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
PREFIX string: <http://www.w3.org/2000/10/swap/string#>
|
|
2
|
+
prefix resource: <https://api-tuner.described.at/resource#>
|
|
3
|
+
prefix tuner: <https://api-tuner.described.at/>
|
|
4
|
+
prefix log: <http://www.w3.org/2000/10/swap/log#>
|
|
5
|
+
prefix graph: <http://www.w3.org/2000/10/swap/graph#>
|
|
6
|
+
|
|
7
|
+
{
|
|
8
|
+
(?resource ?res) resource:getIn ?scope
|
|
9
|
+
} <= {
|
|
10
|
+
("GET" ?resource ?res) resource:requestIn ?scope .
|
|
11
|
+
|
|
12
|
+
?res tuner:http_code 200 .
|
|
13
|
+
} .
|
|
14
|
+
|
|
15
|
+
{
|
|
16
|
+
(?resource ?body) resource:putIn ?scope
|
|
17
|
+
} <= {
|
|
18
|
+
(?resource ?body ?res) resource:putIn ?scope .
|
|
19
|
+
|
|
20
|
+
?res tuner:http_code 200 .
|
|
21
|
+
} .
|
|
22
|
+
|
|
23
|
+
{
|
|
24
|
+
(?resource ?body ?res) resource:putIn ?scope
|
|
25
|
+
} <= {
|
|
26
|
+
("PUT" ?resource ?body ?res) resource:requestIn ?scope
|
|
27
|
+
} .
|
|
28
|
+
|
|
29
|
+
{
|
|
30
|
+
(?resource ?res) resource:postIn ?scope
|
|
31
|
+
} <= {
|
|
32
|
+
("POST" ?resource ?res) resource:requestIn ?scope
|
|
33
|
+
} .
|
|
34
|
+
|
|
35
|
+
{
|
|
36
|
+
(?resource ?body ?res) resource:postIn ?scope
|
|
37
|
+
} <= {
|
|
38
|
+
("POST" ?resource ?body ?res) resource:requestIn ?scope
|
|
39
|
+
} .
|
|
40
|
+
|
|
41
|
+
{
|
|
42
|
+
(?method ?resource ?res) resource:requestIn ?scope
|
|
43
|
+
} <= {
|
|
44
|
+
({[
|
|
45
|
+
a tuner:Request ;
|
|
46
|
+
tuner:method ?method ;
|
|
47
|
+
tuner:url ?resource ;
|
|
48
|
+
]} ?res) <#requestIn> ( ?scope ?id )
|
|
49
|
+
} .
|
|
50
|
+
|
|
51
|
+
{
|
|
52
|
+
(?method ?resource ?body ?res) resource:requestIn ?scope
|
|
53
|
+
} <= {
|
|
54
|
+
({[
|
|
55
|
+
a tuner:Request ;
|
|
56
|
+
tuner:method ?method ;
|
|
57
|
+
tuner:url ?resource ;
|
|
58
|
+
tuner:body ?body ;
|
|
59
|
+
]} ?res) <#requestIn> ?scope
|
|
60
|
+
} .
|
|
61
|
+
|
|
62
|
+
{
|
|
63
|
+
(?g ?res) <#requestIn> ?scope
|
|
64
|
+
} <= {
|
|
65
|
+
?g log:includes {
|
|
66
|
+
?req a tuner:Request ;
|
|
67
|
+
tuner:method ?method ;
|
|
68
|
+
tuner:url ?resource .
|
|
69
|
+
} .
|
|
70
|
+
|
|
71
|
+
( <#request>!log:uri "?method=" ?method "?resource=" ?resource!log:uri ) string:concatenation ?idStr .
|
|
72
|
+
?id log:uri ?idStr .
|
|
73
|
+
({ ?scope ?id [] } false true) log:ifThenElseIn [].
|
|
74
|
+
|
|
75
|
+
( ?g { ?scope ?id ?req } ) graph:union ?union .
|
|
76
|
+
true log:becomes ?union .
|
|
77
|
+
|
|
78
|
+
(
|
|
79
|
+
{ ?scope!?id tuner:response ?res }
|
|
80
|
+
true
|
|
81
|
+
{
|
|
82
|
+
"Request failed"^tuner:info .
|
|
83
|
+
}
|
|
84
|
+
) log:ifThenElseIn [] .
|
|
85
|
+
} .
|
package/rules/requests.n3
CHANGED
|
@@ -6,11 +6,7 @@ PREFIX tuner: <https://api-tuner.described.at/>
|
|
|
6
6
|
prefix file: <http://www.w3.org/2000/10/swap/file#>
|
|
7
7
|
prefix earl: <http://www.w3.org/ns/earl#>
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
(?fieldName ?fieldValue) tuner:headerArg ?curlArg .
|
|
11
|
-
} <= {
|
|
12
|
-
( " -H '" ?fieldName ":" ?fieldValue "'" ) string:concatenation ?curlArg .
|
|
13
|
-
} .
|
|
9
|
+
|
|
14
10
|
|
|
15
11
|
{
|
|
16
12
|
?req tuner:response ?res .
|
|
@@ -34,6 +30,15 @@ prefix earl: <http://www.w3.org/ns/earl#>
|
|
|
34
30
|
{ ?headersArgs log:equalTo "" }
|
|
35
31
|
) log:ifThenElseIn [] .
|
|
36
32
|
|
|
33
|
+
(
|
|
34
|
+
{ ?req tuner:query [] . }
|
|
35
|
+
{
|
|
36
|
+
( ?queryParam { ?req tuner:query ?queryParam } ?queryParams ) log:collectAllIn [] .
|
|
37
|
+
( ?queryParams tuner:queryParamArg )!list:map string:concatenation ?queryParamArgs .
|
|
38
|
+
}
|
|
39
|
+
{ ?queryParamArgs log:equalTo "" }
|
|
40
|
+
) log:ifThenElseIn [] .
|
|
41
|
+
|
|
37
42
|
?endpointUri log:uri ?endpoint .
|
|
38
43
|
|
|
39
44
|
( ?method " " ?endpoint )!string:concatenation^tuner:trace .
|
|
@@ -55,6 +60,7 @@ prefix earl: <http://www.w3.org/ns/earl#>
|
|
|
55
60
|
"curl -s -X " ?method " '" ?endpoint "'"
|
|
56
61
|
?headersArgs
|
|
57
62
|
?bodyArgs
|
|
63
|
+
?queryParamArgs
|
|
58
64
|
" -w @" ( "lib/curl-format.txt"!file:libPath )!string:concatenation
|
|
59
65
|
" -o " ?responseBodyFile
|
|
60
66
|
" > " ?responseHeadersFile
|