Skip to content

Commit 96e3a17

Browse files
committed
Tests: making fetch test portable by removing njs.dump().
1 parent add642c commit 96e3a17

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

nginx/t/js_fetch.t

+8-8
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ $t->write_file('test.js', <<EOF);
303303
304304
p.then(reply => {
305305
var h = reply.headers[method](r.args.h);
306-
r.return(200, njs.dump(h));
306+
r.return(200, JSON.stringify(h));
307307
})
308308
.catch(e => r.return(501, e.message))
309309
}
@@ -342,7 +342,7 @@ $t->write_file('test.js', <<EOF);
342342
}
343343
}
344344
345-
r.return(200, njs.dump(out));
345+
r.return(200, JSON.stringify(out));
346346
}
347347
348348
function multi(r) {
@@ -446,23 +446,23 @@ like(http_get('/property?pr=statusText&code=403'), qr/200 OK.*Forbidden$/s,
446446
'fetch statusText Forbidden');
447447
like(http_get('/property?pr=type'), qr/200 OK.*basic$/s,
448448
'fetch type');
449-
like(http_get('/header?loc=duplicate_header&h=BAR'), qr/200 OK.*c$/s,
449+
like(http_get('/header?loc=duplicate_header&h=BAR'), qr/200 OK.*"c"$/s,
450450
'fetch header');
451451
like(http_get('/header?loc=duplicate_header&h=BARR'), qr/200 OK.*null$/s,
452452
'fetch no header');
453-
like(http_get('/header?loc=duplicate_header&h=foo'), qr/200 OK.*a, ?b$/s,
453+
like(http_get('/header?loc=duplicate_header&h=foo'), qr/200 OK.*"a, ?b"$/s,
454454
'fetch header duplicate');
455455
like(http_get('/header?loc=duplicate_header&h=BAR&method=getAll'),
456-
qr/200 OK.*\['c']$/s, 'fetch getAll header');
456+
qr/200 OK.*\["c"]$/s, 'fetch getAll header');
457457
like(http_get('/header?loc=duplicate_header&h=BARR&method=getAll'),
458458
qr/200 OK.*\[]$/s, 'fetch getAll no header');
459459
like(http_get('/header?loc=duplicate_header&h=FOO&method=getAll'),
460-
qr/200 OK.*\['a','b']$/s, 'fetch getAll duplicate');
460+
qr/200 OK.*\["a","b"]$/s, 'fetch getAll duplicate');
461461
like(http_get('/header?loc=duplicate_header&h=bar&method=has'),
462462
qr/200 OK.*true$/s, 'fetch header has');
463463
like(http_get('/header?loc=duplicate_header&h=buz&method=has'),
464464
qr/200 OK.*false$/s, 'fetch header does not have');
465-
like(http_get('/header?loc=chunked/big&h=BAR&readBody=1'), qr/200 OK.*xxx$/s,
465+
like(http_get('/header?loc=chunked/big&h=BAR&readBody=1'), qr/200 OK.*"xxx"$/s,
466466
'fetch chunked header');
467467
is(get_json('/multi'),
468468
'[{"b":"GET::","c":201,"u":"http://127.0.0.1:'.$p0.'/loc"},' .
@@ -477,7 +477,7 @@ like(http_get('/chunked_fail'), qr/200/s, 'fetch chunked fail');
477477
like(http_get('/chain'), qr/200 OK.*SUCCESS$/s, 'fetch chain');
478478

479479
like(http_get('/header_iter?loc=duplicate_header_large'),
480-
qr/\['A:a','B:a','C:a','D:a','E:a','F:a','G:a','H:a','Moo:a, ?b']$/s,
480+
qr/\["A:a","B:a","C:a","D:a","E:a","F:a","G:a","H:a","Moo:a, ?b"]$/s,
481481
'fetch header duplicate large');
482482

483483
TODO: {

nginx/t/js_fetch_objects.t

+2-2
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,8 @@ $t->write_file('test.js', <<EOF);
186186
}, 'A, B, C, D, E, F'],
187187
['getAll', () => {
188188
var h = new Headers({a: 'X', A: 'Z'});
189-
return njs.dump(h.getAll('a'));
190-
}, "['X','Z']"],
189+
return JSON.stringify(h.getAll('a'));
190+
}, '["X","Z"]'],
191191
['inherit', () => {
192192
var h = new Headers({a: 'X', b: 'Y'});
193193
var h2 = new Headers(h);

nginx/t/js_fetch_timeout.t

+4-4
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ $t->write_file('test.js', <<EOF);
9595
].map(v => ngx.fetch(v)));
9696
9797
let bs = rs.map(v => ({s: v.status, v: v.value ? v.value.headers.X
98-
: v.reason}));
98+
: v.reason.message}));
9999
100-
r.return(200, njs.dump(bs));
100+
r.return(200, JSON.stringify(bs));
101101
}
102102
103103
function normal_reply(r) {
@@ -123,10 +123,10 @@ $t->plan(2);
123123
###############################################################################
124124

125125
like(http_get('/normal_timeout'),
126-
qr/\[\{s:'fulfilled',v:'N'},\{s:'fulfilled',v:'D'}]$/s,
126+
qr/\[\{"s":"fulfilled","v":"N"},\{"s":"fulfilled","v":"D"}]$/s,
127127
'normal timeout');
128128
like(http_get('/short_timeout'),
129-
qr/\[\{s:'fulfilled',v:'N'},\{s:'rejected',v:Error: read timed out}]$/s,
129+
qr/\[\{"s":"fulfilled","v":"N"},\{"s":"rejected","v":"read timed out"}]$/s,
130130
'short timeout');
131131

132132
###############################################################################

0 commit comments

Comments
 (0)