1
1
'use strict'
2
2
3
- const { test } = require ( 'tap ' )
3
+ const { test } = require ( 'node:test ' )
4
4
const Fastify = require ( 'fastify' )
5
- const { GraphQLError } = require ( 'graphql' )
6
5
const GQL = require ( '..' )
7
6
8
7
const schema = `
@@ -33,7 +32,7 @@ test('validationRules array - reports an error', async (t) => {
33
32
function ( context ) {
34
33
return {
35
34
Document ( ) {
36
- context . reportError ( new GraphQLError ( 'Validation rule error' ) )
35
+ context . reportError ( { message : 'Validation rule error' } )
37
36
}
38
37
}
39
38
}
@@ -42,7 +41,7 @@ test('validationRules array - reports an error', async (t) => {
42
41
43
42
// needed so that graphql is defined
44
43
await app . ready ( )
45
- await t . rejects ( app . graphql ( query ) , { errors : [ { message : 'Validation rule error' } ] } )
44
+ await t . assert . rejects ( app . graphql ( query ) , { errors : [ { message : 'Validation rule error' } ] } )
46
45
} )
47
46
48
47
test ( 'validationRules array - passes when no errors' , async ( t ) => {
@@ -68,7 +67,7 @@ test('validationRules array - passes when no errors', async (t) => {
68
67
await app . ready ( )
69
68
70
69
const res = await app . graphql ( query )
71
- t . same ( res , { data : { add : 4 } } )
70
+ t . assert . deepStrictEqual ( res . data . add , 4 )
72
71
} )
73
72
74
73
test ( 'validationRules array - works with empty validationRules' , async ( t ) => {
@@ -85,7 +84,7 @@ test('validationRules array - works with empty validationRules', async (t) => {
85
84
await app . ready ( )
86
85
87
86
const res = await app . graphql ( query )
88
- t . same ( res , { data : { add : 4 } } )
87
+ t . assert . deepStrictEqual ( res . data . add , 4 )
89
88
} )
90
89
91
90
test ( 'validationRules - reports an error' , async ( t ) => {
@@ -100,7 +99,7 @@ test('validationRules - reports an error', async (t) => {
100
99
function ( context ) {
101
100
return {
102
101
Document ( ) {
103
- context . reportError ( new GraphQLError ( 'Validation rule error' ) )
102
+ context . reportError ( { message : 'Validation rule error' } )
104
103
}
105
104
}
106
105
}
@@ -109,7 +108,7 @@ test('validationRules - reports an error', async (t) => {
109
108
110
109
// needed so that graphql is defined
111
110
await app . ready ( )
112
- await t . rejects ( app . graphql ( query ) , { errors : [ { message : 'Validation rule error' } ] } )
111
+ await t . assert . rejects ( app . graphql ( query ) , { errors : [ { message : 'Validation rule error' } ] } )
113
112
} )
114
113
115
114
test ( 'validationRules - passes when no errors' , async ( t ) => {
@@ -136,7 +135,7 @@ test('validationRules - passes when no errors', async (t) => {
136
135
await app . ready ( )
137
136
138
137
const res = await app . graphql ( query )
139
- t . same ( res , { data : { add : 4 } } )
138
+ t . assert . deepStrictEqual ( res . data . add , 4 )
140
139
} )
141
140
142
141
test ( 'validationRules - works with empty validationRules' , async ( t ) => {
@@ -154,7 +153,7 @@ test('validationRules - works with empty validationRules', async (t) => {
154
153
await app . ready ( )
155
154
156
155
const res = await app . graphql ( query )
157
- t . same ( res , { data : { add : 4 } } )
156
+ t . assert . deepStrictEqual ( res . data . add , 4 )
158
157
} )
159
158
160
159
test ( 'validationRules - works with missing validationRules' , async ( t ) => {
@@ -171,7 +170,7 @@ test('validationRules - works with missing validationRules', async (t) => {
171
170
await app . ready ( )
172
171
173
172
const res = await app . graphql ( query )
174
- t . same ( res , { data : { add : 4 } } )
173
+ t . assert . deepStrictEqual ( res . data . add , 4 )
175
174
} )
176
175
177
176
test ( 'validationRules - includes graphql request metadata' , async ( t ) => {
@@ -189,9 +188,9 @@ test('validationRules - includes graphql request metadata', async (t) => {
189
188
resolvers,
190
189
cache : false ,
191
190
validationRules : function ( { source, variables, operationName } ) {
192
- t . equal ( source , query )
193
- t . same ( variables , { x : 2 , y : 2 } )
194
- t . same ( operationName , 'Add' )
191
+ t . assert . strictEqual ( source , query )
192
+ t . assert . deepStrictEqual ( variables , { x : 2 , y : 2 } )
193
+ t . assert . deepStrictEqual ( operationName , 'Add' )
195
194
return [
196
195
// validation rule that reports no errors
197
196
function ( _context ) {
@@ -209,7 +208,7 @@ test('validationRules - includes graphql request metadata', async (t) => {
209
208
await app . ready ( )
210
209
211
210
const res = await app . graphql ( query , null , { x : 2 , y : 2 } , 'Add' )
212
- t . same ( res , { data : { add : 4 } } )
211
+ t . assert . deepStrictEqual ( res . data . add , 4 )
213
212
} )
214
213
215
214
test ( 'validationRules - errors if cache is used with the function' , async ( t ) => {
@@ -223,5 +222,5 @@ test('validationRules - errors if cache is used with the function', async (t) =>
223
222
} )
224
223
225
224
// needed so that graphql is defined
226
- await t . rejects ( app . ready ( ) , { message : 'Invalid options: Using a function for the validationRules is incompatible with query caching' } )
225
+ await t . assert . rejects ( app . ready ( ) , { message : 'Invalid options: Using a function for the validationRules is incompatible with query caching' } )
227
226
} )
0 commit comments