Skip to content

Commit

Permalink
test: move packages to workspace vitest (#3551)
Browse files Browse the repository at this point in the history
  • Loading branch information
holic authored Feb 4, 2025
1 parent e6e01e3 commit 2762cef
Show file tree
Hide file tree
Showing 63 changed files with 282 additions and 991 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"typescript.tsdk": "node_modules/typescript/lib"
"typescript.tsdk": "node_modules/typescript/lib",
"vitest.disableWorkspaceWarning": true
}
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
"release:check": "changeset status --verbose --since=origin/main",
"release:publish": "pnpm install && pnpm build && changeset publish",
"release:version": "changeset version && pnpm install --lockfile-only && pnpm run changelog:generate",
"test": "pnpm run --recursive test",
"test:ci": "pnpm run --recursive test:ci",
"test": "with-anvil turbo run test --concurrency=100%",
"test:ci": "with-anvil turbo run test:ci --concurrency=100%",
"type-bench": "pnpm --filter ./test/ts-benchmarks bench",
"type-stats-repo": "attest stats packages/*",
"vercel:prepare": "ln -sf /vercel/.foundry/bin/* node_modules/.bin/ && forge --version"
Expand All @@ -49,17 +49,19 @@
"glob": "^10.4.2",
"husky": ">=6",
"lint-staged": "^15.2.10",
"mock-game-contracts": "workspace:*",
"prettier": "3.2.5",
"prettier-plugin-solidity": "1.3.1",
"prool": "^0.0.16",
"prool": "^0.0.17",
"shx": "^0.3.4",
"sort-package-json": "^2.10.1",
"tsup": "8.3.0",
"tsx": "4.19.0",
"turbo": "^1.9.3",
"typescript": "5.4.2",
"viem": "2.21.19",
"vitest": "2.1.2"
"vitest": "2.1.2",
"with-anvil": "workspace:*"
},
"packageManager": "[email protected]",
"engines": {
Expand Down
2 changes: 1 addition & 1 deletion packages/abi-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"build": "tsup",
"clean": "shx rm -rf dist",
"dev": "tsup --watch",
"test": "vitest typecheck --run --passWithNoTests && vitest --run --passWithNoTests",
"test": "vitest --run",
"test:ci": "pnpm run test"
},
"dependencies": {
Expand Down
5 changes: 2 additions & 3 deletions packages/block-logs-stream/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"clean:js": "shx rm -rf dist",
"dev": "tsup --watch",
"lint": "eslint .",
"test": "vitest typecheck --run --passWithNoTests && vitest --run --passWithNoTests",
"test": "vitest --run",
"test:ci": "pnpm run test"
},
"dependencies": {
Expand All @@ -39,8 +39,7 @@
},
"devDependencies": {
"@types/debug": "^4.1.7",
"viem": "2.21.19",
"vitest": "3.0.4"
"viem": "2.21.19"
},
"peerDependencies": {
"viem": "2.x"
Expand Down
3 changes: 1 addition & 2 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@
"@types/toposort": "^2.0.6",
"@types/yargs": "^17.0.10",
"ds-test": "https://github.com/dapphub/ds-test.git#e282159d5170298eb2455a6c05280ab5a73a4ef0",
"forge-std": "https://github.com/foundry-rs/forge-std.git#74cfb77e308dd188d2f58864aaf44963ae6b88b1",
"vitest": "0.34.6"
"forge-std": "https://github.com/foundry-rs/forge-std.git#74cfb77e308dd188d2f58864aaf44963ae6b88b1"
}
}
6 changes: 2 additions & 4 deletions packages/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"clean": "pnpm run clean:js",
"clean:js": "shx rm -rf dist",
"dev": "tsup --watch",
"test": "vitest typecheck --run --passWithNoTests && vitest --run",
"test": "vitest --run",
"test:ci": "pnpm run test"
},
"dependencies": {
Expand All @@ -82,9 +82,7 @@
},
"devDependencies": {
"@types/debug": "^4.1.7",
"@viem/anvil": "^0.0.7",
"viem": "2.21.19",
"vitest": "0.34.6"
"viem": "2.21.19"
},
"peerDependencies": {
"@aws-sdk/client-kms": "3.x",
Expand Down
14 changes: 8 additions & 6 deletions packages/common/src/account/kms/kmsKeyToAccount.test.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import { describe, it, expect, beforeAll } from "vitest";
import { describe, it, expect, beforeAll, beforeEach } from "vitest";
import { KmsAccount, kmsKeyToAccount } from "./kmsKeyToAccount";
import { CreateKeyCommand, KMSClient } from "@aws-sdk/client-kms";
import { parseGwei, http, verifyMessage, verifyTypedData, createClient, parseEther } from "viem";
import { foundry } from "viem/chains";
import { anvilRpcUrl, testClient } from "../../../test/common";
import { getAnvilRpcUrl, createTestClient, snapshotAnvilState } from "with-anvil";
import { waitForTransaction } from "../../test/waitForTransaction";
import { getTransactionReceipt, sendTransaction } from "viem/actions";
import { getTransactionReceipt, sendTransaction, setBalance } from "viem/actions";

describe.skipIf(!process.env.AWS_ENDPOINT_URL)("kmsKeyToAccount", () => {
let account: KmsAccount;
let keyId: string;

beforeAll(snapshotAnvilState);
beforeEach(snapshotAnvilState);

beforeAll(async () => {
const client = new KMSClient({
region: "local",
Expand All @@ -32,7 +35,6 @@ describe.skipIf(!process.env.AWS_ENDPOINT_URL)("kmsKeyToAccount", () => {
}

keyId = createResponse.KeyMetadata.KeyId;

account = await kmsKeyToAccount({ keyId, client });
});

Expand Down Expand Up @@ -108,11 +110,11 @@ describe.skipIf(!process.env.AWS_ENDPOINT_URL)("kmsKeyToAccount", () => {

it("can execute transactions", async () => {
// Fund the KMS account
testClient.setBalance({ address: account.address, value: parseEther("1") });
setBalance(createTestClient(), { address: account.address, value: parseEther("1") });

const kmsClient = createClient({
chain: foundry,
transport: http(anvilRpcUrl),
transport: http(getAnvilRpcUrl()),
account,
});

Expand Down
4 changes: 2 additions & 2 deletions packages/common/src/codegen/render-solidity/common.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ describe("renderTableId", () => {
it("returns Solidity code to compute table ID", () => {
expect(renderTableId({ namespace: "somewhere", name: "Player", offchainOnly: false })).toMatchInlineSnapshot(`
"
// Hex below is the result of \`WorldResourceIdLib.encode({ namespace: \\"somewhere\\", name: \\"Player\\", typeId: RESOURCE_TABLE });\`
// Hex below is the result of \`WorldResourceIdLib.encode({ namespace: "somewhere", name: "Player", typeId: RESOURCE_TABLE });\`
ResourceId constant _tableId = ResourceId.wrap(0x7462736f6d6577686572650000000000506c6179657200000000000000000000);
"
`);
Expand All @@ -71,7 +71,7 @@ describe("renderTableId", () => {
it("returns Solidity code to compute offchain table ID", () => {
expect(renderTableId({ namespace: "somewhere", name: "Player", offchainOnly: true })).toMatchInlineSnapshot(`
"
// Hex below is the result of \`WorldResourceIdLib.encode({ namespace: \\"somewhere\\", name: \\"Player\\", typeId: RESOURCE_OFFCHAIN_TABLE });\`
// Hex below is the result of \`WorldResourceIdLib.encode({ namespace: "somewhere", name: "Player", typeId: RESOURCE_OFFCHAIN_TABLE });\`
ResourceId constant _tableId = ResourceId.wrap(0x6f74736f6d6577686572650000000000506c6179657200000000000000000000);
"
`);
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/resourceToHex.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe("resourceToHex", () => {
name: "name",
}),
).toThrowErrorMatchingInlineSnapshot(
'"Namespaces must fit into `bytes14`, but \\"AVeryLongNamespace\\" is too long."',
`[Error: Namespaces must fit into \`bytes14\`, but "AVeryLongNamespace" is too long.]`,
);
});

Expand Down
9 changes: 6 additions & 3 deletions packages/common/src/test/minePending.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { testClient } from "../../test/common";
import { getTxpoolContent, mine } from "viem/actions";
import { createTestClient } from "with-anvil";

export async function minePending(): Promise<void> {
const content = await testClient.getTxpoolContent();
const testClient = createTestClient();

const content = await getTxpoolContent(testClient);
if (!Object.keys(content.pending).length) return;

await testClient.mine({ blocks: 1 });
await mine(testClient, { blocks: 1 });
await minePending();
}
4 changes: 2 additions & 2 deletions packages/common/src/test/waitForTransaction.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Hex } from "viem";
import { getTransactionReceipt } from "viem/actions";
import { testClient } from "../../test/common";
import { minePending } from "./minePending";
import { createTestClient } from "with-anvil";

export async function waitForTransaction(hash: Hex): Promise<void> {
await minePending();
const receipt = await getTransactionReceipt(testClient, { hash });
const receipt = await getTransactionReceipt(createTestClient(), { hash });
if (receipt.status === "reverted") {
// TODO: better error
throw new Error(`Transaction reverted (${hash})`);
Expand Down
18 changes: 0 additions & 18 deletions packages/common/test/common.ts

This file was deleted.

13 changes: 0 additions & 13 deletions packages/common/test/globalSetup.ts

This file was deleted.

18 changes: 0 additions & 18 deletions packages/common/test/setup.ts

This file was deleted.

12 changes: 0 additions & 12 deletions packages/common/vitest.config.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/create-mud/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"copy-templates": "tsx ./scripts/copy-templates.ts",
"dev": "tsup --watch",
"prepublishOnly": "npm run clean && npm run build",
"test": "pnpm run copy-templates && pnpm vitest --run && pnpm run test:vanilla && pnpm run test:react && pnpm run test:react-ecs && pnpm run test:phaser && pnpm run test:threejs",
"test": "shx rm -rf test-project && pnpm run copy-templates && pnpm vitest --run && pnpm run test:vanilla && pnpm run test:react && pnpm run test:react-ecs && pnpm run test:phaser && pnpm run test:threejs",
"test:ci": "pnpm run test",
"test:phaser": "bin/cli.js --name test-project --template phaser && pnpm --dir test-project install && shx rm -rf test-project",
"test:react": "bin/cli.js --name test-project --template react && pnpm --dir test-project install && shx rm -rf test-project",
Expand Down
3 changes: 1 addition & 2 deletions packages/dev-tools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@
"autoprefixer": "^10.4.14",
"postcss": "^8.4.23",
"tailwindcss": "^3.3.2",
"viem": "2.21.19",
"vitest": "0.34.6"
"viem": "2.21.19"
},
"peerDependencies": {
"@latticexyz/common": "2.x",
Expand Down
1 change: 0 additions & 1 deletion packages/entrykit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@
"vite": "^5.4.1",
"vite-plugin-dts": "^4.2.4",
"vite-plugin-externalize-deps": "^0.8.0",
"vitest": "0.34.6",
"wagmi": "2.12.11"
},
"peerDependencies": {
Expand Down
3 changes: 1 addition & 2 deletions packages/faucet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@
},
"devDependencies": {
"@types/debug": "^4.1.7",
"viem": "2.21.19",
"vitest": "0.34.6"
"viem": "2.21.19"
},
"peerDependencies": {
"viem": "2.x"
Expand Down
5 changes: 2 additions & 3 deletions packages/gas-report/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"build": "tsup",
"clean": "shx rm -rf dist",
"dev": "tsup --watch",
"test": "vitest typecheck --run --passWithNoTests && vitest --run --passWithNoTests && forge test",
"test": "vitest --run && forge test",
"test:ci": "pnpm run test"
},
"dependencies": {
Expand All @@ -48,7 +48,6 @@
"@types/stream-to-array": "^2.3.1",
"@types/yargs": "^17.0.10",
"ds-test": "https://github.com/dapphub/ds-test.git#e282159d5170298eb2455a6c05280ab5a73a4ef0",
"forge-std": "https://github.com/foundry-rs/forge-std.git#74cfb77e308dd188d2f58864aaf44963ae6b88b1",
"vitest": "0.34.6"
"forge-std": "https://github.com/foundry-rs/forge-std.git#74cfb77e308dd188d2f58864aaf44963ae6b88b1"
}
}
5 changes: 2 additions & 3 deletions packages/protocol-parser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"clean:js": "shx rm -rf dist",
"dev": "tsup --watch",
"lint": "eslint .",
"test": "vitest typecheck --run && vitest --run",
"test": "vitest --run",
"test:ci": "pnpm run test"
},
"dependencies": {
Expand All @@ -43,8 +43,7 @@
"abitype": "1.0.6"
},
"devDependencies": {
"viem": "2.21.19",
"vitest": "0.34.6"
"viem": "2.21.19"
},
"peerDependencies": {
"viem": "2.x"
Expand Down
4 changes: 2 additions & 2 deletions packages/protocol-parser/src/hexToEncodedLengths.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe("hexToEncodedLengths", () => {

it("throws if schema hex data is not bytes32", () => {
expect(() => hexToEncodedLengths("0x01234")).toThrowErrorMatchingInlineSnapshot(
'"Hex value \\"0x01234\\" has length of 5, but expected length of 64 for encoded lengths."',
`[InvalidHexLengthForEncodedLengthsError: Hex value "0x01234" has length of 5, but expected length of 64 for encoded lengths.]`,
);
});

Expand All @@ -29,7 +29,7 @@ describe("hexToEncodedLengths", () => {
hexToEncodedLengths("0x0000000000000000000000000000400000000020000000002000000000000040"),
).toThrowErrorMatchingInlineSnapshot(
// eslint-disable-next-line max-len
'"EncodedLengths \\"0x0000000000000000000000000000400000000020000000002000000000000040\\" total bytes length (64) did not match the summed length of all field byte lengths (128)."',
`[EncodedLengthsLengthMismatchError: EncodedLengths "0x0000000000000000000000000000400000000020000000002000000000000040" total bytes length (64) did not match the summed length of all field byte lengths (128).]`,
);
});
});
3 changes: 1 addition & 2 deletions packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
"eslint-plugin-react-hooks": "4.6.0",
"jsdom": "^22.1.0",
"react-test-renderer": "^18.2.0",
"vite": "^4.3.6",
"vitest": "0.34.6"
"vite": "^4.3.6"
}
}
5 changes: 2 additions & 3 deletions packages/schema-type/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"clean:js": "shx rm -rf dist/typescript",
"dev": "tsup --watch",
"gas-report": "gas-report --save gas-report.json",
"test": "vitest typecheck --run && vitest --run && forge test",
"test": "vitest --run && forge test",
"test:ci": "pnpm run test"
},
"dependencies": {
Expand All @@ -49,8 +49,7 @@
"@latticexyz/gas-report": "workspace:*",
"ds-test": "https://github.com/dapphub/ds-test.git#e282159d5170298eb2455a6c05280ab5a73a4ef0",
"forge-std": "https://github.com/foundry-rs/forge-std.git#74cfb77e308dd188d2f58864aaf44963ae6b88b1",
"viem": "2.21.19",
"vitest": "0.34.6"
"viem": "2.21.19"
},
"peerDependencies": {
"viem": "2.x"
Expand Down
Loading

0 comments on commit 2762cef

Please sign in to comment.