Skip to content

Commit

Permalink
First try at running with tests
Browse files Browse the repository at this point in the history
  • Loading branch information
reaktivo committed Jul 28, 2018
1 parent cada809 commit 1259387
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/apollo-server-cloud-function/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"apollo-server-env": "2.0.0",
"graphql-tools": "^3.0.4"
},
"xdevDependencies": {
"devDependencies": {
"apollo-server-integration-testsuite": "2.0.0"
},
"peerDependencies": {
Expand Down
30 changes: 30 additions & 0 deletions packages/apollo-server-cloud-function/src/gqlApollo.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { ApolloServer } from './ApolloServer';
import testSuite, {
schema as Schema,
CreateAppOptions,
} from 'apollo-server-integration-testsuite';
import { Config } from 'apollo-server-core';
import 'mocha';
import { IncomingMessage, ServerResponse } from 'http';

const createCloudFunction = (options: CreateAppOptions = {}) => {
const server = new ApolloServer(
(options.graphqlOptions as Config) || { schema: Schema },
);

const handler = server.createHandler();

return (req: IncomingMessage, res: ServerResponse) => {
// return 404 if path is /bogus-route to pass the test, lambda doesn't have paths
if (req.url.includes('/bogus-route')) {
res.statusCode = 404;
return res.end();
}

return handler(req, res);
};
};

describe('integration:CloudFunction', () => {
testSuite(createCloudFunction);
});

0 comments on commit 1259387

Please sign in to comment.