Skip to content

Commit 1324048

Browse files
committed
Tests: migrate from karma (deprecated) to vitest
1 parent 7632956 commit 1324048

21 files changed

Lines changed: 916 additions & 2399 deletions

eslint.config.mjs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ import eslint from '@eslint/js';
33
import { defineConfig } from 'eslint/config';
44
import tseslint from 'typescript-eslint';
55
import globals from 'globals';
6-
// @ts-expect-error
7-
import pluginChaiFriendly from 'eslint-plugin-chai-friendly';
86
import pluginImport from 'eslint-plugin-import';
97
// @ts-expect-error
108
import pluginEnforceUint8ArrayArrayBuffer from '@protontech/eslint-plugin-enforce-uint8array-arraybuffer';
@@ -32,7 +30,6 @@ export default defineConfig(
3230
}
3331
},
3432
plugins: {
35-
'chai-friendly': pluginChaiFriendly,
3633
'import': pluginImport,
3734
'@protontech/enforce-uint8array-arraybuffer': pluginEnforceUint8ArrayArrayBuffer,
3835
'@stylistic': pluginStylistic
@@ -65,7 +62,6 @@ export default defineConfig(
6562
capIsNew: false
6663
}],
6764
'class-methods-use-this': 'error',
68-
'chai-friendly/no-unused-expressions': [ 'error', { allowShortCircuit: true } ],
6965
'arrow-body-style': 'off',
7066
'space-before-function-paren': 'off',
7167
'operator-linebreak': 'off',

karma.conf.js

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

package.json

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"tsconfig.json"
1414
],
1515
"scripts": {
16-
"test": "karma start karma.conf.js",
16+
"test": "vitest --config test/vitest.config.ts --run",
1717
"lint": "eslint eslint.config.mjs lib test",
1818
"postversion": "git push && git push --tags",
1919
"test-type-definitions": "tsc"
@@ -39,37 +39,21 @@
3939
"@protontech/eslint-plugin-enforce-uint8array-arraybuffer": "^2.0.0",
4040
"@stylistic/eslint-plugin": "^5.9.0",
4141
"@types/bn.js": "^5.2.0",
42-
"@types/chai": "^5.2.3",
43-
"@types/chai-as-promised": "^8.0.2",
4442
"@types/elliptic": "^6.4.18",
45-
"@types/mocha": "^10.0.10",
4643
"@types/sinon": "^21.0.0",
47-
"@types/webpack-env": "^1.18.8",
4844
"@typescript-eslint/eslint-plugin": "^8.56.1",
45+
"@vitest/browser-playwright": "^4.1.2",
4946
"bn.js": "^5.2.3",
50-
"chai": "^6.2.2",
51-
"chai-as-promised": "^8.0.2",
5247
"elliptic": "^6.6.1",
5348
"eslint": "^9.39.3",
5449
"eslint-import-resolver-typescript": "^4.4.4",
55-
"eslint-plugin-chai-friendly": "^1.1.0",
5650
"eslint-plugin-import": "^2.32.0",
57-
"karma": "^6.4.4",
58-
"karma-chrome-launcher": "^3.2.0",
59-
"karma-firefox-launcher": "^2.1.3",
60-
"karma-mocha": "^2.0.1",
61-
"karma-mocha-reporter": "^2.2.5",
62-
"karma-webkit-launcher": "^2.6.0",
63-
"karma-webpack": "^5.0.1",
64-
"mocha": "^11.7.5",
6551
"playwright": "^1.58.1",
6652
"sinon": "^21.0.1",
67-
"ts-loader": "^9.5.4",
68-
"typescript": "^5.9.3",
53+
"typescript": "^6.0.2",
6954
"typescript-eslint": "^8.56.1",
70-
"web-streams-polyfill": "^3.3.3",
71-
"webpack": "^5.105.2",
72-
"webpack-cli": "^6.0.1"
55+
"vitest": "^4.1.2",
56+
"web-streams-polyfill": "^3.3.3"
7357
},
7458
"packageManager": "yarn@4.10.2",
7559
"engines": {

test/bigInteger.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { expect } from 'chai';
1+
import { describe, it, expect } from 'vitest';
22

33
import BN from 'bn.js';
44
import { bigIntToUint8Array, bitLength, byteLength, modExp, modInv } from '../lib/bigInteger';

test/config.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { expect } from 'chai';
1+
import { describe, it, expect } from 'vitest';
22
import { config, SymEncryptedSessionKeyPacket, GrammarError } from '../lib/openpgp';
33
import { decryptMessage, readMessage, VERIFICATION_STATUS, verifyMessage, readKey, readSignature, readPrivateKey } from '../lib';
44

@@ -115,7 +115,7 @@ habAyxd1AGKaNp1wbGFpbnRleHQgbWVzc2FnZQ==
115115

116116
await expect(
117117
readMessage({ armoredMessage: skeskPlusLiteralData })
118-
).to.be.rejectedWith(GrammarError);
118+
).rejects.toThrow(GrammarError);
119119

