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

Commit 59d258b

Browse files
integrationTests: test built package on all supported node versions (#680)
Motivated by #665
1 parent f894ae8 commit 59d258b

File tree

5 files changed

+85
-0
lines changed

5 files changed

+85
-0
lines changed

.eslintrc.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,9 @@ overrides:
596596
import/no-extraneous-dependencies: [error, { devDependencies: true }]
597597
import/no-nodejs-modules: off
598598
no-console: off
599+
- files: 'integrationTests/*/**'
600+
rules:
601+
node/no-missing-require: off
599602
- files: 'resources/**'
600603
rules:
601604
node/no-unpublished-import: off

integrationTests/integration-test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,12 @@ describe('Integration Tests', () => {
3131
exec('npm install --silent', { cwd });
3232
exec('npm test', { cwd });
3333
}).timeout(40000);
34+
35+
it('Should work on all supported node versions', () => {
36+
exec(`cp -R ${path.join(__dirname, 'node')} ${tmpDir}`);
37+
38+
const cwd = path.join(tmpDir, 'node');
39+
exec('npm install', { cwd });
40+
exec('npm test', { cwd });
41+
}).timeout(40000);
3442
});

integrationTests/node/index.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
'use strict';
2+
3+
const assert = require('assert');
4+
5+
const { buildSchema } = require('graphql');
6+
7+
const { graphqlHTTP } = require('express-graphql');
8+
9+
const schema = buildSchema('type Query { hello: String }');
10+
11+
const middleware = graphqlHTTP({
12+
graphiql: true,
13+
schema,
14+
rootValue: { hello: 'world' },
15+
});
16+
17+
assert(typeof middleware === 'function');
18+
19+
const request = {
20+
url: 'http://example.com',
21+
method: 'GET',
22+
headers: {},
23+
body: {
24+
query: '{ hello }',
25+
},
26+
};
27+
28+
const response = {
29+
headers: {},
30+
setHeader(name, value) {
31+
this.headers[name] = value;
32+
},
33+
text: null,
34+
end(buffer) {
35+
this.text = buffer.toString();
36+
},
37+
};
38+
39+
middleware(request, response).then(() => {
40+
assert.deepStrictEqual(response.headers, {
41+
'Content-Length': '26',
42+
'Content-Type': 'application/json; charset=utf-8',
43+
});
44+
assert.deepStrictEqual(response.text, '{"data":{"hello":"world"}}');
45+
});

integrationTests/node/package.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"scripts": {
3+
"test": "node test.js"
4+
},
5+
"dependencies": {
6+
"express-graphql": "file:../express-graphql.tgz",
7+
"graphql": "14.7.0",
8+
"node-10": "npm:[email protected]",
9+
"node-12": "npm:[email protected]",
10+
"node-14": "npm:[email protected]"
11+
}
12+
}

integrationTests/node/test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
'use strict';
2+
3+
const path = require('path');
4+
const childProcess = require('child_process');
5+
6+
const { dependencies } = require('./package.json');
7+
8+
const nodeVersions = Object.keys(dependencies)
9+
.filter((pkg) => pkg.startsWith('node-'))
10+
.sort((a, b) => b.localeCompare(a));
11+
12+
for (const version of nodeVersions) {
13+
console.log(`Testing on ${version} ...`);
14+
15+
const nodePath = path.join(__dirname, 'node_modules', version, 'bin/node');
16+
childProcess.execSync(nodePath + ' index.js', { stdio: 'inherit' });
17+
}

0 commit comments

Comments
 (0)