Mercurial > hg > nginx-tests
comparison js_internal_redirect.t @ 1346:4d5d1e59f45e
Tests: TODO js_internal_redirect.t on njs < 0.2.2.
On older njs versions, js runtime exception is thrown:
"TypeError: cannot find property 'internalRedirect' of an external object".
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Thu, 14 Jun 2018 10:47:51 +0300 |
parents | 9fbe84b7ddc6 |
children | 106d9f806288 |
comparison
equal
deleted
inserted
replaced
1345:9fbe84b7ddc6 | 1346:4d5d1e59f45e |
---|---|
41 | 41 |
42 server { | 42 server { |
43 listen 127.0.0.1:8080; | 43 listen 127.0.0.1:8080; |
44 server_name localhost; | 44 server_name localhost; |
45 | 45 |
46 location /njs { | |
47 js_content test_njs; | |
48 } | |
49 | |
46 location /test { | 50 location /test { |
47 js_content test_redirect; | 51 js_content test_redirect; |
48 } | 52 } |
49 | 53 |
50 location /redirect { | 54 location /redirect { |
59 } | 63 } |
60 | 64 |
61 EOF | 65 EOF |
62 | 66 |
63 $t->write_file('test.js', <<EOF); | 67 $t->write_file('test.js', <<EOF); |
68 function test_njs(r) { | |
69 r.return(200, njs.version); | |
70 } | |
71 | |
64 function test_redirect(req) { | 72 function test_redirect(req) { |
65 if (req.variables.arg_dest.startsWith('named')) { | 73 if (req.variables.arg_dest.startsWith('named')) { |
66 req.internalRedirect('\@named'); | 74 req.internalRedirect('\@named'); |
67 | 75 |
68 } else { | 76 } else { |
75 } | 83 } |
76 } | 84 } |
77 | 85 |
78 EOF | 86 EOF |
79 | 87 |
80 $t->try_run('no njs internalRedirect')->plan(3); | 88 $t->try_run('no njs available')->plan(3); |
81 | 89 |
82 ############################################################################### | 90 ############################################################################### |
91 | |
92 TODO: { | |
93 local $TODO = 'no njs internalRedirect' | |
94 unless http_get('/njs') =~ /^([.0-9]+)$/m && $1 ge '0.2.2'; | |
83 | 95 |
84 like(http_get('/test'), qr/redirect/s, 'redirect'); | 96 like(http_get('/test'), qr/redirect/s, 'redirect'); |
85 like(http_get('/test?a=A'), qr/redirectA/s, 'redirect with args'); | 97 like(http_get('/test?a=A'), qr/redirectA/s, 'redirect with args'); |
86 like(http_get('/test?dest=named'), qr/named/s, 'redirect to named location'); | 98 like(http_get('/test?dest=named'), qr/named/s, 'redirect to named location'); |
87 | 99 |
100 } | |
101 | |
88 ############################################################################### | 102 ############################################################################### |