Skip to content

Commit 15368cc

Browse files
authored
Merge pull request #123 from simonsobs/dev
Reorganize test code
2 parents edc704c + b21f374 commit 15368cc

14 files changed

+37
-62
lines changed

eslint.config.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,13 @@ export default [
117117
"no-unused-vars": "off",
118118
"@typescript-eslint/no-var-requires": "off",
119119
"@typescript-eslint/no-explicit-any": "off",
120+
"@typescript-eslint/no-unused-vars": [
121+
"error",
122+
{
123+
argsIgnorePattern: "^_",
124+
varsIgnorePattern: "^_",
125+
},
126+
],
120127
"@typescript-eslint/ban-ts-comment": "off",
121128
"prettier/prettier": ["warn", { printWidth: 88 }],
122129
},

src/api/__tests__/run-property-test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import { useQuery, useSubscription } from "@urql/vue";
44
import type { UseQueryResponse, UseSubscriptionResponse } from "@urql/vue";
55
import fc from "fast-check";
66

7+
import { mockUseQueryResponse, mockUseSubscriptionResponse } from "@/graphql/tests";
8+
79
import { fcMockUseQueryResponseArg, fcMockUseSubscriptionResponseArg } from "./fc";
8-
import { mockUseQueryResponse } from "./mock-use-query-response";
9-
import { mockUseSubscriptionResponse } from "./mock-use-subscription-response";
1010

1111
interface _UseSubscribeXXXReturn<R> {
1212
data: ComputedRef<R | undefined>;

src/api/__tests__/scratch.spec.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ import { fromValue, makeSubject, never } from "wonka";
77

88
import type { CtrlStateQuery } from "@/graphql/codegen/generated";
99
import { useCtrlStateQuery } from "@/graphql/codegen/generated";
10-
11-
import { useInSetupWithUrqlClient } from "./setup-with-client";
10+
import { useInSetupWithUrqlClient } from "@/graphql/tests";
1211

1312
function useQueryFromClient(client: MaybeRef<Client>) {
1413
const disposable = useInSetupWithUrqlClient(

src/api/__tests__/use-mapped-with-fallback.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { describe, expect, it } from "vitest";
22
import fc from "fast-check";
33

4-
import { useMappedWithFallback } from "../use-mapped-with-fallback";
4+
import { mockUseQueryResponse } from "@/graphql/tests";
5+
import { mockUseSubscriptionResponse } from "@/graphql/tests/mock-use-subscription-response";
56

6-
import { mockUseQueryResponse } from "./mock-use-query-response";
7-
import { mockUseSubscriptionResponse } from "./mock-use-subscription-response";
7+
import { useMappedWithFallback } from "../use-mapped-with-fallback";
88

99
type QueryData = { ctrl: { state: string } };
1010
type SubscriptionData = { ctrlState: string };

src/api/__tests__/example-use-query.spec.ts renamed to src/graphql/tests/__tests__/example-wonka.spec.ts

Lines changed: 9 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,11 @@
11
import { describe, expect, it } from "vitest";
2-
import type { App, MaybeRef } from "vue";
3-
import { createApp, defineComponent, ref } from "vue";
4-
import { Client, CombinedError, provideClient, useQuery } from "@urql/vue";
2+
import type { MaybeRef } from "vue";
3+
import { ref } from "vue";
4+
import { Client, CombinedError, useQuery } from "@urql/vue";
55
import gql from "graphql-tag";
66
import { fromValue, never } from "wonka";
77

8-
type SetupFunction = () => Record<string, unknown>;
9-
10-
interface WitSetupsOptions {
11-
setupParent: SetupFunction;
12-
setupChild: SetupFunction;
13-
}
14-
15-
class DisposableApp implements Disposable {
16-
constructor(private app: App) {}
17-
18-
[Symbol.dispose]() {
19-
this.app.unmount();
20-
}
21-
}
22-
23-
function withSetups(options: WitSetupsOptions) {
24-
const ParentComponent = defineComponent({
25-
setup: options.setupParent,
26-
template: "<child-component />",
27-
});
28-
29-
const ChildComponent = defineComponent({
30-
setup: options.setupChild,
31-
template: "<template />",
32-
});
33-
34-
const app = createApp(ParentComponent);
35-
app.component("ChildComponent", ChildComponent);
36-
app.mount(document.createElement("div"));
37-
const disposable = new DisposableApp(app);
38-
return { app, [Symbol.dispose]: () => disposable[Symbol.dispose]() };
39-
}
8+
import { useInSetupWithUrqlClient } from "@/graphql/tests";
409

4110
export const FooDocument = gql`
4211
query foo {
@@ -50,19 +19,11 @@ export type FooQuery = {
5019
};
5120

5221
function useQueryFromClient(client: MaybeRef<Client>) {
53-
let query: ReturnType<typeof useQuery<FooQuery>> | undefined;
54-
const app = withSetups({
55-
setupParent() {
56-
provideClient(client);
57-
return {};
58-
},
59-
setupChild() {
60-
query = useQuery<FooQuery>({ query: FooDocument });
61-
return {};
62-
},
63-
});
64-
if (!query) throw new Error("query is undefined");
65-
return { ...app, query, [Symbol.dispose]: () => app[Symbol.dispose]() };
22+
const { ret: query, [Symbol.dispose]: dispose } = useInSetupWithUrqlClient(
23+
() => useQuery<FooQuery>({ query: FooDocument }),
24+
client,
25+
);
26+
return { query, [Symbol.dispose]: () => dispose() };
6627
}
6728

6829
describe("one", () => {

src/api/__tests__/mock-use-query-response.spec.ts renamed to src/graphql/tests/__tests__/mock-use-query-response.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type { UseQueryResponse } from "@urql/vue";
44
import gql from "graphql-tag";
55
import fc from "fast-check";
66

7-
import { mockUseQueryResponse } from "./mock-use-query-response";
7+
import { mockUseQueryResponse } from "..";
88

99
vi.mock("@urql/vue", () => ({
1010
useQuery: vi.fn(),

src/api/__tests__/mock-use-subscription-response.spec.ts renamed to src/graphql/tests/__tests__/mock-use-subscription-response.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type { UseSubscriptionResponse } from "@urql/vue";
44
import gql from "graphql-tag";
55
import fc from "fast-check";
66

7-
import { mockUseSubscriptionResponse } from "./mock-use-subscription-response";
7+
import { mockUseSubscriptionResponse } from "..";
88

99
vi.mock("@urql/vue", () => ({
1010
useSubscription: vi.fn(),

src/graphql/tests/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export * from "./mock-use-query-response";
2+
export * from "./mock-use-subscription-response"
3+
export * from "./setup-with-client";
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)