Skip to content

enable conditional exports #4448

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: next
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions cspell.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ words:
# TODO: contribute upstream
- deno
- hashbang
- Rspack
- Rollup

# Website tech
- Nextra
Expand Down
24 changes: 23 additions & 1 deletion integrationTests/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,23 @@
# TBD
# Integration Tests

This directory contains integration tests for GraphQL.js across different environments and bundlers, testing basic GraphQL.JS functionality, as well as development mode and production mode behavior.

Tests are run via the main integration test suite in `resources/integration-test.ts`.

## Test Structure

### Basic GraphQL.JS Functionality Tests

Each subdirectory represents a different environment/bundler:

- `node` - tests for supported Node.js versions
- `ts` - tests for supported Typescript versions
- `webpack` - tests for Webpack

### Verifying Development Mode Tests

Each subdirectory represents a different environment/bundler demonstrating enabling development mode by setting the environment variable `NODE_ENV` to `development`.

### Verifying Production Mode Tests

Each subdirectory represents a different environment/bundler demonstrating production mode when development mode is not enabled.
10 changes: 10 additions & 0 deletions integrationTests/dev-bun/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"description": "graphql-js development mode should work with Bun",
"private": true,
"scripts": {
"test": "docker run --rm --volume \"$PWD:/usr/src/app\" -w /usr/src/app oven/bun:latest bun test.js"
},
"dependencies": {
"graphql": "file:../graphql.tgz"
}
}
18 changes: 18 additions & 0 deletions integrationTests/dev-bun/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { isObjectType } from 'graphql';

class GraphQLObjectType {
get [Symbol.toStringTag]() {
return 'GraphQLObjectType';
}
}

try {
isObjectType(new GraphQLObjectType());
throw new Error(
'Expected isObjectType to throw an error in Bun development mode.',
);
} catch (error) {
if (!error.message.includes('from another module or realm')) {
throw error;
}
}
10 changes: 10 additions & 0 deletions integrationTests/dev-deno/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"description": "graphql-js development mode should work with Deno",
"private": true,
"scripts": {
"test": "docker run --rm --volume \"$PWD:/usr/src/app\" -w /usr/src/app denoland/deno:latest deno run --allow-env=NODE_ENV test.js"
},
"dependencies": {
"graphql": "file:../graphql.tgz"
}
}
18 changes: 18 additions & 0 deletions integrationTests/dev-deno/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { isObjectType } from 'graphql';

class GraphQLObjectType {
get [Symbol.toStringTag]() {
return 'GraphQLObjectType';
}
}

try {
isObjectType(new GraphQLObjectType());
throw new Error(
'Expected isObjectType to throw an error in Deno implicit dev mode.',
);
} catch (error) {
if (!error.message.includes('from another module or realm')) {
throw error;
}
}
18 changes: 18 additions & 0 deletions integrationTests/dev-esbuild/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { isObjectType } from 'graphql';

class GraphQLObjectType {
get [Symbol.toStringTag]() {
return 'GraphQLObjectType';
}
}

try {
isObjectType(new GraphQLObjectType());
throw new Error(
'Expected isObjectType to throw an error in esbuild development mode.',
);
} catch (error) {
if (!error.message.includes('from another module or realm')) {
throw error;
}
}
13 changes: 13 additions & 0 deletions integrationTests/dev-esbuild/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"description": "graphql-js development mode should work with esbuild",
"private": true,
"type": "module",
"scripts": {
"build": "esbuild index.js --bundle --outfile=dist/bundle.js --format=esm",
"test": "npm run build && node dist/bundle.js"
},
"dependencies": {
"graphql": "file:../graphql.tgz",
"esbuild": "^0.25.0"
}
}
18 changes: 18 additions & 0 deletions integrationTests/dev-jest/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/* eslint-disable import/unambiguous */
/* eslint-disable import/no-commonjs */
/* eslint-disable no-undef */
const { isObjectType } = require('graphql');

class FakeGraphQLObjectType {
get [Symbol.toStringTag]() {
return 'GraphQLObjectType';
}
}

describe('Jest with SWC development mode tests', () => {
test('isObjectType should throw in development mode for instances from another realm/module', () => {
expect(() => isObjectType(new FakeGraphQLObjectType())).toThrowError(
/from another module or realm/,
);
});
});
14 changes: 14 additions & 0 deletions integrationTests/dev-jest/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"description": "graphql-js development mode should work with Jest",
"private": true,
"type": "module",
"scripts": {
"test": "jest"
},
"dependencies": {
"graphql": "file:../graphql.tgz"
},
"devDependencies": {
"jest": "^29.7.0"
}
}
11 changes: 11 additions & 0 deletions integrationTests/dev-node/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"description": "graphql-js development mode should work with node",
"private": true,
"type": "module",
"scripts": {
"test": "node test.js"
},
"dependencies": {
"graphql": "file:../graphql.tgz"
}
}
18 changes: 18 additions & 0 deletions integrationTests/dev-node/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { isObjectType } from 'graphql';

class GraphQLObjectType {
get [Symbol.toStringTag]() {
return 'GraphQLObjectType';
}
}

try {
isObjectType(new GraphQLObjectType());
throw new Error(
'Expected isObjectType to throw an error in Node.js implicit dev mode.',
);
} catch (error) {
if (!error.message.includes('from another module or realm')) {
throw error;
}
}
18 changes: 18 additions & 0 deletions integrationTests/dev-rollup/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { isObjectType } from 'graphql';

