-
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- `test.assert` -> `assert` - `test.strictSame` -> `assert.strictEqual` / `assert.deepStrictEqual` - `test.error` -> `assert.ifError` - `test.throws` -> `assert.throws` - Remove `test.end` - Remove `test.plan` Refs: #261
- Loading branch information
1 parent
d90f5ea
commit d2368a4
Showing
11 changed files
with
358 additions
and
399 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,69 @@ | ||
'use strict'; | ||
|
||
const metatests = require('metatests'); | ||
const test = require('node:test'); | ||
const assert = require('node:assert'); | ||
const { toBool, timeout, delay, timeoutify } = require('..'); | ||
|
||
metatests.test('Async: toBool', async (test) => { | ||
test('Async: toBool', async () => { | ||
const success = await Promise.resolve('success').then(...toBool); | ||
test.strictSame(success, true); | ||
assert.strictEqual(success, true); | ||
const rejected = await Promise.reject(new Error('Ups')).then(...toBool); | ||
test.strictSame(rejected, false); | ||
test.end(); | ||
assert.strictEqual(rejected, false); | ||
}); | ||
|
||
metatests.test('Async: Abortable timeout', async (test) => { | ||
test('Async: Abortable timeout', async () => { | ||
try { | ||
await timeout(10); | ||
test.error(new Error('Should not be executed')); | ||
assert.ifError(new Error('Should not be executed')); | ||
} catch (err) { | ||
test.strictSame(err.code, 'ETIMEOUT'); | ||
test.strictSame(err.message, 'Timeout of 10ms reached'); | ||
assert.strictEqual(err.code, 'ETIMEOUT'); | ||
assert.strictEqual(err.message, 'Timeout of 10ms reached'); | ||
} | ||
const ac = new AbortController(); | ||
setTimeout(() => { | ||
ac.abort(); | ||
}, 10); | ||
try { | ||
await timeout(100, ac.signal); | ||
test.error(new Error('Should not be executed')); | ||
assert.ifError(new Error('Should not be executed')); | ||
} catch (err) { | ||
test.strictSame(err.message, 'Timeout aborted'); | ||
test.end(); | ||
assert.strictEqual(err.message, 'Timeout aborted'); | ||
} | ||
}); | ||
|
||
metatests.test('Async: Abortable delay', async (test) => { | ||
test('Async: Abortable delay', async () => { | ||
try { | ||
const res = await delay(10); | ||
test.strictSame(res, undefined); | ||
assert.strictEqual(res, undefined); | ||
} catch { | ||
test.error(new Error('Should not be executed')); | ||
assert.ifError(new Error('Should not be executed')); | ||
} | ||
const ac = new AbortController(); | ||
setTimeout(() => { | ||
ac.abort(); | ||
}, 10); | ||
try { | ||
await delay(100, ac.signal); | ||
test.error(new Error('Should not be executed')); | ||
assert.ifError(new Error('Should not be executed')); | ||
} catch (err) { | ||
test.strictSame(err.message, 'Delay aborted'); | ||
test.end(); | ||
assert.strictEqual(err.message, 'Delay aborted'); | ||
} | ||
}); | ||
|
||
metatests.test('Async: timeoutify', async (test) => { | ||
test('Async: timeoutify', async () => { | ||
try { | ||
const request = delay(1000); | ||
await timeoutify(request, 10); | ||
test.error(new Error('Should not be executed')); | ||
assert.ifError(new Error('Should not be executed')); | ||
} catch (err) { | ||
test.strictSame(err.code, 'ETIMEOUT'); | ||
test.strictSame(err.message, 'Timeout of 10ms reached'); | ||
assert.strictEqual(err.code, 'ETIMEOUT'); | ||
assert.strictEqual(err.message, 'Timeout of 10ms reached'); | ||
} | ||
try { | ||
const request = delay(10); | ||
const response = await timeoutify(request, 1000); | ||
test.strictSame(response, undefined); | ||
test.end(); | ||
assert.strictEqual(response, undefined); | ||
} catch { | ||
test.error(new Error('Should not be executed')); | ||
assert.ifError(new Error('Should not be executed')); | ||
} | ||
}); |
Oops, something went wrong.