Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions package.json
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: i do not think the testing dependencies should be at the root package.json but the existing jest packages are there so continuining this pattern

Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,13 @@
"@codama/cli": "^1.1.1",
"@eslint/js": "^9.15.0",
"@eslint/json": "^0.7.0",
"@jest/globals": "^30.1.2",
"@solana/eslint-config-solana": "^4.0.0",
"@swc/jest": "^0.2.37",
"@testing-library/dom": "^10.4.1",
"@testing-library/jest-dom": "^6.8.0",
"@testing-library/react": "^16.3.0",
"@testing-library/user-event": "^14.6.1",
"@types/jest": "^29.5.14",
"@types/jscodeshift": "^0.12.0",
"@types/node": "^22",
Expand All @@ -65,6 +70,7 @@
"jscodeshift": "^17.1.1",
"prettier": "^3.3",
"rimraf": "5.0.10",
"ts-jest": "^29.4.1",
"ts-node": "^10.9.2",
"tsup": "^8.3.5",
"turbo": "^2.3.1",
Expand Down
7 changes: 2 additions & 5 deletions packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"test:typecheck": "tsc --noEmit",
"test:unit:node": "TERM_OVERRIDE=\"${TURBO_HASH:+dumb}\" TERM=${TERM_OVERRIDE:-$TERM} jest -c ../../packages/test-config/jest-unit.config.node.ts --rootDir . --silent",
"test:unit:browser": "TERM_OVERRIDE=\"${TURBO_HASH:+dumb}\" TERM=${TERM_OVERRIDE:-$TERM} jest -c ../../packages/test-config/jest-unit.config.browser.ts --rootDir . --silent",
"test:unit:react": "TERM_OVERRIDE=\"${TURBO_HASH:+dumb}\" TERM=${TERM_OVERRIDE:-$TERM} jest -c ../../packages/test-config/jest-unit.config.react.ts --rootDir . --silent",
"test:treeshakability:browser": "agadoo dist/index.browser.mjs",
"test:treeshakability:native": "agadoo dist/index.native.mjs",
"test:treeshakability:node": "agadoo dist/index.node.mjs",
Expand Down Expand Up @@ -63,11 +64,6 @@
"supports bigint and not dead",
"maintained node versions"
],
"devDependencies": {
"@types/react": "^18",
"@types/react-test-renderer": "^18",
"react": "^18"
},
Comment on lines -66 to -70
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: i believe we should only be using peer dependencies for react

"dependencies": {
"gill": "workspace:*"
},
Expand All @@ -76,6 +72,7 @@
"@types/react": "^18",
"@types/react-dom": "^18",
"react": "^18",
"react-dom": "^18",
"typescript": ">=5"
},
"engines": {
Expand Down
31 changes: 31 additions & 0 deletions packages/react/src/__tests__/client.react.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React from "react";
import "@testing-library/jest-dom";
import { renderHook } from "@testing-library/react";
import { createSolanaClient } from "gill";
import { SolanaProvider } from "../providers";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { useSolanaClient } from "../hooks";

describe("useSolanaClient", () => {
test("returns solana client from provider", () => {
const client = createSolanaClient({ urlOrMoniker: "mainnet" });

const { result } = renderHook(() => useSolanaClient(), {
wrapper: ({ children }) => <SolanaProvider client={client}>{children}</SolanaProvider>,
});

expect(result.current).toBe(client);
expect(result.current.rpc).toBeDefined();
});

test("returns fallback devnet client when no provider", () => {
const queryClient = new QueryClient();

const { result } = renderHook(() => useSolanaClient(), {
wrapper: ({ children }) => <QueryClientProvider client={queryClient}>{children}</QueryClientProvider>,
});

expect(result.current).toBeDefined();
expect(result.current.rpc).toBeDefined();
});
});
2 changes: 1 addition & 1 deletion packages/test-config/jest-unit.config.browser.ts
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: i could not find instances of this -test.*.ts pattern in existing test naming conventions so updated it to match how test files are currently named.

Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const config: Partial<Config.InitialProjectOptions> = {
],
testEnvironment: path.resolve(__dirname, "browser-environment.ts"),
testEnvironmentOptions: {},
testPathIgnorePatterns: [...(commonConfig.testPathIgnorePatterns ?? []), "-test.node.ts$"],
testPathIgnorePatterns: [...(commonConfig.testPathIgnorePatterns ?? []), ".node.ts$", ".react.tsx$"],
};

export default config;
7 changes: 2 additions & 5 deletions packages/test-config/jest-unit.config.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,8 @@ const config: Partial<Config.InitialProjectOptions> = {
__NODEJS__: true,
__REACTNATIVE__: false,
},
setupFilesAfterEnv: [
...(commonConfig.setupFilesAfterEnv ?? []),
path.resolve(__dirname, "setup-undici-fetch.ts"),
],
testPathIgnorePatterns: [...(commonConfig.testPathIgnorePatterns ?? []), "-test.browser.ts$"],
setupFilesAfterEnv: [...(commonConfig.setupFilesAfterEnv ?? []), path.resolve(__dirname, "setup-undici-fetch.ts")],
testPathIgnorePatterns: [...(commonConfig.testPathIgnorePatterns ?? []), ".browser.ts$", ".react.tsx$"],
};

export default config;
33 changes: 33 additions & 0 deletions packages/test-config/jest-unit.config.react.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import type { Config } from "jest";
import path from "path";
import { createDefaultPreset } from "ts-jest";

import commonConfig from "./jest-unit.config.common";

const tsJestTransformCfg = createDefaultPreset().transform;

const config: Config = {
...commonConfig,
displayName: {
color: "grey",
name: "Unit Test (React)",
},
globals: {
...commonConfig.globals,
__BROWSER__: false,
__NODEJS__: false,
__REACTNATIVE__: false,
},
setupFilesAfterEnv: [
...(commonConfig.setupFilesAfterEnv ?? []),
path.resolve(__dirname, "setup-testing-library-jest-dom.ts"),
],
testEnvironment: "jsdom",
testPathIgnorePatterns: [...(commonConfig.testPathIgnorePatterns ?? []), ".browser.ts$", ".node.ts$"],
transform: {
...commonConfig.transform,
...tsJestTransformCfg,
},
};

export default config;
1 change: 1 addition & 0 deletions packages/test-config/setup-testing-library-jest-dom.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import "@testing-library/jest-dom";
Loading