Skip to content

Commit

Permalink
add node-esm integrationTests
Browse files Browse the repository at this point in the history
  • Loading branch information
PabloSzx committed Nov 4, 2021
1 parent 8173caa commit c497a17
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 0 deletions.
11 changes: 11 additions & 0 deletions integrationTests/integration-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ describe('Integration Tests', () => {
path.join(tmpDir, 'graphql.tgz'),
);

const esmDistDir = path.resolve('./npmEsmDist');
const esmArchiveName = exec(`npm --quiet pack ${esmDistDir}`, {
cwd: tmpDir,
});

fs.renameSync(
path.join(tmpDir, esmArchiveName),
path.join(tmpDir, 'graphql-esm.tgz'),
);

function testOnNodeProject(projectName) {
const projectPath = path.join(__dirname, projectName);

Expand All @@ -45,4 +55,5 @@ describe('Integration Tests', () => {
testOnNodeProject('ts');
testOnNodeProject('node');
testOnNodeProject('webpack');
testOnNodeProject('node-esm');
});
33 changes: 33 additions & 0 deletions integrationTests/node-esm/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { deepStrictEqual, strictEqual } from 'assert';
import { readFileSync } from 'fs';

// Regular import
import { graphqlSync } from 'graphql';
// import with explicit extensions
import { version } from 'graphql/version.js';
// _/index.js import
import { buildSchema } from 'graphql/utilities';
// import without explicit extensions
import { isPromise } from 'graphql/jsutils/isPromise';

deepStrictEqual(
version,
JSON.parse(readFileSync('./node_modules/graphql/package.json')).version,
);

const schema = buildSchema('type Query { hello: String }');

const result = graphqlSync({
schema,
source: '{ hello }',
rootValue: { hello: 'world' },
});

deepStrictEqual(result, {
data: {
__proto__: null,
hello: 'world',
},
});

strictEqual(isPromise(Promise.resolve()), true);
13 changes: 13 additions & 0 deletions integrationTests/node-esm/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"type": "module",
"description": "graphql-js should work on all supported node versions with ESM",
"scripts": {
"test": "node test.js"
},
"dependencies": {
"graphql": "file:../graphql-esm.tgz",
"node-12": "npm:[email protected]",
"node-14": "npm:[email protected]",
"node-16": "npm:[email protected]"
}
}
22 changes: 22 additions & 0 deletions integrationTests/node-esm/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { execSync } from 'child_process';
import { createRequire } from 'module';
import { dirname, join } from 'path';
import { fileURLToPath } from 'url';

const { dependencies } = createRequire(import.meta.url)('./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 = join(
dirname(fileURLToPath(import.meta.url)),
'node_modules',
version,
'bin/node',
);
execSync(nodePath + ' index.js', { stdio: 'inherit' });
}

0 comments on commit c497a17

Please sign in to comment.