Skip to content
This repository has been archived by the owner on Mar 20, 2023. It is now read-only.

Commit

Permalink
integrationTests: test built package on all supported node versions (#…
Browse files Browse the repository at this point in the history
…680)

Motivated by #665
  • Loading branch information
IvanGoncharov authored Aug 10, 2020
1 parent f894ae8 commit 59d258b
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions integrationTests/integration-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
45 changes: 45 additions & 0 deletions integrationTests/node/index.js
Original file line number Diff line number Diff line change
@@ -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"}}');
});
12 changes: 12 additions & 0 deletions integrationTests/node/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
17 changes: 17 additions & 0 deletions integrationTests/node/test.js
Original file line number Diff line number Diff line change
@@ -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' });
}

0 comments on commit 59d258b

Please sign in to comment.