|
1 | | -import { bench, describe } from 'vitest'; |
| 1 | +import { describe, test } from 'vitest'; |
2 | 2 |
|
3 | 3 | type Uint8ArrayWithBase64 = typeof Uint8Array & { |
4 | 4 | fromBase64?: (str: string) => Uint8Array; |
@@ -79,22 +79,28 @@ for (const payload of payloads) { |
79 | 79 | describe('decode base64 for basic-auth payloads', () => { |
80 | 80 | for (const payload of payloads) { |
81 | 81 | describe(payload.name, () => { |
82 | | - bench.skipIf(!hasUint8ArrayFromBase64)( |
| 82 | + test.skipIf(!hasUint8ArrayFromBase64)( |
83 | 83 | 'Uint8Array.fromBase64 + TextDecoder', |
84 | | - () => { |
85 | | - decodeBase64WithUint8Array(payload.encoded); |
| 84 | + async ({ bench }) => { |
| 85 | + await bench('Uint8Array.fromBase64 + TextDecoder', () => { |
| 86 | + decodeBase64WithUint8Array(payload.encoded); |
| 87 | + }).run(); |
86 | 88 | }, |
87 | 89 | ); |
88 | 90 |
|
89 | | - bench.skipIf(!hasNodeBuffer)( |
| 91 | + test.skipIf(!hasNodeBuffer)( |
90 | 92 | 'Buffer.from(base64).toString(utf-8)', |
91 | | - () => { |
92 | | - decodeBase64WithNodeBuffer(payload.encoded); |
| 93 | + async ({ bench }) => { |
| 94 | + await bench('Buffer.from(base64).toString(utf-8)', () => { |
| 95 | + decodeBase64WithNodeBuffer(payload.encoded); |
| 96 | + }).run(); |
93 | 97 | }, |
94 | 98 | ); |
95 | 99 |
|
96 | | - bench('atob + Uint8Array.from + TextDecoder', () => { |
97 | | - decodeBase64WithAtob(payload.encoded); |
| 100 | + test('atob + Uint8Array.from + TextDecoder', async ({ bench }) => { |
| 101 | + await bench('atob + Uint8Array.from + TextDecoder', () => { |
| 102 | + decodeBase64WithAtob(payload.encoded); |
| 103 | + }).run(); |
98 | 104 | }); |
99 | 105 | }); |
100 | 106 | } |
|
0 commit comments