Skip to content

Commit fcb22d7

Browse files
authored
Merge pull request #127 from ilteoood/master
BREAKING CHANGE: fastify v5
2 parents 796b88b + ff3467a commit fcb22d7

File tree

4 files changed

+26
-26
lines changed

4 files changed

+26
-26
lines changed

.eslintrc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
],
99
"env": {
1010
"node": true,
11-
"es6": true,
12-
"jest":true
11+
"es6": true
1312
},
1413
"parserOptions": {
1514
"sourceType": "script",

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jobs:
77
runs-on: ubuntu-latest
88
strategy:
99
matrix:
10-
node: [16, 18, 20]
10+
node: [20, 22]
1111

1212
name: Node.js ${{ matrix.node }}
1313

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "Fastify Plugin to manage MSSQL connections",
55
"main": "plugin.js",
66
"scripts": {
7-
"test": "jest --testTimeout=15000",
7+
"test": "node --test",
88
"lint": "eslint .",
99
"test:docker:start": "docker-compose -f tests/docker-compose.dev.yml up -d",
1010
"test:docker:stop": "docker-compose -f tests/docker-compose.dev.yml stop"
@@ -37,14 +37,12 @@
3737
"fastify-plugin": "^5.0.0"
3838
},
3939
"devDependencies": {
40-
"@types/jest": "^29.0.0",
4140
"@types/mssql": "^9.1.1",
4241
"eslint": "^8.0.1",
4342
"eslint-config-prettier": "^9.0.0",
4443
"eslint-plugin-import": "^2.23.3",
4544
"eslint-plugin-prettier": "^5.0.0",
4645
"fastify": "^5.1.0",
47-
"jest": "^29.0.0",
4846
"mssql": "^11.0.0",
4947
"prettier": "^3.0.2"
5048
},

tests/plugin.test.js

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
const { describe, before, after, test } = require('node:test')
2+
const assert = require('node:assert')
13
const buildServer = require('./build-server')
24

35
const plugin = require('../plugin.js')
@@ -7,9 +9,10 @@ const { getPool } = require('./utils')
79
describe('fastify-mssql', () => {
810
let app
911

10-
beforeAll(async () => {
12+
before(async () => {
1113
const pool = await getPool()
1214
app = buildServer()
15+
1316
await pool.query(`
1417
IF NOT EXISTS (SELECT 1 FROM sys.databases WHERE name = 'TestSuite')
1518
CREATE DATABASE TestSuite;
@@ -24,17 +27,7 @@ describe('fastify-mssql', () => {
2427
await pool.query(
2528
"INSERT INTO [dbo].[Users] ([id], [name], [email]) VALUES ('2', N'fizzbuzz', N'fizzbuzz@gmail.com');"
2629
)
27-
})
28-
29-
afterAll(async () => {
30-
const pool = await getPool()
31-
await pool.query(`USE TestSuite`)
32-
await pool.query('DROP TABLE IF EXISTS [dbo].[Users]')
33-
await pool.close()
34-
app.close()
35-
})
3630

37-
test('MSSQL plugin is loaded', async () => {
3831
app.register(plugin, {
3932
user: 'sa',
4033
password: 'S3cretP4ssw0rd!',
@@ -67,27 +60,37 @@ describe('fastify-mssql', () => {
6760
return { error: err.message }
6861
}
6962
})
63+
})
7064

71-
{
65+
after(async () => {
66+
const pool = await getPool()
67+
await pool.query(`USE TestSuite`)
68+
await pool.query('DROP TABLE IF EXISTS [dbo].[Users]')
69+
await pool.close()
70+
app.close()
71+
})
72+
73+
describe('MSSQL plugin is loaded', () => {
74+
test('correctly return users', async () => {
7275
const response = await app.inject({
7376
method: 'GET',
7477
url: '/users'
7578
})
7679
const body = JSON.parse(response.body)
77-
expect(app.mssql.pool).not.toBe(undefined)
78-
expect(response.statusCode).toBe(200)
79-
expect(body.users.length).toBe(2)
80-
}
80+
assert.ok(app.mssql.pool)
81+
assert.deepStrictEqual(response.statusCode, 200)
82+
assert.deepStrictEqual(body.users.length, 2)
83+
})
8184

82-
{
85+
test('correctly return user', async () => {
8386
const response = await app.inject({
8487
method: 'GET',
8588
url: '/users/2'
8689
})
87-
expect(response.statusCode).toBe(200)
88-
expect(response.json()).toEqual({
90+
assert.deepStrictEqual(response.statusCode, 200)
91+
assert.deepStrictEqual(response.json(), {
8992
user: [{ id: '2', name: 'fizzbuzz', email: 'fizzbuzz@gmail.com' }]
9093
})
91-
}
94+
})
9295
})
9396
})

0 commit comments

Comments
 (0)