Skip to content

Commit 76e38e6

Browse files
fix: update types, tests, examples and harmonize repository structure (#132)
* types: use `FastifyPluginCallback` instead of the deprecated `FastifyPlugin` * refactor: remove unused imports * fix (tests): use tap `teardown()` instead of the deprecated `tearDown()` * chore: upgrade package dependencies * chore: harmonize repository structure * fix (examples): make use of the current plugin * chore: add `.taprc` configuration file * fix: update test script Co-authored-by: KaKa <[email protected]> Co-authored-by: KaKa <[email protected]>
1 parent 2ea531a commit 76e38e6

File tree

10 files changed

+42
-26
lines changed

10 files changed

+42
-26
lines changed

.taprc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
100: true
2+
ts: false
3+
jsx: false
4+
flow: false
5+
coverage: true
6+
check-coverage: true

examples/apple.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
const fastify = require('fastify')({ logger: { level: 'trace' } })
1111
const appleSignin = require('apple-signin')
1212

13+
// const oauthPlugin = require('fastify-oauth2')
1314
const oauthPlugin = require('..')
1415

1516
const CLIENT_ID = '<CLIENT_ID>'

examples/facebook.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
const fastify = require('fastify')({ logger: { level: 'trace' } })
44
const sget = require('simple-get')
55

6-
const oauthPlugin = require('../')
6+
// const oauthPlugin = require('fastify-oauth2')
7+
const oauthPlugin = require('..')
78

89
fastify.register(oauthPlugin, {
910
name: 'facebookOAuth2',

examples/google.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
const fastify = require('fastify')({ logger: { level: 'trace' } })
44
const sget = require('simple-get')
55

6+
// const oauthPlugin = require('fastify-oauth2')
67
const oauthPlugin = require('..')
78

89
fastify.register(oauthPlugin, {

examples/spotify.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
const fastify = require('fastify')({ logger: true })
2-
const oauthPlugin = require('fastify-oauth2')
2+
3+
// const oauthPlugin = require('fastify-oauth2')
4+
const oauthPlugin = require('..')
35

46
fastify.register(oauthPlugin, {
57
name: 'Spotify',

examples/vkontakte.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
const fastify = require('fastify')({ logger: { level: 'trace' } })
2-
const oauthPlugin = require('fastify-oauth2')
2+
3+
// const oauthPlugin = require('fastify-oauth2')
4+
const oauthPlugin = require('..')
35

46
fastify.register(oauthPlugin, {
57
name: 'vkOAuth2',

index.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { FastifyPlugin, FastifyRequest } from 'fastify';
1+
import { FastifyPluginCallback, FastifyRequest } from 'fastify';
22

33
interface FastifyOAuth2 {
44
APPLE_CONFIGURATION: ProviderConfiguration;
@@ -13,7 +13,7 @@ interface FastifyOAuth2 {
1313
TWITCH_CONFIGURATION: ProviderConfiguration;
1414
}
1515

16-
export const fastifyOauth2: FastifyPlugin<FastifyOAuth2Options> & FastifyOAuth2
16+
export const fastifyOauth2: FastifyPluginCallback<FastifyOAuth2Options> & FastifyOAuth2
1717

1818
export interface FastifyOAuth2Options {
1919
name: string;

package.json

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
"version": "4.4.0",
44
"description": "Perform login using oauth2 protocol",
55
"main": "index.js",
6+
"types": "index.d.ts",
67
"scripts": {
78
"coverage": "npm run unit -- --cov --coverage-report=html",
89
"lint": "standard | snazzy",
910
"test": "npm run lint && npm run unit && npm run test:typescript",
1011
"test:typescript": "tsd",
11-
"unit": "tap test.js"
12+
"unit": "tap -J \"test/*.test.js\""
1213
},
1314
"repository": {
1415
"type": "git",
@@ -25,18 +26,21 @@
2526
],
2627
"homepage": "https://github.com/fastify/fastify-oauth2#readme",
2728
"devDependencies": {
28-
"@types/node": "^17.0.0",
29-
"fastify": "^3.0.3",
30-
"nock": "^13.0.0",
29+
"@types/node": "^17.0.8",
30+
"fastify": "^3.25.3",
31+
"nock": "^13.2.1",
3132
"pre-commit": "^1.2.2",
3233
"simple-get": "^4.0.0",
3334
"snazzy": "^9.0.0",
34-
"standard": "^16.0.0",
35-
"tap": "^15.0.0",
36-
"tsd": "^0.19.0"
35+
"standard": "^16.0.4",
36+
"tap": "^15.1.6",
37+
"tsd": "^0.19.1"
3738
},
3839
"dependencies": {
3940
"fastify-plugin": "^3.0.0",
4041
"simple-oauth2": "^3.4.0"
42+
},
43+
"tsd": {
44+
"directory": "test/types"
4145
}
4246
}

test.js renamed to test/plugin.test.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const t = require('tap')
44
const nock = require('nock')
55
const createFastify = require('fastify')
66

7-
const oauthPlugin = require('./index')
7+
const oauthPlugin = require('..')
88

99
nock.disableNetConnect()
1010

@@ -107,7 +107,7 @@ t.test('fastify-oauth2', t => {
107107
})
108108
})
109109

110-
t.tearDown(fastify.close.bind(fastify))
110+
t.teardown(fastify.close.bind(fastify))
111111

112112
makeRequests(t, fastify)
113113
})
@@ -145,7 +145,7 @@ t.test('fastify-oauth2', t => {
145145
})
146146
})
147147

148-
t.tearDown(fastify.close.bind(fastify))
148+
t.teardown(fastify.close.bind(fastify))
149149

150150
makeRequests(t, fastify)
151151
})
@@ -174,7 +174,7 @@ t.test('fastify-oauth2', t => {
174174
})
175175
})
176176

