Skip to content

Commit

Permalink
Faster E2E Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ardatan committed Jan 21, 2025
1 parent 0c0abe0 commit 0961a6a
Show file tree
Hide file tree
Showing 14 changed files with 257 additions and 291 deletions.
13 changes: 0 additions & 13 deletions e2e/auto-type-merging/__snapshots__/auto-type-merging.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -524,16 +524,3 @@ input User_Input @join__type(graph: PETSTORE) {
"
`;

exports[`should execute GetPet 1`] = `
{
"data": {
"getPetById": {
"__typename": "Pet",
"id": 1,
"name": "Cat 1",
"vaccinated": false,
},
},
}
`;
69 changes: 40 additions & 29 deletions e2e/auto-type-merging/auto-type-merging.test.ts
Original file line number Diff line number Diff line change
@@ -1,44 +1,55 @@
import { createTenv, type Container } from '@e2e/tenv';
import { createTenv, type Tenv } from '@e2e/tenv';

const { compose, service, serve, container } = createTenv(__dirname);

let petstore!: Container;
beforeAll(async () => {
petstore = await container({
function createPetstore(tenv: Tenv) {
return tenv.container({
name: 'petstore',
image: 'swaggerapi/petstore3:1.0.7',
containerPort: 8080,
healthcheck: ['CMD-SHELL', 'wget --spider http://localhost:8080'],
});
});
}

it('should compose the appropriate schema', async () => {
const { result } = await compose({
services: [petstore, await service('vaccination')],
it.concurrent('should compose the appropriate schema', async () => {
await using tenv = createTenv(__dirname);
await using petstore = await createPetstore(tenv);
await using vaccination = await tenv.service('vaccination');
const { supergraphSdl: result } = await tenv.compose({
services: [petstore, vaccination],
maskServicePorts: true,
});
expect(result).toMatchSnapshot();
});

it.concurrent.each([
{
name: 'GetPet',
query: /* GraphQL */ `
query GetPet {
getPetById(petId: 1) {
__typename
id
name
vaccinated
}
}
`,
},
])('should execute $name', async ({ query }) => {
const { output } = await compose({
it.concurrent('should execute GetPet', async () => {
await using tenv = createTenv(__dirname);
await using petstore = await createPetstore(tenv);
await using vaccination = await tenv.service('vaccination');
await using composition = await tenv.compose({
output: 'graphql',
services: [petstore, await service('vaccination')],
services: [petstore, vaccination],
});
await using gw = await tenv.gateway({ supergraph: composition.supergraphPath });
await expect(
gw.execute({
query: /* GraphQL */ `
query GetPet {
getPetById(petId: 1) {
__typename
id
name
vaccinated
}
}
`,
}),
).resolves.toMatchObject({
data: {
getPetById: {
__typename: 'Pet',
id: 1,
name: 'Cat 1',
vaccinated: false,
},
},
});
const { execute } = await serve({ supergraph: output });
await expect(execute({ query })).resolves.toMatchSnapshot();
});
16 changes: 8 additions & 8 deletions e2e/cjs-project/cjs-project.test.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { createTenv } from '@e2e/tenv';
import { fetch } from '@whatwg-node/fetch';

const { serve, compose, fs } = createTenv(__dirname);

it('should serve', async () => {
const proc = await serve({
supergraph: await fs.tempfile('supergraph.graphql', 'type Query { hello: String }'),
it.concurrent('should serve', async () => {
await using tenv = createTenv(__dirname);
await using proc = await tenv.gateway({
supergraph: await tenv.fs.tempfile('supergraph.graphql', 'type Query { hello: String }'),
});
const res = await fetch(`http://${proc.hostname}:${proc.port}/healthcheck`);
expect(res.ok).toBeTruthy();
});

