Skip to content

Commit c497a17

Browse files
committed
add node-esm integrationTests
1 parent 8173caa commit c497a17

File tree

4 files changed

+79
-0
lines changed

4 files changed

+79
-0
lines changed

integrationTests/integration-test.js

+11
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,16 @@ describe('Integration Tests', () => {
2727
path.join(tmpDir, 'graphql.tgz'),
2828
);
2929

30+
const esmDistDir = path.resolve('./npmEsmDist');
31+
const esmArchiveName = exec(`npm --quiet pack ${esmDistDir}`, {
32+
cwd: tmpDir,
33+
});
34+
35+
fs.renameSync(
36+
path.join(tmpDir, esmArchiveName),
37+
path.join(tmpDir, 'graphql-esm.tgz'),
38+
);
39+
3040
function testOnNodeProject(projectName) {
3141
const projectPath = path.join(__dirname, projectName);
3242

@@ -45,4 +55,5 @@ describe('Integration Tests', () => {
4555
testOnNodeProject('ts');
4656
testOnNodeProject('node');
4757
testOnNodeProject('webpack');
58+
testOnNodeProject('node-esm');
4859
});

integrationTests/node-esm/index.js

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { deepStrictEqual, strictEqual } from 'assert';
2+
import { readFileSync } from 'fs';
3+
4+
// Regular import
5+
import { graphqlSync } from 'graphql';
6+
// import with explicit extensions
7+
import { version } from 'graphql/version.js';
8+
// _/index.js import
9+
import { buildSchema } from 'graphql/utilities';
10+
// import without explicit extensions
11+
import { isPromise } from 'graphql/jsutils/isPromise';
12+
13+
deepStrictEqual(
14+
version,
15+
JSON.parse(readFileSync('./node_modules/graphql/package.json')).version,
16+
);
17+
18+
const schema = buildSchema('type Query { hello: String }');
19+
20+
const result = graphqlSync({
21+
schema,
22+
source: '{ hello }',
23+
rootValue: { hello: 'world' },
24+
});
25+
26+
deepStrictEqual(result, {
27+
data: {
28+
__proto__: null,
29+
hello: 'world',
30+
},
31+
});
32+
33+
strictEqual(isPromise(Promise.resolve()), true);
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"type": "module",
3+
"description": "graphql-js should work on all supported node versions with ESM",
4+
"scripts": {
5+
"test": "node test.js"
6+
},
7+
"dependencies": {
8+
"graphql": "file:../graphql-esm.tgz",
9+
"node-12": "npm:[email protected]",
10+
"node-14": "npm:[email protected]",
11+
"node-16": "npm:[email protected]"
12+
}
13+
}

integrationTests/node-esm/test.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { execSync } from 'child_process';
2+
import { createRequire } from 'module';
3+
import { dirname, join } from 'path';
4+
import { fileURLToPath } from 'url';
5+
6+
const { dependencies } = createRequire(import.meta.url)('./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 = join(
16+
dirname(fileURLToPath(import.meta.url)),
17+
'node_modules',
18+
version,
19+
'bin/node',
20+
);
21+
execSync(nodePath + ' index.js', { stdio: 'inherit' });
22+
}

0 commit comments

Comments
 (0)