Skip to content

Commit c3918f6

Browse files
committed
Migrate near-operation-file preset to vitrest
1 parent 34495d8 commit c3918f6

3 files changed

Lines changed: 46 additions & 21 deletions

File tree

packages/presets/near-operation-file/jest.config.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/presets/near-operation-file/tests/near-operation-file.spec.ts

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ describe('near-operation-file preset', () => {
383383
});
384384

385385
it('#6439 - generating code only for the last query inside a file', async () => {
386-
const result = await executeCodegen({
386+
const { result } = await executeCodegen({
387387
schema: [
388388
/* GraphQL */ `
389389
type Query {
@@ -427,7 +427,7 @@ describe('near-operation-file preset', () => {
427427
});
428428

429429
it('#6520 - self-importing fragment', async () => {
430-
const result = await executeCodegen({
430+
const { result } = await executeCodegen({
431431
schema: [
432432
/* GraphQL */ `
433433
type Query {
@@ -457,7 +457,7 @@ describe('near-operation-file preset', () => {
457457
});
458458

459459
it('#6546 - duplicate fragment imports', async () => {
460-
const result = await executeCodegen({
460+
const { result } = await executeCodegen({
461461
schema: [
462462
/* GraphQL */ `
463463
type Query {
@@ -556,7 +556,7 @@ describe('near-operation-file preset', () => {
556556
});
557557

558558
it('#7798 - importing type definitions of dependent fragments when `inlineFragmentType` is `mask`', async () => {
559-
const result = await executeCodegen({
559+
const { result } = await executeCodegen({
560560
schema: [
561561
/* GraphQL */ `
562562
type User {
@@ -593,7 +593,7 @@ describe('near-operation-file preset', () => {
593593
});
594594

595595
it('#406 - duplicate fragment imports', async () => {
596-
const result = await executeCodegen({
596+
const { result } = await executeCodegen({
597597
schema: [
598598
/* GraphQL */ `
599599
type Query {
@@ -1192,7 +1192,7 @@ describe('near-operation-file preset', () => {
11921192
});
11931193

11941194
it('Should allow external fragments to be imported from packages with function', async () => {
1195-
const spy = jest.fn();
1195+
const spy = vi.fn();
11961196
await executePreset({
11971197
baseOutputDir: './src/',
11981198
config: {},
@@ -1478,7 +1478,7 @@ describe('near-operation-file preset', () => {
14781478
});
14791479

14801480
it('#1112 - should import only interface types that are in use', async () => {
1481-
const result = await executeCodegen({
1481+
const { result } = await executeCodegen({
14821482
schema: [
14831483
/* GraphQL */ `
14841484
type Query {
@@ -1526,23 +1526,37 @@ describe('near-operation-file preset', () => {
15261526
generatedDoc.filename.match(/issue-1112-operation/),
15271527
).content;
15281528

1529-
expect(interfaceContent).toContain(
1530-
"export type AnimalFragment_Cat = { __typename?: 'Cat', name: string };",
1531-
);
1532-
expect(interfaceContent).toContain(
1533-
"export type AnimalFragment_Dog = { __typename?: 'Dog', name: string };",
1534-
);
1535-
expect(interfaceContent).toContain(
1536-
'export type AnimalFragment = AnimalFragment_Cat | AnimalFragment_Dog;',
1537-
);
1529+
expect(interfaceContent).toMatchInlineSnapshot(`
1530+
"import * as Types from '../../../../../out1.ts/types';
15381531
1539-
expect(operationContent).toContain(
1540-
"import { AnimalFragment_Cat } from './issue-1112-interface.generated'",
1541-
);
1532+
export type AnimalFragment_Cat = { __typename?: 'Cat', name: string };
1533+
1534+
export type AnimalFragment_Dog = { __typename?: 'Dog', name: string };
1535+
1536+
export type AnimalFragment =
1537+
| AnimalFragment_Cat
1538+
| AnimalFragment_Dog
1539+
;
1540+
"
1541+
`);
1542+
1543+
expect(operationContent).toMatchInlineSnapshot(`
1544+
"import * as Types from '../../../../../out1.ts/types';
1545+
1546+
import { AnimalFragment_Cat } from './issue-1112-interface.generated';
1547+
export type CatsQueryVariables = Types.Exact<{ [key: string]: never; }>;
1548+
1549+
1550+
export type CatsQuery = { __typename?: 'Query', cats: Array<(
1551+
{ __typename?: 'Cat' }
1552+
& AnimalFragment_Cat
1553+
)> };
1554+
"
1555+
`);
15421556
});
15431557

15441558
it('generates correctly without baseTypesPath for standalone typescript-operations', async () => {
1545-
const result = await executeCodegen({
1559+
const { result } = await executeCodegen({
15461560
schema: /* GraphQL */ `
15471561
type Query {
15481562
user: User
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { defineProject, mergeConfig } from 'vitest/config';
2+
import { sharedConfig } from '../../../vitest.config.js';
3+
4+
export default mergeConfig(
5+
sharedConfig,
6+
defineProject({
7+
test: {
8+
name: 'near-operation-file-preset',
9+
include: ['**/*.spec.ts'],
10+
},
11+
}),
12+
);

0 commit comments

Comments
 (0)