Skip to content

Commit 295acdc

Browse files
authored
refactor(testing): replace custom Deno adapter with @std/expect and @std/testing/bdd (#821)
Remove the 248-line custom Deno test adapter that reimplemented describe/it/expect and use Deno's standard library instead. The deno.test.ts file now follows the same pattern as node.test.ts and bun.test.ts.
1 parent 6196fbd commit 295acdc

File tree

4 files changed

+32
-290
lines changed

4 files changed

+32
-290
lines changed

deno.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
"@noble/hashes/sha2.js": "npm:@noble/hashes@^2.0.1/sha2.js",
1919
"@noble/hashes/utils.js": "npm:@noble/hashes@^2.0.1/utils.js",
2020
"@scure/base": "npm:@scure/base@^2.0.0",
21-
"@std/assert": "https://deno.land/[email protected]/assert/mod.ts"
21+
"@std/expect": "https://deno.land/[email protected]/expect/mod.ts",
22+
"@std/testing/bdd": "https://deno.land/[email protected]/testing/bdd.ts"
2223
},
2324
"nodeModulesDir": "auto"
2425
}

internal/distribution-tests/src/deno.test.ts

Lines changed: 30 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,8 @@
44
* Tests the built artifacts using Noble crypto plugin (Deno-compatible).
55
*/
66

7-
import {
8-
assertEquals,
9-
assertNotEquals,
10-
assertMatch,
11-
assertThrows,
12-
assertInstanceOf,
13-
} from "@std/assert";
7+
import { describe, it } from "@std/testing/bdd";
8+
import { expect } from "@std/expect";
149
import { NobleCryptoPlugin } from "@otplib/plugin-crypto-noble";
1510
import { ScureBase32Plugin } from "@otplib/plugin-base32-scure";
1611
import { TOTP } from "@otplib/totp";
@@ -23,7 +18,6 @@ import {
2318
verifySync,
2419
OTP,
2520
} from "otplib";
26-
import { createDenoTestContext } from "@repo/testing";
2721

2822
import { createHOTPDistributionTests } from "./hotp-test.ts";
2923
import { createTOTPDistributionTests } from "./totp-test.ts";
@@ -33,41 +27,38 @@ import { createURIDistributionTests } from "./uri-test.ts";
3327
const crypto = new NobleCryptoPlugin();
3428
const base32 = new ScureBase32Plugin();
3529

36-
// Create Deno test context for URI
37-
const uriCtx = createDenoTestContext(
38-
{ assertEquals, assertNotEquals, assertMatch, assertThrows, assertInstanceOf },
39-
{},
40-
);
41-
42-
createURIDistributionTests(uriCtx);
43-
uriCtx.runTests();
44-
45-
// Create Deno test context for HOTP
46-
const hotpCtx = createDenoTestContext(
47-
{ assertEquals, assertNotEquals, assertMatch, assertThrows, assertInstanceOf },
48-
{ crypto, base32 },
49-
);
50-
51-
createHOTPDistributionTests(hotpCtx);
52-
hotpCtx.runTests();
53-
54-
// Create Deno test context for TOTP
55-
const totpCtx = createDenoTestContext(
56-
{ assertEquals, assertNotEquals, assertMatch, assertThrows, assertInstanceOf },
57-
{ crypto, base32 },
58-
);
30+
// Run URI distribution tests
31+
createURIDistributionTests({
32+
describe,
33+
it,
34+
expect,
35+
});
5936

60-
createTOTPDistributionTests(totpCtx);
61-
totpCtx.runTests();
37+
// Run HOTP distribution tests
38+
createHOTPDistributionTests({
39+
describe,
40+
it,
41+
expect,
42+
crypto,
43+
base32,
44+
});
6245

63-
// Create Deno test context for otplib
64-
const otplibCtx = createDenoTestContext(
65-
{ assertEquals, assertNotEquals, assertMatch, assertThrows, assertInstanceOf },
66-
{ crypto, base32 },
67-
);
46+
// Run TOTP distribution tests
47+
createTOTPDistributionTests({
48+
describe,
49+
it,
50+
expect,
51+
crypto,
52+
base32,
53+
});
6854

55+
// Run otplib distribution tests
6956
createOtplibDistributionTests({
70-
...otplibCtx,
57+
describe,
58+
it,
59+
expect,
60+
crypto,
61+
base32,
7162
otplib: {
7263
generateSecret,
7364
generateURI,
@@ -79,4 +70,3 @@ createOtplibDistributionTests({
7970
OTP,
8071
},
8172
});
82-
otplibCtx.runTests();

internal/testing/src/deno-adapter.ts

Lines changed: 0 additions & 248 deletions
This file was deleted.

internal/testing/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
export * from "./deno-adapter.js";
21
export * from "./hooks.js";
32
export * from "./rfc-hmac-tests.js";
43
export * from "./rfc-test-vectors.js";

0 commit comments

Comments
 (0)