graphql-server-test 1.1.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/esm/server.js CHANGED
@@ -1,27 +1,4 @@
1
1
  import { Server } from '@constructive-io/graphql-server';
2
- import { createServer } from 'http';
3
- /**
4
- * Find an available port starting from the given port
5
- * Uses 127.0.0.1 explicitly to avoid IPv6/IPv4 mismatch issues with supertest
6
- */
7
- const findAvailablePort = async (startPort, host = '127.0.0.1') => {
8
- return new Promise((resolve, reject) => {
9
- const server = createServer();
10
- server.listen(startPort, host, () => {
11
- const address = server.address();
12
- const port = typeof address === 'object' && address ? address.port : startPort;
13
- server.close(() => resolve(port));
14
- });
15
- server.on('error', (err) => {
16
- if (err.code === 'EADDRINUSE') {
17
- resolve(findAvailablePort(startPort + 1));
18
- }
19
- else {
20
- reject(err);
21
- }
22
- });
23
- });
24
- };
25
2
  /**
26
3
  * Create a test server for SuperTest testing
27
4
  *
@@ -32,9 +9,10 @@ export const createTestServer = async (opts, serverOpts = {}) => {
32
9
  // Use 127.0.0.1 by default to avoid IPv6/IPv4 mismatch issues with supertest
33
10
  // On some systems, 'localhost' resolves to ::1 (IPv6) but supertest connects to 127.0.0.1 (IPv4)
34
11
  const host = serverOpts.host ?? '127.0.0.1';
35
- const requestedPort = serverOpts.port ?? 0;
36
- const port = requestedPort === 0 ? await findAvailablePort(5555, host) : requestedPort;
37
- // Merge server options into the PgpmOptions
12
+ // Use port 0 to let the OS assign an available port atomically
13
+ // This avoids race conditions that can occur with manual port scanning
14
+ const port = serverOpts.port ?? 0;
15
+ // Merge server options into the ConstructiveOptions
38
16
  const serverConfig = {
39
17
  ...opts,
40
18
  server: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "graphql-server-test",
3
- "version": "1.1.0",
3
+ "version": "2.0.0",
4
4
  "author": "Constructive <developers@constructive.io>",
5
5
  "description": "Constructive GraphQL Server Testing with SuperTest HTTP requests",
6
6
  "main": "index.js",
@@ -35,15 +35,15 @@
35
35
  "makage": "^0.1.12"
36
36
  },
37
37
  "dependencies": {
38
- "@constructive-io/graphql-env": "^2.10.0",
39
- "@constructive-io/graphql-server": "^3.1.0",
40
- "@constructive-io/graphql-types": "^2.15.0",
38
+ "@constructive-io/graphql-env": "^3.0.0",
39
+ "@constructive-io/graphql-server": "^4.0.0",
40
+ "@constructive-io/graphql-types": "^3.0.0",
41
41
  "@pgpmjs/types": "^2.16.0",
42
42
  "express": "^5.2.1",
43
43
  "graphql": "15.10.1",
44
44
  "pg": "^8.17.1",
45
- "pg-cache": "^2.1.0",
46
- "pgsql-test": "^3.1.0",
45
+ "pg-cache": "^3.0.0",
46
+ "pgsql-test": "^4.0.0",
47
47
  "supertest": "^7.0.0"
48
48
  },
49
49
  "keywords": [
@@ -57,5 +57,5 @@
57
57
  "e2e",
58
58
  "server"
59
59
  ],
60
- "gitHead": "048188f6b43ffaa6146e7694b2b0d35d34cb2945"
60
+ "gitHead": "b2daeefe49cdefb3d01ea63cf778fb9b847ab5fe"
61
61
  }
package/server.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { PgpmOptions } from '@pgpmjs/types';
1
+ import type { ConstructiveOptions } from '@constructive-io/graphql-types';
2
2
  import type { ServerInfo, ServerOptions } from './types';
3
3
  /**
4
4
  * Create a test server for SuperTest testing
@@ -6,4 +6,4 @@ import type { ServerInfo, ServerOptions } from './types';
6
6
  * This uses the Server class from @constructive-io/graphql-server directly,
7
7
  * which includes all the standard middleware (CORS, authentication, GraphQL, etc.)
8
8
  */
9
- export declare const createTestServer: (opts: PgpmOptions, serverOpts?: ServerOptions) => Promise<ServerInfo>;
9
+ export declare const createTestServer: (opts: ConstructiveOptions, serverOpts?: ServerOptions) => Promise<ServerInfo>;
package/server.js CHANGED
@@ -2,29 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createTestServer = void 0;
4
4
  const graphql_server_1 = require("@constructive-io/graphql-server");
5
- const http_1 = require("http");
6
- /**
7
- * Find an available port starting from the given port
8
- * Uses 127.0.0.1 explicitly to avoid IPv6/IPv4 mismatch issues with supertest
9
- */
10
- const findAvailablePort = async (startPort, host = '127.0.0.1') => {
11
- return new Promise((resolve, reject) => {
12
- const server = (0, http_1.createServer)();
13
- server.listen(startPort, host, () => {
14
- const address = server.address();
15
- const port = typeof address === 'object' && address ? address.port : startPort;
16
- server.close(() => resolve(port));
17
- });
18
- server.on('error', (err) => {
19
- if (err.code === 'EADDRINUSE') {
20
- resolve(findAvailablePort(startPort + 1));
21
- }
22
- else {
23
- reject(err);
24
- }
25
- });
26
- });
27
- };
28
5
  /**
29
6
  * Create a test server for SuperTest testing
30
7
  *
@@ -35,9 +12,10 @@ const createTestServer = async (opts, serverOpts = {}) => {
35
12
  // Use 127.0.0.1 by default to avoid IPv6/IPv4 mismatch issues with supertest
36
13
  // On some systems, 'localhost' resolves to ::1 (IPv6) but supertest connects to 127.0.0.1 (IPv4)
37
14
  const host = serverOpts.host ?? '127.0.0.1';
38
- const requestedPort = serverOpts.port ?? 0;
39
- const port = requestedPort === 0 ? await findAvailablePort(5555, host) : requestedPort;
40
- // Merge server options into the PgpmOptions
15
+ // Use port 0 to let the OS assign an available port atomically
16
+ // This avoids race conditions that can occur with manual port scanning
17
+ const port = serverOpts.port ?? 0;
18
+ // Merge server options into the ConstructiveOptions
41
19
  const serverConfig = {
42
20
  ...opts,
43
21
  server: {