it('should compose', async () => {
const proc = await compose();
expect(proc.result).toMatchSnapshot();
it.concurrent('should compose', async () => {
await using tenv = createTenv(__dirname);
await using proc = await tenv.compose();
expect(proc.supergraphSdl).toMatchSnapshot();
});
30 changes: 9 additions & 21 deletions e2e/compose-to-output/compose-to-output.test.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,11 @@
import { createTenv } from '@e2e/tenv';

const { compose, fs } = createTenv(__dirname);

it('should write compose output to supergraph.graphql', async () => {
const { output } = await compose({ output: 'graphql' });
await expect(fs.read(output)).resolves.toMatchSnapshot();
});

it('should write compose output to supergraph.json', async () => {
const { output } = await compose({ output: 'json' });
await expect(fs.read(output)).resolves.toMatchSnapshot();
});

it('should write compose output to supergraph.js', async () => {
const { output } = await compose({ output: 'js' });
await expect(fs.read(output)).resolves.toMatchSnapshot();
});

it('should write compose output to supergraph.ts', async () => {
const { output } = await compose({ output: 'ts' });
await expect(fs.read(output)).resolves.toMatchSnapshot();
});
const outputTypes = ['graphql', 'json', 'js', 'ts'] as const;

for (const output of outputTypes) {
it.concurrent(`should write compose output to supergraph.${output}`, async () => {
await using tenv = createTenv(__dirname);
await using composition = await tenv.compose({ output });
await expect(tenv.fs.read(composition.supergraphPath)).resolves.toMatchSnapshot();
});
}
18 changes: 9 additions & 9 deletions e2e/esm-config-in-cjs-project/esm-config-in-cjs-project.test.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { createTenv } from '@e2e/tenv';
import { fetch } from '@whatwg-node/fetch';

const { serve, compose, fs } = createTenv(__dirname);

it('should serve', async () => {
const proc = await serve({
supergraph: await fs.tempfile('supergraph.graphql', 'type Query { hello: String }'),
it.concurrent('should serve', async () => {
await using tenv = createTenv(__dirname);
await using gw = await tenv.gateway({
supergraph: await tenv.fs.tempfile('supergraph.graphql', 'type Query { hello: String }'),
});
const res = await fetch(`http://${proc.hostname}:${proc.port}/healthcheck`);
const res = await fetch(`http://${gw.hostname}:${gw.port}/healthcheck`);
expect(res.ok).toBeTruthy();
});

it('should compose', async () => {
const proc = await compose();
expect(proc.result).toMatchSnapshot();
it.concurrent('should compose', async () => {
await using tenv = createTenv(__dirname);
await using proc = await tenv.compose();
expect(proc.supergraphSdl).toMatchSnapshot();
});
18 changes: 9 additions & 9 deletions e2e/esm-project/esm-project.test.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { createTenv } from '@e2e/tenv';
import { fetch } from '@whatwg-node/fetch';

const { serve, compose, fs } = createTenv(__dirname);

it('should serve', async () => {
const proc = await serve({
supergraph: await fs.tempfile('supergraph.graphql', 'type Query { hello: String }'),
it.concurrent('should serve', async () => {
await using tenv = createTenv(__dirname);
await using gw = await tenv.gateway({
supergraph: await tenv.fs.tempfile('supergraph.graphql', 'type Query { hello: String }'),
});
const res = await fetch(`http://${proc.hostname}:${proc.port}/healthcheck`);
const res = await fetch(`http://${gw.hostname}:${gw.port}/healthcheck`);
expect(res.ok).toBeTruthy();
});

it('should compose', async () => {
const proc = await compose();
expect(proc.result).toMatchSnapshot();
it.concurrent('should compose', async () => {
await using tenv = createTenv(__dirname);
await using composition = await tenv.compose();
expect(composition.supergraphSdl).toMatchSnapshot();
});
15 changes: 8 additions & 7 deletions e2e/extra-fields/extra-fields.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { createTenv } from '@e2e/tenv';

const { serve, compose, service } = createTenv(__dirname);

it('works', async () => {
const { output } = await compose({
services: [await service('foo'), await service('bar')],
it.concurrent('works', async () => {
await using tenv = createTenv(__dirname);
await using foo = await tenv.service('foo');
await using bar = await tenv.service('bar');
await using composition = await tenv.compose({
services: [foo, bar],
output: 'graphql',
});
const { execute } = await serve({ supergraph: output });
await using gw = await tenv.gateway({ supergraph: composition.supergraphPath });
await expect(
execute({
gw.execute({
query: /* GraphQL */ `
query FooBarFoo {
foo {
Expand Down
38 changes: 18 additions & 20 deletions e2e/federation-mixed/federation-mixed.test.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import { createTenv } from '@e2e/tenv';

const { service, serve, compose } = createTenv(__dirname);

it('should compose the appropriate schema', async () => {
const { result } = await compose({
services: [
await service('accounts'),
await service('inventory'),
await service('products'),
await service('reviews'),
],
it.concurrent('should compose the appropriate schema', async () => {
await using tenv = createTenv(__dirname);
await using accounts = await tenv.service('accounts');
await using inventory = await tenv.service('inventory');
await using products = await tenv.service('products');
await using reviews = await tenv.service('reviews');
await using composition = await tenv.compose({
services: [accounts, inventory, products, reviews],
maskServicePorts: true,
});
expect(result).toMatchSnapshot();
expect(composition.supergraphSdl).toMatchSnapshot();
});

it.concurrent.each([
Expand Down Expand Up @@ -80,15 +78,15 @@ it.concurrent.each([
`,
},
])('should execute $name', async ({ query }) => {
const { output } = await compose({
await using tenv = createTenv(__dirname);
await using accounts = await tenv.service('accounts');
await using inventory = await tenv.service('inventory');
await using products = await tenv.service('products');
await using reviews = await tenv.service('reviews');
await using composition = await tenv.compose({
output: 'graphql',
services: [
await service('accounts'),
await service('inventory'),
await service('products'),
await service('reviews'),
],
services: [accounts, inventory, products, reviews],
});
const { execute } = await serve({ supergraph: output });
await expect(execute({ query })).resolves.toMatchSnapshot();
await using gw = await tenv.gateway({ supergraph: composition.supergraphPath });
await expect(gw.execute({ query })).resolves.toMatchSnapshot();
});
24 changes: 11 additions & 13 deletions e2e/file-upload/file-upload.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { createTenv } from '@e2e/tenv';
import { fetch, File, FormData } from '@whatwg-node/fetch';

const { compose, serve, service } = createTenv(__dirname);

it('should upload file', async () => {
const { output } = await compose({ output: 'graphql', services: [await service('bucket')] });
const { hostname, port } = await serve({ supergraph: output });
it.concurrent('should upload file', async () => {
await using tenv = createTenv(__dirname);
await using bucketService = await tenv.service('bucket');
await using composition = await tenv.compose({ output: 'graphql', services: [bucketService] });
await using gw = await tenv.gateway({ supergraph: composition.supergraphPath });

const form = new FormData();
form.append(
Expand All @@ -23,16 +23,14 @@ it('should upload file', async () => {
);
form.append('map', JSON.stringify({ 0: ['variables.file'] }));
form.append('0', new File(['Hello World!'], 'hello.txt', { type: 'text/plain' }));
const res = await fetch(`http://${hostname}:${port}/graphql`, {
const res = await fetch(`http://${gw.hostname}:${gw.port}/graphql`, {
method: 'POST',
body: form,
});

await expect(res.json()).resolves.toMatchInlineSnapshot(`
{
"data": {
"readFile": "Hello World!",
},
}
`);
await expect(res.json()).resolves.toMatchObject({
data: {
readFile: 'Hello World!',
},
});
});
Loading

0 comments on commit 0961a6a

Please sign in to comment.