This repository has been archived by the owner on Jun 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move tests/ to tests-old/ and exclude from tests
- Loading branch information
Showing
29 changed files
with
195 additions
and
1 deletion.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
import { | ||
createClient, | ||
dedupExchange, | ||
cacheExchange, | ||
fetchExchange, | ||
makeOperation, | ||
} from "@urql/core"; | ||
import { authExchange } from "@urql/exchange-auth"; | ||
import { pipe, fromValue, fromArray, subscribe } from "wonka"; | ||
import { gql } from "graphql-tag"; | ||
|
||
describe("one", () => { | ||
it("wonka test", async () => { | ||
pipe( | ||
fromArray([1, 2, 3]), | ||
subscribe((x) => console.log(x)) | ||
); | ||
}); | ||
|
||
it("one", async () => { | ||
const url = "http://localhost:5001/graphql"; | ||
|
||
const getAuth = async ({ authState }) => { | ||
if (!authState) { | ||
const token = "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"; | ||
// const token = "HV41CNl97jxwbDtQ"; | ||
return { token }; | ||
} | ||
return null; | ||
}; | ||
|
||
const addAuthToOperation = ({ authState, operation }) => { | ||
if (!authState || !authState.token) { | ||
return operation; | ||
} | ||
|
||
const fetchOptions = | ||
typeof operation.context.fetchOptions === "function" | ||
? operation.context.fetchOptions() | ||
: operation.context.fetchOptions || {}; | ||
|
||
return makeOperation(operation.kind, operation, { | ||
...operation.context, | ||
fetchOptions: { | ||
...fetchOptions, | ||
headers: { | ||
...fetchOptions.headers, | ||
Authorization: `Bearer "${authState.token}"`, | ||
}, | ||
}, | ||
}); | ||
}; | ||
|
||
const client = createClient({ | ||
url: url, | ||
exchanges: [ | ||
// dedupExchange, | ||
// cacheExchange, // default document cache | ||
authExchange({ getAuth, addAuthToOperation }), | ||
fetchExchange, | ||
], | ||
}); | ||
|
||
// const executeQuery = () => | ||
// fromValue({ | ||
// data: { foo: "bar" }, | ||
// }); | ||
|
||
const executeQuery = vi.fn().mockReturnValue( | ||
fromValue({ | ||
data: { foo: "bar" }, | ||
}) | ||
); | ||
|
||
// @ts-ignore | ||
// client.executeQuery = executeQuery; | ||
|
||
console.log("subscribeToDebugTarget: ", client.subscribeToDebugTarget); | ||
const { unsubscribe } = | ||
client.subscribeToDebugTarget?.((event) => { | ||
// console.log(event); | ||
console.log(JSON.stringify(event, null, 2)); | ||
}) || {}; | ||
|
||
const spy = vi.spyOn(client, "query"); | ||
|
||
const r = await client | ||
.query( | ||
gql` | ||
{ | ||
version | ||
} | ||
`, | ||
{} | ||
) | ||
.toPromise(); | ||
// console.log(r); | ||
// console.log(executeQuery.mock.calls); | ||
// console.log(JSON.stringify(executeQuery.mock.calls, null, 2)); | ||
// console.log(spy.mock.calls); | ||
|
||
unsubscribe?.(); | ||
}); | ||
}); |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { setActivePinia, createPinia } from "pinia"; | ||
import { defineStore } from "pinia"; | ||
|
||
console.log("before useAStore()"); | ||
const useAStore = defineStore("A", () => { | ||
console.log("in defineStore()"); | ||
return { a: 1 }; | ||
}); | ||
// const useAStore = (() => { | ||
// console.log("in useAStore()"); | ||
// return defineStore("A", () => { | ||
// console.log("in defineStore()"); | ||
// return { a: 1 }; | ||
// }); | ||
// })(); | ||
console.log("after useAStore()"); | ||
|
||
describe("scratch", () => { | ||
beforeEach(() => { | ||
setActivePinia(createPinia()); | ||
}); | ||
|
||
it("one", () => { | ||
console.log("in one()"); | ||
const aStore = useAStore(); | ||
console.log("end one()"); | ||
}); | ||
}); |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { defineComponent, ref, Ref } from "vue"; | ||
import { mount, createLocalVue } from "@vue/test-utils"; | ||
import { PiniaVuePlugin } from "pinia"; | ||
import { useQuery, CombinedError } from "@urql/vue"; | ||
import { createTestingPinia } from "@pinia/testing"; | ||
import gql from "graphql-tag"; | ||
import { fromValue, never } from "wonka"; | ||
|
||
import { useStore } from "@/plugins/pinia/stores/main"; | ||
import { useQueryState } from "@/utils/query-state"; | ||
|
||
export const FooDocument = gql` | ||
query foo { | ||
foo | ||
} | ||
`; | ||
|
||
export type FooQuery = { | ||
__typename?: "Query"; | ||
foo?: string | null; | ||
}; | ||
|
||
describe("one", () => { | ||
let localVue: ReturnType<typeof createLocalVue>; | ||
let store: ReturnType<typeof useStore>; | ||
|
||
function createQueryResponse(client: Ref<{ executeQuery: () => unknown }>) { | ||
// queryResponse is the return value of useQuery, which needs to be called | ||
// inside of a component setup(). The useQuery() injects the urql client | ||
// with the key "$urql". | ||
let ret: ReturnType<typeof useQuery<FooQuery>> | undefined; | ||
const dummyComponent = defineComponent({ | ||
setup() { | ||
ret = useQuery<FooQuery>({ query: FooDocument }); | ||
}, | ||
render() {}, | ||
}); | ||
const pinia = createTestingPinia(); | ||
store = useStore(pinia); | ||
mount(dummyComponent, { | ||
localVue, | ||
pinia, | ||
provide: { $urql: client }, | ||
}); | ||
if (!ret) throw new Error("query is undefined"); | ||
return ret; | ||
} | ||
|
||
beforeEach(() => { | ||
localVue = createLocalVue(); | ||
localVue.use(PiniaVuePlugin); | ||
}) | ||
|
||
it("loading", () => { | ||
const executeQuery = () => never; // fetching | ||
const client = ref({ executeQuery }); | ||
const query = createQueryResponse(client); | ||
expect(query.fetching.value).toBe(true); | ||
const queryState = useQueryState(query); | ||
// console.log(queryState); | ||
}); | ||
}); |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters