Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ardatan committed Feb 6, 2025
1 parent 23b2dcc commit 3165b07
Showing 1 changed file with 50 additions and 1 deletion.
51 changes: 50 additions & 1 deletion packages/graphql-yoga/__integration-tests__/browser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { setTimeout as setTimeout$ } from 'node:timers/promises';
// eslint-disable-next-line
import { Browser, chromium, ElementHandle, Page } from 'playwright';
import { fakePromise } from '@whatwg-node/server';
import { CORSOptions, createYoga, Repeater } from '../src/index.js';
import { CORSOptions, createSchema, createYoga, GraphiQLOptions, Repeater } from '../src/index.js';

let resolveOnReturn: VoidFunction;
const timeoutsSignal = new AbortController();
Expand Down Expand Up @@ -226,9 +226,11 @@ describe('browser', () => {
const liveQueryStore = new InMemoryLiveQueryStore();
const endpoint = '/test-graphql';
let cors: CORSOptions = {};
let graphiqlOptions: GraphiQLOptions | undefined;
const yogaApp = createYoga({
schema: createTestSchema(),
cors: () => cors,
graphiql: () => graphiqlOptions || true,
logging: false,
graphqlEndpoint: endpoint,
plugins: [
Expand Down Expand Up @@ -724,4 +726,51 @@ describe('browser', () => {
`);
});
});

let anotherServer: Server;
afterAll(async () => {
if (anotherServer) {
await new Promise<void>((resolve, reject) =>
anotherServer.close(err => {
if (err) {
reject(err);
} else {
resolve();
}
}),
);
}
});
test('\`endpoint\` configures GraphiQL to point another server', async () => {

Check failure on line 744 in packages/graphql-yoga/__integration-tests__/browser.spec.ts

View workflow job for this annotation

GitHub Actions / check

Unnecessary escape character: \`

Check failure on line 744 in packages/graphql-yoga/__integration-tests__/browser.spec.ts

View workflow job for this annotation

GitHub Actions / check

Unnecessary escape character: \`
const anotherYoga = createYoga({
schema: createSchema({
typeDefs: /* GraphQL */ `
type Query {
greetings: String!
}
`,
resolvers: {
Query: {
greetings: () => 'Hello from another server',
},
},
}),
});
anotherServer = createServer(anotherYoga);
await new Promise<void>(resolve => anotherServer.listen(0, resolve));
const anotherPort = (anotherServer.address() as AddressInfo).port;
const anotherEndpoint = `http://localhost:${anotherPort}/graphql`;
graphiqlOptions = {
endpoint: anotherEndpoint,
};
await page.goto(`http://localhost:${port}${endpoint}`);
await page.waitForSelector('.graphiql-query-editor .CodeMirror textarea');
await typeOperationText('{ greetings }');
await page.click(playButtonSelector);
await expect(waitForResult()).resolves.toEqual({
data: {
greetings: 'Hello from another server',
},
});
});
});

0 comments on commit 3165b07

Please sign in to comment.