diff --git a/.eslintrc.yml b/.eslintrc.yml index d31b2ae2..28e16aa6 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -596,6 +596,9 @@ overrides: import/no-extraneous-dependencies: [error, { devDependencies: true }] import/no-nodejs-modules: off no-console: off + - files: 'integrationTests/*/**' + rules: + node/no-missing-require: off - files: 'resources/**' rules: node/no-unpublished-import: off diff --git a/integrationTests/integration-test.js b/integrationTests/integration-test.js index 58df9573..75522c1f 100644 --- a/integrationTests/integration-test.js +++ b/integrationTests/integration-test.js @@ -31,4 +31,12 @@ describe('Integration Tests', () => { exec('npm install --silent', { cwd }); exec('npm test', { cwd }); }).timeout(40000); + + it('Should work on all supported node versions', () => { + exec(`cp -R ${path.join(__dirname, 'node')} ${tmpDir}`); + + const cwd = path.join(tmpDir, 'node'); + exec('npm install', { cwd }); + exec('npm test', { cwd }); + }).timeout(40000); }); diff --git a/integrationTests/node/index.js b/integrationTests/node/index.js new file mode 100644 index 00000000..e2ca9375 --- /dev/null +++ b/integrationTests/node/index.js @@ -0,0 +1,45 @@ +'use strict'; + +const assert = require('assert'); + +const { buildSchema } = require('graphql'); + +const { graphqlHTTP } = require('express-graphql'); + +const schema = buildSchema('type Query { hello: String }'); + +const middleware = graphqlHTTP({ + graphiql: true, + schema, + rootValue: { hello: 'world' }, +}); + +assert(typeof middleware === 'function'); + +const request = { + url: 'http://example.com', + method: 'GET', + headers: {}, + body: { + query: '{ hello }', + }, +}; + +const response = { + headers: {}, + setHeader(name, value) { + this.headers[name] = value; + }, + text: null, + end(buffer) { + this.text = buffer.toString(); + }, +}; + +middleware(request, response).then(() => { + assert.deepStrictEqual(response.headers, { + 'Content-Length': '26', + 'Content-Type': 'application/json; charset=utf-8', + }); + assert.deepStrictEqual(response.text, '{"data":{"hello":"world"}}'); +}); diff --git a/integrationTests/node/package.json b/integrationTests/node/package.json new file mode 100644 index 00000000..55ba96d7 --- /dev/null +++ b/integrationTests/node/package.json @@ -0,0 +1,12 @@ +{ + "scripts": { + "test": "node test.js" + }, + "dependencies": { + "express-graphql": "file:../express-graphql.tgz", + "graphql": "14.7.0", + "node-10": "npm:node@10.x.x", + "node-12": "npm:node@12.x.x", + "node-14": "npm:node@14.x.x" + } +} diff --git a/integrationTests/node/test.js b/integrationTests/node/test.js new file mode 100644 index 00000000..94cc957b --- /dev/null +++ b/integrationTests/node/test.js @@ -0,0 +1,17 @@ +'use strict'; + +const path = require('path'); +const childProcess = require('child_process'); + +const { dependencies } = require('./package.json'); + +const nodeVersions = Object.keys(dependencies) + .filter((pkg) => pkg.startsWith('node-')) + .sort((a, b) => b.localeCompare(a)); + +for (const version of nodeVersions) { + console.log(`Testing on ${version} ...`); + + const nodePath = path.join(__dirname, 'node_modules', version, 'bin/node'); + childProcess.execSync(nodePath + ' index.js', { stdio: 'inherit' }); +}