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"

0 commit comments

Comments
 (0)