changeset 1787:e55aa7021ea5

Tests: added js r.internal test.
author Dmitry Volyntsev <xeioex@nginx.com>
date Thu, 25 Aug 2022 16:53:15 -0700
parents cadf15e2e2b3
children 78fe648d54a7
files js.t
diffstat 1 files changed, 31 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/js.t
+++ b/js.t
@@ -45,6 +45,7 @@ http {
     js_set $test_type     test.type;
     js_set $test_global   test.global_obj;
     js_set $test_log      test.log;
+    js_set $test_internal test.sub_internal;
     js_set $test_except   test.except;
 
     js_import test.js;
@@ -118,6 +119,15 @@ http {
             return 200 $test_log;
         }
 
+        location /internal {
+            js_content test.internal;
+        }
+
+        location /sub_internal {
+            internal;
+            return 200 $test_internal;
+        }
+
         location /except {
             return 200 $test_except;
         }
@@ -215,6 +225,16 @@ EOF
         r.log('SEE-LOG');
     }
 
+    async function internal(r) {
+        let reply = await r.subrequest('/sub_internal');
+
+        r.return(200, `parent: \${r.internal} sub: \${reply.responseText}`);
+    }
+
+    function sub_internal(r) {
+        return r.internal;
+    }
+
     function except(r) {
         var fs = require('fs');
         fs.readFileSync();
@@ -229,13 +249,13 @@ EOF
     }
 
     export default {njs:test_njs, method, version, addr, uri,
-                    variable, global_obj, status, request_body,
-                    request_body_cache, send, return_method,
+                    variable, global_obj, status, request_body, internal,
+                    request_body_cache, send, return_method, sub_internal,
                     type, log, except, content_except, content_empty};
 
 EOF
 
-$t->try_run('no njs available')->plan(26);
+$t->try_run('no njs available')->plan(27);
 
 ###############################################################################
 
@@ -286,6 +306,14 @@ like(http_get('/var'), qr/variable=127.0
 like(http_get('/global'), qr/global=njs/, 'global code');
 like(http_get('/log'), qr/200 OK/, 'r.log');
 
+TODO: {
+local $TODO = 'not yet'
+	unless http_get('/njs') =~ /^([.0-9]+)$/m && $1 ge '0.7.7';
+
+like(http_get('/internal'), qr/parent: false sub: true/, 'r.internal');
+
+}
+
 http_get('/except');
 http_get('/content_except');