Tests: added js promise test with standalone promises.
diff --git a/js_promise.t b/js_promise.t
index cf54c18..a380496 100644
--- a/js_promise.t
+++ b/js_promise.t
@@ -40,6 +40,10 @@
listen 127.0.0.1:8080;
server_name localhost;
+ location /njs {
+ js_content test_njs;
+ }
+
location /promise {
js_content promise;
}
@@ -48,6 +52,10 @@
js_content promise_throw;
}
+ location /promise_pure {
+ js_content promise_pure;
+ }
+
location /timeout {
js_content timeout;
}
@@ -63,6 +71,10 @@
$t->write_file('test.js', <<EOF);
var global_token = '';
+ function test_njs(r) {
+ r.return(200, njs.version);
+ }
+
function promise(r) {
promisified_subrequest(r, '/sub_token', 'code=200&token=a')
.then(reply => {
@@ -109,6 +121,18 @@
});
}
+ function promise_pure(r) {
+ var count = 0;
+
+ Promise.resolve(true)
+ .then(() => count++)
+ .then(() => not_exist_ref)
+ .finally(() => count++)
+ .catch(() => {
+ r.return((count != 2) ? 500 : 200);
+ });
+ }
+
function timeout(r) {
promisified_subrequest(r, '/sub_token', 'code=200&token=R')
.then(reply => JSON.parse(reply.responseBody))
@@ -162,7 +186,7 @@
EOF
-$t->try_run('no njs available')->plan(3);
+$t->try_run('no njs available')->plan(4);
###############################################################################
@@ -170,4 +194,13 @@
like(http_get('/promise_throw'), qr/{"token": "x"}/, "Promise throw and catch");
like(http_get('/timeout'), qr/{"token": "R"}/, "Promise with timeout");
+TODO: {
+local $TODO = 'not yet'
+ unless http_get('/njs') =~ /^([.0-9]+)$/m && $1 ge '0.5.0';
+
+like(http_get('/promise_pure'), qr/200 OK/, "events handling");
+}
+
+$t->todo_alerts() unless http_get('/njs') =~ /^([.0-9]+)$/m && $1 ge '0.5.0';
+
###############################################################################