api-tuner 0.3.4 → 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/index.js +3 -5
- package/package.json +3 -3
- package/rules/formula.n3 +11 -0
- package/rules/http-helpers.n3 +85 -0
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/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,7 +8,7 @@
|
|
|
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",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"rules"
|
|
29
29
|
],
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@changesets/cli": "^2.
|
|
31
|
+
"@changesets/cli": "^2.29.7",
|
|
32
32
|
"@jeswr/pretty-turtle": "^1.5.0",
|
|
33
33
|
"@zazuko/env-node": "^2.1.4",
|
|
34
34
|
"commander": "^13.1.0",
|
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
|
+
} .
|
|
@@ -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
|
+
} .
|