Skip to content

Commit 197019c

Browse files
Raynosljharb
authored andcommitted
[Tests] update tests for more async/await cases
1 parent f248610 commit 197019c

File tree

3 files changed

+25
-16
lines changed

3 files changed

+25
-16
lines changed

test/async-await.js

+17-7
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ tap.test('async4', function (t) {
119119

120120
tap.test('async5', function (t) {
121121
runProgram('async-await', 'async5.js', function (r) {
122-
t.same(r.stdout.toString('utf8'), [
122+
t.same(stripFullStack(r.stdout.toString('utf8')), [
123123
'TAP version 13',
124124
'# async5',
125125
'ok 1 before server',
@@ -128,14 +128,24 @@ tap.test('async5', function (t) {
128128
'ok 4 after request',
129129
'ok 5 should be equal',
130130
'ok 6 should be equal',
131+
'ok 7 undefined',
132+
'not ok 8 .end() called twice',
133+
' ---',
134+
' operator: fail',
135+
' at: Server.<anonymous> ($TEST/async-await/async5.js:$LINE:$COL)',
136+
' stack: |-',
137+
' Error: .end() called twice',
138+
' [... stack stripped ...]',
139+
' at Server.<anonymous> ($TEST/async-await/async5.js:$LINE:$COL)',
140+
' [... stack stripped ...]',
141+
' ...',
131142
'',
132-
'1..6',
133-
'# tests 6',
134-
'# pass 6',
135-
'',
136-
'# ok'
143+
'1..8',
144+
'# tests 8',
145+
'# pass 7',
146+
'# fail 1'
137147
].join('\n') + '\n\n');
138-
t.same(r.exitCode, 0);
148+
t.same(r.exitCode, 1);
139149
t.same(r.stderr.toString('utf8'), '');
140150
t.end();
141151
});

test/async-await/async1.js

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ test('async1', async function myTest(t) {
77
setTimeout(resolve, 10);
88
});
99
t.ok(true, 'after await');
10+
t.end();
1011
} catch (err) {
1112
t.ifError(err);
1213
}

test/async-await/async5.js

+7-9
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,14 @@ test('async5', async function myTest(t) {
4242
res.resume();
4343
t.equal(res.statusCode, 200);
4444

45-
await new Promise(function (resolve, reject) {
46-
setTimeout(function () {
47-
t.equal(mockDb.state, 'new');
45+
setTimeout(function () {
46+
t.equal(mockDb.state, 'new');
4847

49-
server.close(function (err) {
50-
if (err) { reject(err); }
51-
else { resolve(); }
52-
});
53-
}, 50);
54-
});
48+
server.close(function (err) {
49+
t.ifError(err);
50+
t.end();
51+
});
52+
}, 50);
5553
} catch (err) {
5654
t.ifError(err);
5755
t.end();

0 commit comments

Comments
 (0)