# HG changeset patch # User Dmitry Volyntsev # Date 1639071389 0 # Node ID 18ac4d9e5a2af23dea199e668688e17feda38352 # Parent b28f88e352dd3decc68d24ba1ec07434a6194c35 Tests: rewriting njs tests without deprecated "js_include". diff --git a/h2_request_body_js.t b/h2_request_body_js.t --- a/h2_request_body_js.t +++ b/h2_request_body_js.t @@ -36,7 +36,7 @@ events { http { %%TEST_GLOBALS_HTTP%% - js_include test.js; + js_import test.js; server { listen 127.0.0.1:8080 http2; @@ -45,7 +45,7 @@ http { lingering_close off; location / { - js_content sr_body; + js_content test.sr_body; add_header X-Body $request_body; } @@ -64,6 +64,8 @@ function sr_body(r) { r.subrequest('/sr', body_fwd_cb); } +export default {sr_body}; + EOF $t->write_file('sr', 'SEE-THIS'); diff --git a/js.t b/js.t --- a/js.t +++ b/js.t @@ -37,26 +37,26 @@ events { http { %%TEST_GLOBALS_HTTP%% - js_set $test_method test_method; - js_set $test_version test_version; - js_set $test_addr test_addr; - js_set $test_uri test_uri; - js_set $test_arg test_arg; - js_set $test_iarg test_iarg; - js_set $test_var test_var; - js_set $test_type test_type; - js_set $test_global test_global; - js_set $test_log test_log; - js_set $test_except test_except; + js_set $test_method test.method; + js_set $test_version test.version; + js_set $test_addr test.addr; + js_set $test_uri test.uri; + js_set $test_arg test.arg; + js_set $test_iarg test.iarg; + js_set $test_var test.variable; + js_set $test_type test.type; + js_set $test_global test.global_obj; + js_set $test_log test.log; + js_set $test_except test.except; - js_include test.js; + js_import test.js; server { listen 127.0.0.1:8080; server_name localhost; location /njs { - js_content test_njs; + js_content test.njs; } location /method { @@ -92,40 +92,40 @@ http { } location /body { - js_content request_body; + js_content test.request_body; } location /in_file { client_body_in_file_only on; - js_content request_body; + js_content test.request_body; } location /status { - js_content status; + js_content test.status; } location /request_body { - js_content request_body; + js_content test.request_body; } location /request_body_cache { - js_content request_body_cache; + js_content test.request_body_cache; } location /send { - js_content send; + js_content test.send; } location /return_method { - js_content return_method; + js_content test.return_method; } location /arg_keys { - js_content arg_keys; + js_content test.arg_keys; } location /type { - js_content test_type; + js_content test.type; } location /log { @@ -137,11 +137,11 @@ http { } location /content_except { - js_content content_except; + js_content test.content_except; } location /content_empty { - js_content content_empty; + js_content test.content_empty; } } } @@ -155,27 +155,27 @@ EOF r.return(200, njs.version); } - function test_method(r) { + function method(r) { return 'method=' + r.method; } - function test_version(r) { + function version(r) { return 'version=' + r.httpVersion; } - function test_addr(r) { + function addr(r) { return 'addr=' + r.remoteAddress; } - function test_uri(r) { + function uri(r) { return 'uri=' + r.uri; } - function test_arg(r) { + function arg(r) { return 'arg=' + r.args.foo; } - function test_iarg(r) { + function iarg(r) { var s = '', a; for (a in r.args) { if (a.substr(0, 3) == 'foo') { @@ -185,11 +185,11 @@ EOF return s; } - function test_var(r) { + function variable(r) { return 'variable=' + r.variables.remote_addr; } - function test_global(r) { + function global_obj(r) { return 'global=' + global; } @@ -236,18 +236,18 @@ EOF r.return(200, Object.keys(r.args).sort()); } - function test_type(r) { + function type(r) { var p = r.args.path.split('.').reduce((a, v) => a[v], r); - var type = Buffer.isBuffer(p) ? 'buffer' : (typeof p); - r.return(200, `type: \${type}`); + var typ = Buffer.isBuffer(p) ? 'buffer' : (typeof p); + r.return(200, `type: \${typ}`); } - function test_log(r) { + function log(r) { r.log('SEE-LOG'); } - function test_except(r) { + function except(r) { var fs = require('fs'); fs.readFileSync(); } @@ -260,6 +260,11 @@ EOF function content_empty(r) { } + export default {njs:test_njs, method, version, addr, uri, arg, iarg, + variable, global_obj, status, request_body, + request_body_cache, send, return_method, arg_keys, + type, log, except, content_except, content_empty}; + EOF $t->try_run('no njs available')->plan(33); diff --git a/js_async.t b/js_async.t --- a/js_async.t +++ b/js_async.t @@ -35,18 +35,18 @@ events { http { %%TEST_GLOBALS_HTTP%% - js_set $test_async set_timeout; - js_set $context_var context_var; - js_set $test_set_rv_var set_rv_var; + js_set $test_async test.set_timeout; + js_set $context_var test.context_var; + js_set $test_set_rv_var test.set_rv_var; - js_include test.js; + js_import test.js; server { listen 127.0.0.1:8080; server_name localhost; location /njs { - js_content test_njs; + js_content test.njs; } location /async_var { @@ -55,30 +55,30 @@ http { location /shared_ctx { add_header H $context_var; - js_content shared_ctx; + js_content test.shared_ctx; } location /set_timeout { - js_content set_timeout; + js_content test.set_timeout; } location /set_timeout_many { - js_content set_timeout_many; + js_content test.set_timeout_many; } location /set_timeout_data { postpone_output 0; - js_content set_timeout_data; + js_content test.set_timeout_data; } location /limit_rate { postpone_output 0; sendfile_max_chunk 5; - js_content limit_rate; + js_content test.limit_rate; } location /async_content { - js_content async_content; + js_content test.async_content; } location /set_rv_var { @@ -194,6 +194,10 @@ EOF r.setReturnValue(`retval: \${a1 + a2}`); } + export default {njs:test_njs, set_timeout, set_timeout_data, + set_timeout_many, context_var, shared_ctx, limit_rate, + async_content, set_rv_var}; + EOF $t->try_run('no njs available')->plan(9); diff --git a/js_dump.t b/js_dump.t --- a/js_dump.t +++ b/js_dump.t @@ -36,22 +36,22 @@ events { http { %%TEST_GLOBALS_HTTP%% - js_include test.js; + js_import test.js; server { listen 127.0.0.1:8080; server_name localhost; location /dump { - js_content test_dump; + js_content test.dump; } location /stringify { - js_content test_stringify; + js_content test.stringify; } location /stringify_subrequest { - js_content test_stringify_subrequest; + js_content test.stringify_subrequest; } location /js_sub { @@ -63,23 +63,25 @@ http { EOF $t->write_file('test.js', < { r.return(200, JSON.stringify(reply)) }); } + export default {dump, stringify, stringify_subrequest}; + EOF $t->try_run('no njs dump')->plan(3); diff --git a/js_headers.t b/js_headers.t --- a/js_headers.t +++ b/js_headers.t @@ -37,55 +37,55 @@ events { http { %%TEST_GLOBALS_HTTP%% - js_set $test_foo_in test_foo_in; - js_set $test_ifoo_in test_ifoo_in; + js_set $test_foo_in test.foo_in; + js_set $test_ifoo_in test.ifoo_in; - js_include test.js; + js_import test.js; server { listen 127.0.0.1:8080; server_name localhost; location /njs { - js_content test_njs; + js_content test.njs; } location /content_length { - js_content content_length; + js_content test.content_length; } location /content_length_arr { - js_content content_length_arr; + js_content test.content_length_arr; } location /content_length_keys { - js_content content_length_keys; + js_content test.content_length_keys; } location /content_type { charset windows-1251; default_type text/plain; - js_content content_type; + js_content test.content_type; } location /content_type_arr { charset windows-1251; default_type text/plain; - js_content content_type_arr; + js_content test.content_type_arr; } location /content_encoding { - js_content content_encoding; + js_content test.content_encoding; } location /content_encoding_arr { - js_content content_encoding_arr; + js_content test.content_encoding_arr; } location /headers_list { - js_content headers_list; + js_content test.headers_list; } location /foo_in { @@ -97,39 +97,39 @@ http { } location /hdr_in { - js_content hdr_in; + js_content test.hdr_in; } location /raw_hdr_in { - js_content raw_hdr_in; + js_content test.raw_hdr_in; } location /hdr_out { - js_content hdr_out; + js_content test.hdr_out; } location /raw_hdr_out { - js_content raw_hdr_out; + js_content test.raw_hdr_out; } location /hdr_out_array { - js_content hdr_out_array; + js_content test.hdr_out_array; } location /hdr_out_set_cookie { - js_content hdr_out_set_cookie; + js_content test.hdr_out_set_cookie; } location /hdr_out_single { - js_content hdr_out_single; + js_content test.hdr_out_single; } location /ihdr_out { - js_content ihdr_out; + js_content test.ihdr_out; } location /hdr_sorted_keys { - js_content hdr_sorted_keys; + js_content test.hdr_sorted_keys; } } } @@ -243,11 +243,11 @@ EOF r.return(200, Object.keys(hdr).sort()); } - function test_foo_in(r) { + function foo_in(r) { return 'hdr=' + r.headersIn.foo; } - function test_ifoo_in(r) { + function ifoo_in(r) { var s = '', h; for (h in r.headersIn) { if (h.substr(0, 3) == 'foo') { @@ -323,6 +323,13 @@ EOF r.finish(); } + export default {njs:test_njs, content_length, content_length_arr, + content_length_keys, content_type, content_type_arr, + content_encoding, content_encoding_arr, headers_list, + hdr_in, raw_hdr_in, hdr_sorted_keys, foo_in, ifoo_in, + hdr_out, raw_hdr_out, hdr_out_array, hdr_out_single, + hdr_out_set_cookie, ihdr_out}; + EOF diff --git a/js_internal_redirect.t b/js_internal_redirect.t --- a/js_internal_redirect.t +++ b/js_internal_redirect.t @@ -35,14 +35,14 @@ events { http { %%TEST_GLOBALS_HTTP%% - js_include test.js; + js_import test.js; server { listen 127.0.0.1:8080; server_name localhost; location /test { - js_content test_redirect; + js_content test.redirect; } location /redirect { @@ -59,7 +59,7 @@ http { EOF $t->write_file('test.js', <try_run('no njs available')->plan(3); diff --git a/js_modules.t b/js_modules.t --- a/js_modules.t +++ b/js_modules.t @@ -35,14 +35,14 @@ events { http { %%TEST_GLOBALS_HTTP%% - js_include test.js; + js_import test.js; server { listen 127.0.0.1:8080; server_name localhost; location /test { - js_content test; + js_content test.test; } } } @@ -56,6 +56,8 @@ EOF r.return(200, m[r.args.fun](r.args.a, r.args.b)); } + export default {test}; + EOF $t->write_file('module.js', <try_run('no njs request object')->plan(7); diff --git a/js_paths.t b/js_paths.t --- a/js_paths.t +++ b/js_paths.t @@ -38,18 +38,18 @@ http { js_path "%%TESTDIR%%/lib1"; js_path "lib2"; - js_include test.js; + js_import test.js; server { listen 127.0.0.1:8080; server_name localhost; location /test { - js_content test; + js_content test.test; } location /test2 { - js_content test2; + js_content test.test2; } } } @@ -73,6 +73,8 @@ EOF r.return(200, m3.sum(r.args.a, r.args.b)); } + export default {test, test2}; + EOF my $d = $t->testdir(); diff --git a/js_promise.t b/js_promise.t --- a/js_promise.t +++ b/js_promise.t @@ -34,34 +34,34 @@ events { http { %%TEST_GLOBALS_HTTP%% - js_include test.js; + js_import test.js; server { listen 127.0.0.1:8080; server_name localhost; location /njs { - js_content test_njs; + js_content test.njs; } location /promise { - js_content promise; + js_content test.promise; } location /promise_throw { - js_content promise_throw; + js_content test.promise_throw; } location /promise_pure { - js_content promise_pure; + js_content test.promise_pure; } location /timeout { - js_content timeout; + js_content test.timeout; } location /sub_token { - js_content sub_token; + js_content test.sub_token; } } } @@ -184,6 +184,9 @@ EOF r.return(parseInt(code), '{"token": "'+ token +'"}'); } + export default {njs:test_njs, promise, promise_throw, promise_pure, + timeout, sub_token}; + EOF $t->try_run('no njs available')->plan(4); diff --git a/js_request_body.t b/js_request_body.t --- a/js_request_body.t +++ b/js_request_body.t @@ -37,19 +37,19 @@ events { http { %%TEST_GLOBALS_HTTP%% - js_include test.js; + js_import test.js; server { listen 127.0.0.1:8080; server_name localhost; location /body { - js_content test_body; + js_content test.body; } location /in_file { client_body_in_file_only on; - js_content test_body; + js_content test.body; } } } @@ -57,7 +57,7 @@ http { EOF $t->write_file('test.js', <try_run('no njs request body')->plan(3); diff --git a/js_return.t b/js_return.t --- a/js_return.t +++ b/js_return.t @@ -37,14 +37,14 @@ events { http { %%TEST_GLOBALS_HTTP%% - js_include test.js; + js_import test.js; server { listen 127.0.0.1:8080; server_name localhost; location / { - js_content test_return; + js_content test.returnf; } } } @@ -52,10 +52,12 @@ http { EOF $t->write_file('test.js', <try_run('no njs return')->plan(5); diff --git a/js_subrequests.t b/js_subrequests.t --- a/js_subrequests.t +++ b/js_subrequests.t @@ -43,70 +43,70 @@ http { proxy_cache_path %%TESTDIR%%/cache1 keys_zone=ON:1m use_temp_path=on; - js_include test.js; + js_import test.js; - js_set $async_var async_var; - js_set $subrequest_var subrequest_var; + js_set $async_var test.async_var; + js_set $subrequest_var test.subrequest_var; server { listen 127.0.0.1:8080; server_name localhost; location /njs { - js_content test_njs; + js_content test.njs; } location /sr { - js_content sr; + js_content test.sr; } location /sr_pr { - js_content sr_pr; + js_content test.sr_pr; } location /sr_args { - js_content sr_args; + js_content test.sr_args; } location /sr_options_args { - js_content sr_options_args; + js_content test.sr_options_args; } location /sr_options_args_pr { - js_content sr_options_args_pr; + js_content test.sr_options_args_pr; } location /sr_options_method { - js_content sr_options_method; + js_content test.sr_options_method; } location /sr_options_method_pr { - js_content sr_options_method_pr; + js_content test.sr_options_method_pr; } location /sr_options_body { - js_content sr_options_body; + js_content test.sr_options_body; } location /sr_options_method_head { - js_content sr_options_method_head; + js_content test.sr_options_method_head; } location /sr_body { - js_content sr_body; + js_content test.sr_body; } location /sr_body_pr { - js_content sr_body_pr; + js_content test.sr_body_pr; } location /sr_body_special { - js_content sr_body_special; + js_content test.sr_body_special; } location /sr_in_variable_handler { set $_ $async_var; - js_content sr_in_variable_handler; + js_content test.sr_in_variable_handler; } location /sr_detached_in_variable_handler { @@ -120,64 +120,64 @@ http { } location /sr_error_page { - js_content sr_error_page; + js_content test.sr_error_page; } location /sr_js_in_subrequest { - js_content sr_js_in_subrequest; + js_content test.sr_js_in_subrequest; } location /sr_js_in_subrequest_pr { - js_content sr_js_in_subrequest_pr; + js_content test.sr_js_in_subrequest_pr; } location /sr_file { - js_content sr_file; + js_content test.sr_file; } location /sr_cache { - js_content sr_cache; + js_content test.sr_cache; } location /sr_unavail { - js_content sr_unavail; + js_content test.sr_unavail; } location /sr_unavail_pr { - js_content sr_unavail_pr; + js_content test.sr_unavail_pr; } location /sr_broken { - js_content sr_broken; + js_content test.sr_broken; } location /sr_too_large { - js_content sr_too_large; + js_content test.sr_too_large; } location /sr_out_of_order { - js_content sr_out_of_order; + js_content test.sr_out_of_order; } location /sr_except_not_a_func { - js_content sr_except_not_a_func; + js_content test.sr_except_not_a_func; } location /sr_except_failed_to_convert_options_arg { - js_content sr_except_failed_to_convert_options_arg; + js_content test.sr_except_failed_to_convert_options_arg; } location /sr_except_invalid_options_header_only { - js_content sr_except_invalid_options_header_only; + js_content test.sr_except_invalid_options_header_only; } location /sr_in_sr_callback { - js_content sr_in_sr_callback; + js_content test.sr_in_sr_callback; } location /sr_uri_except { - js_content sr_uri_except; + js_content test.sr_uri_except; } @@ -200,7 +200,7 @@ http { } location /sr_in_sr { - js_content sr_in_sr; + js_content test.sr_in_sr; } location /unavail { @@ -208,11 +208,11 @@ http { } location /sr_parent { - js_content sr_parent; + js_content test.sr_parent; } location /js_sub { - js_content js_sub; + js_content test.js_sub; } location /return { @@ -244,15 +244,15 @@ http { } location /body { - js_content body; + js_content test.body; } location /detached { - js_content detached; + js_content test.detached; } location /delayed { - js_content delayed; + js_content test.delayed; } } @@ -267,8 +267,6 @@ http { EOF $t->write_file('test.js', <{}); } @@ -489,6 +489,17 @@ EOF r.return(200, '["JS-SUB"]'); } + export default {njs:test_njs, sr, sr_pr, sr_args, sr_options_args, + sr_options_args_pr, sr_options_method, sr_options_method_pr, + sr_options_method_head, sr_options_body, sr_body, + sr_body_pr, sr_body_special, body, delayed, detached, + sr_in_variable_handler, async_var, sr_error_page, + subrequest_var, sr_file, sr_cache, sr_unavail, sr_parent, + sr_unavail_pr, sr_broken, sr_too_large, sr_in_sr, + sr_js_in_subrequest, sr_js_in_subrequest_pr, js_sub, + sr_in_sr_callback, sr_out_of_order, sr_except_not_a_func, + sr_uri_except, sr_except_failed_to_convert_options_arg}; + EOF $t->write_file('t', '["SEE-THIS"]'); diff --git a/js_variables.t b/js_variables.t --- a/js_variables.t +++ b/js_variables.t @@ -35,26 +35,26 @@ events { http { %%TEST_GLOBALS_HTTP%% - js_set $test_var test_var; + js_set $test_var test.variable; - js_include test.js; + js_import test.js; server { listen 127.0.0.1:8080; server_name localhost; - set $foo foo_orig; + set $foo test.foo_orig; location /var_set { return 200 $test_var$foo; } location /content_set { - js_content content_set; + js_content test.content_set; } location /not_found_set { - js_content not_found_set; + js_content test.not_found_set; } } } @@ -62,7 +62,7 @@ http { EOF $t->write_file('test.js', <try_run('no njs')->plan(3); diff --git a/stream_js.t b/stream_js.t --- a/stream_js.t +++ b/stream_js.t @@ -37,14 +37,14 @@ events { http { %%TEST_GLOBALS_HTTP%% - js_include test.js; + js_import test.js; server { listen 127.0.0.1:8079; server_name localhost; location /njs { - js_content test_njs; + js_content test.njs; } location /p/ { @@ -61,15 +61,15 @@ http { stream { %%TEST_GLOBALS_STREAM%% - js_set $js_addr js_addr; - js_set $js_var js_var; - js_set $js_log js_log; - js_set $js_unk js_unk; - js_set $js_req_line js_req_line; - js_set $js_sess_unk js_sess_unk; - js_set $js_async js_async; + js_set $js_addr test.addr; + js_set $js_var test.variable; + js_set $js_log test.log; + js_set $js_unk test.unk; + js_set $js_req_line test.req_line; + js_set $js_sess_unk test.sess_unk; + js_set $js_async test.asyncf; - js_include test.js; + js_import test.js; log_format status $server_port:$status; @@ -105,84 +105,84 @@ stream { server { listen 127.0.0.1:8086; - js_access js_access_step; - js_preread js_preread_step; - js_filter js_filter_step; + js_access test.access_step; + js_preread test.preread_step; + js_filter test.filter_step; proxy_pass 127.0.0.1:8090; } server { listen 127.0.0.1:8087; - js_access js_access_undecided; + js_access test.access_undecided; return OK; access_log %%TESTDIR%%/status.log status; } server { listen 127.0.0.1:8088; - js_access js_access_allow; + js_access test.access_allow; return OK; access_log %%TESTDIR%%/status.log status; } server { listen 127.0.0.1:8089; - js_access js_access_deny; + js_access test.access_deny; return OK; access_log %%TESTDIR%%/status.log status; } server { listen 127.0.0.1:8091; - js_preread js_preread_async; + js_preread test.preread_async; proxy_pass 127.0.0.1:8090; } server { listen 127.0.0.1:8092; - js_preread js_preread_data; + js_preread test.preread_data; proxy_pass 127.0.0.1:8090; } server { listen 127.0.0.1:8093; - js_preread js_preread_req_line; + js_preread test.preread_req_line; return $js_req_line; } server { listen 127.0.0.1:8094; - js_filter js_filter_empty; + js_filter test.filter_empty; proxy_pass 127.0.0.1:8090; } server { listen 127.0.0.1:8095; - js_filter js_filter_header_inject; + js_filter test.filter_header_inject; proxy_pass 127.0.0.1:8079; } server { listen 127.0.0.1:8096; - js_filter js_filter_search; + js_filter test.filter_search; proxy_pass 127.0.0.1:8090; } server { listen 127.0.0.1:8097; - js_access js_access_except; + js_access test.access_except; proxy_pass 127.0.0.1:8090; } server { listen 127.0.0.1:8098; - js_preread js_preread_except; + js_preread test.preread_except; proxy_pass 127.0.0.1:8090; } server { listen 127.0.0.1:8099; - js_filter js_filter_except; + js_filter test.filter_except; proxy_pass 127.0.0.1:8090; } @@ -199,25 +199,25 @@ EOF r.return(200, njs.version); } - function js_addr(s) { + function addr(s) { return 'addr=' + s.remoteAddress; } - function js_var(s) { + function variable(s) { return 'variable=' + s.variables.remote_addr; } - function js_sess_unk(s) { + function sess_unk(s) { return 'sess_unk=' + s.unk; } - function js_log(s) { + function log(s) { s.log("SEE-THIS"); } var res = ''; - function js_access_step(s) { + function access_step(s) { res += '1'; setTimeout(function() { @@ -227,7 +227,7 @@ EOF }, 1); } - function js_preread_step(s) { + function preread_step(s) { s.on('upload', function (data) { res += '2'; if (res.length >= 3) { @@ -236,7 +236,7 @@ EOF }); } - function js_filter_step(s) { + function filter_step(s) { s.on('upload', function(data, flags) { s.send(data); res += '3'; @@ -256,11 +256,11 @@ EOF }); } - function js_access_undecided(s) { + function access_undecided(s) { s.decline(); } - function js_access_allow(s) { + function access_allow(s) { if (s.remoteAddress.match('127.0.0.1')) { s.done(); return; @@ -269,7 +269,7 @@ EOF s.deny(); } - function js_access_deny(s) { + function access_deny(s) { if (s.remoteAddress.match('127.0.0.1')) { s.deny(); return; @@ -279,13 +279,13 @@ EOF } - function js_preread_async(s) { + function preread_async(s) { setTimeout(function() { s.done(); }, 1); } - function js_preread_data(s) { + function preread_data(s) { s.on('upload', function (data, flags) { if (data.indexOf('z') != -1) { s.done(); @@ -295,7 +295,7 @@ EOF var line = ''; - function js_preread_req_line(s) { + function preread_req_line(s) { s.on('upload', function (data, flags) { var n = data.indexOf('\\n'); if (n != -1) { @@ -305,14 +305,14 @@ EOF }); } - function js_req_line(s) { + function req_line(s) { return line; } - function js_filter_empty(s) { + function filter_empty(s) { } - function js_filter_header_inject(s) { + function filter_header_inject(s) { var req = ''; s.on('upload', function(data, flags) { @@ -330,7 +330,7 @@ EOF }); } - function js_filter_search(s) { + function filter_search(s) { s.on('download', function(data, flags) { var n = data.search('y'); if (n != -1) { @@ -346,19 +346,19 @@ EOF }); } - function js_access_except(s) { + function access_except(s) { function done() {return s.a.a}; setTimeout(done, 1); setTimeout(done, 2); } - function js_preread_except(s) { + function preread_except(s) { var fs = require('fs'); fs.readFileSync(); } - function js_filter_except(s) { + function filter_except(s) { s.on('unknown', function() {}); } @@ -366,13 +366,19 @@ EOF return new Promise(resolve => {resolve(x)}).then(v => v).then(v => v); } - async function js_async(s) { + async function asyncf(s) { const a1 = await pr(10); const a2 = await pr(20); s.setReturnValue(`retval: \${a1 + a2}`); } + export default {njs:test_njs, addr, variable, sess_unk, log, access_step, + preread_step, filter_step, access_undecided, access_allow, + access_deny, preread_async, preread_data, preread_req_line, + req_line, filter_empty, filter_header_inject, filter_search, + access_except, preread_except, filter_except, asyncf}; + EOF $t->run_daemon(\&stream_daemon, port(8090)); @@ -393,17 +399,17 @@ is(stream('127.0.0.1:' . port(8084))->re is(stream('127.0.0.1:' . port(8086))->io('0'), '0122345', 'async handlers order'); -is(stream('127.0.0.1:' . port(8087))->io('#'), 'OK', 'js_access_undecided'); -is(stream('127.0.0.1:' . port(8088))->io('#'), 'OK', 'js_access_allow'); -is(stream('127.0.0.1:' . port(8089))->io('#'), '', 'js_access_deny'); +is(stream('127.0.0.1:' . port(8087))->io('#'), 'OK', 'access_undecided'); +is(stream('127.0.0.1:' . port(8088))->io('#'), 'OK', 'access_allow'); +is(stream('127.0.0.1:' . port(8089))->io('#'), '', 'access_deny'); -is(stream('127.0.0.1:' . port(8091))->io('#'), '#', 'js_preread_async'); -is(stream('127.0.0.1:' . port(8092))->io('#z'), '#z', 'js_preread_async_data'); -is(stream('127.0.0.1:' . port(8093))->io("xy\na"), 'xy', 'js_preread_req_line'); +is(stream('127.0.0.1:' . port(8091))->io('#'), '#', 'preread_async'); +is(stream('127.0.0.1:' . port(8092))->io('#z'), '#z', 'preread_async_data'); +is(stream('127.0.0.1:' . port(8093))->io("xy\na"), 'xy', 'preread_req_line'); -is(stream('127.0.0.1:' . port(8094))->io('x'), 'x', 'js_filter_empty'); -like(get('/p/return'), qr/foo/, 'js_filter_injected_header'); -is(stream('127.0.0.1:' . port(8096))->io('x'), 'z', 'js_filter_search'); +is(stream('127.0.0.1:' . port(8094))->io('x'), 'x', 'filter_empty'); +like(get('/p/return'), qr/foo/, 'filter_injected_header'); +is(stream('127.0.0.1:' . port(8096))->io('x'), 'z', 'filter_search'); stream('127.0.0.1:' . port(8097))->io('x'); stream('127.0.0.1:' . port(8098))->io('x'); @@ -413,7 +419,7 @@ TODO: { local $TODO = 'not yet' unless get('/njs') =~ /^([.0-9]+)$/m && $1 ge '0.7.0'; -is(stream('127.0.0.1:' . port(8100))->read(), 'retval: 30', 'js_async'); +is(stream('127.0.0.1:' . port(8100))->read(), 'retval: 30', 'asyncf'); } @@ -422,7 +428,7 @@ is(stream('127.0.0.1:' . port(8100))->re ok(index($t->read_file('error.log'), 'SEE-THIS') > 0, 'stream js log'); ok(index($t->read_file('error.log'), 'at fs.readFileSync') > 0, 'stream js_preread backtrace'); -ok(index($t->read_file('error.log'), 'at js_filter_except') > 0, +ok(index($t->read_file('error.log'), 'at filter_except') > 0, 'stream js_filter backtrace'); my @p = (port(8087), port(8088), port(8089)); diff --git a/stream_js_object.t b/stream_js_object.t --- a/stream_js_object.t +++ b/stream_js_object.t @@ -36,9 +36,9 @@ events { stream { %%TEST_GLOBALS_STREAM%% - js_set $test test; + js_set $test test.test; - js_include test.js; + js_import test.js; server { listen 127.0.0.1:8081; @@ -85,6 +85,8 @@ EOF ].every(v=>v(s)); } + export default {test}; + EOF $t->try_run('no njs stream session object')->plan(1); diff --git a/stream_js_variables.t b/stream_js_variables.t --- a/stream_js_variables.t +++ b/stream_js_variables.t @@ -36,10 +36,10 @@ events { stream { %%TEST_GLOBALS_STREAM%% - js_set $test_var test_var; - js_set $test_not_found test_not_found; + js_set $test_var test.variable; + js_set $test_not_found test.not_found; - js_include test.js; + js_import test.js; server { listen 127.0.0.1:8081; @@ -55,12 +55,12 @@ stream { EOF $t->write_file('test.js', <try_run('no stream njs available')->plan(2);