Skip to content

Commit

Permalink
chore(testing): replaced jest with vitest
Browse files Browse the repository at this point in the history
  • Loading branch information
piotr-roslaniec committed Sep 12, 2023
1 parent 908fef9 commit b7a4b79
Show file tree
Hide file tree
Showing 34 changed files with 222 additions and 291 deletions.
22 changes: 0 additions & 22 deletions jest.config.base.js

This file was deleted.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"typecheck": "pnpm --parallel --aggregate-output --reporter append-only typecheck",
"build": "tsc --build --verbose ./tsconfig.prod.json",
"watch": "tsc --build --verbose --watch ./tsconfig.prod.json",
"test": "pnpm run --parallel --aggregate-output --reporter append-only --filter './packages/**' test",
"test": "vitest run",
"test:fix": "pnpm fix && pnpm format:fix && pnpm typecheck && pnpm test",
"package:check": "pnpm run --parallel --aggregate-output --reporter append-only --filter './packages/**' package-check",
"packages:lint": "pnpm packages:sort --check",
Expand All @@ -31,6 +31,7 @@
"@types/node": "^18.17.14",
"@typescript-eslint/eslint-plugin": "^6.6.0",
"@typescript-eslint/parser": "^6.6.0",
"@vitest/coverage-v8": "^0.34.4",
"bundlemon": "^2.0.2",
"eslint": "^8.48.0",
"eslint-config-prettier": "^9.0.0",
Expand All @@ -52,7 +53,8 @@
"ts-unused-exports": "^10.0.1",
"typedoc": "^0.25.1",
"typedoc-plugin-missing-exports": "^2.1.0",
"typescript": "^5.2.2"
"typescript": "^5.2.2",
"vitest": "^0.34.4"
},
"bundlemon": {
"baseDir": ".",
Expand Down
6 changes: 0 additions & 6 deletions packages/pre/babel.config.json

This file was deleted.

10 changes: 0 additions & 10 deletions packages/pre/jest.config.js

This file was deleted.

3 changes: 1 addition & 2 deletions packages/pre/test/pre.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {test, expect} from 'vitest';

import { test, expect } from 'vitest';

test('pre', () => {
expect('pre').toBe('pre');
Expand Down
6 changes: 0 additions & 6 deletions packages/shared/babel.config.json

This file was deleted.

7 changes: 0 additions & 7 deletions packages/shared/jest.config.js

This file was deleted.

4 changes: 1 addition & 3 deletions packages/shared/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@ export * from './types';
export * from './utils';
export * from './web3';


// Forming modules for convenience
// TODO: Should we strucutre shared exports like this?
import * as conditions from './conditions';

export {conditions};

export { conditions };

// Re-exports
export {
Expand Down
9 changes: 5 additions & 4 deletions packages/shared/test/acceptance/alice-grants.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
PublicKey,
VerifiedKeyFrag,
} from '@nucypher/nucypher-core';
import { test } from 'vitest';

import { EnactedPolicy, Enrico } from '../../src';
import { Ursula } from '../../src';
Expand All @@ -29,7 +30,7 @@ import {
reencryptKFrags,
} from '../utils';

describe('story: alice shares message with bob through policy', () => {
test('story: alice shares message with bob through policy', () => {
const message = 'secret-message-from-alice';
const threshold = 2;
const shares = 3;
Expand All @@ -51,7 +52,7 @@ describe('story: alice shares message with bob through policy', () => {
let aliceVerifyingKey: PublicKey;
let policyEncryptingKey: PublicKey;

it('alice grants a new policy to bob', async () => {
test('alice grants a new policy to bob', async () => {
const getUrsulasSpy = mockGetUrsulas(mockedUrsulas);
const generateKFragsSpy = mockGenerateKFrags();
const publishToBlockchainSpy = mockPublishToBlockchain();
Expand Down Expand Up @@ -95,12 +96,12 @@ describe('story: alice shares message with bob through policy', () => {
verifiedKFrags = makeTreasureMapSpy.mock.calls[0][1] as VerifiedKeyFrag[];
});

it('enrico encrypts the message', () => {
test('enrico encrypts the message', () => {
const enrico = new Enrico(policyEncryptingKey);
encryptedMessage = enrico.encryptMessagePre(toBytes(message));
});

it('bob retrieves and decrypts the message', async () => {
test('bob retrieves and decrypts the message', async () => {
const bob = fakeBob();
const getUrsulasSpy = mockGetUrsulas(mockedUrsulas);
const retrieveCFragsSpy = mockRetrieveCFragsRequest(
Expand Down
5 changes: 3 additions & 2 deletions packages/shared/test/acceptance/delay-enact.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import {
mockGetUrsulas,
mockPublishToBlockchain,
} from '../utils';
import { test } from 'vitest';

describe('story: alice creates a policy but someone else enacts it', () => {
test('story: alice creates a policy but someone else enacts it', () => {
const threshold = 2;
const shares = 3;
const startDate = new Date();
Expand All @@ -22,7 +23,7 @@ describe('story: alice creates a policy but someone else enacts it', () => {
const provider = fakeProvider();
const signer = fakeSigner();

it('alice generates a new policy', async () => {
test('alice generates a new policy', async () => {
const getUrsulasSpy = mockGetUrsulas(mockedUrsulas);
const generateKFragsSpy = mockGenerateKFrags();
const publishToBlockchainSpy = mockPublishToBlockchain();
Expand Down
15 changes: 9 additions & 6 deletions packages/shared/test/docs/cbd.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { MessageKit, VerifiedKeyFrag } from '@nucypher/nucypher-core';
import { providers } from 'ethers';
import { SpyInstance, test, vi } from 'vitest';

import {
Cohort,
Expand Down Expand Up @@ -27,9 +28,11 @@ import {
mockRetrieveCFragsRequest,
} from '../utils';

describe('Get Started (CBD PoC)', () => {
// TODO: move to packages/taco

test('Get Started (CBD PoC)', () => {
function mockRetrieveAndDecrypt(
makeTreasureMapSpy: jest.SpyInstance,
makeTreasureMapSpy: SpyInstance,
encryptedMessageKit: MessageKit,
) {
// Setup mocks for `retrieveAndDecrypt`
Expand All @@ -45,7 +48,7 @@ describe('Get Started (CBD PoC)', () => {
);
}

it('can run the get started example', async () => {
test('can run the get started example', async () => {
const detectEthereumProvider = mockDetectEthereumProvider();
const mockedUrsulas = fakeUrsulas();
const getUrsulasSpy = mockGetUrsulas(mockedUrsulas);
Expand All @@ -54,9 +57,9 @@ describe('Get Started (CBD PoC)', () => {
const makeTreasureMapSpy = mockMakeTreasureMap();
const encryptTreasureMapSpy = mockEncryptTreasureMap();

jest
.spyOn(providers, 'Web3Provider')
.mockImplementation(() => fakeProvider(SecretKey.random().toBEBytes()));
vi.spyOn(providers, 'Web3Provider').mockImplementation(() =>
fakeProvider(SecretKey.random().toBEBytes()),
);

//
// Start of the code example
Expand Down
15 changes: 8 additions & 7 deletions packages/shared/test/integration/dkg-client.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { SecretKey } from '@nucypher/nucypher-core';
import { test, vi, afterEach } from 'vitest';

import { DkgCoordinatorAgent } from '../../src';
import {
Expand All @@ -9,25 +10,25 @@ import {
mockRitualId,
} from '../utils';

jest.mock('../../src/contracts/agents/coordinator', () => ({
vi.mock('../../src/contracts/agents/coordinator', () => ({
DkgCoordinatorAgent: {
getRitual: () => Promise.resolve(mockCoordinatorRitual(mockRitualId)),
getParticipants: () => Promise.resolve(mockDkgParticipants(mockRitualId)),
},
}));

describe('DkgCoordinatorAgent', () => {
test('DkgCoordinatorAgent', () => {
afterEach(() => {
jest.restoreAllMocks();
vi.restoreAllMocks();
});

it('fetches transcripts from the coordinator', async () => {
test('fetches transcripts from the coordinator', async () => {
const provider = fakeProvider(SecretKey.random().toBEBytes());
const ritual = await DkgCoordinatorAgent.getRitual(provider, mockRitualId);
expect(ritual).toBeDefined();
});

it('fetches participants from the coordinator', async () => {
test('fetches participants from the coordinator', async () => {
const provider = fakeProvider(SecretKey.random().toBEBytes());
const fakeParticipants = await mockDkgParticipants(mockRitualId);
const getParticipantsSpy = mockGetParticipants(
Expand All @@ -43,8 +44,8 @@ describe('DkgCoordinatorAgent', () => {
});

// TODO: Fix this test after the DkgClient.verifyRitual() method is implemented
// describe('DkgClient', () => {
// it('verifies the dkg ritual', async () => {
// test('DkgClient', () => {
// test('verifies the dkg ritual', async () => {
// const provider = fakeWeb3Provider(SecretKey.random().toBEBytes());
//
// const dkgClient = new DkgClient(provider);
Expand Down
11 changes: 6 additions & 5 deletions packages/shared/test/integration/enrico.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ import {
fromBytes,
reencryptKFrags,
} from '../utils';
import { test } from 'vitest';

describe('enrico', () => {
it('alice decrypts message encrypted by enrico', async () => {
test('enrico', () => {
test('alice decrypts message encrypted by enrico', async () => {
const label = 'fake-label';
const message = 'fake-message';
const alice = fakeAlice();
Expand All @@ -28,7 +29,7 @@ describe('enrico', () => {
expect(alicePlaintext).toEqual(alicePlaintext);
});

it('bob decrypts reencrypted message', async () => {
test('bob decrypts reencrypted message', async () => {
const label = 'fake-label';
const alice = fakeAlice();
const bob = fakeBob();
Expand Down Expand Up @@ -88,7 +89,7 @@ describe('enrico', () => {
expect(bytesEqual(decrypted, plaintextBytes)).toBeTruthy();
});

it('enrico generates a message kit with conditions', async () => {
test('enrico generates a message kit with conditions', async () => {
const label = 'fake-label';
const message = 'fake-message';
const alice = fakeAlice();
Expand All @@ -112,7 +113,7 @@ describe('enrico', () => {
expect(alicePlaintext).toEqual(alicePlaintext);
});

it('can overwrite conditions at encryption time', async () => {
test('can overwrite conditions at encryption time', async () => {
const label = 'fake-label';
const message = 'fake-message';
const alice = fakeAlice();
Expand Down
5 changes: 3 additions & 2 deletions packages/shared/test/integration/message-kit.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { MessageKit } from '../../src';
import { toBytes } from '../../src/utils';
import { fakeBob } from '../utils';
import { test } from 'vitest';

describe('message kit', () => {
it('bob decrypts', () => {
test('message kit', () => {
test('bob decrypts', () => {
const bob = fakeBob();
const plaintext = toBytes('fake-message');
const messageKit = new MessageKit(bob.decryptingKey, plaintext, null);
Expand Down
9 changes: 5 additions & 4 deletions packages/shared/test/integration/pre.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { CapsuleFrag, reencrypt } from '@nucypher/nucypher-core';
import { test } from 'vitest';

import {
ConditionExpression,
Expand All @@ -12,7 +13,7 @@ import { CompoundCondition } from '../../src/conditions/base';
import { fakeAlice, fakeBob, fakeUrsulas, reencryptKFrags } from '../utils';
import { ERC721Ownership } from '../../src/conditions/predefined';

describe('proxy reencryption', () => {
test('proxy reencryption', () => {
const plaintext = toBytes('plaintext-message');
const threshold = 2;
const shares = 3;
Expand All @@ -21,7 +22,7 @@ describe('proxy reencryption', () => {
const alice = fakeAlice();
const bob = fakeBob();

it('verifies capsule frags', async () => {
test('verifies capsule frags', async () => {
const { capsule } = new MessageKit(bob.decryptingKey, plaintext, null);
const { delegatingKey, verifiedKFrags } = alice.generateKFrags(
bob,
Expand All @@ -45,7 +46,7 @@ describe('proxy reencryption', () => {
expect(areVerified).toBeTruthy();
});

it('encrypts and decrypts reencrypted message', async () => {
test('encrypts and decrypts reencrypted message', async () => {
const { verifiedKFrags } = alice.generateKFrags(
bob,
label,
Expand Down Expand Up @@ -75,7 +76,7 @@ describe('proxy reencryption', () => {
expect(bobPlaintext).toEqual(plaintext);
});

it('encrypts and decrypts reencrypted message with conditions', async () => {
test('encrypts and decrypts reencrypted message with conditions', async () => {
const { verifiedKFrags } = alice.generateKFrags(
bob,
label,
Expand Down
Loading

0 comments on commit b7a4b79

Please sign in to comment.