UNPKG

5.13 kBJSONView Raw
1{
2 "initiator": {
3 "http": {
4 "port": "50299",
5 "domain": "127.0.0.1",
6 "static": {
7 "root": "./test"
8 },
9
10 "prepare": {
11 "post": {
12 "tasks": [{
13 "$class": "post",
14 "request": "{$request}",
15 "$set": "request.body"
16 }]
17 }
18 },
19 "flows":[{
20 "path": ""
21 }, {
22 "path": "^(\\w+)$",
23 "prepare": ["post"],
24 "tasks": [{
25 "$function": "dfHandleGet",
26 "require": "{$request.GET}"
27 }],
28 "presenter": "json"
29 }, {
30 "path": "test",
31 "flows": [{
32 "path": "redirect",
33 "tasks":[{
34 "$class": "redirect",
35 "url": "/test/redirected",
36 "output": "{$response}"
37 }],
38 "presenter": {
39 "headers": {
40 "Set-Cookie": "auth=123; expires=Fri, 31 Jan 2031 00:00:00 GMT; path=/; domain=127.0.0.1"
41 }
42 }
43 }, {
44 "path": "redirected",
45 "presenter": {
46 "type": "json",
47 "vars": "{$request.headers}",
48 "verbose": true
49 }
50 }, {
51 "path": "timeout",
52 "data": {
53 "empty response": true
54 },
55 "tasks":[{
56 "$class": "sleep",
57 "amount": 500
58 }],
59 "presenter": {
60 "type": "json",
61 "dump": true
62 }
63 }, {
64 "path": "post",
65 "prepare": ["post"],
66 "tasks": [{
67 "$function": "dfHandleGet",
68 "$logTitle": "12345",
69 "require": "{$request.POST}"
70 }],
71 "presenter": {
72 "type": "json",
73 "vars": "{$request.body}"
74 }
75
76 }]
77 }]
78 }
79 },
80 "templates": {
81 "task": {
82 "jsonParseAndMerge": {
83 "$origin": "{$global.JSON}",
84 "$function": "parse",
85 "$mergeWith": "result"
86 },
87 "jsonParseAndSet": {
88 "$origin": "{$global.JSON}",
89 "$function": "parse",
90 "$set": "result"
91 },
92 "indexEqItem": {
93 "$function": "throwUnlessEqual",
94 "$args": [
95 "[*every.index]",
96 "[*every.item]"
97 ]
98 },
99 "testHttpResource": {
100 "$class":"remoteResource",
101 "$method": "toBuffer"
102 }
103 }
104 },
105 "tests": {
106 "static": {
107 "expect": "ok",
108 "tasks": [{
109 "$template": "testHttpResource",
110 "url": "http://{$initiator.http.domain}:{$initiator.http.port}/favicon.ico",
111 "successCodes": "2xx",
112 "$setOnFail": "favicon"
113 }, {
114 "$function": "dfThrowUnlessEqual",
115 "$args": [404, "{$favicon.code}", "favicon http response:"],
116 "$important": true
117 }, {
118 "$template": "testHttpResource",
119 "url": "http://{$initiator.http.domain}:{$initiator.http.port}/000-string.interpolate.js",
120 "successCodes": "2xx",
121 "$set": "indexPage"
122 }, {
123 "$function": "dfThrowUnlessEqual",
124 "$args": [200, "{$indexPage.code}", "index page http response:"],
125 "$important": true
126 }]
127 },
128 "post": {
129 "expect": "ok",
130 "tasks": [{
131 "$template": "testHttpResource",
132 "url": "http://{$initiator.http.domain}:{$initiator.http.port}/test/post",
133 "successCodes": "2xx",
134 "$setOnFail": "postNoDataObj"
135 }, {
136 "$function": "dfThrowUnlessEqual",
137 "$args": [500, "{$postNoDataObj.code}", "post page http response:"],
138 "$important": true
139 }, {
140 "$template": "testHttpResource",
141 "url": "http://{$initiator.http.domain}:{$initiator.http.port}/test/post",
142 "bodyData": {
143 "a": "b",
144 "c": "d"
145 },
146 "successCodes": "2xx",
147 "$set": "postObj"
148 }, {
149 "$function": "dfShowBuffer",
150 "$args": "{$postObj.data}"
151 }, {
152 "$function": "JSON.parse",
153 "$args": ["{$postObj.data}"],
154 "$set": "postData"
155 }, {
156 "$function": "dfThrowUnlessEqual",
157 "$args": ["b", "{$postData.fields.a}", "post page http response:"],
158 "$important": true
159 }, {
160 "$function": "dfThrowUnlessEqual",
161 "$args": ["d", "{$postData.fields.c}", "post page http response:"],
162 "$important": true
163 }]
164 },
165 "redirect": {
166 "expect": "ok",
167 "tasks": [{
168 "$template": "testHttpResource",
169 "url": "http://{$initiator.http.domain}:{$initiator.http.port}/test/redirect",
170 "successCodes": "2xx",
171 "$set": "redirectObj"
172 }, {
173 "$function": "JSON.parse",
174 "$args": ["{$redirectObj.data}"],
175 "$set": "redirectData"
176 }, {
177 "$function": "console.log",
178 "$args": [
179 "{$redirectData}"
180 ]
181 }, {
182 "$function": "dfThrowUnlessEqual",
183 "$args": ["auth=123", "{$redirectData.cookie}", "redirect cookie page http response:"],
184 "$important": true
185 }]
186 },
187 "timeout": {
188 "expect": "ok",
189 "tasks": [{
190 "$template": "testHttpResource",
191 "url": "http://{$initiator.http.domain}:{$initiator.http.port}/test/timeout",
192 "successCodes": "2xx",
193 "timeout": 1000,
194 "$set": "noTimeoutObj"
195 }, {
196 "$function": "console.log",
197 "$args": [
198 "{$noTimeoutObj.data}"
199 ],
200 "$important": true
201 }, {
202 "$template": "testHttpResource",
203 "url": "http://{$initiator.http.domain}:{$initiator.http.port}/test/timeout",
204 "successCodes": "2xx",
205 "timeout": 100,
206 "$setOnFail": "timeoutObj"
207 }, {
208 "$function": "console.log",
209 "$args": [
210 "{$timeoutObj}"
211 ],
212 "$important": true
213 }, {
214 "$function": "dfThrowUnlessEqual",
215 "$args": [504, "{$timeoutObj.code}", "timeout page http response:"],
216 "$important": true
217
218 }]
219 }
220 }
221}