Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dulnan committed Nov 15, 2024
1 parent 16bbfaf commit 2a28940
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 26 deletions.
6 changes: 3 additions & 3 deletions test/codegen/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export type GetTextQuery = { __typename?: 'Query', getText?: string | null };
"
`;
exports[`generateTemplates > Generates the correct delarations. > nuxt-graphql-middleware.d.ts 1`] = `
exports[`generateTemplates > Generates the correct delarations. > nuxt-graphql-middleware/generated-types.d.ts 1`] = `
"
import type { GraphqlResponse } from '#graphql-middleware-server-options-build'
import type {
Expand All @@ -107,10 +107,10 @@ import type {
GetTextQuery,
LoginMutation,
LoginMutationVariables
} from './graphql-operations'
} from './../graphql-operations'
declare module '#build/nuxt-graphql-middleware' {
declare module '#nuxt-graphql-middleware/generated-types' {
export type GraphqlMiddlewareResponseUnion = TranslateQuery | GetTextQuery | LoginMutation
export type GraphqlMiddlewareQuery = {
translate: [TranslateQueryVariables, false, TranslateQuery],
Expand Down
30 changes: 15 additions & 15 deletions test/helpers/__snapshots__/generate.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`generate > Generates templates correctly for auto imported documents 1`] = `
exports[`generate > Generates templates correctly for auto imported documents > graphql-documents.mjs 1`] = `
{
"content": "const documents = {
"query": {
Expand Down Expand Up @@ -32,7 +32,7 @@ export { documents };",
}
`;

