Skip to content

Commit 2e8d3a3

Browse files
committed
test: Refactor integration tests to use throw; update package.json
1 parent ddc0cf1 commit 2e8d3a3

File tree

37 files changed

+141
-129
lines changed

37 files changed

+141
-129
lines changed

integrationTests/dev-bun/package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
{
2-
"name": "graphql-js-test-dev-bun",
3-
"description": "Bun development mode integration test",
4-
"version": "1.0.0",
2+
"description": "graphql-js development condition should work with Bun",
53
"private": true,
64
"scripts": {
75
"test": "bun --conditions=development test.js"

integrationTests/dev-bun/test.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import assert from 'assert';
21
import { isObjectType } from 'graphql';
32

43
class GraphQLObjectType {
@@ -9,10 +8,14 @@ class GraphQLObjectType {
98

109
try {
1110
isObjectType(new GraphQLObjectType());
12-
assert.fail('Expected isObjectType to throw an error in Bun development mode.');
11+
throw new Error('Expected isObjectType to throw an error in Bun development mode.');
1312
} catch (error) {
14-
assert.ok(
15-
error.message.includes('multiple') || error.message.includes('GraphQL'),
16-
`Expected error message to include 'multiple' or 'GraphQL', but got: "${error.message}"`
17-
);
13+
if (error.message === 'Expected isObjectType to throw an error in Bun development mode.') {
14+
throw error;
15+
}
16+
if (!(error.message.includes('multiple') || error.message.includes('GraphQL'))) {
17+
throw new Error(
18+
`Expected error message to include 'multiple' or 'GraphQL', but got: "${error.message}"`
19+
);
20+
}
1821
}

integrationTests/dev-deno/package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
{
2-
"name": "graphql-js-test-dev-deno",
3-
"description": "Deno development mode integration test",
4-
"version": "1.0.0",
2+
"description": "graphql-js development condition should work with Deno",
53
"private": true,
64
"scripts": {
75
"test": "deno run --unstable-node-conditions=development test.js"

integrationTests/dev-deno/test.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import assert from 'assert';
21
import { isObjectType } from 'graphql';
32

43
class GraphQLObjectType {
@@ -9,10 +8,14 @@ class GraphQLObjectType {
98

109
try {
1110
isObjectType(new GraphQLObjectType());
12-
assert.fail('Expected isObjectType to throw an error in Deno development mode.');
11+
throw new Error('Expected isObjectType to throw an error in Deno development mode.');
1312
} catch (error) {
14-
assert.ok(
15-
error.message.includes('multiple') || error.message.includes('GraphQL'),
16-
`Expected error message to include 'multiple' or 'GraphQL', but got: "${error.message}"`
17-
);
13+
if (error.message === 'Expected isObjectType to throw an error in Deno development mode.') {
14+
throw error;
15+
}
16+
if (!(error.message.includes('multiple') || error.message.includes('GraphQL'))) {
17+
throw new Error(
18+
`Expected error message to include 'multiple' or 'GraphQL', but got: "${error.message}"`
19+
);
20+
}
1821
}

integrationTests/dev-esbuild/package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
{
2-
"name": "graphql-js-test-dev-esbuild",
3-
"description": "esbuild development mode integration test",
4-
"version": "1.0.0",
2+
"description": "graphql-js development condition should work with esbuild",
53
"private": true,
64
"type": "module",
75
"scripts": {
Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import assert from 'assert';
21
import { isObjectType } from 'graphql';
32

43
class GraphQLObjectType {
@@ -9,10 +8,14 @@ class GraphQLObjectType {
98

109
try {
1110
isObjectType(new GraphQLObjectType());
12-
assert.fail('Expected isObjectType to throw an error in esbuild development mode.');
11+
throw new Error('Expected isObjectType to throw an error in esbuild development mode.');
1312
} catch (error) {
14-
assert.ok(
15-
error.message.includes('multiple') || error.message.includes('GraphQL'),
16-
`Expected error message to include 'multiple' or 'GraphQL', but got: "${error.message}"`
17-
);
13+
if (error.message === 'Expected isObjectType to throw an error in esbuild development mode.') {
14+
throw error;
15+
}
16+
if (!(error.message.includes('multiple') || error.message.includes('GraphQL'))) {
17+
throw new Error(
18+
`Expected error message to include 'multiple' or 'GraphQL', but got: "${error.message}"`
19+
);
20+
}
1821
}

integrationTests/dev-nextjs/package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
{
2-
"name": "graphql-js-test-dev-nextjs",
3-
"description": "Next.js development mode integration test",
4-
"version": "1.0.0",
2+
"description": "graphql-js development condition should work with Next.js",
53
"private": true,
64
"scripts": {
75
"build": "next build",

integrationTests/dev-nextjs/test.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import assert from 'assert';
21
import { isObjectType } from 'graphql';
32

43
class GraphQLObjectType {
@@ -9,10 +8,14 @@ class GraphQLObjectType {
98

109
try {
1110
isObjectType(new GraphQLObjectType());
12-
assert.fail('Expected isObjectType to throw an error in Next.js development mode.');
11+
throw new Error('Expected isObjectType to throw an error in Next.js development mode.');
1312
} catch (error) {
14-
assert.ok(
15-
error.message.includes('multiple') || error.message.includes('GraphQL'),
16-
`Expected error message to include 'multiple' or 'GraphQL', but got: "${error.message}"`
17-
);
13+
if (error.message === 'Expected isObjectType to throw an error in Next.js development mode.') {
14+
throw error;
15+
}
16+
if (!(error.message.includes('multiple') || error.message.includes('GraphQL'))) {
17+
throw new Error(
18+
`Expected error message to include 'multiple' or 'GraphQL', but got: "${error.message}"`
19+
);
20+
}
1821
}

integrationTests/dev-node-explicit/test.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,23 @@ class GraphQLObjectType {
88

99
try {
1010
isObjectType(new GraphQLObjectType());
11+
// If isObjectType did not throw, this line will be reached.
1112
throw new Error(
1213
'Expected isObjectType to throw an error in Node.js explicit development mode.',
1314
);
1415
} catch (error) {
15-
if (
16-
!error.message.includes('from another module or realm'),
17-
`Expected error message to include 'from another module or realm', but got: "${error.message}"`,
18-
);
16+
// Case 1: The error is the one we threw from the 'try' block.
17+
// This means isObjectType() itself did NOT throw an error.
18+
if (error.message === 'Expected isObjectType to throw an error in Node.js explicit development mode.') {
19+
throw error; // Re-throw this error to indicate the test failure.
20+
}
21+
// Case 2: isObjectType() itself threw an error. Now check if it's the correct error.
22+
else if (!error.message.includes('from another module or realm')) {
23+
// If the message does NOT include the expected text, then it's the wrong error.
24+
throw new Error(
25+
`Expected error message to include 'from another module or realm', but got: "${error.message}"`
26+
);
27+
}
28+
// If none of the above, it means isObjectType() threw an error, AND that error's message was correct.
29+
// So, the test passes by not throwing anything further from the catch block.
1930
}

integrationTests/dev-node-implicit/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"private": true,
32
"description": "graphql-js development condition should work with node",
3+
"private": true,
44
"type": "module",
55
"scripts": {
66
"test": "node --conditions=development test.js"
Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import assert from 'node:assert';
2-
31
import { isObjectType } from 'graphql';
42

53
class GraphQLObjectType {
@@ -10,12 +8,16 @@ class GraphQLObjectType {
108

119
try {
1210
isObjectType(new GraphQLObjectType());
13-
assert.fail(
11+
throw new Error(
1412
'Expected isObjectType to throw an error in Node.js implicit development mode.',
1513
);
1614
} catch (error) {
17-
assert.ok(
18-
error.message.includes('multiple') || error.message.includes('GraphQL'),
19-
`Expected error message to include 'multiple' or 'GraphQL', but got: "${error.message}"`,
20-
);
15+
if (error.message === 'Expected isObjectType to throw an error in Node.js implicit development mode.') {
16+
throw error;
17+
}
18+
if (!(error.message.includes('multiple') || error.message.includes('GraphQL'))) {
19+
throw new Error(
20+
`Expected error message to include 'multiple' or 'GraphQL', but got: "${error.message}"`
21+
);
22+
}
2123
}

integrationTests/dev-rollup/package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
{
2-
"name": "graphql-js-test-dev-rollup",
3-
"description": "Rollup development mode integration test",
4-
"version": "1.0.0",
2+
"description": "graphql-js development condition should work with Rollup",
53
"private": true,
64
"type": "module",
75
"scripts": {
Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import assert from 'assert';
21
import { isObjectType } from 'graphql';
32

43
class GraphQLObjectType {
@@ -9,10 +8,14 @@ class GraphQLObjectType {
98

109
try {
1110
isObjectType(new GraphQLObjectType());
12-
assert.fail('Expected isObjectType to throw an error in Rollup development mode.');
11+
throw new Error('Expected isObjectType to throw an error in Rollup development mode.');
1312
} catch (error) {
14-
assert.ok(
15-
error.message.includes('multiple') || error.message.includes('GraphQL'),
16-
`Expected error message to include 'multiple' or 'GraphQL', but got: "${error.message}"`
17-
);
13+
if (error.message === 'Expected isObjectType to throw an error in Rollup development mode.') {
14+
throw error;
15+
}
16+
if (!(error.message.includes('multiple') || error.message.includes('GraphQL'))) {
17+
throw new Error(
18+
`Expected error message to include 'multiple' or 'GraphQL', but got: "${error.message}"`
19+
);
20+
}
1821
}

integrationTests/dev-swc/package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
{
2-
"name": "graphql-js-test-dev-swc",
3-
"description": "SWC development mode integration test",
4-
"version": "1.0.0",
2+
"description": "graphql-js development condition should work with SWC",
53
"private": true,
64
"type": "module",
75
"scripts": {

integrationTests/dev-swc/src/index.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import assert from 'assert';
21
import { isObjectType } from 'graphql';
32

43
class GraphQLObjectType {
@@ -9,10 +8,14 @@ class GraphQLObjectType {
98

109
try {
1110
isObjectType(new GraphQLObjectType());
12-
assert.fail('Expected isObjectType to throw an error in SWC development mode.');
11+
throw new Error('Expected isObjectType to throw an error in SWC development mode.');
1312
} catch (error) {
14-
assert.ok(
15-
error.message.includes('multiple') || error.message.includes('GraphQL'),
16-
`Expected error message to include 'multiple' or 'GraphQL', but got: "${error.message}"`
17-
);
13+
if (error.message === 'Expected isObjectType to throw an error in SWC development mode.') {
14+
throw error;
15+
}
16+
if (!(error.message.includes('multiple') || error.message.includes('GraphQL'))) {
17+
throw new Error(
18+
`Expected error message to include 'multiple' or 'GraphQL', but got: "${error.message}"`
19+
);
20+
}
1821
}

integrationTests/dev-vite/package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
{
2-
"name": "graphql-js-test-dev-vite",
3-
"description": "Vite development mode integration test",
4-
"version": "1.0.0",
2+
"description": "graphql-js development condition should work with Vite",
53
"private": true,
64
"type": "module",
75
"scripts": {
Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import assert from 'assert';
21
import { isObjectType } from 'graphql';
32

43
class GraphQLObjectType {
@@ -9,10 +8,14 @@ class GraphQLObjectType {
98

109
try {
1110
isObjectType(new GraphQLObjectType());
12-
assert.fail('Expected isObjectType to throw an error in Vite development mode.');
11+
throw new Error('Expected isObjectType to throw an error in Vite development mode.');
1312
} catch (error) {
14-
assert.ok(
15-
error.message.includes('multiple') || error.message.includes('GraphQL'),
16-
`Expected error message to include 'multiple' or 'GraphQL', but got: "${error.message}"`
17-
);
13+
if (error.message === 'Expected isObjectType to throw an error in Vite development mode.') {
14+
throw error;
15+
}
16+
if (!(error.message.includes('multiple') || error.message.includes('GraphQL'))) {
17+
throw new Error(
18+
`Expected error message to include 'multiple' or 'GraphQL', but got: "${error.message}"`
19+
);
20+
}
1821
}

integrationTests/dev-webpack/package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
{
2-
"name": "graphql-js-test-dev-webpack",
3-
"description": "Webpack development mode integration test",
4-
"version": "1.0.0",
2+
"description": "graphql-js development condition should work with Webpack",
53
"private": true,
64
"scripts": {
75
"test": "webpack --mode=development && node dist/main.js"
Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import assert from 'assert';
21
import { isObjectType } from 'graphql';
32

43
class GraphQLObjectType {
@@ -9,10 +8,14 @@ class GraphQLObjectType {
98

109
try {
1110
isObjectType(new GraphQLObjectType());
12-
assert.fail('Expected isObjectType to throw an error in Webpack development mode.');
11+
throw new Error('Expected isObjectType to throw an error in Webpack development mode.');
1312
} catch (error) {
14-
assert.ok(
15-
error.message.includes('multiple') || error.message.includes('GraphQL'),
16-
`Expected error message to include 'multiple' or 'GraphQL', but got: "${error.message}"`
17-
);
13+
if (error.message === 'Expected isObjectType to throw an error in Webpack development mode.') {
14+
throw error;
15+
}
16+
if (!(error.message.includes('multiple') || error.message.includes('GraphQL'))) {
17+
throw new Error(
18+
`Expected error message to include 'multiple' or 'GraphQL', but got: "${error.message}"`
19+
);
20+
}
1821
}

integrationTests/prod-bun/package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
{
2-
"name": "graphql-js-test-prod-bun",
3-
"description": "Bun production mode integration test",
4-
"version": "1.0.0",
2+
"description": "graphql-js production mode should work with Bun",
53
"private": true,
64
"scripts": {
75
"test": "bun test.js"

integrationTests/prod-bun/test.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import assert from 'assert';
21
import { isObjectType } from 'graphql';
32

43
class GraphQLObjectType {
@@ -8,4 +7,6 @@ class GraphQLObjectType {
87
}
98

109
const result = isObjectType(new GraphQLObjectType());
11-
assert.strictEqual(result, false, 'isObjectType should return false in Bun production mode.');
10+
if (result !== false) {
11+
throw new Error('isObjectType should return false in Bun production mode.');
12+
}

integrationTests/prod-deno/package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
{
2-
"name": "graphql-js-test-prod-deno",
3-
"description": "Deno production mode integration test",
4-
"version": "1.0.0",
2+
"description": "graphql-js production mode should work with Deno",
53
"private": true,
64
"scripts": {
75
"test": "deno run test.js"

integrationTests/prod-deno/test.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import assert from 'assert';
21
import { isObjectType } from 'graphql';
32

43
class GraphQLObjectType {
@@ -8,4 +7,6 @@ class GraphQLObjectType {
87
}
98

109
const result = isObjectType(new GraphQLObjectType());
11-
assert.strictEqual(result, false, 'isObjectType should return false in Deno production mode.');
10+
if (result !== false) {
11+
throw new Error('isObjectType should return false in Deno production mode.');
12+
}

integrationTests/prod-esbuild/package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
{
2-
"name": "graphql-js-test-prod-esbuild",
3-
"description": "esbuild production mode integration test",
4-
"version": "1.0.0",
2+
"description": "graphql-js production mode should work with esbuild",
53
"private": true,
64
"type": "module",
75
"scripts": {

0 commit comments

Comments
 (0)