Skip to content

Commit

Permalink
test: migrate to vitest from jest (#64)
Browse files Browse the repository at this point in the history
We use vitest on UI, migrating other projects to use vitest as well.
  • Loading branch information
Sekhmet authored Feb 20, 2024
1 parent 3dda61b commit 2653413
Show file tree
Hide file tree
Showing 42 changed files with 103 additions and 1,398 deletions.
20 changes: 0 additions & 20 deletions apps/api/jest.config.ts

This file was deleted.

10 changes: 4 additions & 6 deletions apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"build": "tsc -p tsconfig.build.json",
"dev": "nodemon src/index.ts",
"start": "node dist/src/index.js",
"test": "jest"
"test": "vitest run"
},
"eslintConfig": {
"extends": "@snapshot-labs"
Expand All @@ -27,7 +27,6 @@
"@snapshot-labs/checkpoint": "^0.1.0-beta.27",
"@snapshot-labs/sx": "^0.1.0",
"@types/bn.js": "^5.1.0",
"@types/jest": "^29.4.1",
"@types/mysql": "^2.15.21",
"@types/node": "^18.11.6",
"cross-fetch": "^4.0.0",
Expand All @@ -38,12 +37,11 @@
"@snapshot-labs/eslint-config": "0.1.0-beta.13",
"@snapshot-labs/prettier-config": "0.1.0-beta.11",
"eslint": "^8.53.0",
"jest": "^29.4.1",
"jest-mock-extended": "^2.0.6",
"nodemon": "^3.0.1",
"prettier": "^3.1.0",
"ts-jest": "^29.1.1",
"ts-node": "^10.9.1",
"typescript": "^5.2.2"
"typescript": "^5.2.2",
"vitest": "^1.2.2",
"vitest-mock-extended": "^1.3.1"
}
}
4 changes: 2 additions & 2 deletions apps/api/test/unit/__snapshots__/writer.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`handleDeploy should create space with correct parameters 1`] = `
exports[`handleDeploy > should create space with correct parameters 1`] = `
[
[
"INSERT IGNORE INTO spaces SET ?;",
Expand Down
3 changes: 2 additions & 1 deletion apps/api/test/unit/writer.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { mockDeep } from 'jest-mock-extended';
import { describe, it, expect } from 'vitest';
import { mockDeep } from 'vitest-mock-extended';
import { AsyncMySqlPool } from '@snapshot-labs/checkpoint';
import { validateAndParseAddress } from 'starknet';

Expand Down
14 changes: 6 additions & 8 deletions packages/sx.js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
"prepublishOnly": "yarn run lint",
"node:evm": "anvil",
"node:starknet": "OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES starknet-devnet --seed 1",
"test": "jest -c test/jest.config.unit.js",
"test:integration:starknet": "jest -c test/jest.config.integration.js test/integration/starknet",
"test:integration:evm": "jest -c test/jest.config.integration.js test/integration/evm",
"test:integration:offchain": "jest -c test/jest.config.integration.js test/integration/offchain"
"test": "vitest run test/unit",
"test:integration:starknet": "vitest run test/integration/starknet",
"test:integration:evm": "vitest run test/integration/evm",
"test:integration:offchain": "vitest run test/integration/offchain"
},
"eslintConfig": {
"extends": "@snapshot-labs"
Expand Down Expand Up @@ -60,13 +60,11 @@
"@snapshot-labs/prettier-config": "0.1.0-beta.11",
"@types/bn.js": "^5.1.1",
"@types/elliptic": "^6.4.14",
"@types/jest": "^29.4.1",
"@types/node": "^18.11.9",
"eslint": "^8.53.0",
"jest": "^29.4.1",
"prettier": "^3.1.0",
"ts-jest": "^29.1.1",
"typescript": "^5.2.2"
"typescript": "^5.2.2",
"vitest": "^1.2.2"
},
"files": [
"dist/**/*",
Expand Down
1 change: 1 addition & 0 deletions packages/sx.js/test/integration/evm/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it, expect, beforeAll } from 'vitest';
import { JsonRpcProvider } from '@ethersproject/providers';
import { Wallet } from '@ethersproject/wallet';
import { EthereumTx } from '../../../src/clients/evm/ethereum-tx';
Expand Down
1 change: 1 addition & 0 deletions packages/sx.js/test/integration/offchain/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it, expect } from 'vitest';
import { Wallet } from '@ethersproject/wallet';
import { EthereumSig } from '../../../src/clients/offchain/ethereum-sig';
import { offchainGoerli } from '../../../src/offchainNetworks';
Expand Down
1 change: 1 addition & 0 deletions packages/sx.js/test/integration/starknet/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it, expect, beforeAll } from 'vitest';
import { Account, Provider, uint256 } from 'starknet';
import { JsonRpcProvider } from '@ethersproject/providers';
import { Wallet } from '@ethersproject/wallet';
Expand Down
7 changes: 0 additions & 7 deletions packages/sx.js/test/jest.config.base.js

This file was deleted.

6 changes: 0 additions & 6 deletions packages/sx.js/test/jest.config.integration.js

This file was deleted.

6 changes: 0 additions & 6 deletions packages/sx.js/test/jest.config.unit.js

This file was deleted.

3 changes: 0 additions & 3 deletions packages/sx.js/test/setup.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it, expect } from 'vitest';
import createEthSigAuthenticator from '../../../../src/authenticators/starknet/ethSig';
import { proposeEthSigEnvelope } from '../../fixtures';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it, expect } from 'vitest';
import createEthTxAuthenticator from '../../../../src/authenticators/starknet/ethTx';
import { proposeEnvelope } from '../../fixtures';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it, expect } from 'vitest';
import { getAuthenticator } from '../../../../src/authenticators/starknet';
import { starknetNetworks, starknetGoerli } from '../../../../src/networks';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it, expect } from 'vitest';
import createStarkSigAuthenticator from '../../../../src/authenticators/starknet/starkSig';
import { proposeEnvelope } from '../../fixtures';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it, expect } from 'vitest';
import createStarkTxAuthenticator from '../../../../src/authenticators/starknet/starkTx';
import { proposeEnvelope } from '../../fixtures';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it, expect } from 'vitest';
import createVanillaAuthenticator from '../../../../src/authenticators/starknet/vanilla';
import { proposeEnvelope } from '../../fixtures';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`EthereumSig should create propose envelope 1`] = `
exports[`EthereumSig > should create propose envelope 1`] = `
{
"data": {
"authenticator": "0xc537d997ddc783e071f82ccbfaa0d768d310001b",
Expand Down Expand Up @@ -79,7 +79,7 @@ exports[`EthereumSig should create propose envelope 1`] = `
}
`;

exports[`EthereumSig should create update proposal envelope 1`] = `
exports[`EthereumSig > should create update proposal envelope 1`] = `
{
"data": {
"authenticator": "0xc537d997ddc783e071f82ccbfaa0d768d310001b",
Expand Down Expand Up @@ -153,7 +153,7 @@ exports[`EthereumSig should create update proposal envelope 1`] = `
}
`;

exports[`EthereumSig should create vote envelope 1`] = `
exports[`EthereumSig > should create vote envelope 1`] = `
{
"data": {
"authenticator": "0xc537d997ddc783e071f82ccbfaa0d768d310001b",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it, expect, beforeAll, afterAll, vi } from 'vitest';
import { JsonRpcProvider } from '@ethersproject/providers';
import { Wallet } from '@ethersproject/wallet';
import { EthereumSig } from '../../../../../src/clients/evm/ethereum-sig';
Expand All @@ -15,11 +16,11 @@ describe('EthereumSig', () => {
const ethSigClient = new EthereumSig();

beforeAll(() => {
jest.spyOn(ethSigClient, 'generateSalt').mockImplementation(() => 0);
vi.spyOn(ethSigClient, 'generateSalt').mockImplementation(() => 0);
});

afterAll(() => {
jest.restoreAllMocks();
vi.restoreAllMocks();
});

it('should create propose envelope', async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`EthereumSig should create vote envelope 1`] = `
exports[`EthereumSig > should create vote envelope 1`] = `
{
"data": {
"authenticator": "",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it, expect, beforeAll, afterAll, vi } from 'vitest';
import { Wallet } from '@ethersproject/wallet';
import { EthereumSig } from '../../../../../src/clients/offchain/ethereum-sig';
import { offchainGoerli } from '../../../../../src/offchainNetworks';
Expand All @@ -9,13 +10,13 @@ describe('EthereumSig', () => {
const client = new EthereumSig({ networkConfig: offchainGoerli });

beforeAll(() => {
jest.useFakeTimers({
vi.useFakeTimers({
now: new Date('2024-01-21').getTime()
});
});

afterAll(() => {
jest.restoreAllMocks();
vi.restoreAllMocks();
});

it('should create vote envelope', async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`EthereumSig should create propose envelope 1`] = `
exports[`EthereumSig > should create propose envelope 1`] = `
{
"data": {
"authenticator": "0x48b33fe56e9b9354d4278ffdd5f6d546b13aa3d8c33149db2e2e2fdb48a369e",
Expand Down Expand Up @@ -51,7 +51,7 @@ exports[`EthereumSig should create propose envelope 1`] = `
}
`;

exports[`EthereumSig should create update proposal envelope 1`] = `
exports[`EthereumSig > should create update proposal envelope 1`] = `
{
"data": {
"authenticator": "0x48b33fe56e9b9354d4278ffdd5f6d546b13aa3d8c33149db2e2e2fdb48a369e",
Expand Down Expand Up @@ -95,7 +95,7 @@ exports[`EthereumSig should create update proposal envelope 1`] = `
}
`;

exports[`EthereumSig should create vote envelope 1`] = `
exports[`EthereumSig > should create vote envelope 1`] = `
{
"data": {
"authenticator": "0x48b33fe56e9b9354d4278ffdd5f6d546b13aa3d8c33149db2e2e2fdb48a369e",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it, expect, beforeAll, afterAll, vi } from 'vitest';
import { JsonRpcProvider } from '@ethersproject/providers';
import { Wallet } from '@ethersproject/wallet';
import { starkProvider } from '../../../helpers';
Expand All @@ -18,11 +19,11 @@ describe('EthereumSig', () => {
});

beforeAll(() => {
jest.spyOn(client, 'generateSalt').mockImplementation(() => '0x0');
vi.spyOn(client, 'generateSalt').mockImplementation(() => '0x0');
});

afterAll(() => {
jest.restoreAllMocks();
vi.restoreAllMocks();
});

const { EthSig } = starknetNetworks['sn-tn'].Authenticators;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it, expect } from 'vitest';
import { Wallet } from '@ethersproject/wallet';
import { EthereumTx } from '../../../../../src/clients/starknet/ethereum-tx';
import { starkProvider } from '../../../helpers';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`StarknetSig should create propose envelope 1`] = `
exports[`StarknetSig > should create propose envelope 1`] = `
{
"data": {
"authenticator": "0x5280813396bf63dd47531ccdbfa5887099d44421d3f62db3de8f7bed68794f5",
Expand Down Expand Up @@ -48,7 +48,7 @@ exports[`StarknetSig should create propose envelope 1`] = `
}
`;

exports[`StarknetSig should create update proposal envelope 1`] = `
exports[`StarknetSig > should create update proposal envelope 1`] = `
{
"data": {
"authenticator": "0x5280813396bf63dd47531ccdbfa5887099d44421d3f62db3de8f7bed68794f5",
Expand Down Expand Up @@ -92,7 +92,7 @@ exports[`StarknetSig should create update proposal envelope 1`] = `
}
`;

exports[`StarknetSig should create vote envelope 1`] = `
exports[`StarknetSig > should create vote envelope 1`] = `
{
"data": {
"authenticator": "0x5280813396bf63dd47531ccdbfa5887099d44421d3f62db3de8f7bed68794f5",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it, expect, beforeAll, afterAll, vi } from 'vitest';
import { Account } from 'starknet';
import { starkProvider } from '../../../helpers';
import { StarknetSig } from '../../../../../src/clients/starknet/starknet-sig';
Expand All @@ -17,11 +18,11 @@ describe('StarknetSig', () => {
});

beforeAll(() => {
jest.spyOn(client, 'generateSalt').mockImplementation(() => '0x0');
vi.spyOn(client, 'generateSalt').mockImplementation(() => '0x0');
});

afterAll(() => {
jest.restoreAllMocks();
vi.restoreAllMocks();
});

const { StarkSig } = starknetNetworks['sn-tn'].Authenticators;
Expand Down
1 change: 1 addition & 0 deletions packages/sx.js/test/unit/executors/ethRelayer.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it, expect } from 'vitest';
import createEthRelayerExecutor from '../../../src/executors/ethRelayer';

describe('ethRelayerExecutor', () => {
Expand Down
1 change: 1 addition & 0 deletions packages/sx.js/test/unit/executors/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it, expect } from 'vitest';
import { getExecutionData } from '../../../src/executors';

describe('getExecutionData', () => {
Expand Down
1 change: 1 addition & 0 deletions packages/sx.js/test/unit/executors/vanilla.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it, expect } from 'vitest';
import createVanillaExecutor from '../../../src/executors/vanilla';

describe('vanillaExecutor', () => {
Expand Down
1 change: 1 addition & 0 deletions packages/sx.js/test/unit/strategies/evm/comp.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it, expect } from 'vitest';
import { JsonRpcProvider } from '@ethersproject/providers';
import createCompStrategy from '../../../../src/strategies/evm/comp';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it, expect } from 'vitest';
import { JsonRpcProvider } from '@ethersproject/providers';
import { AbiCoder } from '@ethersproject/abi';
import { StandardMerkleTree } from '@openzeppelin/merkle-tree';
Expand Down
1 change: 1 addition & 0 deletions packages/sx.js/test/unit/strategies/evm/ozVotes.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it, expect } from 'vitest';
import { JsonRpcProvider } from '@ethersproject/providers';
import createOzVotesStrategy from '../../../../src/strategies/evm/ozVotes';

Expand Down
1 change: 1 addition & 0 deletions packages/sx.js/test/unit/strategies/evm/vanilla.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it, expect } from 'vitest';
import { JsonRpcProvider } from '@ethersproject/providers';
import createVanillaStrategy from '../../../../src/strategies/evm/vanilla';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it, expect } from 'vitest';
import createErc20VotesStrategy from '../../../../src/strategies/starknet/erc20Votes';
import { defaultNetwork } from '../../../../src/networks';
import { starkProvider } from '../../helpers';
Expand Down
1 change: 1 addition & 0 deletions packages/sx.js/test/unit/strategies/starknet/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it, expect } from 'vitest';
import { getStrategy } from '../../../../src/strategies/starknet';
import { starknetNetworks, starknetGoerli } from '../../../../src/networks';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it, expect } from 'vitest';
import createMerkleWhitelistStrategy from '../../../../src/strategies/starknet/merkleWhitelist';
import { AddressType, Leaf } from '../../../../src/utils/merkletree';
import { defaultNetwork } from '../../../../src/networks';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it, expect } from 'vitest';
import createOzVotesStorageProofStrategy from '../../../../src/strategies/starknet/ozVotesStorageProof';
import { defaultNetwork } from '../../../../src/networks';
import { starkProvider } from '../../helpers';
Expand Down
Loading

0 comments on commit 2653413

Please sign in to comment.