exports[`generate > Generates templates correctly for auto imported documents 2`] = `
exports[`generate > Generates templates correctly for auto imported documents > graphql-operations.d.ts 1`] = `
{
"content": "export type Maybe<T> = T | null;
export type InputMaybe<T> = Maybe<T>;
Expand Down Expand Up @@ -289,7 +289,7 @@ export type DeleteUserMutation = { __typename?: 'Mutation', deleteUser?: boolean
}
`;
exports[`generate > Generates templates correctly for auto imported documents 3`] = `
exports[`generate > Generates templates correctly for auto imported documents > nuxt-graphql-middleware/generated-types.d.ts 1`] = `
{
"content": "
import type { GraphqlResponse } from '#graphql-middleware-server-options-build'
Expand Down Expand Up @@ -318,10 +318,10 @@ import type {
TriggerErrorMutation,
DeleteUserMutation,
DeleteUserMutationVariables
} from './graphql-operations'
} from './../graphql-operations'
declare module '#build/nuxt-graphql-middleware' {
declare module '#nuxt-graphql-middleware/generated-types' {
export type GraphqlMiddlewareResponseUnion = SimulateEndpointDownQuery | FetchOptionsQuery | TestClientOptionsQuery | UsersQuery | GetErrorQuery | UserByIdQuery | FetchOptionsComposableQuery | GetSubmissionsQuery | FoobarQuery | QueryTwoQuery | QueryOneQuery | GetCurrentTimeQuery | TestUploadMutation | TestFormSubmitMutation | InitStateMutation | AddUserMutation | TriggerErrorMutation | DeleteUserMutation
export type GraphqlMiddlewareQuery = {
simulateEndpointDown: [null, true, SimulateEndpointDownQuery],
Expand Down Expand Up @@ -408,12 +408,12 @@ declare module 'nitropack' {
}
}
",
"filename": "nuxt-graphql-middleware.d.ts",
"filename": "nuxt-graphql-middleware/generated-types.d.ts",
"hooks": {},
}
`;
exports[`generate > Generates templates correctly for auto imported documents using autoInlineFragments 1`] = `
exports[`generate > Generates templates correctly for auto imported documents using autoInlineFragments > graphql-documents.mjs 1`] = `
{
"content": "const documents = {
"query": {
Expand All @@ -427,7 +427,7 @@ export { documents };",
}
`;
exports[`generate > Generates templates correctly for auto imported documents using autoInlineFragments 2`] = `
exports[`generate > Generates templates correctly for auto imported documents using autoInlineFragments > graphql-operations.d.ts 1`] = `
{
"content": "export type Maybe<T> = T | null;
export type InputMaybe<T> = Maybe<T>;
Expand Down Expand Up @@ -589,16 +589,16 @@ export type DepthOneQueryFragment = { __typename?: 'Query', one: Array<{ __typen
}
`;
exports[`generate > Generates templates correctly for auto imported documents using autoInlineFragments 3`] = `
exports[`generate > Generates templates correctly for auto imported documents using autoInlineFragments > nuxt-graphql-middleware/generated-types.d.ts 1`] = `
{
"content": "
import type { GraphqlResponse } from '#graphql-middleware-server-options-build'
import type {
HighDepthOneQuery
} from './graphql-operations'
} from './../graphql-operations'
declare module '#build/nuxt-graphql-middleware' {
declare module '#nuxt-graphql-middleware/generated-types' {
export type GraphqlMiddlewareResponseUnion = HighDepthOneQuery
export type GraphqlMiddlewareQuery = {
highDepthOne: [null, true, HighDepthOneQuery]
Expand All @@ -616,7 +616,7 @@ declare module 'nitropack' {
}
}
",
"filename": "nuxt-graphql-middleware.d.ts",
"filename": "nuxt-graphql-middleware/generated-types.d.ts",
"hooks": {},
}
`;
Expand Down Expand Up @@ -833,10 +833,10 @@ import type {
OneQuery,
TwoMutation,
TwoMutationVariables
} from './graphql-operations'
} from './../graphql-operations'
declare module '#build/nuxt-graphql-middleware' {
declare module '#nuxt-graphql-middleware/generated-types' {
export type GraphqlMiddlewareResponseUnion = OneQuery | TwoMutation
export type GraphqlMiddlewareQuery = {
one: [null, true, OneQuery]
Expand All @@ -859,7 +859,7 @@ declare module 'nitropack' {
}
}
",
"filename": "nuxt-graphql-middleware.d.ts",
"filename": "nuxt-graphql-middleware/generated-types.d.ts",
"hooks": {},
},
],
Expand Down
32 changes: 24 additions & 8 deletions test/helpers/generate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,19 @@ describe('generate', () => {
(t) => t.filename === 'graphql-operations.d.ts',
)
const c = result.templates.find(
(t) => t.filename === 'nuxt-graphql-middleware.d.ts',
(t) => t.filename === 'nuxt-graphql-middleware/generated-types.d.ts',
)
expect(a).toMatchSnapshot()
expect(b).toMatchSnapshot()
expect(c).toMatchSnapshot()
expect(result.hasErrors).toBeFalsy()
expect(result.templates.map((v) => v.filename)).toMatchInlineSnapshot(`
[
"graphql-documents.mjs",
"graphql-operations.d.ts",
"nuxt-graphql-middleware/generated-types.d.ts",
]
`)
expect(a).toMatchSnapshot(a?.filename)
expect(b).toMatchSnapshot(b?.filename)
expect(c).toMatchSnapshot(c?.filename)
})

test('Generates templates correctly for auto imported documents using autoInlineFragments', async () => {
Expand All @@ -82,11 +90,19 @@ describe('generate', () => {
(t) => t.filename === 'graphql-operations.d.ts',
)
const c = result.templates.find(
(t) => t.filename === 'nuxt-graphql-middleware.d.ts',
(t) => t.filename === 'nuxt-graphql-middleware/generated-types.d.ts',
)
expect(a).toMatchSnapshot()
expect(b).toMatchSnapshot()
expect(c).toMatchSnapshot()
expect(result.hasErrors).toBeFalsy()
expect(result.templates.map((v) => v.filename)).toMatchInlineSnapshot(`
[
"graphql-documents.mjs",
"graphql-operations.d.ts",
"nuxt-graphql-middleware/generated-types.d.ts",
]
`)
expect(a).toMatchSnapshot(a?.filename)
expect(b).toMatchSnapshot(b?.filename)
expect(c).toMatchSnapshot(c?.filename)
})

test('Generates templates correctly for provided documents', async () => {
Expand Down

0 comments on commit 2a28940

Please sign in to comment.