Skip to content

Commit 0961a6a

Browse files
committed
Faster E2E Tests
1 parent 0c0abe0 commit 0961a6a

File tree

14 files changed

+257
-291
lines changed

14 files changed

+257
-291
lines changed

e2e/auto-type-merging/__snapshots__/auto-type-merging.test.ts.snap

-13
Original file line numberDiff line numberDiff line change
@@ -524,16 +524,3 @@ input User_Input @join__type(graph: PETSTORE) {
524524
525525
"
526526
`;
527-
528-
exports[`should execute GetPet 1`] = `
529-
{
530-
"data": {
531-
"getPetById": {
532-
"__typename": "Pet",
533-
"id": 1,
534-
"name": "Cat 1",
535-
"vaccinated": false,
536-
},
537-
},
538-
}
539-
`;
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,55 @@
1-
import { createTenv, type Container } from '@e2e/tenv';
1+
import { createTenv, type Tenv } from '@e2e/tenv';
22

3-
const { compose, service, serve, container } = createTenv(__dirname);
4-
5-
let petstore!: Container;
6-
beforeAll(async () => {
7-
petstore = await container({
3+
function createPetstore(tenv: Tenv) {
4+
return tenv.container({
85
name: 'petstore',
96
image: 'swaggerapi/petstore3:1.0.7',
107
containerPort: 8080,
118
healthcheck: ['CMD-SHELL', 'wget --spider http://localhost:8080'],
129
});
13-
});
10+
}
1411

15-
it('should compose the appropriate schema', async () => {
16-
const { result } = await compose({
17-
services: [petstore, await service('vaccination')],
12+
it.concurrent('should compose the appropriate schema', async () => {
13+
await using tenv = createTenv(__dirname);
14+
await using petstore = await createPetstore(tenv);
15+
await using vaccination = await tenv.service('vaccination');
16+
const { supergraphSdl: result } = await tenv.compose({
17+
services: [petstore, vaccination],
1818
maskServicePorts: true,
1919
});
2020
expect(result).toMatchSnapshot();
2121
});
2222

23-
it.concurrent.each([
24-
{
25-
name: 'GetPet',
26-
query: /* GraphQL */ `
27-
query GetPet {
28-
getPetById(petId: 1) {
29-
__typename
30-
id
31-
name
32-
vaccinated
33-
}
34-
}
35-
`,
36-
},
37-
])('should execute $name', async ({ query }) => {
38-
const { output } = await compose({
23+
it.concurrent('should execute GetPet', async () => {
24+
await using tenv = createTenv(__dirname);
25+
await using petstore = await createPetstore(tenv);
26+
await using vaccination = await tenv.service('vaccination');
27+
await using composition = await tenv.compose({
3928
output: 'graphql',
40-
services: [petstore, await service('vaccination')],
29+
services: [petstore, vaccination],
30+
});
31+
await using gw = await tenv.gateway({ supergraph: composition.supergraphPath });
32+
await expect(
33+
gw.execute({
34+
query: /* GraphQL */ `
35+
query GetPet {
36+
getPetById(petId: 1) {
37+
__typename
38+
id
39+
name
40+
vaccinated
41+
}
42+
}
43+
`,
44+
}),
45+
).resolves.toMatchObject({
46+
data: {
47+
getPetById: {
48+
__typename: 'Pet',
49+
id: 1,
50+
name: 'Cat 1',
51+
vaccinated: false,
52+
},
53+
},
4154
});
42-
const { execute } = await serve({ supergraph: output });
43-
await expect(execute({ query })).resolves.toMatchSnapshot();
4455
});

e2e/cjs-project/cjs-project.test.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import { createTenv } from '@e2e/tenv';
22
import { fetch } from '@whatwg-node/fetch';
33

4-
const { serve, compose, fs } = createTenv(__dirname);
5-
6-
it('should serve', async () => {
7-
const proc = await serve({
8-
supergraph: await fs.tempfile('supergraph.graphql', 'type Query { hello: String }'),
4+
it.concurrent('should serve', async () => {
5+
await using tenv = createTenv(__dirname);
6+
await using proc = await tenv.gateway({
7+
supergraph: await tenv.fs.tempfile('supergraph.graphql', 'type Query { hello: String }'),
98
});
109
const res = await fetch(`http://${proc.hostname}:${proc.port}/healthcheck`);
1110
expect(res.ok).toBeTruthy();
1211
});
1312

