Skip to content

Commit

Permalink
add unit and e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zapaz committed Dec 27, 2024
1 parent 57f68cf commit 46868bd
Show file tree
Hide file tree
Showing 29 changed files with 446 additions and 159 deletions.
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@kredeum/wagmi-svelte5",
"version": "0.1.4",
"version": "0.1.5",
"description": "Svelte5 Web3 library based on Wagmi",
"keywords": [
"svelte",
Expand Down Expand Up @@ -33,10 +33,10 @@
"format": "prettier --write --list-different .",
"check": "prettier --check . && eslint . && svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
"build": "vite build",
"test": "npm run test:unit -- --run && npm run test:e2e",
"test": "npm run test:unit && npm run test:e2e",
"dev": "vite dev",
"preview": "vite preview",
"test:unit": "vitest",
"test:unit": "vitest run",
"test:e2e": "playwright test",
"package": "NODE_ENV=prod svelte-kit sync && svelte-package && publint"
},
Expand All @@ -53,6 +53,7 @@
"@sveltejs/kit": "^2.15.0",
"@sveltejs/package": "^2.3.7",
"@sveltejs/vite-plugin-svelte": "^4.0.4",
"@types/node": "^22.10.2",
"@wagmi/connectors": "^5.7.3",
"@wagmi/core": "^2.16.3",
"@walletconnect/ethereum-provider": "^2.17.3",
Expand All @@ -63,6 +64,7 @@
"eslint-plugin-svelte": "^2.46.1",
"esm-env": "^1.2.1",
"globals": "^15.14.0",
"happy-dom": "^16.0.1",
"prettier": "^3.4.2",
"prettier-plugin-svelte": "^3.3.2",
"prettier-plugin-tailwindcss": "^0.6.9",
Expand Down
3 changes: 2 additions & 1 deletion playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ export default defineConfig({
port: 4173
},

testDir: "tests/e2e"
testDir: "tests/e2e",
testMatch: "*.t.ts"
});
105 changes: 74 additions & 31 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions src/lib/wagmi/classes/Account.svelte.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { getAccount, watchAccount } from "@wagmi/core";
import { Address, wagmiConfig } from "..";
import type { Nullable } from "..";

type AccountType = ReturnType<typeof getAccount>;
import type { Nullable, AccountType } from "..";

// Account => account & chain & chainId & isConnected & connectorId
// Address => address & balance & symbol & decimals & ensName & ensAvatar
Expand All @@ -25,7 +23,7 @@ class Account extends Address {
watch = () =>
watchAccount(wagmiConfig, {
onChange: (newAccount: AccountType) => {
console.log("watchAccount Change:", newAccount);
console.info("watchAccount Change:", newAccount);
this.#account = newAccount;
super.address = newAccount.address;
}
Expand Down
13 changes: 4 additions & 9 deletions src/lib/wagmi/classes/Events.svelte.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import { type Address as AddressType, type ContractEventName, type Log } from "viem";
import { type Address as AddressType, type ContractEventName } from "viem";
import { watchContractEvent, getBlockNumber } from "@wagmi/core";

import { type LogWithArgs, SmartContract, wagmi, wagmiConfig, getContractEvents } from "..";

type EventsFilter = { eventName?: ContractEventName; args?: Record<string, unknown> };
type EventsSortOrder = "DESC" | "ASC" | undefined;
import { type LogWithArgs, type EventsFilter, type EventsSortOrder, SmartContract, wagmi, wagmiConfig, getContractEvents } from "..";

class Events extends SmartContract {
limit: number = $state(0);
Expand Down Expand Up @@ -73,7 +69,7 @@ class Events extends SmartContract {
return blockDelta > 0 ? 1 : blockDelta < 0 ? -1 : indexDelta;
}
);
console.log("EVENTS fetch", this.listAll.length, params, $state.snapshot(this.listAll));
// console.log("EVENTS fetch", this.listAll.length, params, $state.snapshot(this.listAll));
} catch (error) {
console.error("EVENTS Failed to fetch logs:", error);
}
Expand Down Expand Up @@ -106,7 +102,7 @@ class Events extends SmartContract {

$effect(() => {
wagmi.chainId;
console.log("EVENTS $effect ~ chainId :", wagmi.chainId);
// console.log("EVENTS $effect ~ chainId :", wagmi.chainId);
this.fetch(watch);
});

Expand All @@ -115,4 +111,3 @@ class Events extends SmartContract {
}

export { Events };
export type { EventsFilter, EventsSortOrder };
Loading

0 comments on commit 46868bd

Please sign in to comment.