Welcome! Log In Create A New Profile

Advanced

[njs] Added TypeScript test.

Dmitry Volyntsev
July 06, 2020 02:40PM
details: https://hg.nginx.org/njs/rev/29ff89055e29
branches:
changeset: 1452:29ff89055e29
user: Dmitry Volyntsev <xeioex@nginx.com>
date: Mon Jul 06 18:37:13 2020 +0000
description:
Added TypeScript test.

diffstat:

auto/make | 3 ++
test/ts/test.ts | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 69 insertions(+), 0 deletions(-)

diffs (83 lines):

diff -r 5c84e6e56386 -r 29ff89055e29 auto/make
--- a/auto/make Mon Jul 06 16:44:03 2020 +0000
+++ b/auto/make Mon Jul 06 18:37:13 2020 +0000
@@ -265,6 +265,9 @@ ts:
cp nginx/ts/*.ts $NJS_BUILD_DIR/ts/
cp src/ts/*.ts $NJS_BUILD_DIR/ts/

+ts_test: ts
+ tsc ./test/ts/test.ts
+
dist:
NJS_VER=`grep NJS_VERSION src/njs.h | sed -e 's/.*"\(.*\)".*/\1/'`; \\
rm -rf njs-\$\${NJS_VER} \\
diff -r 5c84e6e56386 -r 29ff89055e29 test/ts/test.ts
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/ts/test.ts Mon Jul 06 18:37:13 2020 +0000
@@ -0,0 +1,66 @@
+/// <reference path="../../build/ts/ngx_http_js_module.d.ts" />
+
+function handler(r: NginxHTTPRequest) {
+ var bs: NjsByteString;
+ var s: string;
+
+ // builtin string vs NjsByteString
+
+ s = 'ordinary string';
+ bs = String.bytesFrom('000000', 'hex');
+ bs = s.toBytes();
+ bs = s.toUTF8();
+ bs.fromBytes(null, null);
+
+ s = bs + '';
+
+ // r.uri
+
+ if (r.uri == '/') {
+ }
+
+ // r.args
+
+ bs = r.args.x;
+ bs = r.args[1];
+ s = r.args.x.fromUTF8();
+ s = r.args.x + '';
+
+ // r.headersIn
+
+ r.headersIn['Accept'].fromBytes() == 'dddd';
+
+ // r.headersOut
+
+ r.headersOut['Content-Type'] = 'text/plain';
+ // Warning: r.headersOut['Content-Type'] = ['a', 'b'];
+ r.headersOut['Connection'] = undefined;
+ r.headersOut['Connection'] = null;
+
+ r.headersOut['Set-Cookie'] = ['aaa', 'bbb'];
+ r.headersOut['Foo'] = ['aaa', 'bbb'];
+
+ r.subrequest('/uri', reply => r.return(200, reply.headersOut["Location"]));
+
+ // r.log
+
+ r.log(bs);
+ r.log(r.headersOut['Connection']);
+
+ // r.variables
+
+ r.variables.a == 'a';
+ r.variables.cookie_a = 'b';
+
+ // r.subrequest
+ r.subrequest('/p/sub1').then(reply => r.return(reply.status));
+ r.subrequest('/p/sub2', reply => r.return(reply.status));
+ r.subrequest('/p/sub3', {detached:true});
+ r.subrequest('/p/sub4', 'a=1&b=2').then(reply => r.return(reply.status,
+ JSON.stringify(JSON.parse(reply.responseBody))));
+
+ // builtin objects
+
+ njs.dump('asdf');
+ njs.version != process.argv[1];
+}
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[njs] Added TypeScript test.

Dmitry Volyntsev 235 July 06, 2020 02:40PM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 298
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready