Skip to content

Commit

Permalink
Stop testing Koa on Node.js v6.
Browse files Browse the repository at this point in the history
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 (2dd0592), 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: #3184
  • Loading branch information
abernix committed Aug 31, 2019
1 parent 1abf851 commit 7188aad
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 39 deletions.
38 changes: 28 additions & 10 deletions packages/apollo-server-koa/src/__tests__/ApolloServer.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import Koa from 'koa';

import http from 'http';

import request from 'request';
Expand Down Expand Up @@ -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);
Expand All @@ -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(
Expand All @@ -63,8 +81,8 @@ describe('apollo-server-koa', () => {

server.applyMiddleware({ ...options, app });

httpServer = await new Promise<http.Server>(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);
Expand Down
63 changes: 38 additions & 25 deletions packages/apollo-server-koa/src/__tests__/datasource.test.ts
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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 () => {
Expand All @@ -76,7 +89,7 @@ describe('apollo-server-koa', () => {
await restServer.close();
});

let server: ApolloServer;
let server: import('../ApolloServer').ApolloServer;
let httpServer: http.Server;

beforeEach(() => {
Expand Down
28 changes: 24 additions & 4 deletions packages/apollo-server-koa/src/__tests__/koaApollo.test.ts
Original file line number Diff line number Diff line change
@@ -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(
Expand All @@ -23,14 +24,33 @@ 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.',
);
});
});

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);
});

0 comments on commit 7188aad

Please sign in to comment.