Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 116 additions & 7 deletions integrationTests/conditions/check.mjs
Original file line number Diff line number Diff line change
@@ -1,15 +1,40 @@
import assert from 'node:assert';

import { GraphQLObjectType as ESMGraphQLObjectType } from 'graphql';
import {
GraphQLObjectType as ESMGraphQLObjectType,
GraphQLString as ESMGraphQLString,
isCompositeType as ESMIsCompositeType,
} from 'graphql';
import {
GraphQLObjectType as ESMTypeGraphQLObjectType,
GraphQLString as ESMTypeGraphQLString,
isCompositeType as ESMTypeIsCompositeType,
} from 'graphql/type';

import { CJSGraphQLObjectType, cjsPath } from './cjs-importer.cjs';
import {
CJSGraphQLObjectType,
CJSGraphQLString,
CJSIsCompositeType,
cjsPath,
CJSTypeGraphQLObjectType,
CJSTypeGraphQLString,
CJSTypeIsCompositeType,
cjsTypePath,
} from './cjs-importer.cjs';

const moduleSync = process.env.MODULE_SYNC === 'true';
const expectedExtension = moduleSync ? '.mjs' : '.js';
assert.ok(
cjsPath.endsWith(expectedExtension),
`require('graphql') should resolve to a file with extension "${expectedExtension}", but got "${cjsPath}".`,
);
const resolvedPaths = [
["require('graphql')", cjsPath],
["require('graphql/type')", cjsTypePath],
];

for (const [specifier, resolvedPath] of resolvedPaths) {
assert.ok(
resolvedPath.endsWith(expectedExtension),
`${specifier} should resolve to a file with extension "${expectedExtension}", but got "${resolvedPath}".`,
);
}

const isSameModule = ESMGraphQLObjectType === CJSGraphQLObjectType;
assert.strictEqual(
Expand All @@ -18,4 +43,88 @@ assert.strictEqual(
'ESM and CJS imports should be the same module instances.',
);

console.log('Module identity and path checks passed.');
assert.strictEqual(
ESMGraphQLObjectType,
ESMTypeGraphQLObjectType,
'Root and graphql/type ESM imports should use the same GraphQLObjectType instance.',
);
assert.strictEqual(
CJSGraphQLObjectType,
CJSTypeGraphQLObjectType,
'Root and graphql/type CJS imports should use the same GraphQLObjectType instance.',
);
assert.strictEqual(
ESMIsCompositeType,
ESMTypeIsCompositeType,
'Root and graphql/type ESM imports should use the same isCompositeType predicate.',
);
assert.strictEqual(
CJSIsCompositeType,
CJSTypeIsCompositeType,
'Root and graphql/type CJS imports should use the same isCompositeType predicate.',
);
assert.strictEqual(
ESMIsCompositeType,
CJSIsCompositeType,
'ESM and CJS imports should use the same isCompositeType predicate.',
);
assert.strictEqual(
ESMGraphQLString,
ESMTypeGraphQLString,
'Root and graphql/type ESM imports should use the same GraphQLString instance.',
);
assert.strictEqual(
CJSGraphQLString,
CJSTypeGraphQLString,
'Root and graphql/type CJS imports should use the same GraphQLString instance.',
);

const objectTypes = [
[
'ESM root GraphQLObjectType',
new ESMGraphQLObjectType({
name: 'ESMRootObjectType',
fields: { field: { type: ESMGraphQLString } },
}),
],
[
'ESM graphql/type GraphQLObjectType',
new ESMTypeGraphQLObjectType({
name: 'ESMTypeObjectType',
fields: { field: { type: ESMTypeGraphQLString } },
}),
],
[
'CJS root GraphQLObjectType',
new CJSGraphQLObjectType({
name: 'CJSRootObjectType',
fields: { field: { type: CJSGraphQLString } },
}),
],
[
'CJS graphql/type GraphQLObjectType',
new CJSTypeGraphQLObjectType({
name: 'CJSTypeObjectType',
fields: { field: { type: CJSTypeGraphQLString } },
}),
],
];

const predicates = [
['ESM root isCompositeType', ESMIsCompositeType],
['ESM graphql/type isCompositeType', ESMTypeIsCompositeType],
['CJS root isCompositeType', CJSIsCompositeType],
['CJS graphql/type isCompositeType', CJSTypeIsCompositeType],
];

for (const [objectTypeLabel, objectType] of objectTypes) {
for (const [predicateLabel, isCompositeType] of predicates) {
assert.strictEqual(
isCompositeType(objectType),
true,
`${predicateLabel} should return true for ${objectTypeLabel}.`,
);
}
}

console.log('Module identity, subpath identity, and path checks passed.');
18 changes: 17 additions & 1 deletion integrationTests/conditions/cjs-importer.cjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
'use strict';

const { GraphQLObjectType } = require('graphql');
const {
GraphQLObjectType,
GraphQLString,
isCompositeType,
} = require('graphql');
const {
GraphQLObjectType: TypeGraphQLObjectType,
GraphQLString: TypeGraphQLString,
isCompositeType: typeIsCompositeType,
} = require('graphql/type');

const cjsPath = require.resolve('graphql');
const cjsTypePath = require.resolve('graphql/type');

// eslint-disable-next-line import/no-commonjs
module.exports = {
CJSGraphQLObjectType: GraphQLObjectType,
CJSGraphQLString: GraphQLString,
CJSIsCompositeType: isCompositeType,
CJSTypeGraphQLObjectType: TypeGraphQLObjectType,
CJSTypeGraphQLString: TypeGraphQLString,
CJSTypeIsCompositeType: typeIsCompositeType,
cjsPath,
cjsTypePath,
};
Loading