-
-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use the Node.js test runner API and remove the dev dependency `test-d…
…irector`.
- Loading branch information
1 parent
f24d71b
commit 3b7f034
Showing
9 changed files
with
638 additions
and
713 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,59 +1,62 @@ | ||
// @ts-check | ||
|
||
import { ok, rejects, strictEqual } from "node:assert"; | ||
import { describe, it } from "node:test"; | ||
|
||
import Upload from "./Upload.mjs"; | ||
|
||
/** | ||
* Adds `Upload` tests. | ||
* @param {import("test-director").default} tests Test director. | ||
*/ | ||
export default (tests) => { | ||
tests.add("`Upload` class resolving a file.", async () => { | ||
const upload = new Upload(); | ||
describe( | ||
"Class `Upload`.", | ||
{ | ||
concurrency: true, | ||
}, | ||
() => { | ||
it("Resolving a file.", async () => { | ||
const upload = new Upload(); | ||
|
||
ok(upload.promise instanceof Promise); | ||
strictEqual(typeof upload.resolve, "function"); | ||
ok(upload.promise instanceof Promise); | ||
strictEqual(typeof upload.resolve, "function"); | ||
|
||
/** @type {any} */ | ||
const file = {}; | ||
/** @type {any} */ | ||
const file = {}; | ||
|
||
upload.resolve(file); | ||
upload.resolve(file); | ||
|
||
const resolved = await upload.promise; | ||
const resolved = await upload.promise; | ||
|
||
strictEqual(resolved, file); | ||
strictEqual(upload.file, file); | ||
}); | ||
strictEqual(resolved, file); | ||
strictEqual(upload.file, file); | ||
}); | ||
|
||
tests.add("`Upload` class with a handled rejection.", async () => { | ||
const upload = new Upload(); | ||
it("Handled rejection.", async () => { | ||
const upload = new Upload(); | ||
|
||
ok(upload.promise instanceof Promise); | ||
strictEqual(typeof upload.reject, "function"); | ||
ok(upload.promise instanceof Promise); | ||
strictEqual(typeof upload.reject, "function"); | ||
|
||
const error = new Error("Message."); | ||
const error = new Error("Message."); | ||
|
||
upload.reject(error); | ||
upload.reject(error); | ||
|
||
// This is the safe way to check the promise status, see: | ||
// https://github.com/nodejs/node/issues/31392#issuecomment-575451230 | ||
await rejects(Promise.race([upload.promise, Promise.resolve()]), error); | ||
}); | ||
// This is the safe way to check the promise status, see: | ||
// https://github.com/nodejs/node/issues/31392#issuecomment-575451230 | ||
await rejects(Promise.race([upload.promise, Promise.resolve()]), error); | ||
}); | ||
|
||
tests.add("`Upload` class with an unhandled rejection.", async () => { | ||
const upload = new Upload(); | ||
it("Unhandled rejection.", async () => { | ||
const upload = new Upload(); | ||
|
||
ok(upload.promise instanceof Promise); | ||
strictEqual(typeof upload.reject, "function"); | ||
ok(upload.promise instanceof Promise); | ||
strictEqual(typeof upload.reject, "function"); | ||
|
||
const error = new Error("Message."); | ||
const error = new Error("Message."); | ||
|
||
upload.reject(error); | ||
upload.reject(error); | ||
|
||
// Node.js CLI flag `--unhandled-rejections=throw` must be used when these | ||
// tests are run with Node.js v14 (it’s unnecessary for Node.js v15+) or the | ||
// process won’t exit with an error if the unhandled rejection is’t silenced | ||
// as intended. | ||
}); | ||
}; | ||
// Node.js CLI flag `--unhandled-rejections=throw` must be used when these | ||
// tests are run with Node.js v14 (it’s unnecessary for Node.js v15+) or | ||
// the process won’t exit with an error if the unhandled rejection is’t | ||
// silenced as intended. | ||
}); | ||
}, | ||
); |
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
Oops, something went wrong.