Mercurial > hg > nginx-tests
comparison js.t @ 1247:edf5a3c9e36a
Tests: added tests for js backtraces.
author | Dmitry Volyntsev <xeioex@nginx.com> |
---|---|
date | Mon, 20 Nov 2017 20:23:24 +0300 |
parents | 4b0b10e39a08 |
children | 3882f8f3b2bc |
comparison
equal
deleted
inserted
replaced
1246:ebaa2c72879d | 1247:edf5a3c9e36a |
---|---|
42 js_set $test_ihdr test_ihdr; | 42 js_set $test_ihdr test_ihdr; |
43 js_set $test_arg test_arg; | 43 js_set $test_arg test_arg; |
44 js_set $test_iarg test_iarg; | 44 js_set $test_iarg test_iarg; |
45 js_set $test_var test_var; | 45 js_set $test_var test_var; |
46 js_set $test_log test_log; | 46 js_set $test_log test_log; |
47 js_set $test_except test_except; | |
47 | 48 |
48 js_include test.js; | 49 js_include test.js; |
49 | 50 |
50 server { | 51 server { |
51 listen 127.0.0.1:8080; | 52 listen 127.0.0.1:8080; |
89 | 90 |
90 location /req_log { | 91 location /req_log { |
91 return 200 $test_log; | 92 return 200 $test_log; |
92 } | 93 } |
93 | 94 |
95 location /req_except { | |
96 return 200 $test_except; | |
97 } | |
98 | |
94 location /res_status { | 99 location /res_status { |
95 js_content status; | 100 js_content status; |
96 } | 101 } |
97 | 102 |
98 location /res_ctype { | 103 location /res_ctype { |
111 js_content hdr; | 116 js_content hdr; |
112 } | 117 } |
113 | 118 |
114 location /res_ihdr { | 119 location /res_ihdr { |
115 js_content ihdr; | 120 js_content ihdr; |
121 } | |
122 | |
123 location /res_except { | |
124 js_content content_except; | |
116 } | 125 } |
117 } | 126 } |
118 } | 127 } |
119 | 128 |
120 EOF | 129 EOF |
170 | 179 |
171 function test_log(req, res) { | 180 function test_log(req, res) { |
172 req.log("SEE-THIS"); | 181 req.log("SEE-THIS"); |
173 } | 182 } |
174 | 183 |
184 function test_except(req, res) { | |
185 var fs = require('fs'); | |
186 fs.readFileSync(); | |
187 } | |
188 | |
175 function status(req, res) { | 189 function status(req, res) { |
176 res.status = 204; | 190 res.status = 204; |
177 if (res.status != 204) | 191 if (res.status != 204) |
178 res.status = 404; | 192 res.status = 404; |
179 res.sendHeader(); | 193 res.sendHeader(); |
238 | 252 |
239 res.sendHeader(); | 253 res.sendHeader(); |
240 res.send(s); | 254 res.send(s); |
241 res.finish(); | 255 res.finish(); |
242 } | 256 } |
257 | |
258 function content_except(req, res) { | |
259 JSON.parse({}.a.a); | |
260 } | |
261 | |
243 EOF | 262 EOF |
244 | 263 |
245 $t->try_run('no njs available')->plan(20); | 264 $t->try_run('no njs available')->plan(22); |
246 | 265 |
247 ############################################################################### | 266 ############################################################################### |
248 | 267 |
249 like(http_get('/req_method'), qr/method=GET/, 'req.method'); | 268 like(http_get('/req_method'), qr/method=GET/, 'req.method'); |
250 like(http_get('/req_version'), qr/version=1.0/, 'req.httpVersion'); | 269 like(http_get('/req_version'), qr/version=1.0/, 'req.httpVersion'); |
267 like(http_get('/res_hdr?foo=12345'), qr/Foo: 12345/, 'res.headers'); | 286 like(http_get('/res_hdr?foo=12345'), qr/Foo: 12345/, 'res.headers'); |
268 like(http_get('/res_hdr?foo=123&bar=copy'), qr/Bar: 123/, 'res.headers get'); | 287 like(http_get('/res_hdr?foo=123&bar=copy'), qr/Bar: 123/, 'res.headers get'); |
269 like(http_get('/res_hdr?bar=empty'), qr/Bar: \x0d/, 'res.headers empty'); | 288 like(http_get('/res_hdr?bar=empty'), qr/Bar: \x0d/, 'res.headers empty'); |
270 like(http_get('/res_ihdr?a=12&b=34'), qr/^1234$/m, 'res.headers iteration'); | 289 like(http_get('/res_ihdr?a=12&b=34'), qr/^1234$/m, 'res.headers iteration'); |
271 | 290 |
291 http_get('/req_except'); | |
292 http_get('/res_except'); | |
293 | |
272 TODO: { | 294 TODO: { |
273 local $TODO = 'zero size buf in writer'; | 295 local $TODO = 'zero size buf in writer'; |
274 | 296 |
275 like(http_get('/res_ihdr'), qr/\x0d\x0a?\x0d\x0a?$/m, 'res.send zero'); | 297 like(http_get('/res_ihdr'), qr/\x0d\x0a?\x0d\x0a?$/m, 'res.send zero'); |
276 | 298 |
279 } | 301 } |
280 | 302 |
281 $t->stop(); | 303 $t->stop(); |
282 | 304 |
283 ok(index($t->read_file('error.log'), 'SEE-THIS') > 0, 'log js'); | 305 ok(index($t->read_file('error.log'), 'SEE-THIS') > 0, 'log js'); |
306 ok(index($t->read_file('error.log'), 'at fs.readFileSync') > 0, | |
307 'js_set backtrace'); | |
308 ok(index($t->read_file('error.log'), 'at JSON.parse') > 0, | |
309 'js_content backtrace'); | |
284 | 310 |
285 ############################################################################### | 311 ############################################################################### |
286 | 312 |
287 sub http_get_hdr { | 313 sub http_get_hdr { |
288 my ($url, %extra) = @_; | 314 my ($url, %extra) = @_; |