Skip to content

Commit 175bb79

Browse files
committed
add integration tests for dev/prod
extracted from graphql#4437
1 parent 3283f8a commit 175bb79

Some content is hidden

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

49 files changed

+686
-1
lines changed

cspell.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ words:
6767
# TODO: contribute upstream
6868
- deno
6969
- hashbang
70+
- Rspack
71+
- Rollup
7072

7173
# Website tech
7274
- 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.

integrationTests/dev-bun/package.json

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+
}

integrationTests/dev-esbuild/index.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 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+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"description": "graphql-js development mode should work with node",
3+
"private": true,
4+
"type": "module",
5+
"scripts": {
6+
"test": "node test.js"
7+
},
8+
"dependencies": {
9+
"graphql": "file:../graphql.tgz"
10+
}
11+
}

integrationTests/dev-node/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 Node.js implicit dev mode.',
13+
);
14+
} catch (error) {
15+
if (!error.message.includes('from another module or realm')) {
16+
throw error;
17+
}
18+
}

integrationTests/dev-rollup/index.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 Rollup 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 Rollup",
3+
"private": true,
4+
"type": "module",
5+
"scripts": {
6+
"build": "rollup -c",
7+
"test": "npm run build && node dist/bundle.js"
8+
},
9+
"dependencies": {
10+
"graphql": "file:../graphql.tgz",
11+
"rollup": "^4.0.0"
12+
}
13+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const rollupConfig = {
2+
input: 'index.js',
3+
output: {
4+
file: 'dist/bundle.js',
5+
format: 'es',
6+
},
7+
};
8+
9+
// eslint-disable-next-line no-restricted-exports, import/no-default-export
10+
export default rollupConfig;

integrationTests/dev-rspack/index.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 Rspack development mode.',
13+
);
14+
} catch (error) {
15+
if (!error.message.includes('from another module or realm')) {
16+
throw error;
17+
}
18+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"description": "graphql-js development mode should work with Rspack",
3+
"private": true,
4+
"scripts": {
5+
"test": "rspack --mode=development && node dist/main.js"
6+
},
7+
"dependencies": {
8+
"graphql": "file:../graphql.tgz",
9+
"@rspack/core": "^1.0.0",
10+
"@rspack/cli": "^1.0.0"
11+
}
12+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { fileURLToPath } from 'node:url';
2+
3+
const rspack = {
4+
entry: './index.js',
5+
output: {
6+
filename: 'main.js',
7+
path: fileURLToPath(new URL('dist', import.meta.url)),
8+
library: {
9+
type: 'commonjs2',
10+
},
11+
},
12+
mode: 'development',
13+
target: 'node',
14+
};
15+
16+
// eslint-disable-next-line no-restricted-exports, import/no-default-export
17+
export default rspack;

integrationTests/dev-swc/.swcrc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"jsc": {
3+
"parser": {
4+
"syntax": "ecmascript",
5+
"jsx": false
6+
},
7+
"target": "es2020"
8+
},
9+
"module": {
10+
"type": "es6"
11+
}
12+
}

integrationTests/dev-swc/index.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 SWC development mode.',
13+
);
14+
} catch (error) {
15+
if (!error.message.includes('from another module or realm')) {
16+
throw error;
17+
}
18+
}

integrationTests/dev-swc/package.json

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 SWC",
3+
"private": true,
4+
"type": "module",
5+
"scripts": {
6+
"build": "swc index.js -d dist",
7+
"test": "npm run build && node dist/index.js"
8+
},
9+
"dependencies": {
10+
"graphql": "file:../graphql.tgz",
11+
"@swc/cli": "^0.1.0",
12+
"@swc/core": "^1.3.0"
13+
}
14+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { isObjectType } from 'graphql';
2+
// eslint-disable-next-line n/no-missing-import
3+
import { expect, test } from 'vitest';
4+
5+
class FakeGraphQLObjectType {
6+
get [Symbol.toStringTag]() {
7+
return 'GraphQLObjectType';
8+
}
9+
}
10+
11+
test('isObjectType should throw in development mode for instances from another realm/module', () => {
12+
expect(() => isObjectType(new FakeGraphQLObjectType())).toThrowError(
13+
/from another module or realm/,
14+
);
15+
});
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"description": "graphql-js development mode should work with Vitest",
3+
"private": true,
4+
"type": "module",
5+
"scripts": {
6+
"test": "vitest run"
7+
},
8+
"dependencies": {
9+
"graphql": "file:../graphql.tgz",
10+
"vitest": "^1.0.0"
11+
}
12+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// eslint-disable-next-line n/no-missing-import
2+
import { defineConfig } from 'vitest/config';
3+
4+
const vitestConfig = defineConfig({
5+
test: {
6+
include: ['**/*.test.js'],
7+
},
8+
});
9+
10+
// eslint-disable-next-line no-restricted-exports, import/no-default-export
11+
export default vitestConfig;

integrationTests/dev-webpack/index.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 Webpack development mode.',
13+
);
14+
} catch (error) {
15+
if (!error.message.includes('from another module or realm')) {
16+
throw error;
17+
}
18+
}

0 commit comments

Comments
 (0)