From 93f6f24f348f3961dce3b42a27270773af455dec Mon Sep 17 00:00:00 2001 From: Sceat Date: Fri, 7 Nov 2025 02:10:31 +0700 Subject: [PATCH 1/6] chore: fix lint errors - remove unused catch parameter, apply prettier formatting --- src/fastify.js | 12 ++++++++++-- src/koa.js | 7 ++++++- src/lambda.js | 6 ++++-- src/tinyhttp.js | 7 ++++++- test/index.test.js | 15 +++++++++------ test/lambda.test.js | 27 +++++++++++++++------------ 6 files changed, 50 insertions(+), 24 deletions(-) diff --git a/src/fastify.js b/src/fastify.js index daab086..95ecdd6 100644 --- a/src/fastify.js +++ b/src/fastify.js @@ -9,8 +9,16 @@ const Fastify = ({ body }, reply) => { } catch (error) { const graphql_error = error instanceof GraphQLError ? error : new GraphQLError(error.message) - reply.status(200).type('application/json').send({ errors: [graphql_error] }) - return { query: null, variable_values: null, operation_name: null, reply: () => {} } + reply + .status(200) + .type('application/json') + .send({ errors: [graphql_error] }) + return { + query: null, + variable_values: null, + operation_name: null, + reply: () => {}, + } } const { query, variables, operationName, operation_name } = body diff --git a/src/koa.js b/src/koa.js index fbfb1a3..d204b11 100644 --- a/src/koa.js +++ b/src/koa.js @@ -14,7 +14,12 @@ const Koa = context => { context.status = 200 context.type = 'application/json' context.body = { errors: [graphql_error] } - return { query: null, variable_values: null, operation_name: null, reply: () => {} } + return { + query: null, + variable_values: null, + operation_name: null, + reply: () => {}, + } } const { query, variables, operationName, operation_name } = request_body diff --git a/src/lambda.js b/src/lambda.js index 92d14b1..ba5d4c5 100644 --- a/src/lambda.js +++ b/src/lambda.js @@ -7,7 +7,7 @@ const Lambda = ({ body: raw_body }, context, reply) => { let parsed try { parsed = JSON.parse(raw_body) - } catch (error) { + } catch { reply(null, { statusCode: 400, body: JSON.stringify({ @@ -24,7 +24,9 @@ const Lambda = ({ body: raw_body }, context, reply) => { reply(null, { statusCode: 200, body: JSON.stringify({ - errors: [error instanceof GraphQLError ? error : { message: error.message }], + errors: [ + error instanceof GraphQLError ? error : { message: error.message }, + ], }), }) return { query: null, variable_values: null, operation_name: null, reply } diff --git a/src/tinyhttp.js b/src/tinyhttp.js index 1188d64..21340e3 100644 --- a/src/tinyhttp.js +++ b/src/tinyhttp.js @@ -10,7 +10,12 @@ const TinyHttp = ({ body = {} }, response) => { const graphql_error = error instanceof GraphQLError ? error : new GraphQLError(error.message) response.status(200).json({ errors: [graphql_error] }) - return { query: null, variable_values: null, operation_name: null, reply: () => {} } + return { + query: null, + variable_values: null, + operation_name: null, + reply: () => {}, + } } const { query, variables, operationName, operation_name } = body diff --git a/test/index.test.js b/test/index.test.js index bce20c0..f310c38 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -145,12 +145,15 @@ test('koa adapter', async t => { } }) - await t.test('should return error for query exceeding size limit', async () => { - const huge_query = `{ ${'me { name } '.repeat(20000)} }` - const { errors } = await request({ query: huge_query }) - assert.ok(errors) - assert.ok(errors[0].message.toLowerCase().includes('too large')) - }) + await t.test( + 'should return error for query exceeding size limit', + async () => { + const huge_query = `{ ${'me { name } '.repeat(20000)} }` + const { errors } = await request({ query: huge_query }) + assert.ok(errors) + assert.ok(errors[0].message.toLowerCase().includes('too large')) + }, + ) await t.test('should timeout slow build_context', async () => { const Koa = (await import('koa')).default diff --git a/test/lambda.test.js b/test/lambda.test.js index 59b01ad..55f9e35 100644 --- a/test/lambda.test.js +++ b/test/lambda.test.js @@ -146,18 +146,21 @@ test('lambda adapter', async t => { assert.ok(body.errors[0].message.toLowerCase().includes('json')) }) - await t.test('should return error for query exceeding size limit', async () => { - const huge_query = `{ ${'me { name } '.repeat(20000)} }` - const event = create_lambda_event({ - query: huge_query, - }) - const result = await invoke_lambda(event) - - assert.strictEqual(result.statusCode, 200) - const body = JSON.parse(result.body) - assert.ok(body.errors) - assert.ok(body.errors[0].message.toLowerCase().includes('too large')) - }) + await t.test( + 'should return error for query exceeding size limit', + async () => { + const huge_query = `{ ${'me { name } '.repeat(20000)} }` + const event = create_lambda_event({ + query: huge_query, + }) + const result = await invoke_lambda(event) + + assert.strictEqual(result.statusCode, 200) + const body = JSON.parse(result.body) + assert.ok(body.errors) + assert.ok(body.errors[0].message.toLowerCase().includes('too large')) + }, + ) await t.test('should return error for non-object request body', async () => { const event = { From f71bd5df9572a2d4a60e766770c1e63a21b42ccc Mon Sep 17 00:00:00 2001 From: Sceat Date: Fri, 7 Nov 2025 02:21:04 +0700 Subject: [PATCH 2/6] fix(ci): update Node.js version to 20 for ESLint 9 compatibility ESLint 9 requires Node.js 18.18+ or 20.9+ (uses structuredClone). Updated all CI jobs from Node 16.9 to Node 20. --- .github/workflows/CI.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 829ca42..d342973 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -15,7 +15,7 @@ jobs: - uses: actions/checkout@v2 - uses: actions/setup-node@v1 with: - node-version: 16.9 + node-version: 20 - run: npm i - run: npm run lint - run: npm test @@ -27,7 +27,7 @@ jobs: - uses: actions/checkout@v2 - uses: actions/setup-node@v1 with: - node-version: 16.9 + node-version: 20 - run: npm i - run: npm run coverage - uses: codecov/codecov-action@v1 @@ -42,7 +42,7 @@ jobs: - uses: actions/checkout@v2 - uses: actions/setup-node@v1 with: - node-version: 16.9 + node-version: 20 registry-url: https://registry.npmjs.org/ scope: '@hydre' - run: npm ci From 4bf43475b3c3c63875c8b8b39c38f8f39490f37e Mon Sep 17 00:00:00 2001 From: Sceat Date: Fri, 7 Nov 2025 02:23:00 +0700 Subject: [PATCH 3/6] fix(test): quote glob pattern for cross-platform compatibility Node's --test flag requires quoted glob patterns in npm scripts to work correctly across different shells (bash/sh/zsh). --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index eafa002..6f44598 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "./tinyhttp": "./src/tinyhttp.js" }, "scripts": { - "test": "node --test test/**/*.test.js", + "test": "node --test 'test/**/*.test.js'", "test:coverage": "c8 --reporter=text --reporter=html --reporter=lcov npm test", "typecheck": "tsc --noEmit", "lint": "eslint . && prettier . --check", From d2676ca60e0e254f34c92496cb76c09020c9f3fc Mon Sep 17 00:00:00 2001 From: Sceat Date: Fri, 7 Nov 2025 02:24:30 +0700 Subject: [PATCH 4/6] fix(test): use simple glob pattern instead of recursive Changed from test/**/*.test.js to test/*.test.js since all test files are in the root test directory. The recursive glob wasn't expanding correctly in CI bash environment. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6f44598..c3c98e4 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "./tinyhttp": "./src/tinyhttp.js" }, "scripts": { - "test": "node --test 'test/**/*.test.js'", + "test": "node --test test/*.test.js", "test:coverage": "c8 --reporter=text --reporter=html --reporter=lcov npm test", "typecheck": "tsc --noEmit", "lint": "eslint . && prettier . --check", From 34f1bee7a2856ffc71c7032a72a1e81bb8345cd0 Mon Sep 17 00:00:00 2001 From: Sceat Date: Fri, 7 Nov 2025 02:26:29 +0700 Subject: [PATCH 5/6] fix(test): change fastify test port to 3002 to avoid conflicts Fastify tests were conflicting with Koa timeout test (both using port 3001). Changed fastify to use port 3002 to prevent EADDRINUSE errors in parallel test execution. --- test/fastify.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/fastify.test.js b/test/fastify.test.js index 78f1382..4e89df7 100644 --- a/test/fastify.test.js +++ b/test/fastify.test.js @@ -10,12 +10,12 @@ import graphql_http from '../src/fastify.js' async function create_server(options) { const fastify = Fastify() fastify.post('/', graphql_http(options)) - await fastify.listen({ port: 3001 }) + await fastify.listen({ port: 3002 }) return fastify } async function request({ query, variables = {}, operation_name = null } = {}) { - const response = await fetch('http://localhost:3001', { + const response = await fetch('http://localhost:3002', { method: 'POST', headers: { 'Content-Type': 'application/json', From 4698747017bcef62a1949c8ccfb297d12732334e Mon Sep 17 00:00:00 2001 From: Sceat Date: Fri, 7 Nov 2025 02:28:20 +0700 Subject: [PATCH 6/6] fix(ci): use correct coverage script name Changed from 'npm run coverage' to 'npm run test:coverage' to match the actual script name in package.json. --- .github/workflows/CI.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index d342973..088c234 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -29,7 +29,7 @@ jobs: with: node-version: 20 - run: npm i - - run: npm run coverage + - run: npm run test:coverage - uses: codecov/codecov-action@v1 publish-npm: