Skip to content

Commit

Permalink
chore: move to nodejs tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Eomm committed Mar 1, 2025
1 parent beb7c08 commit ceba978
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 101 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"scripts": {
"lint": "eslint",
"lint:fix": "eslint --fix",
"test": "tap --show-full-coverage && tsd",
"test:unit": "tap --show-full-coverage",
"test": "npm run test:unit && npm run test:types",
"test:unit": "c8 --100 node --test",
"test:types": "tsd"
},
"repository": {
Expand All @@ -33,14 +33,14 @@
},
"homepage": "https://github.com/Eomm/mercurius-logging#readme",
"devDependencies": {
"c8": "^10.1.3",
"eslint": "^9.21.0",
"fastify": "^5.0.0",
"graphql": "^16.8.0",
"mercurius": "^16.0.0",
"neostandard": "^0.12.1",
"split2": "^4.1.0",
"standard": "^17.0.0",
"tap": "^21.0.0",
"tsd": "^0.31.0"
},
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion test/_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ exports.buildApp = function buildApp (t, logger, opts) {
logger,
disableRequestLogging: true
})
t.teardown(app.close.bind(app))
t.after(() => app.close())

app.register(mercurius, {
schema,
Expand Down
12 changes: 6 additions & 6 deletions test/handle-reply-undefined.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const { test } = require('tap')
const { test } = require('node:test')
const { buildApp, jsonLogger } = require('./_helper')

test('should handle without logging when context.reply is undefined', async (t) => {
Expand All @@ -24,7 +24,7 @@ test('should handle without logging when context.reply is undefined', async (t)
url: '/custom-endpoint'
})

t.same(response.json(), {
t.assert.deepStrictEqual(response.json(), {
data: {
four: 4,
six: 6,
Expand All @@ -39,9 +39,9 @@ test('should log when using graphql mercurius decorator providing reply object i

const stream = jsonLogger(
line => {
t.same(line.req, undefined)
t.same(line.reqId, 'req-1')
t.same(line.graphql, {
t.assert.deepStrictEqual(line.req, undefined)
t.assert.deepStrictEqual(line.reqId, 'req-1')
t.assert.deepStrictEqual(line.graphql, {
queries: ['add', 'add', 'echo', 'counter']
})
})
Expand All @@ -64,7 +64,7 @@ test('should log when using graphql mercurius decorator providing reply object i
url: '/custom-endpoint'
})

t.same(response.json(), {
t.assert.deepStrictEqual(response.json(), {
data: {
four: 4,
six: 6,
Expand Down
16 changes: 8 additions & 8 deletions test/issue-22.test.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
'use strict'

const { test } = require('tap')
const { test } = require('node:test')
const { buildApp, jsonLogger } = require('./_helper')

test('should deal GET request', async (t) => {
t.plan(4)

const stream = jsonLogger(
line => {
t.same(line.req, undefined)
t.same(line.reqId, 'req-1')
t.same(line.graphql, {
t.assert.deepStrictEqual(line.req, undefined)
t.assert.deepStrictEqual(line.reqId, 'req-1')
t.assert.deepStrictEqual(line.graphql, {
queries: ['add', 'add', 'echo', 'counter']
})
})
Expand All @@ -30,7 +30,7 @@ test('should deal GET request', async (t) => {
url: '/graphql',
query: { query }
})
t.same(response.json(), {
t.assert.deepStrictEqual(response.json(), {
data: {
four: 4,
six: 6,
Expand All @@ -56,8 +56,8 @@ test('should log the whole request when operationName same set', async (t) => {

const stream = jsonLogger(
line => {
t.same(line.reqId, 'req-1')
t.same(line.graphql, {
t.assert.deepStrictEqual(line.reqId, 'req-1')
t.assert.deepStrictEqual(line.graphql, {
queries: ['add', 'add', 'add', 'add'],
operationName: 'baam',
body: query,
Expand All @@ -81,5 +81,5 @@ test('should log the whole request when operationName same set', async (t) => {
}
})

t.same(response.json(), { data: { c: 5, d: 5 } })
t.assert.deepStrictEqual(response.json(), { data: { c: 5, d: 5 } })
})
62 changes: 31 additions & 31 deletions test/logMessage.test.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
'use strict'

const { test } = require('tap')
const { test } = require('node:test')
const { buildApp, jsonLogger } = require('./_helper')

test('should log without msg when logMessage is undefined', async (t) => {
t.plan(5)

const stream = jsonLogger(
line => {
t.equal(line.req, undefined)
t.equal(line.reqId, 'req-1')
t.same(line.msg, undefined)
t.same(line.graphql, {
t.assert.strictEqual(line.req, undefined)
t.assert.strictEqual(line.reqId, 'req-1')
t.assert.deepStrictEqual(line.msg, undefined)
t.assert.deepStrictEqual(line.graphql, {
operationName: 'logMe',
queries: ['add', 'add', 'echo', 'counter']
})
Expand All @@ -32,7 +32,7 @@ test('should log without msg when logMessage is undefined', async (t) => {
url: '/graphql',
body: JSON.stringify({ query })
})
t.same(response.json(), {
t.assert.deepStrictEqual(response.json(), {
data: {
four: 4,
six: 6,
Expand All @@ -47,10 +47,10 @@ test('should log without msg when logMessage is\'nt a valid function', async (t)

const stream = jsonLogger(
line => {
t.equal(line.req, undefined)
t.equal(line.reqId, 'req-1')
t.same(line.msg, undefined)
t.same(line.graphql, {
t.assert.strictEqual(line.req, undefined)
t.assert.strictEqual(line.reqId, 'req-1')
t.assert.deepStrictEqual(line.msg, undefined)
t.assert.deepStrictEqual(line.graphql, {
operationName: 'logMe',
queries: ['add', 'add', 'echo', 'counter']
})
Expand All @@ -71,7 +71,7 @@ test('should log without msg when logMessage is\'nt a valid function', async (t)
url: '/graphql',
body: JSON.stringify({ query })
})
t.same(response.json(), {
t.assert.deepStrictEqual(response.json(), {
data: {
four: 4,
six: 6,
Expand All @@ -88,10 +88,10 @@ test('should log without msg using a logMessage function returning an undefined

const stream = jsonLogger(
line => {
t.equal(line.req, undefined)
t.equal(line.reqId, 'req-1')
t.same(line.msg, undefined)
t.same(line.graphql, {
t.assert.strictEqual(line.req, undefined)
t.assert.strictEqual(line.reqId, 'req-1')
t.assert.deepStrictEqual(line.msg, undefined)
t.assert.deepStrictEqual(line.graphql, {
operationName: 'logMe',
queries: ['add', 'add', 'echo', 'counter']
})
Expand All @@ -112,7 +112,7 @@ test('should log without msg using a logMessage function returning an undefined
url: '/graphql',
body: JSON.stringify({ query })
})
t.same(response.json(), {
t.assert.deepStrictEqual(response.json(), {
data: {
four: 4,
six: 6,
Expand All @@ -129,10 +129,10 @@ test('should log without msg using a logMessage function throwing an error', asy

const stream = jsonLogger(
line => {
t.equal(line.req, undefined)
t.equal(line.reqId, 'req-1')
t.same(line.msg, undefined)
t.same(line.graphql, {
t.assert.strictEqual(line.req, undefined)
t.assert.strictEqual(line.reqId, 'req-1')
t.assert.deepStrictEqual(line.msg, undefined)
t.assert.deepStrictEqual(line.graphql, {
operationName: 'logMe',
queries: ['add', 'add', 'echo', 'counter']
})
Expand All @@ -153,7 +153,7 @@ test('should log without msg using a logMessage function throwing an error', asy
url: '/graphql',
body: JSON.stringify({ query })
})
t.same(response.json(), {
t.assert.deepStrictEqual(response.json(), {
data: {
four: 4,
six: 6,
Expand All @@ -170,10 +170,10 @@ test('should log with msg using a logMessage function returning a string', async

const stream = jsonLogger(
line => {
t.equal(line.req, undefined)
t.equal(line.reqId, 'req-1')
t.same(line.msg, 'This is a request made with method POST')
t.same(line.graphql, {
t.assert.strictEqual(line.req, undefined)
t.assert.strictEqual(line.reqId, 'req-1')
t.assert.deepStrictEqual(line.msg, 'This is a request made with method POST')
t.assert.deepStrictEqual(line.graphql, {
operationName: 'logMe',
queries: ['add', 'add', 'echo', 'counter']
})
Expand All @@ -194,7 +194,7 @@ test('should log with msg using a logMessage function returning a string', async
url: '/graphql',
body: JSON.stringify({ query })
})
t.same(response.json(), {
t.assert.deepStrictEqual(response.json(), {
data: {
four: 4,
six: 6,
Expand All @@ -211,10 +211,10 @@ test('should log with msg using a logMessage function returning an array', async

const stream = jsonLogger(
line => {
t.equal(line.req, undefined)
t.equal(line.reqId, 'req-1')
t.same(line.msg, 'This is a request made with method POST by foobar')
t.same(line.graphql, {
t.assert.strictEqual(line.req, undefined)
t.assert.strictEqual(line.reqId, 'req-1')
t.assert.deepStrictEqual(line.msg, 'This is a request made with method POST by foobar')
t.assert.deepStrictEqual(line.graphql, {
operationName: 'logMe',
queries: ['add', 'add', 'echo', 'counter']
})
Expand All @@ -235,7 +235,7 @@ test('should log with msg using a logMessage function returning an array', async
url: '/graphql',
body: JSON.stringify({ query })
})
t.same(response.json(), {
t.assert.deepStrictEqual(response.json(), {
data: {
four: 4,
six: 6,
Expand Down
Loading

0 comments on commit ceba978

Please sign in to comment.