Skip to content

Commit 8c74ed8

Browse files
authored
test: migrated validation-rules.test.js from tap to node:test (#1162)
1 parent a99010c commit 8c74ed8

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

test/validation-rules.js renamed to test/validation-rules.test.js

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
'use strict'
22

3-
const { test } = require('tap')
3+
const { test } = require('node:test')
44
const Fastify = require('fastify')
5-
const { GraphQLError } = require('graphql')
65
const GQL = require('..')
76

87
const schema = `
@@ -33,7 +32,7 @@ test('validationRules array - reports an error', async (t) => {
3332
function (context) {
3433
return {
3534
Document () {
36-
context.reportError(new GraphQLError('Validation rule error'))
35+
context.reportError({ message: 'Validation rule error' })
3736
}
3837
}
3938
}
@@ -42,7 +41,7 @@ test('validationRules array - reports an error', async (t) => {
4241

4342
// needed so that graphql is defined
4443
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' }] })
4645
})
4746

4847
test('validationRules array - passes when no errors', async (t) => {
@@ -68,7 +67,7 @@ test('validationRules array - passes when no errors', async (t) => {
6867
await app.ready()
6968

7069
const res = await app.graphql(query)
71-
t.same(res, { data: { add: 4 } })
70+
t.assert.deepStrictEqual(res.data.add, 4)
7271
})
7372

7473
test('validationRules array - works with empty validationRules', async (t) => {
@@ -85,7 +84,7 @@ test('validationRules array - works with empty validationRules', async (t) => {
8584
await app.ready()
8685

8786
const res = await app.graphql(query)
88-
t.same(res, { data: { add: 4 } })
87+
t.assert.deepStrictEqual(res.data.add, 4)
8988
})
9089

9190
test('validationRules - reports an error', async (t) => {
@@ -100,7 +99,7 @@ test('validationRules - reports an error', async (t) => {
10099
function (context) {
101100
return {
102101
Document () {
103-
context.reportError(new GraphQLError('Validation rule error'))
102+
context.reportError({ message: 'Validation rule error' })
104103
}
105104
}
106105
}
@@ -109,7 +108,7 @@ test('validationRules - reports an error', async (t) => {
109108

110109
// needed so that graphql is defined
111110
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' }] })
113112
})
114113

115114
test('validationRules - passes when no errors', async (t) => {
@@ -136,7 +135,7 @@ test('validationRules - passes when no errors', async (t) => {
136135
await app.ready()
137136

138137
const res = await app.graphql(query)
139-
t.same(res, { data: { add: 4 } })
138+
t.assert.deepStrictEqual(res.data.add, 4)
140139
})
141140

142141
test('validationRules - works with empty validationRules', async (t) => {
@@ -154,7 +153,7 @@ test('validationRules - works with empty validationRules', async (t) => {
154153
await app.ready()
155154

156155
const res = await app.graphql(query)
157-
t.same(res, { data: { add: 4 } })
156+
t.assert.deepStrictEqual(res.data.add, 4)
158157
})
159158

160159
test('validationRules - works with missing validationRules', async (t) => {
@@ -171,7 +170,7 @@ test('validationRules - works with missing validationRules', async (t) => {
171170
await app.ready()
172171

173172
const res = await app.graphql(query)
174-
t.same(res, { data: { add: 4 } })
173+
t.assert.deepStrictEqual(res.data.add, 4)
175174
})
176175

177176
test('validationRules - includes graphql request metadata', async (t) => {
@@ -189,9 +188,9 @@ test('validationRules - includes graphql request metadata', async (t) => {
189188
resolvers,
190189
cache: false,
191190
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')
195194
return [
196195
// validation rule that reports no errors
197196
function (_context) {
@@ -209,7 +208,7 @@ test('validationRules - includes graphql request metadata', async (t) => {
209208
await app.ready()
210209

211210
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)
213212
})
214213

215214
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) =>
223222
})
224223

225224
// 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' })
227226
})

0 commit comments

Comments
 (0)