Skip to content

Commit 72c3403

Browse files
committed
test: cleanup the test suite of no longer needed workarounds
Signed-off-by: Filip Skokan <panva.ip@gmail.com>
1 parent afc7ad3 commit 72c3403

5 files changed

Lines changed: 24 additions & 26 deletions

File tree

test/buffer-slice.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,16 @@ import * as HPKE from '../index.ts'
1515
import { supported } from './support.ts'
1616

1717
test.describe('Buffer.prototype.slice() compatibility', () => {
18-
const run = supported.KEM_MLKEM768_X25519!() ? it : it.skip
18+
const hybridKemOptions = {
19+
skip: supported.KEM_MLKEM768_X25519!()
20+
? false
21+
: 'KEM_MLKEM768_X25519 is unsupported in this runtime',
22+
} satisfies test.TestOptions
23+
1924
test.describe('Hybrid KEM DeserializePrivateKey', () => {
20-
run(
25+
it(
2126
'should not be affected by modifications to the original Buffer after deserialization',
27+
hybridKemOptions,
2228
async () => {
2329
const suite = new HPKE.CipherSuite(
2430
HPKE.KEM_MLKEM768_X25519,
@@ -55,7 +61,7 @@ test.describe('Buffer.prototype.slice() compatibility', () => {
5561
})
5662

5763
test.describe('Hybrid KEM Decap (split function)', () => {
58-
run('should use copied data, not views that can be corrupted', async () => {
64+
it('should use copied data, not views that can be corrupted', hybridKemOptions, async () => {
5965
const suite = new HPKE.CipherSuite(
6066
HPKE.KEM_MLKEM768_X25519,
6167
HPKE.KDF_HKDF_SHA256,
@@ -93,8 +99,9 @@ test.describe('Buffer.prototype.slice() compatibility', () => {
9399
})
94100

95101
test.describe('Hybrid KEM SerializePrivateKey (getSeed)', () => {
96-
run(
102+
it(
97103
'should return independent copies that do not share memory with internal state',
104+
hybridKemOptions,
98105
async () => {
99106
const suite = new HPKE.CipherSuite(
100107
HPKE.KEM_MLKEM768_X25519,

test/custom-keys.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ function getNobleKEM(): HPKE.KEMFactory | undefined {
3030
}
3131

3232
const pqKEMFactory = getSupportedPQKEM()!
33+
// TODO: Use test.describe(..., { skip }) once Bun honors node:test suite skip options.
3334
if (pqKEMFactory) {
3435
test.describe('HybridKey internal protection', () => {
3536
async function getHybridKeyPair() {

test/pummel.ts

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import it, * as test from 'node:test'
2+
import { setImmediate } from 'node:timers/promises'
23

34
import * as HPKE from '../index.ts'
45
import {
@@ -53,9 +54,7 @@ function runPummelTests(
5354
}
5455

5556
test.describe(`pummel (${name})`, () => {
56-
// @ts-ignore
57-
if (typeof Deno !== 'object')
58-
test.afterEach(() => new Promise((resolve) => setImmediate(resolve)))
57+
test.afterEach(() => setImmediate())
5958

6059
test.describe('Algorithm implementation returns', () => {
6160
for (const Algorithm of [...KEMS.values(), ...KDFS.values(), ...AEADS.values()]) {
@@ -686,20 +685,8 @@ test.describe('Unsupported WebCrypto algorithms', () => {
686685
await suite.Open(skR, enc, ct)
687686
},
688687
(err: Error) => {
689-
try {
690-
t.assert.strictEqual(err.name, 'NotSupportedError')
691-
t.assert.strictEqual(
692-
err.message,
693-
`${expectedAlgorithmName} is unsupported in this runtime`,
694-
)
695-
} catch (assertion) {
696-
// @ts-ignore Deno doesn't always conform to throwing DOMException with name=NotSupportedError on unsupported algorithms
697-
if (typeof Deno === 'object') {
698-
if (err.name === 'DeriveKeyPairError') return true
699-
}
700-
701-
throw assertion
702-
}
688+
t.assert.strictEqual(err.name, 'NotSupportedError')
689+
t.assert.strictEqual(err.message, `${expectedAlgorithmName} is unsupported in this runtime`)
703690

704691
return true
705692
},

test/validations.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ const notBoolean = [
2525
{ name: 'object', value: {} },
2626
]
2727

28+
// TODO: Replace table-case assertion loops with t.test() subtests once Bun's node:test
29+
// implementation supports nested tests.
2830
async function assertRejectsSharedArrayBuffer(
2931
t: test.TestContext,
3032
name: string,

test/vectors.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import it, * as test from 'node:test'
22
import * as fs from 'node:fs/promises'
3+
import { setImmediate } from 'node:timers/promises'
34

45
import * as HPKE from '../index.ts'
56
import {
@@ -96,9 +97,7 @@ const implementations = [
9697

9798
for (const impl of implementations) {
9899
test.describe(`vectors ${impl.name}`, () => {
99-
// @ts-ignore
100-
if (typeof Deno !== 'object')
101-
test.afterEach(() => new Promise((resolve) => setImmediate(resolve)))
100+
test.afterEach(() => setImmediate())
102101

103102
let total = 0
104103
for (const vector of vectors) {
@@ -183,14 +182,16 @@ for (const impl of implementations) {
183182
KDF: KDF ?? { id: vector.kdf_id, name: getSuiteName('KDF', vector.kdf_id) },
184183
AEAD: AEAD ?? { id: vector.aead_id, name: getSuiteName('AEAD', vector.aead_id) },
185184
}
186-
it.skip(`[${i}][not implemented] ${label(suite as HPKE.CipherSuite, vector.mode)}`)
185+
it(`[${i}][not implemented] ${label(suite as HPKE.CipherSuite, vector.mode)}`, {
186+
skip: 'not implemented',
187+
})
187188
continue
188189
}
189190

190191
const suite = new HPKE.CipherSuite(KEM.factory, KDF.factory, AEAD.factory)
191192

192193
if (!KEM.supported || !KDF.supported || !AEAD.supported) {
193-
it.skip(`[${i}][not supported] ${label(suite, vector.mode)}`)
194+
it(`[${i}][not supported] ${label(suite, vector.mode)}`, { skip: 'not supported' })
194195
continue
195196
}
196197

0 commit comments

Comments
 (0)