# HG changeset patch # User Alexander Borisov # Date 1606406303 -10800 # Node ID 54f867e69cb536a749e7d9f59c94ffdd8b83f72a # Parent 456bf219d768855efab5764fd2bf9fe90227f2b9 Tests: added js promise test with standalone promises. diff --git a/js_promise.t b/js_promise.t --- a/js_promise.t +++ b/js_promise.t @@ -40,6 +40,10 @@ http { listen 127.0.0.1:8080; server_name localhost; + location /njs { + js_content test_njs; + } + location /promise { js_content promise; } @@ -48,6 +52,10 @@ http { js_content promise_throw; } + location /promise_pure { + js_content promise_pure; + } + location /timeout { js_content timeout; } @@ -63,6 +71,10 @@ EOF $t->write_file('test.js', < { @@ -109,6 +121,18 @@ EOF }); } + 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 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'), qr/{"token": 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'; + ###############################################################################