14-
it('should compose', async () => {
15-
const proc = await compose();
16-
expect(proc.result).toMatchSnapshot();
13+
it.concurrent('should compose', async () => {
14+
await using tenv = createTenv(__dirname);
15+
await using proc = await tenv.compose();
16+
expect(proc.supergraphSdl).toMatchSnapshot();
1717
});
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,11 @@
11
import { createTenv } from '@e2e/tenv';
22

3-
const { compose, fs } = createTenv(__dirname);
4-
5-
it('should write compose output to supergraph.graphql', async () => {
6-
const { output } = await compose({ output: 'graphql' });
7-
await expect(fs.read(output)).resolves.toMatchSnapshot();
8-
});
9-
10-
it('should write compose output to supergraph.json', async () => {
11-
const { output } = await compose({ output: 'json' });
12-
await expect(fs.read(output)).resolves.toMatchSnapshot();
13-
});
14-
15-
it('should write compose output to supergraph.js', async () => {
16-
const { output } = await compose({ output: 'js' });
17-
await expect(fs.read(output)).resolves.toMatchSnapshot();
18-
});
19-
20-
it('should write compose output to supergraph.ts', async () => {
21-
const { output } = await compose({ output: 'ts' });
22-
await expect(fs.read(output)).resolves.toMatchSnapshot();
23-
});
3+
const outputTypes = ['graphql', 'json', 'js', 'ts'] as const;
4+
5+
for (const output of outputTypes) {
6+
it.concurrent(`should write compose output to supergraph.${output}`, async () => {
7+
await using tenv = createTenv(__dirname);
8+
await using composition = await tenv.compose({ output });
9+
await expect(tenv.fs.read(composition.supergraphPath)).resolves.toMatchSnapshot();
10+
});
11+
}
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import { createTenv } from '@e2e/tenv';
22
import { fetch } from '@whatwg-node/fetch';
33

4-
const { serve, compose, fs } = createTenv(__dirname);
5-
6-
it('should serve', async () => {
7-
const proc = await serve({
8-
supergraph: await fs.tempfile('supergraph.graphql', 'type Query { hello: String }'),
4+
it.concurrent('should serve', async () => {
5+
await using tenv = createTenv(__dirname);
6+
await using gw = await tenv.gateway({
7+
supergraph: await tenv.fs.tempfile('supergraph.graphql', 'type Query { hello: String }'),
98
});
10-
const res = await fetch(`http://${proc.hostname}:${proc.port}/healthcheck`);
9+
const res = await fetch(`http://${gw.hostname}:${gw.port}/healthcheck`);
1110
expect(res.ok).toBeTruthy();
1211
});
1312

14-
it('should compose', async () => {
15-
const proc = await compose();
16-
expect(proc.result).toMatchSnapshot();
13+
it.concurrent('should compose', async () => {
14+
await using tenv = createTenv(__dirname);
15+
await using proc = await tenv.compose();
16+
expect(proc.supergraphSdl).toMatchSnapshot();
1717
});

e2e/esm-project/esm-project.test.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import { createTenv } from '@e2e/tenv';
22
import { fetch } from '@whatwg-node/fetch';
33

4-
const { serve, compose, fs } = createTenv(__dirname);
5-
6-
it('should serve', async () => {
7-
const proc = await serve({
8-
supergraph: await fs.tempfile('supergraph.graphql', 'type Query { hello: String }'),
4+
it.concurrent('should serve', async () => {
5+
await using tenv = createTenv(__dirname);
6+
await using gw = await tenv.gateway({
7+
supergraph: await tenv.fs.tempfile('supergraph.graphql', 'type Query { hello: String }'),
98
});
10-
const res = await fetch(`http://${proc.hostname}:${proc.port}/healthcheck`);
9+
const res = await fetch(`http://${gw.hostname}:${gw.port}/healthcheck`);
1110
expect(res.ok).toBeTruthy();
1211
});
1312

14-
it('should compose', async () => {
15-
const proc = await compose();
16-
expect(proc.result).toMatchSnapshot();
13+
it.concurrent('should compose', async () => {
14+
await using tenv = createTenv(__dirname);
15+
await using composition = await tenv.compose();
16+
expect(composition.supergraphSdl).toMatchSnapshot();
1717
});

e2e/extra-fields/extra-fields.test.ts

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
import { createTenv } from '@e2e/tenv';
22

3-
const { serve, compose, service } = createTenv(__dirname);
4-
5-
it('works', async () => {
6-
const { output } = await compose({
7-
services: [await service('foo'), await service('bar')],
3+
it.concurrent('works', async () => {
4+
await using tenv = createTenv(__dirname);
5+
await using foo = await tenv.service('foo');
6+
await using bar = await tenv.service('bar');
7+
await using composition = await tenv.compose({
8+
services: [foo, bar],
89
output: 'graphql',
910
});
10-
const { execute } = await serve({ supergraph: output });
11+
await using gw = await tenv.gateway({ supergraph: composition.supergraphPath });
1112
await expect(
12-
execute({
13+
gw.execute({
1314
query: /* GraphQL */ `
1415
query FooBarFoo {
1516
foo {

e2e/federation-mixed/federation-mixed.test.ts

+18-20
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
import { createTenv } from '@e2e/tenv';
22

3-
const { service, serve, compose } = createTenv(__dirname);
4-
5-
it('should compose the appropriate schema', async () => {
6-
const { result } = await compose({
7-
services: [
8-
await service('accounts'),
9-
await service('inventory'),
10-
await service('products'),
11-
await service('reviews'),
12-
],
3+
it.concurrent('should compose the appropriate schema', async () => {
4+
await using tenv = createTenv(__dirname);
5+
await using accounts = await tenv.service('accounts');
6+
await using inventory = await tenv.service('inventory');
7+
await using products = await tenv.service('products');
8+
await using reviews = await tenv.service('reviews');
9+
await using composition = await tenv.compose({
10+
services: [accounts, inventory, products, reviews],
1311
maskServicePorts: true,
1412
});
15-
expect(result).toMatchSnapshot();
13+
expect(composition.supergraphSdl).toMatchSnapshot();
1614
});
1715

1816
it.concurrent.each([
@@ -80,15 +78,15 @@ it.concurrent.each([
8078
`,
8179
},
8280
])('should execute $name', async ({ query }) => {
83-
const { output } = await compose({
81+
await using tenv = createTenv(__dirname);
82+
await using accounts = await tenv.service('accounts');
83+
await using inventory = await tenv.service('inventory');
84+
await using products = await tenv.service('products');
85+
await using reviews = await tenv.service('reviews');
86+
await using composition = await tenv.compose({
8487
output: 'graphql',
85-
services: [
86-
await service('accounts'),
87-
await service('inventory'),
88-
await service('products'),
89-
await service('reviews'),
90-
],
88+
services: [accounts, inventory, products, reviews],
9189
});
92-
const { execute } = await serve({ supergraph: output });
93-
await expect(execute({ query })).resolves.toMatchSnapshot();
90+
await using gw = await tenv.gateway({ supergraph: composition.supergraphPath });
91+
await expect(gw.execute({ query })).resolves.toMatchSnapshot();
9492
});

e2e/file-upload/file-upload.test.ts

+11-13
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { createTenv } from '@e2e/tenv';
22
import { fetch, File, FormData } from '@whatwg-node/fetch';
33

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

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

31-
await expect(res.json()).resolves.toMatchInlineSnapshot(`
32-
{
33-
"data": {
34-
"readFile": "Hello World!",
35-
},
36-
}
37-
`);
31+
await expect(res.json()).resolves.toMatchObject({
32+
data: {
33+
readFile: 'Hello World!',
34+
},
35+
});
3836
});

0 commit comments

Comments
 (0)