Skip to content

Commit

Permalink
Improve integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ardatan committed Dec 26, 2024
1 parent 4a70e66 commit f508510
Show file tree
Hide file tree
Showing 13 changed files with 59 additions and 33 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ jobs:
with:
node-version-file: '.node-version'

- name: Setup Bun Runtime
uses: antongolub/action-setup-bun@v1

- name: Setup Deno Runtime
uses: denoland/setup-deno@v1
with:
Expand Down
1 change: 1 addition & 0 deletions examples/bun-yoga-ws/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"test": "bun test"
},
"dependencies": {
"bun": "^1.1.42",
"bun-types": "^1.0.0",
"graphql": "16.10.0",
"graphql-ws": "^5.14.1",
Expand Down
8 changes: 2 additions & 6 deletions examples/bun/__integration-tests__/bun.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,14 @@ describe('Bun integration', () => {
let server: Server;
let url: string;
beforeEach(() => {
console.log('Starting server');
server = Bun.serve({
fetch: yoga,
port: 3000,
port: 0,
});
url = `http://${server.hostname}:${server.port}${yoga.graphqlEndpoint}`;
});

afterEach(async () => {
server.stop();
console.log('Server stopped');
});
afterEach(() => server.stop());

it('shows GraphiQL', async () => {
const response = await fetch(url, {
Expand Down
4 changes: 3 additions & 1 deletion examples/bun/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
"test": "bun test"
},
"dependencies": {
"bun-types": "^1.0.0",
"bun": "^1.1.42",
"bun-types": "^1.1.42",
"graphql": "16.10.0",
"graphql-yoga": "5.3.1"
},
"devDependencies": {
"@types/bun": "^1.1.14",
"@whatwg-node/fetch": "^0.10.1",
"typescript": "^5.4.5"
}
Expand Down
5 changes: 4 additions & 1 deletion examples/bun/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ const yoga = createYoga({
}),
});

const server = Bun.serve(yoga);
const server = Bun.serve({
fetch: yoga,
port: 4000,
});

console.info(
`Server is running on http://${server.hostname}:${server.port}${yoga.graphqlEndpoint}`,
Expand Down
4 changes: 2 additions & 2 deletions examples/egg/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
run
logs
app/*.js
config/*.js
app/**/*.js
config/**/*.js
36 changes: 27 additions & 9 deletions examples/graphql-ws/__integration-tests__/graphql-ws.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { createServer } from 'node:http';
import { AddressInfo } from 'node:net';
import { createClient } from 'graphql-ws';
import { useServer } from 'graphql-ws/lib/use/ws';
import { createSchema, createYoga } from 'graphql-yoga';
Expand All @@ -7,13 +8,28 @@ import { buildApp } from '../src/app.js';

describe('graphql-ws example integration', () => {
const app = buildApp();
beforeAll(() => app.start(4000));
function findAvailablePort() {
return new Promise<number>((resolve, reject) => {
const server = createServer();
server.listen(0, () => {
const { port } = server.address() as AddressInfo;
server.close(() => resolve(port));
});
server.once('error', reject);
});
}
let url: string;
beforeAll(async () => {
const port = await findAvailablePort();
url = `ws://localhost:${port}/graphql`;
return app.start(port);
});
afterAll(() => app.stop());

it('should execute query', async () => {
const client = createClient({
webSocketImpl: WebSocket,
url: 'ws://localhost:4000/graphql',
url,
retryAttempts: 0, // fail right away
});

Expand All @@ -30,13 +46,13 @@ describe('graphql-ws example integration', () => {
);
});

expect(onNext).toBeCalledWith({ data: { hello: 'world' } });
expect(onNext).toHaveBeenCalledWith({ data: { hello: 'world' } });
});

it('should execute mutation', async () => {
const client = createClient({
webSocketImpl: WebSocket,
url: 'ws://localhost:4000/graphql',
url,
retryAttempts: 0, // fail right away
});

Expand All @@ -59,7 +75,7 @@ describe('graphql-ws example integration', () => {
it('should subscribe', async () => {
const client = createClient({
webSocketImpl: WebSocket,
url: 'ws://localhost:4000/graphql',
url,
retryAttempts: 0, // fail right away
});

Expand Down Expand Up @@ -131,17 +147,19 @@ describe('graphql-ws example integration', () => {
}),
);

const port = await findAvailablePort();

await new Promise<void>((resolve, reject) => {
server.on('error', err => reject(err));
server.on('listening', () => resolve());
server.listen(4001);
server.listen(port);
});

//

const client = createClient({
webSocketImpl: WebSocket,
url: 'ws://localhost:4001/graphql',
url: `ws://localhost:${port}/graphql`,
retryAttempts: 0, // fail right away
});

Expand All @@ -158,8 +176,8 @@ describe('graphql-ws example integration', () => {
);
});

expect(onNext).toBeCalledTimes(1);
expect(onNext).toBeCalledWith({ data: { hello: 'world' } });
expect(onNext).toHaveBeenCalledTimes(1);
expect(onNext).toHaveBeenCalledWith({ data: { hello: 'world' } });

//

Expand Down
1 change: 1 addition & 0 deletions examples/graphql-ws/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"ws": "8.18.0"
},
"devDependencies": {
"@types/ws": "^8.5.13",
"cross-env": "7.0.3",
"ts-node": "10.9.2",
"ts-node-dev": "2.0.0",
Expand Down
19 changes: 14 additions & 5 deletions examples/hapi/__integration-tests__/hapi.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,21 @@ import { fetch } from '@whatwg-node/fetch';
import { startApp } from '../src/app.js';

describe('hapi example integration', () => {
const port = 4000;
let stop = () => {
// noop
};
let port: number;
function findAvailablePort() {
return new Promise<number>((resolve, reject) => {
const server = require('http').createServer();
server.listen(0, () => {
const { port } = server.address();
server.close(() => resolve(port));
});
server.once('error', reject);
});
}
let stop: VoidFunction;
beforeAll(async () => {
stop = await startApp(4000);
port = await findAvailablePort();
stop = await startApp(port);
});
afterAll(() => stop());

Expand Down
6 changes: 0 additions & 6 deletions examples/sveltekit/__integration-tests__/sveltekit.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@ const timings = {
};

describe('SvelteKit integration', () => {
if (process.env.LEAKS_TEST) {
it('dummy', () => {
return;
});
return;
}
beforeAll(async () => {
const tslibDirPath = join(__dirname, '../node_modules/tslib');
const tslibFilePath = join(tslibDirPath, 'tslib.js');
Expand Down
2 changes: 2 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ if (process.env.LEAKS_TEST === 'true') {
'!**/uwebsockets.test.ts',
'!**/apollo-client.test.ts',
'!**/browser.spec.ts',
'!**/egg.spec.ts',
'!**/sveltekit.spec.ts',
);
}

Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f508510

Please sign in to comment.