Skip to content

Commit

Permalink
[Tests] update tests for more async/await cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Raynos authored and ljharb committed Jul 2, 2019
1 parent f248610 commit 197019c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 16 deletions.
24 changes: 17 additions & 7 deletions test/async-await.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ tap.test('async4', function (t) {

tap.test('async5', function (t) {
runProgram('async-await', 'async5.js', function (r) {
t.same(r.stdout.toString('utf8'), [
t.same(stripFullStack(r.stdout.toString('utf8')), [
'TAP version 13',
'# async5',
'ok 1 before server',
Expand All @@ -128,14 +128,24 @@ tap.test('async5', function (t) {
'ok 4 after request',
'ok 5 should be equal',
'ok 6 should be equal',
'ok 7 undefined',
'not ok 8 .end() called twice',
' ---',
' operator: fail',
' at: Server.<anonymous> ($TEST/async-await/async5.js:$LINE:$COL)',
' stack: |-',
' Error: .end() called twice',
' [... stack stripped ...]',
' at Server.<anonymous> ($TEST/async-await/async5.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'',
'1..6',
'# tests 6',
'# pass 6',
'',
'# ok'
'1..8',
'# tests 8',
'# pass 7',
'# fail 1'
].join('\n') + '\n\n');
t.same(r.exitCode, 0);
t.same(r.exitCode, 1);
t.same(r.stderr.toString('utf8'), '');
t.end();
});
Expand Down
1 change: 1 addition & 0 deletions test/async-await/async1.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ test('async1', async function myTest(t) {
setTimeout(resolve, 10);
});
t.ok(true, 'after await');
t.end();
} catch (err) {
t.ifError(err);
}
Expand Down
16 changes: 7 additions & 9 deletions test/async-await/async5.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,14 @@ test('async5', async function myTest(t) {
res.resume();
t.equal(res.statusCode, 200);

await new Promise(function (resolve, reject) {
setTimeout(function () {
t.equal(mockDb.state, 'new');
setTimeout(function () {
t.equal(mockDb.state, 'new');

server.close(function (err) {
if (err) { reject(err); }
else { resolve(); }
});
}, 50);
});
server.close(function (err) {
t.ifError(err);
t.end();
});
}, 50);
} catch (err) {
t.ifError(err);
t.end();
Expand Down

0 comments on commit 197019c

Please sign in to comment.