Skip to content

Commit aabc445

Browse files
committed
add integration tests for dev/prod (#4446)
currently, the only difference between development and production modes is the behavior of the instanceOf() check "production" mode is currently enabled by setting `process.env.NODE_ENV` to `production` with the default mode being "development" mode. this PR demonstrates how to enable production mode with node, bun, deno, esbuild, rollup, swc, webpack, and rspack and demonstrates the default of development mode in those environments as well as with jest and vitest. extracted from #4437
1 parent 9e6cd3b commit aabc445

49 files changed

Lines changed: 686 additions & 1 deletion

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

cspell.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ words:
5959
# TODO: contribute upstream
6060
- deno
6161
- hashbang
62+
- Rspack
63+
- Rollup
6264

6365
# Website tech
6466
- Nextra

integrationTests/README.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,23 @@
1-
# TBD
1+
# Integration Tests
2+
3+
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.
4+
5+
Tests are run via the main integration test suite in `resources/integration-test.ts`.
6+
7+
## Test Structure
8+
9+
### Basic GraphQL.JS Functionality Tests
10+
11+
Each subdirectory represents a different environment/bundler:
12+
13+
- `node` - tests for supported Node.js versions
14+
- `ts` - tests for supported Typescript versions
15+
- `webpack` - tests for Webpack
16+
17+
### Verifying Development Mode Tests
18+
19+
Each subdirectory represents a different environment/bundler demonstrating enabling development mode by setting the environment variable `NODE_ENV` to `development`.
20+
21+
### Verifying Production Mode Tests
22+
23+
Each subdirectory represents a different environment/bundler demonstrating production mode when development mode is not enabled.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"description": "graphql-js development mode should work with Bun",
3+
"private": true,
4+
"scripts": {
5+
"test": "docker run --rm --volume \"$PWD:/usr/src/app\" -w /usr/src/app oven/bun:latest bun test.js"
6+
},
7+
"dependencies": {
8+
"graphql": "file:../graphql.tgz"
9+
}
10+
}

integrationTests/dev-bun/test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { isObjectType } from 'graphql';
2+
3+
class GraphQLObjectType {
4+
get [Symbol.toStringTag]() {
5+
return 'GraphQLObjectType';
6+
}
7+
}
8+
9+
try {
10+
isObjectType(new GraphQLObjectType());
11+
throw new Error(
12+
'Expected isObjectType to throw an error in Bun development mode.',
13+
);
14+
} catch (error) {
15+
if (!error.message.includes('from another module or realm')) {
16+
throw error;
17+
}
18+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"description": "graphql-js development mode should work with Deno",
3+
"private": true,
4+
"scripts": {
5+
"test": "docker run --rm --volume \"$PWD:/usr/src/app\" -w /usr/src/app denoland/deno:latest deno run --allow-env=NODE_ENV test.js"
6+
},
7+
"dependencies": {
8+
"graphql": "file:../graphql.tgz"
9+
}
10+
}

integrationTests/dev-deno/test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { isObjectType } from 'graphql';
2+
3+
class GraphQLObjectType {
4+
get [Symbol.toStringTag]() {
5+
return 'GraphQLObjectType';
6+
}
7+
}
8+
9+
try {
10+
isObjectType(new GraphQLObjectType());
11+
throw new Error(
12+
'Expected isObjectType to throw an error in Deno implicit dev mode.',
13+
);
14+
} catch (error) {
15+
if (!error.message.includes('from another module or realm')) {
16+
throw error;
17+
}
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { isObjectType } from 'graphql';
2+
3+
class GraphQLObjectType {
4+
get [Symbol.toStringTag]() {
5+
return 'GraphQLObjectType';
6+
}
7+
}
8+
9+
try {
10+
isObjectType(new GraphQLObjectType());
11+
throw new Error(
12+
'Expected isObjectType to throw an error in esbuild development mode.',
13+
);
14+
} catch (error) {
15+
if (!error.message.includes('from another module or realm')) {
16+
throw error;
17+
}
18+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"description": "graphql-js development mode should work with esbuild",
3+
"private": true,
4+
"type": "module",
5+
"scripts": {
6+
"build": "esbuild index.js --bundle --outfile=dist/bundle.js --format=esm",
7+
"test": "npm run build && node dist/bundle.js"
8+
},
9+
"dependencies": {
10+
"graphql": "file:../graphql.tgz",
11+
"esbuild": "^0.25.0"
12+
}
13+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/* eslint-disable import/unambiguous */
2+
/* eslint-disable import/no-commonjs */
3+
/* eslint-disable no-undef */
4+
const { isObjectType } = require('graphql');
5+
6+
class FakeGraphQLObjectType {
7+
get [Symbol.toStringTag]() {
8+
return 'GraphQLObjectType';
9+
}
10+
}
11+
12+
describe('Jest with SWC development mode tests', () => {
13+
test('isObjectType should throw in development mode for instances from another realm/module', () => {
14+
expect(() => isObjectType(new FakeGraphQLObjectType())).toThrowError(
15+
/from another module or realm/,
16+
);
17+
});
18+
});
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"description": "graphql-js development mode should work with Jest",
3+
"private": true,
4+
"type": "module",
5+
"scripts": {
6+
"test": "jest"
7+
},
8+
"dependencies": {
9+
"graphql": "file:../graphql.tgz"
10+
},
11+
"devDependencies": {
12+
"jest": "^29.7.0"
13+
}
14+
}

0 commit comments

Comments
 (0)