From 7188aad458a5f34422a9cbf97b8f7d6a133e3a1e Mon Sep 17 00:00:00 2001 From: Jesse Rosenberger Date: Sat, 31 Aug 2019 18:12:22 +0300 Subject: [PATCH] Stop testing Koa on Node.js v6. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It was going to come to this sooner or later, since Node.js v6 is no longer supported by the Node.js Foundation. In this case, I'm adding this exception because after bringing #3229 (2dd0592e), the `koa-bodyparser` package was updated to a new major version which, itself, dropped Node.js 6 support. That update to `koa-bodyparser`, which fixes an incorrect/malformed `Content-length` header calculation is — I think — important enough that we should make sure it's included in Apollo Server, which currently drives the underlying version of Koa for all users because of its close coupling with Koa itself (via the `apollo-server-koa` package). This micro-framework-management will no longer be a concern with Apollo Server, particularly because of the introduction of a transport abstraction, which I've proposed in #3184. Ref: https://github.com/apollographql/apollo-server/issues/3184 --- .../src/__tests__/ApolloServer.test.ts | 38 ++++++++--- .../src/__tests__/datasource.test.ts | 63 +++++++++++-------- .../src/__tests__/koaApollo.test.ts | 28 +++++++-- 3 files changed, 90 insertions(+), 39 deletions(-) diff --git a/packages/apollo-server-koa/src/__tests__/ApolloServer.test.ts b/packages/apollo-server-koa/src/__tests__/ApolloServer.test.ts index eb207fafde4..d182eb81d88 100644 --- a/packages/apollo-server-koa/src/__tests__/ApolloServer.test.ts +++ b/packages/apollo-server-koa/src/__tests__/ApolloServer.test.ts @@ -1,5 +1,3 @@ -import Koa from 'koa'; - import http from 'http'; import request from 'request'; @@ -28,9 +26,19 @@ const resolvers = { }, }; -describe('apollo-server-koa', () => { - let server; - let httpServer; +// If we're on Node.js v6, skip this test, since `koa-bodyparser` has dropped +// support for it and there was an important update to it which we brought in +// through https://github.com/apollographql/apollo-server/pull/3229. +// It's worth noting that Node.js v6 has been out of Long-Term-Support status +// for four months and is no longer recommended by the Node.js Foundation. +( + NODE_MAJOR_VERSION === 6 ? + describe.skip : + describe +)('apollo-server-koa', () => { + const Koa = require('koa'); + let server: ApolloServer; + let httpServer: http.Server; testApolloServer( async options => { server = new ApolloServer(options); @@ -48,10 +56,20 @@ describe('apollo-server-koa', () => { ); }); -describe('apollo-server-koa', () => { - let server: ApolloServer; +// If we're on Node.js v6, skip this test, since `koa-bodyparser` has dropped +// support for it and there was an important update to it which we brought in +// through https://github.com/apollographql/apollo-server/pull/3229. +// It's worth noting that Node.js v6 has been out of Long-Term-Support status +// for four months and is no longer recommended by the Node.js Foundation. +( + NODE_MAJOR_VERSION === 6 ? + describe.skip : + describe +)('apollo-server-koa', () => { + const Koa = require('koa'); - let app: Koa; + let server: ApolloServer; + let app: import('koa'); let httpServer: http.Server; async function createServer( @@ -63,8 +81,8 @@ describe('apollo-server-koa', () => { server.applyMiddleware({ ...options, app }); - httpServer = await new Promise(resolve => { - const l = app.listen({ port: 0 }, () => resolve(l)); + httpServer = await new Promise(resolve => { + const l: http.Server = app.listen({ port: 0 }, () => resolve(l)); }); return createServerInfo(server, httpServer); diff --git a/packages/apollo-server-koa/src/__tests__/datasource.test.ts b/packages/apollo-server-koa/src/__tests__/datasource.test.ts index a0ce2576464..41660a299ca 100644 --- a/packages/apollo-server-koa/src/__tests__/datasource.test.ts +++ b/packages/apollo-server-koa/src/__tests__/datasource.test.ts @@ -1,15 +1,15 @@ -import Koa from 'koa'; -import KoaRouter from 'koa-router'; - import http from 'http'; import { RESTDataSource } from 'apollo-datasource-rest'; import { createApolloFetch } from 'apollo-fetch'; -import { ApolloServer } from '../ApolloServer'; -import { createServerInfo } from 'apollo-server-integration-testsuite'; -import { gql } from '../index'; +import { + NODE_MAJOR_VERSION, + createServerInfo, +} from 'apollo-server-integration-testsuite'; + +import { gql } from 'apollo-server-core'; const restPort = 4002; @@ -43,27 +43,40 @@ const resolvers = { }, }; -let restCalls = 0; -const restAPI = new Koa(); -const router = new KoaRouter(); -router.all('/id/:id', ctx => { - const id = ctx.params.id; - restCalls++; - ctx.set('Cache-Control', 'max-age=2000, public'); - ctx.body = { id }; -}); +// If we're on Node.js v6, skip this test, since `koa-bodyparser` has dropped +// support for it and there was an important update to it which we brought in +// through https://github.com/apollographql/apollo-server/pull/3229. +// It's worth noting that Node.js v6 has been out of Long-Term-Support status +// for four months and is no longer recommended by the Node.js Foundation. +( + NODE_MAJOR_VERSION === 6 ? + describe.skip : + describe +)('apollo-server-koa', () => { + const { ApolloServer } = require('../ApolloServer'); + const Koa = require('koa'); + const KoaRouter = require('koa-router'); + + let restCalls = 0; + const restAPI = new Koa(); + const router = new KoaRouter(); + router.all('/id/:id', ctx => { + const id = ctx.params.id; + restCalls++; + ctx.set('Cache-Control', 'max-age=2000, public'); + ctx.body = { id }; + }); -router.all('/str/:id', ctx => { - const id = ctx.params.id; - restCalls++; - ctx.set('Cache-Control', 'max-age=2000, public'); - ctx.body = id; -}); + router.all('/str/:id', ctx => { + const id = ctx.params.id; + restCalls++; + ctx.set('Cache-Control', 'max-age=2000, public'); + ctx.body = id; + }); -restAPI.use(router.routes()); -restAPI.use(router.allowedMethods()); + restAPI.use(router.routes()); + restAPI.use(router.allowedMethods()); -describe('apollo-server-koa', () => { let restServer; beforeAll(async () => { @@ -76,7 +89,7 @@ describe('apollo-server-koa', () => { await restServer.close(); }); - let server: ApolloServer; + let server: import('../ApolloServer').ApolloServer; let httpServer: http.Server; beforeEach(() => { diff --git a/packages/apollo-server-koa/src/__tests__/koaApollo.test.ts b/packages/apollo-server-koa/src/__tests__/koaApollo.test.ts index 7a4594d3a9a..9c4fa74c7e6 100644 --- a/packages/apollo-server-koa/src/__tests__/koaApollo.test.ts +++ b/packages/apollo-server-koa/src/__tests__/koaApollo.test.ts @@ -1,12 +1,13 @@ -import Koa from 'koa'; -import { ApolloServer } from '../ApolloServer'; import testSuite, { + NODE_MAJOR_VERSION, schema as Schema, CreateAppOptions, } from 'apollo-server-integration-testsuite'; import { GraphQLOptions, Config } from 'apollo-server-core'; function createApp(options: CreateAppOptions = {}) { + const Koa = require('koa'); + const { ApolloServer } = require('../ApolloServer'); const app = new Koa(); const server = new ApolloServer( @@ -23,7 +24,17 @@ async function destroyApp(app) { await new Promise(resolve => app.close(resolve)); } -describe('koaApollo', () => { +// If we're on Node.js v6, skip this test, since `koa-bodyparser` has dropped +// support for it and there was an important update to it which we brought in +// through https://github.com/apollographql/apollo-server/pull/3229. +// It's worth noting that Node.js v6 has been out of Long-Term-Support status +// for four months and is no longer recommended by the Node.js Foundation. +( + NODE_MAJOR_VERSION === 6 ? + describe.skip : + describe +)('koaApollo', () => { + const { ApolloServer } = require('../ApolloServer'); it('throws error if called without schema', function() { expect(() => new ApolloServer(undefined as GraphQLOptions)).toThrow( 'ApolloServer requires options.', @@ -31,6 +42,15 @@ describe('koaApollo', () => { }); }); -describe('integration:Koa', () => { +// If we're on Node.js v6, skip this test, since `koa-bodyparser` has dropped +// support for it and there was an important update to it which we brought in +// through https://github.com/apollographql/apollo-server/pull/3229. +// It's worth noting that Node.js v6 has been out of Long-Term-Support status +// for four months and is no longer recommended by the Node.js Foundation. +( + NODE_MAJOR_VERSION === 6 ? + describe.skip : + describe +)('integration:Koa', () => { testSuite(createApp, destroyApp); });