class GraphQLObjectType {
get [Symbol.toStringTag]() {
return 'GraphQLObjectType';
}
}

try {
isObjectType(new GraphQLObjectType());
throw new Error(
'Expected isObjectType to throw an error in Rollup development mode.',
);
} catch (error) {
if (!error.message.includes('from another module or realm')) {
throw error;
}
}
13 changes: 13 additions & 0 deletions integrationTests/dev-rollup/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"description": "graphql-js development mode should work with Rollup",
"private": true,
"type": "module",
"scripts": {
"build": "rollup -c",
"test": "npm run build && node dist/bundle.js"
},
"dependencies": {
"graphql": "file:../graphql.tgz",
"rollup": "^4.0.0"
}
}
10 changes: 10 additions & 0 deletions integrationTests/dev-rollup/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const rollupConfig = {
input: 'index.js',
output: {
file: 'dist/bundle.js',
format: 'es',
},
};

// eslint-disable-next-line no-restricted-exports, import/no-default-export
export default rollupConfig;
18 changes: 18 additions & 0 deletions integrationTests/dev-rspack/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { isObjectType } from 'graphql';

class GraphQLObjectType {
get [Symbol.toStringTag]() {
return 'GraphQLObjectType';
}
}

try {
isObjectType(new GraphQLObjectType());
throw new Error(
'Expected isObjectType to throw an error in Rspack development mode.',
);
} catch (error) {
if (!error.message.includes('from another module or realm')) {
throw error;
}
}
12 changes: 12 additions & 0 deletions integrationTests/dev-rspack/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"description": "graphql-js development mode should work with Rspack",
"private": true,
"scripts": {
"test": "rspack --mode=development && node dist/main.js"
},
"dependencies": {
"graphql": "file:../graphql.tgz",
"@rspack/core": "^1.0.0",
"@rspack/cli": "^1.0.0"
}
}
17 changes: 17 additions & 0 deletions integrationTests/dev-rspack/rspack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { fileURLToPath } from 'node:url';

const rspack = {
entry: './index.js',
output: {
filename: 'main.js',
path: fileURLToPath(new URL('dist', import.meta.url)),
library: {
type: 'commonjs2',
},
},
mode: 'development',
target: 'node',
};

// eslint-disable-next-line no-restricted-exports, import/no-default-export
export default rspack;
12 changes: 12 additions & 0 deletions integrationTests/dev-swc/.swcrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"jsc": {
"parser": {
"syntax": "ecmascript",
"jsx": false
},
"target": "es2020"
},
"module": {
"type": "es6"
}
}
18 changes: 18 additions & 0 deletions integrationTests/dev-swc/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { isObjectType } from 'graphql';

class GraphQLObjectType {
get [Symbol.toStringTag]() {
return 'GraphQLObjectType';
}
}

try {
isObjectType(new GraphQLObjectType());
throw new Error(
'Expected isObjectType to throw an error in SWC development mode.',
);
} catch (error) {
if (!error.message.includes('from another module or realm')) {
throw error;
}
}
14 changes: 14 additions & 0 deletions integrationTests/dev-swc/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"description": "graphql-js development mode should work with SWC",
"private": true,
"type": "module",
"scripts": {
"build": "swc index.js -d dist",
"test": "npm run build && node dist/index.js"
},
"dependencies": {
"graphql": "file:../graphql.tgz",
"@swc/cli": "^0.1.0",
"@swc/core": "^1.3.0"
}
}
15 changes: 15 additions & 0 deletions integrationTests/dev-vitest/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { isObjectType } from 'graphql';
// eslint-disable-next-line n/no-missing-import
import { expect, test } from 'vitest';

class FakeGraphQLObjectType {
get [Symbol.toStringTag]() {
return 'GraphQLObjectType';
}
}

test('isObjectType should throw in development mode for instances from another realm/module', () => {
expect(() => isObjectType(new FakeGraphQLObjectType())).toThrowError(
/from another module or realm/,
);
});
12 changes: 12 additions & 0 deletions integrationTests/dev-vitest/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"description": "graphql-js development mode should work with Vitest",
"private": true,
"type": "module",
"scripts": {
"test": "vitest run"
},
"dependencies": {
"graphql": "file:../graphql.tgz",
"vitest": "^1.0.0"
}
}
11 changes: 11 additions & 0 deletions integrationTests/dev-vitest/vitest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// eslint-disable-next-line n/no-missing-import
import { defineConfig } from 'vitest/config';

const vitestConfig = defineConfig({
test: {
include: ['**/*.test.js'],
},
});

// eslint-disable-next-line no-restricted-exports, import/no-default-export
export default vitestConfig;
18 changes: 18 additions & 0 deletions integrationTests/dev-webpack/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { isObjectType } from 'graphql';

class GraphQLObjectType {
get [Symbol.toStringTag]() {
return 'GraphQLObjectType';
}
}

try {
isObjectType(new GraphQLObjectType());
throw new Error(
'Expected isObjectType to throw an error in Webpack development mode.',
);
} catch (error) {
if (!error.message.includes('from another module or realm')) {
throw error;
}
}
Loading
Loading