177-
t.tearDown(fastify.close.bind(fastify))
177+
t.teardown(fastify.close.bind(fastify))
178178

179179
fastify.inject({
180180
method: 'GET',
@@ -278,7 +278,7 @@ t.test('options.callbackUriParams', t => {
278278
scope: ['notifications']
279279
})
280280

281-
t.tearDown(fastify.close.bind(fastify))
281+
t.teardown(fastify.close.bind(fastify))
282282

283283
fastify.listen(0, function (err) {
284284
t.error(err)
@@ -320,7 +320,7 @@ t.test('options.generateStateFunction with request', t => {
320320
scope: ['notifications']
321321
})
322322

323-
t.tearDown(fastify.close.bind(fastify))
323+
t.teardown(fastify.close.bind(fastify))
324324

325325
fastify.listen(0, function (err) {
326326
t.error(err)
@@ -365,7 +365,7 @@ t.test('generateAuthorizationUri redirect with request object', t => {
365365
return reply.redirect(redirectUrl)
366366
})
367367

368-
t.tearDown(fastify.close.bind(fastify))
368+
t.teardown(fastify.close.bind(fastify))
369369

370370
fastify.inject({
371371
method: 'GET',
@@ -586,7 +586,7 @@ t.test('preset configuration generate-callback-uri-params', t => {
586586
scope: ['email']
587587
})
588588

589-
t.tearDown(fastify.close.bind(fastify))
589+
t.teardown(fastify.close.bind(fastify))
590590

591591
fastify.listen(0, function (err) {
592592
t.error(err)
@@ -622,7 +622,7 @@ t.test('preset configuration generate-callback-uri-params', t => {
622622
scope: 'name'
623623
})
624624

625-
t.tearDown(fastify.close.bind(fastify))
625+
t.teardown(fastify.close.bind(fastify))
626626

627627
fastify.listen(0, function (err) {
628628
t.error(err)
@@ -658,7 +658,7 @@ t.test('preset configuration generate-callback-uri-params', t => {
658658
scope: ''
659659
})
660660

661-
t.tearDown(fastify.close.bind(fastify))
661+
t.teardown(fastify.close.bind(fastify))
662662

663663
fastify.listen(0, function (err) {
664664
t.error(err)

index.test-d.ts renamed to test/types/index.test-d.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import fastify, { FastifyInstance } from 'fastify';
2-
import fastifyOauth2, { OAuth2Namespace, ProviderConfiguration, Credentials, OAuth2Token } from '.';
3-
import { expectType, expectError, expectAssignable } from 'tsd';
4-
import { Server, IncomingMessage, ServerResponse } from 'http';
1+
import fastify from 'fastify';
2+
import { expectAssignable, expectError, expectType } from 'tsd';
3+
import fastifyOauth2, { Credentials, OAuth2Namespace, OAuth2Token, ProviderConfiguration } from '../..';
54

65
/**
76
* Preparing some data for testing.

0 commit comments

Comments
 (0)