annotate js_modules.t @ 1606:e4e0695552ed

Tests: fixed stream_proxy_ssl_conf_command.t. The stream_proxy_ssl_conf_command.t test used stream return module to return the response. Since this ignores actual request, but the perl test code used http_get(). This might result in the request being sent after the response is returned and the connection closed by the server, resulting in RST being generated and no response seen by the client at all. Fix is to use "stream(...)->read()" instead of http_get(), so no request is sent at all, eliminating possibility of RST being generated.
author Maxim Dounin <mdounin@mdounin.ru>
date Tue, 10 Nov 2020 05:03:29 +0300
parents f4ae08adc23f
children bc0990ea2e5b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1456
f4ae08adc23f Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
1 #!/usr/bin/perl
f4ae08adc23f Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
2
f4ae08adc23f Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
3 # (C) Dmitry Volyntsev
f4ae08adc23f Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
4 # (C) Nginx, Inc.
f4ae08adc23f Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
5
f4ae08adc23f Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
6 # Tests for http njs module, ES6 import, export.
f4ae08adc23f Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
7
f4ae08adc23f Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
8 ###############################################################################
f4ae08adc23f Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
9
f4ae08adc23f Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
10 use warnings;
f4ae08adc23f Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
11 use strict;
f4ae08adc23f Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
12
f4ae08adc23f Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
13 use Test::More;
f4ae08adc23f Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
14
f4ae08adc23f Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
15 BEGIN { use FindBin; chdir($FindBin::Bin); }
f4ae08adc23f Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
16
f4ae08adc23f Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
17 use lib 'lib';
f4ae08adc23f Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
18 use Test::Nginx;
f4ae08adc23f Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
19
f4ae08adc23f Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
20 ###############################################################################
f4ae08adc23f Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
21
f4ae08adc23f Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
22 select STDERR; $| = 1;
f4ae08adc23f Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
23 select STDOUT; $| = 1;
f4ae08adc23f Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
24
f4ae08adc23f Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
25 my $t = Test::Nginx->new()->has(qw/http/)
f4ae08adc23f Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
26 ->write_file_expand('nginx.conf', <<'EOF');
f4ae08adc23f Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
27
f4ae08adc23f Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
28 %%TEST_GLOBALS%%
f4ae08adc23f Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
29
f4ae08adc23f Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
30 daemon off;
f4ae08adc23f Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
31
f4ae08adc23f Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
32 events {
f4ae08adc23f Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
33 }
f4ae08adc23f Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
34
f4ae08adc23f Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
35 http {
f4ae08adc23f Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
36 %%TEST_GLOBALS_HTTP%%
f4ae08adc23f Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
37
f4ae08adc23f Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
38 js_include test.js;
f4ae08adc23f Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
39
f4ae08adc23f Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
40 server {
f4ae08adc23f Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
41 listen 127.0.0.1:8080;
f4ae08adc23f Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
42 server_name localhost;
f4ae08adc23f Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
43
f4ae08adc23f Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
44 location /njs {
f4ae08adc23f Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
45 js_content test_njs;
f4ae08adc23f Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
46 }
f4ae08adc23f Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
47
f4ae08adc23f Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
48 location /test {
f4ae08adc23f Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
49 js_content test;
f4ae08adc23f Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
50 }
f4ae08adc23f Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
51 }
f4ae08adc23f Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
52 }
f4ae08adc23f Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
53
f4ae08adc23f Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
54 EOF
f4ae08adc23f Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
55
f4ae08adc23f Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
56 $t->write_file('test.js', <<EOF);
f4ae08adc23f Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
57 import m from 'module.js';
f4ae08adc23f Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
58
f4ae08adc23f Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
59 function test_njs(r) {
f4ae08adc23f Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
60 r.return(200, njs.version);
f4ae08adc23f Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
61 }
f4ae08adc23f Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
62
f4ae08adc23f Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
63 function test(r) {
f4ae08adc23f Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
64 r.return(200, m[r.args.fun](r.args.a, r.args.b));
f4ae08adc23f Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
65 }
f4ae08adc23f Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
66
f4ae08adc23f Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
67 EOF
f4ae08adc23f Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
68
f4ae08adc23f Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
69 $t->write_file('module.js', <<EOF);
f4ae08adc23f Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
70 function sum(a, b) {
f4ae08adc23f Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
71 return Number(a) + Number(b);
f4ae08adc23f Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
72 }
f4ae08adc23f Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
73
f4ae08adc23f Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
74 function prod(a, b) {
f4ae08adc23f Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
75 return Number(a) * Number(b);
f4ae08adc23f Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
76 }
f4ae08adc23f Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
77
f4ae08adc23f Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
78 export default {sum, prod};
f4ae08adc23f Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
79
f4ae08adc23f Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
80 EOF
f4ae08adc23f Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
81
f4ae08adc23f Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
82
f4ae08adc23f Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
83 $t->try_run('no njs modules')->plan(2);
f4ae08adc23f Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
84
f4ae08adc23f Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
85 ###############################################################################
f4ae08adc23f Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
86
f4ae08adc23f Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
87 like(http_get('/test?fun=sum&a=3&b=4'), qr/7/s, 'test sum');
f4ae08adc23f Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
88 like(http_get('/test?fun=prod&a=3&b=4'), qr/12/s, 'test prod');
f4ae08adc23f Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
89
f4ae08adc23f Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
90 ###############################################################################