120120
const message = await readMessage({ armoredMessage: skeskPlusLiteralData, config: { enforceGrammar: false } });
121121
expect(message.packets[0]).to.be.instanceOf(SymEncryptedSessionKeyPacket);

test/crypto/argon2.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { expect } from 'chai';
1+
import { describe, it, expect } from 'vitest';
22
import { argon2 } from '../../lib';
33
import { ARGON2_PARAMS } from '../../lib/constants';
44
import { arrayToHexString, hexStringToArray } from '../../lib/utils';

test/crypto/hash.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { expect } from 'chai';
1+
import { describe, it, expect } from 'vitest';
22
import { unsafeMD5, unsafeSHA1, SHA256, SHA512 } from '../../lib';
33
import { arrayToHexString, stringToUtf8Array } from '../../lib/utils';
44

test/key/check.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { expect } from 'chai';
1+
import { describe, it, expect } from 'vitest';
22
import { checkKeyStrength, checkKeyCompatibility, readKey } from '../../lib';
33

44
// Test vector from https://www.ietf.org/archive/id/draft-ietf-openpgp-pqc-09.html#appendix-A.4.1

test/key/forwarding.spec.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { expect } from 'chai';
1+
import { describe, it, expect } from 'vitest';
22
import { ec as EllipticCurve } from 'elliptic';
33
import BN from 'bn.js';
44

@@ -76,7 +76,7 @@ yGZuVVMAK/ypFfebDf4D/rlEw3cysv213m8aoK8nAUO8xQX3XQq3Sg+EGm0BNV8E
7676
await expect(decryptMessage({
7777
message: await readMessage({ armoredMessage: fwdCiphertextArmored }),
7878
decryptionKeys: charlieKey
79-
})).to.be.rejectedWith(/Error decrypting message/); // missing config flag
79+
})).rejects.toThrow(/Error decrypting message/); // missing config flag
8080

8181
const result = await decryptMessage({
8282
message: await readMessage({ armoredMessage: fwdCiphertextArmored }),
@@ -189,7 +189,7 @@ z5FbOJXSHsoez1SZ7GKgoxC+X0w=
189189

190190
await expect(
191191
generateForwardingMaterial(keyWithP256Subkey, [{ name: 'Charlie', email: 'info@charlie.com' }])
192-
).to.be.rejectedWith(/unsuitable for forwarding/);
192+
).rejects.toThrow(/unsuitable for forwarding/);
193193
});
194194

195195
it('decryption with forwarding - v4 key', async () => {
@@ -235,7 +235,7 @@ z5FbOJXSHsoez1SZ7GKgoxC+X0w=
235235
decryptionKeys: charlieKey,
236236
config: { allowForwardedMessages: true }
237237
});
238-
expect(decryptionTrialPromise).to.be.rejectedWith(/Error decrypting message/);
238+
await expect(decryptionTrialPromise).rejects.toThrow(/Error decrypting message/);
239239
});
240240

241241
it('decryption with forwarding - v4 key with multiple subkeys', async () => {
@@ -426,9 +426,9 @@ siLL+xMJ+Hy4AhsMAAAKagEA4Knj6S6nG24nuXfqkkytPlFTHwzurjv3+qqXwWL6
426426
=un5O
427427
-----END PGP PRIVATE KEY BLOCK-----` });
428428

429-
await expect(isForwardingKey(signOnlyKey)).to.eventually.be.false;
430-
await expect(isForwardingKey(charlieKeyEncrypted)).to.eventually.be.true;
431-
await expect(isForwardingKey(charlieKey)).to.eventually.be.true;
432-
await expect(isForwardingKey(bobKey)).to.eventually.be.false;
429+
await expect(isForwardingKey(signOnlyKey)).resolves.toBe(false);
430+
await expect(isForwardingKey(charlieKeyEncrypted)).resolves.toBe(true);
431+
await expect(isForwardingKey(charlieKey)).resolves.toBe(true);
432+
await expect(isForwardingKey(bobKey)).resolves.toBe(false);
433433
});
434434
});

test/key/utils.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { expect } from 'chai';
1+
import { describe, it, expect } from 'vitest';
22
import { createSandbox as createSinonSandbox } from 'sinon';
33
import { revokeKey, sign, createMessage, enums } from '../../lib/openpgp';
44
import {

0 commit comments

Comments
 (0)