diff --git a/cspell.yml b/cspell.yml index 3870f6f531..fe9583e043 100644 --- a/cspell.yml +++ b/cspell.yml @@ -67,6 +67,8 @@ words: # TODO: contribute upstream - deno - hashbang + - Rspack + - Rollup # Website tech - Nextra diff --git a/integrationTests/README.md b/integrationTests/README.md index 706449103a..bcfe425cfd 100644 --- a/integrationTests/README.md +++ b/integrationTests/README.md @@ -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. diff --git a/integrationTests/dev-bun/package.json b/integrationTests/dev-bun/package.json new file mode 100644 index 0000000000..126269a891 --- /dev/null +++ b/integrationTests/dev-bun/package.json @@ -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" + } +} diff --git a/integrationTests/dev-bun/test.js b/integrationTests/dev-bun/test.js new file mode 100644 index 0000000000..ebf7e79e4b --- /dev/null +++ b/integrationTests/dev-bun/test.js @@ -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; + } +} diff --git a/integrationTests/dev-deno/package.json b/integrationTests/dev-deno/package.json new file mode 100644 index 0000000000..7884e364fa --- /dev/null +++ b/integrationTests/dev-deno/package.json @@ -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" + } +} diff --git a/integrationTests/dev-deno/test.js b/integrationTests/dev-deno/test.js new file mode 100644 index 0000000000..3f2143191f --- /dev/null +++ b/integrationTests/dev-deno/test.js @@ -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; + } +} diff --git a/integrationTests/dev-esbuild/index.js b/integrationTests/dev-esbuild/index.js new file mode 100644 index 0000000000..2c54b87c0e --- /dev/null +++ b/integrationTests/dev-esbuild/index.js @@ -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; + } +} diff --git a/integrationTests/dev-esbuild/package.json b/integrationTests/dev-esbuild/package.json new file mode 100644 index 0000000000..df513566e4 --- /dev/null +++ b/integrationTests/dev-esbuild/package.json @@ -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" + } +} diff --git a/integrationTests/dev-jest/index.test.js b/integrationTests/dev-jest/index.test.js new file mode 100644 index 0000000000..bac3b9d84e --- /dev/null +++ b/integrationTests/dev-jest/index.test.js @@ -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/, + ); + }); +}); diff --git a/integrationTests/dev-jest/package.json b/integrationTests/dev-jest/package.json new file mode 100644 index 0000000000..7d8e9ccf19 --- /dev/null +++ b/integrationTests/dev-jest/package.json @@ -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" + } +} diff --git a/integrationTests/dev-node/package.json b/integrationTests/dev-node/package.json new file mode 100644 index 0000000000..ab7124ef6a --- /dev/null +++ b/integrationTests/dev-node/package.json @@ -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" + } +} diff --git a/integrationTests/dev-node/test.js b/integrationTests/dev-node/test.js new file mode 100644 index 0000000000..303ba7f590 --- /dev/null +++ b/integrationTests/dev-node/test.js @@ -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; + } +} diff --git a/integrationTests/dev-rollup/index.js b/integrationTests/dev-rollup/index.js new file mode 100644 index 0000000000..2d4eee896d --- /dev/null +++ b/integrationTests/dev-rollup/index.js @@ -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; + } +} diff --git a/integrationTests/dev-rollup/package.json b/integrationTests/dev-rollup/package.json new file mode 100644 index 0000000000..9f6cf1084b --- /dev/null +++ b/integrationTests/dev-rollup/package.json @@ -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" + } +} diff --git a/integrationTests/dev-rollup/rollup.config.js b/integrationTests/dev-rollup/rollup.config.js new file mode 100644 index 0000000000..d46fd8fedb --- /dev/null +++ b/integrationTests/dev-rollup/rollup.config.js @@ -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; diff --git a/integrationTests/dev-rspack/index.js b/integrationTests/dev-rspack/index.js new file mode 100644 index 0000000000..57865dad1d --- /dev/null +++ b/integrationTests/dev-rspack/index.js @@ -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; + } +} diff --git a/integrationTests/dev-rspack/package.json b/integrationTests/dev-rspack/package.json new file mode 100644 index 0000000000..955037ace9 --- /dev/null +++ b/integrationTests/dev-rspack/package.json @@ -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" + } +} diff --git a/integrationTests/dev-rspack/rspack.config.js b/integrationTests/dev-rspack/rspack.config.js new file mode 100644 index 0000000000..a39f3e5b4f --- /dev/null +++ b/integrationTests/dev-rspack/rspack.config.js @@ -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; diff --git a/integrationTests/dev-swc/.swcrc b/integrationTests/dev-swc/.swcrc new file mode 100644 index 0000000000..b080b3cd3f --- /dev/null +++ b/integrationTests/dev-swc/.swcrc @@ -0,0 +1,12 @@ +{ + "jsc": { + "parser": { + "syntax": "ecmascript", + "jsx": false + }, + "target": "es2020" + }, + "module": { + "type": "es6" + } +} diff --git a/integrationTests/dev-swc/index.js b/integrationTests/dev-swc/index.js new file mode 100644 index 0000000000..4db39b4ffb --- /dev/null +++ b/integrationTests/dev-swc/index.js @@ -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; + } +} diff --git a/integrationTests/dev-swc/package.json b/integrationTests/dev-swc/package.json new file mode 100644 index 0000000000..e86428e472 --- /dev/null +++ b/integrationTests/dev-swc/package.json @@ -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" + } +} diff --git a/integrationTests/dev-vitest/index.test.js b/integrationTests/dev-vitest/index.test.js new file mode 100644 index 0000000000..46f2840c10 --- /dev/null +++ b/integrationTests/dev-vitest/index.test.js @@ -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/, + ); +}); diff --git a/integrationTests/dev-vitest/package.json b/integrationTests/dev-vitest/package.json new file mode 100644 index 0000000000..984cb0185d --- /dev/null +++ b/integrationTests/dev-vitest/package.json @@ -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" + } +} diff --git a/integrationTests/dev-vitest/vitest.config.js b/integrationTests/dev-vitest/vitest.config.js new file mode 100644 index 0000000000..e6d9de6ed7 --- /dev/null +++ b/integrationTests/dev-vitest/vitest.config.js @@ -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; diff --git a/integrationTests/dev-webpack/index.js b/integrationTests/dev-webpack/index.js new file mode 100644 index 0000000000..719ce7c6db --- /dev/null +++ b/integrationTests/dev-webpack/index.js @@ -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; + } +} diff --git a/integrationTests/dev-webpack/package.json b/integrationTests/dev-webpack/package.json new file mode 100644 index 0000000000..56ffb550ef --- /dev/null +++ b/integrationTests/dev-webpack/package.json @@ -0,0 +1,12 @@ +{ + "description": "graphql-js development mode should work with Webpack", + "private": true, + "scripts": { + "test": "webpack --mode=development && node dist/main.js" + }, + "dependencies": { + "graphql": "file:../graphql.tgz", + "webpack": "^5.0.0", + "webpack-cli": "^5.0.0" + } +} diff --git a/integrationTests/dev-webpack/webpack.config.js b/integrationTests/dev-webpack/webpack.config.js new file mode 100644 index 0000000000..4715eee3a1 --- /dev/null +++ b/integrationTests/dev-webpack/webpack.config.js @@ -0,0 +1,17 @@ +import { fileURLToPath } from 'node:url'; + +const webpackConfig = { + 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 webpackConfig; diff --git a/integrationTests/prod-bun/package.json b/integrationTests/prod-bun/package.json new file mode 100644 index 0000000000..7ba0f677d9 --- /dev/null +++ b/integrationTests/prod-bun/package.json @@ -0,0 +1,10 @@ +{ + "description": "graphql-js production 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 --define process.env.NODE_ENV='\"production\"' test.js" + }, + "dependencies": { + "graphql": "file:../graphql.tgz" + } +} diff --git a/integrationTests/prod-bun/test.js b/integrationTests/prod-bun/test.js new file mode 100644 index 0000000000..43a1bd1c2d --- /dev/null +++ b/integrationTests/prod-bun/test.js @@ -0,0 +1,12 @@ +import { isObjectType } from 'graphql'; + +class GraphQLObjectType { + get [Symbol.toStringTag]() { + return 'GraphQLObjectType'; + } +} + +const result = isObjectType(new GraphQLObjectType()); +if (result !== false) { + throw new Error('isObjectType should return false in Bun production mode.'); +} diff --git a/integrationTests/prod-deno/env-shim.js b/integrationTests/prod-deno/env-shim.js new file mode 100644 index 0000000000..dbb9d9dace --- /dev/null +++ b/integrationTests/prod-deno/env-shim.js @@ -0,0 +1,4 @@ +// eslint-disable-next-line n/prefer-global/process +import process from 'node:process'; + +process.env.NODE_ENV = 'production'; diff --git a/integrationTests/prod-deno/package.json b/integrationTests/prod-deno/package.json new file mode 100644 index 0000000000..177c2f7371 --- /dev/null +++ b/integrationTests/prod-deno/package.json @@ -0,0 +1,10 @@ +{ + "description": "graphql-js production 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 --preload env-shim.js test.js" + }, + "dependencies": { + "graphql": "file:../graphql.tgz" + } +} diff --git a/integrationTests/prod-deno/test.js b/integrationTests/prod-deno/test.js new file mode 100644 index 0000000000..6ed13f37bf --- /dev/null +++ b/integrationTests/prod-deno/test.js @@ -0,0 +1,12 @@ +import { isObjectType } from 'graphql'; + +class GraphQLObjectType { + get [Symbol.toStringTag]() { + return 'GraphQLObjectType'; + } +} + +const result = isObjectType(new GraphQLObjectType()); +if (result !== false) { + throw new Error('isObjectType should return false in Deno production mode.'); +} diff --git a/integrationTests/prod-esbuild/index.js b/integrationTests/prod-esbuild/index.js new file mode 100644 index 0000000000..c9f2bea824 --- /dev/null +++ b/integrationTests/prod-esbuild/index.js @@ -0,0 +1,14 @@ +import { isObjectType } from 'graphql'; + +class GraphQLObjectType { + get [Symbol.toStringTag]() { + return 'GraphQLObjectType'; + } +} + +const result = isObjectType(new GraphQLObjectType()); +if (result !== false) { + throw new Error( + 'isObjectType should return false in esbuild production mode.', + ); +} diff --git a/integrationTests/prod-esbuild/package.json b/integrationTests/prod-esbuild/package.json new file mode 100644 index 0000000000..c6e9077d3a --- /dev/null +++ b/integrationTests/prod-esbuild/package.json @@ -0,0 +1,13 @@ +{ + "description": "graphql-js production mode should work with esbuild", + "private": true, + "type": "module", + "scripts": { + "build": "esbuild index.js --bundle --outfile=dist/bundle.js --format=esm --define:process.env.NODE_ENV='\"production\"'", + "test": "npm run build && node dist/bundle.js" + }, + "dependencies": { + "graphql": "file:../graphql.tgz", + "esbuild": "^0.25.0" + } +} diff --git a/integrationTests/prod-node/package.json b/integrationTests/prod-node/package.json new file mode 100644 index 0000000000..aec74f094f --- /dev/null +++ b/integrationTests/prod-node/package.json @@ -0,0 +1,11 @@ +{ + "description": "graphql-js production mode should work with Node.js", + "private": true, + "type": "module", + "scripts": { + "test": "NODE_ENV=production node test.js" + }, + "dependencies": { + "graphql": "file:../graphql.tgz" + } +} diff --git a/integrationTests/prod-node/test.js b/integrationTests/prod-node/test.js new file mode 100644 index 0000000000..6ff23903cf --- /dev/null +++ b/integrationTests/prod-node/test.js @@ -0,0 +1,14 @@ +import { isObjectType } from 'graphql'; + +class GraphQLObjectType { + get [Symbol.toStringTag]() { + return 'GraphQLObjectType'; + } +} + +const result = isObjectType(new GraphQLObjectType()); +if (result !== false) { + throw new Error( + 'isObjectType should return false in Node.js production mode.', + ); +} diff --git a/integrationTests/prod-rollup/index.js b/integrationTests/prod-rollup/index.js new file mode 100644 index 0000000000..07f63bf7a9 --- /dev/null +++ b/integrationTests/prod-rollup/index.js @@ -0,0 +1,14 @@ +import { isObjectType } from 'graphql'; + +class GraphQLObjectType { + get [Symbol.toStringTag]() { + return 'GraphQLObjectType'; + } +} + +const result = isObjectType(new GraphQLObjectType()); +if (result !== false) { + throw new Error( + 'isObjectType should return false in Rollup production mode.', + ); +} diff --git a/integrationTests/prod-rollup/package.json b/integrationTests/prod-rollup/package.json new file mode 100644 index 0000000000..07aedb43d3 --- /dev/null +++ b/integrationTests/prod-rollup/package.json @@ -0,0 +1,15 @@ +{ + "description": "graphql-js production 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", + "@rollup/plugin-node-resolve": "^15.0.0", + "@rollup/plugin-replace": "^5.0.0" + } +} diff --git a/integrationTests/prod-rollup/rollup.config.js b/integrationTests/prod-rollup/rollup.config.js new file mode 100644 index 0000000000..5b4bdff379 --- /dev/null +++ b/integrationTests/prod-rollup/rollup.config.js @@ -0,0 +1,23 @@ +// eslint-disable-next-line n/no-missing-import +import resolve from '@rollup/plugin-node-resolve'; +// eslint-disable-next-line n/no-missing-import +import replace from '@rollup/plugin-replace'; + +const rollupConfig = { + input: 'index.js', + output: { + file: 'dist/bundle.js', + format: 'es', + }, + plugins: [ + replace({ + preventAssignment: true, + 'process.env.NODE_ENV': JSON.stringify('production'), + include: ['node_modules/graphql/**'], + }), + resolve(), + ], +}; + +// eslint-disable-next-line no-restricted-exports, import/no-default-export +export default rollupConfig; diff --git a/integrationTests/prod-rspack/index.js b/integrationTests/prod-rspack/index.js new file mode 100644 index 0000000000..d5741cf8be --- /dev/null +++ b/integrationTests/prod-rspack/index.js @@ -0,0 +1,14 @@ +import { isObjectType } from 'graphql'; + +class GraphQLObjectType { + get [Symbol.toStringTag]() { + return 'GraphQLObjectType'; + } +} + +const result = isObjectType(new GraphQLObjectType()); +if (result !== false) { + throw new Error( + 'isObjectType should return false in Rspack production mode.', + ); +} diff --git a/integrationTests/prod-rspack/package.json b/integrationTests/prod-rspack/package.json new file mode 100644 index 0000000000..1122a8e588 --- /dev/null +++ b/integrationTests/prod-rspack/package.json @@ -0,0 +1,12 @@ +{ + "description": "graphql-js production mode should work with Rspack", + "private": true, + "scripts": { + "test": "rspack --mode=production && node dist/main.js" + }, + "dependencies": { + "graphql": "file:../graphql.tgz", + "@rspack/core": "^1.0.0", + "@rspack/cli": "^1.0.0" + } +} diff --git a/integrationTests/prod-rspack/rspack.config.js b/integrationTests/prod-rspack/rspack.config.js new file mode 100644 index 0000000000..d58cd7693a --- /dev/null +++ b/integrationTests/prod-rspack/rspack.config.js @@ -0,0 +1,16 @@ +import { fileURLToPath } from 'node:url'; + +const rspackConfig = { + entry: './index.js', + output: { + filename: 'main.js', + path: fileURLToPath(new URL('dist', import.meta.url)), + library: { + type: 'commonjs2', + }, + }, + target: 'node', +}; + +// eslint-disable-next-line no-restricted-exports, import/no-default-export +export default rspackConfig; diff --git a/integrationTests/prod-swc/.swcrc b/integrationTests/prod-swc/.swcrc new file mode 100644 index 0000000000..b080b3cd3f --- /dev/null +++ b/integrationTests/prod-swc/.swcrc @@ -0,0 +1,12 @@ +{ + "jsc": { + "parser": { + "syntax": "ecmascript", + "jsx": false + }, + "target": "es2020" + }, + "module": { + "type": "es6" + } +} diff --git a/integrationTests/prod-swc/index.js b/integrationTests/prod-swc/index.js new file mode 100644 index 0000000000..14e814c9ae --- /dev/null +++ b/integrationTests/prod-swc/index.js @@ -0,0 +1,12 @@ +import { isObjectType } from 'graphql'; + +class GraphQLObjectType { + get [Symbol.toStringTag]() { + return 'GraphQLObjectType'; + } +} + +const result = isObjectType(new GraphQLObjectType()); +if (result !== false) { + throw new Error('isObjectType should return false in SWC production mode.'); +} diff --git a/integrationTests/prod-swc/package.json b/integrationTests/prod-swc/package.json new file mode 100644 index 0000000000..78f0f7f259 --- /dev/null +++ b/integrationTests/prod-swc/package.json @@ -0,0 +1,14 @@ +{ + "description": "graphql-js production mode should work with SWC", + "private": true, + "type": "module", + "scripts": { + "build": "swc index.js -d dist", + "test": "npm run build && NODE_ENV=production node dist/index.js" + }, + "dependencies": { + "graphql": "file:../graphql.tgz", + "@swc/cli": "^0.1.0", + "@swc/core": "^1.3.0" + } +} diff --git a/integrationTests/prod-webpack/index.js b/integrationTests/prod-webpack/index.js new file mode 100644 index 0000000000..4c7915287b --- /dev/null +++ b/integrationTests/prod-webpack/index.js @@ -0,0 +1,14 @@ +import { isObjectType } from 'graphql'; + +class GraphQLObjectType { + get [Symbol.toStringTag]() { + return 'GraphQLObjectType'; + } +} + +const result = isObjectType(new GraphQLObjectType()); +if (result !== false) { + throw new Error( + 'isObjectType should return false in Webpack production mode.', + ); +} diff --git a/integrationTests/prod-webpack/package.json b/integrationTests/prod-webpack/package.json new file mode 100644 index 0000000000..02521f48d8 --- /dev/null +++ b/integrationTests/prod-webpack/package.json @@ -0,0 +1,12 @@ +{ + "description": "graphql-js production mode should work with Webpack", + "private": true, + "scripts": { + "test": "webpack --mode=production && node dist/main.js" + }, + "dependencies": { + "graphql": "file:../graphql.tgz", + "webpack": "^5.0.0", + "webpack-cli": "^5.0.0" + } +} diff --git a/integrationTests/prod-webpack/webpack.config.js b/integrationTests/prod-webpack/webpack.config.js new file mode 100644 index 0000000000..1de88c4778 --- /dev/null +++ b/integrationTests/prod-webpack/webpack.config.js @@ -0,0 +1,16 @@ +import { fileURLToPath } from 'node:url'; + +const webpackConfig = { + entry: './index.js', + output: { + filename: 'main.js', + path: fileURLToPath(new URL('dist', import.meta.url)), + library: { + type: 'commonjs2', + }, + }, + target: 'node', +}; + +// eslint-disable-next-line no-restricted-exports, import/no-default-export +export default webpackConfig; diff --git a/resources/integration-test.ts b/resources/integration-test.ts index 47afc844d6..afc391011a 100644 --- a/resources/integration-test.ts +++ b/resources/integration-test.ts @@ -38,4 +38,26 @@ describe('Integration Tests', () => { testOnNodeProject('ts'); testOnNodeProject('node'); testOnNodeProject('webpack'); + + // Development mode tests + testOnNodeProject('dev-node'); + testOnNodeProject('dev-deno'); + testOnNodeProject('dev-bun'); + testOnNodeProject('dev-webpack'); + testOnNodeProject('dev-rspack'); + testOnNodeProject('dev-rollup'); + testOnNodeProject('dev-esbuild'); + testOnNodeProject('dev-swc'); + testOnNodeProject('dev-jest'); + testOnNodeProject('dev-vitest'); + + // Production mode tests + testOnNodeProject('prod-node'); + testOnNodeProject('prod-deno'); + testOnNodeProject('prod-bun'); + testOnNodeProject('prod-webpack'); + testOnNodeProject('prod-rspack'); + testOnNodeProject('prod-rollup'); + testOnNodeProject('prod-esbuild'); + testOnNodeProject('prod-swc'); });