From 8c7b81b550642d6497f875e208114098601405a0 Mon Sep 17 00:00:00 2001 From: "dan.castillo" Date: Mon, 5 Aug 2024 08:54:31 -0400 Subject: [PATCH] fix: move tests into root/test/ directory --- package.json | 6 +++--- src/test/esm/default-esm-export.mjs | 3 --- src/test/esm/named-esm-export.mjs | 3 --- {src/test => test}/authorize.test.ts | 2 +- {src/test => test}/csrf-fixation.test.ts | 0 {src/test => test}/decorators.test.ts | 0 test/esm/default-esm-export.mjs | 3 +++ {src/test => test}/esm/esm.test.ts | 4 ++-- test/esm/named-esm-export.mjs | 3 +++ {src/test => test}/helpers.ts | 6 +++--- {src/test => test}/independent-strategy-instances.test.ts | 2 +- {src/test => test}/multi-instance.test.ts | 4 ++-- {src/test => test}/passport.test.ts | 6 +++--- {src/test => test}/secure-session-manager.test.ts | 4 ++-- {src/test => test}/secure.key | 0 {src/test => test}/session-isolation.test.ts | 0 {src/test => test}/session-serialization.test.ts | 2 +- {src/test => test}/session-strategy.test.ts | 4 ++-- {src/test => test}/strategies-integration.test.ts | 0 {src/test => test}/strategy.test.ts | 4 ++-- tsconfig.json | 4 ++-- 21 files changed, 30 insertions(+), 30 deletions(-) delete mode 100644 src/test/esm/default-esm-export.mjs delete mode 100644 src/test/esm/named-esm-export.mjs rename {src/test => test}/authorize.test.ts (96%) rename {src/test => test}/csrf-fixation.test.ts (100%) rename {src/test => test}/decorators.test.ts (100%) create mode 100644 test/esm/default-esm-export.mjs rename {src/test => test}/esm/esm.test.ts (84%) create mode 100644 test/esm/named-esm-export.mjs rename {src/test => test}/helpers.ts (95%) rename {src/test => test}/independent-strategy-instances.test.ts (99%) rename {src/test => test}/multi-instance.test.ts (99%) rename {src/test => test}/passport.test.ts (99%) rename {src/test => test}/secure-session-manager.test.ts (97%) rename {src/test => test}/secure.key (100%) rename {src/test => test}/session-isolation.test.ts (100%) rename {src/test => test}/session-serialization.test.ts (99%) rename {src/test => test}/session-strategy.test.ts (94%) rename {src/test => test}/strategies-integration.test.ts (100%) rename {src/test => test}/strategy.test.ts (97%) diff --git a/package.json b/package.json index 24ac5ef7..89935b43 100644 --- a/package.json +++ b/package.json @@ -2,11 +2,11 @@ "name": "@fastify/passport", "version": "2.5.0", "description": "Simple, unobtrusive authentication for Fastify.", - "main": "dist/index.js", + "main": "dist/src/index.js", "type": "commonjs", - "types": "dist/index.d.ts", + "types": "dist/src/index.d.ts", "scripts": { - "build": "rimraf ./dist && mkdir dist && tsc --outDir dist && git rev-parse HEAD > BUILD_SHA", + "build": "rimraf ./dist && tsc && git rev-parse HEAD > BUILD_SHA", "lint": "eslint \"*/**/*.{js,ts,tsx}\"", "lint:fix": "prettier --loglevel warn --write \"src/**/*.{ts,tsx}\" && eslint \"*/**/*.{js,ts,tsx}\" --quiet --fix", "prepublishOnly": "npm run build", diff --git a/src/test/esm/default-esm-export.mjs b/src/test/esm/default-esm-export.mjs deleted file mode 100644 index 699ec09e..00000000 --- a/src/test/esm/default-esm-export.mjs +++ /dev/null @@ -1,3 +0,0 @@ -import passport from '../../../dist/index.js' - -passport.initialize() diff --git a/src/test/esm/named-esm-export.mjs b/src/test/esm/named-esm-export.mjs deleted file mode 100644 index 7bacd302..00000000 --- a/src/test/esm/named-esm-export.mjs +++ /dev/null @@ -1,3 +0,0 @@ -import { Strategy } from '../../../dist/index.js' - -class MS extends Strategy {} diff --git a/src/test/authorize.test.ts b/test/authorize.test.ts similarity index 96% rename from src/test/authorize.test.ts rename to test/authorize.test.ts index c8d39dbe..38356a67 100644 --- a/src/test/authorize.test.ts +++ b/test/authorize.test.ts @@ -2,7 +2,7 @@ import { test, describe } from 'node:test' import assert from 'node:assert' import { RouteHandlerMethod } from 'fastify' import { expectType } from 'tsd' -import { Strategy } from '../strategies' +import { Strategy } from '../src/strategies' import { generateTestUser, getConfiguredTestServer } from './helpers' export class TestThirdPartyStrategy extends Strategy { diff --git a/src/test/csrf-fixation.test.ts b/test/csrf-fixation.test.ts similarity index 100% rename from src/test/csrf-fixation.test.ts rename to test/csrf-fixation.test.ts diff --git a/src/test/decorators.test.ts b/test/decorators.test.ts similarity index 100% rename from src/test/decorators.test.ts rename to test/decorators.test.ts diff --git a/test/esm/default-esm-export.mjs b/test/esm/default-esm-export.mjs new file mode 100644 index 00000000..01d3e4a3 --- /dev/null +++ b/test/esm/default-esm-export.mjs @@ -0,0 +1,3 @@ +import passport from '../../dist/src/index.js' + +passport.initialize() diff --git a/src/test/esm/esm.test.ts b/test/esm/esm.test.ts similarity index 84% rename from src/test/esm/esm.test.ts rename to test/esm/esm.test.ts index d48a4808..b88d5ad2 100644 --- a/src/test/esm/esm.test.ts +++ b/test/esm/esm.test.ts @@ -5,12 +5,12 @@ import { join } from 'node:path' describe('Native ESM import', () => { test('should be able to use default export', () => { - const { status } = spawnSync('node', [join(__dirname, '../../../src/test/esm', 'default-esm-export.mjs')]) + const { status } = spawnSync('node', [join(__dirname, '../../../test/esm', 'default-esm-export.mjs')]) assert.strictEqual(status, 0) }) test('should be able to use named export', () => { - const { status } = spawnSync('node', [join(__dirname, '../../../src/test/esm', 'named-esm-export.mjs')]) + const { status } = spawnSync('node', [join(__dirname, '../../../test/esm', 'named-esm-export.mjs')]) assert.strictEqual(status, 0) }) diff --git a/test/esm/named-esm-export.mjs b/test/esm/named-esm-export.mjs new file mode 100644 index 00000000..f0171bd6 --- /dev/null +++ b/test/esm/named-esm-export.mjs @@ -0,0 +1,3 @@ +import { Strategy } from '../../dist/src/index.js' + +class MS extends Strategy {} diff --git a/src/test/helpers.ts b/test/helpers.ts similarity index 95% rename from src/test/helpers.ts rename to test/helpers.ts index 2b610f29..e13e2e64 100644 --- a/src/test/helpers.ts +++ b/test/helpers.ts @@ -3,15 +3,15 @@ import { join } from 'node:path' import fastify, { FastifyInstance } from 'fastify' import fastifySecureSession, { SecureSessionPluginOptions } from '@fastify/secure-session' import fastifyCookie from '@fastify/cookie' -import Authenticator, { AuthenticatorOptions } from '../Authenticator' -import { Strategy } from '../strategies' +import Authenticator, { AuthenticatorOptions } from '../src/Authenticator' +import { Strategy } from '../src/strategies' import { InjectOptions, Response as LightMyRequestResponse } from 'light-my-request' import parseCookies from 'set-cookie-parser' import { IncomingMessage } from 'node:http' import { FastifyRegisterOptions } from 'fastify/types/register' import { fastifySession, FastifySessionOptions } from '@fastify/session' -const SecretKey = fs.readFileSync(join(__dirname, '../../src/test', 'secure.key')) +const SecretKey = fs.readFileSync(join(__dirname, '../../test', 'secure.key')) let counter = 0 export const generateTestUser = () => ({ name: 'test', id: String(counter++) }) diff --git a/src/test/independent-strategy-instances.test.ts b/test/independent-strategy-instances.test.ts similarity index 99% rename from src/test/independent-strategy-instances.test.ts rename to test/independent-strategy-instances.test.ts index 7293915b..2fcddd6e 100644 --- a/src/test/independent-strategy-instances.test.ts +++ b/test/independent-strategy-instances.test.ts @@ -1,6 +1,6 @@ import { test, describe } from 'node:test' import assert from 'node:assert' -import { Strategy } from '../strategies' +import { Strategy } from '../src/strategies' import { TestThirdPartyStrategy } from './authorize.test' import { getConfiguredTestServer, getRegisteredTestServer, TestStrategy } from './helpers' diff --git a/src/test/multi-instance.test.ts b/test/multi-instance.test.ts similarity index 99% rename from src/test/multi-instance.test.ts rename to test/multi-instance.test.ts index 0b64eb8c..57a5e250 100644 --- a/src/test/multi-instance.test.ts +++ b/test/multi-instance.test.ts @@ -1,8 +1,8 @@ import { test, describe, beforeEach } from 'node:test' import assert from 'node:assert' import { FastifyInstance } from 'fastify' -import { Authenticator } from '../Authenticator' -import { Strategy } from '../strategies' +import { Authenticator } from '../src/Authenticator' +import { Strategy } from '../src/strategies' import { getTestServer, TestBrowserSession } from './helpers' let counter: number diff --git a/src/test/passport.test.ts b/test/passport.test.ts similarity index 99% rename from src/test/passport.test.ts rename to test/passport.test.ts index 8893202f..801514aa 100644 --- a/src/test/passport.test.ts +++ b/test/passport.test.ts @@ -2,9 +2,9 @@ import { test, describe } from 'node:test' import assert from 'node:assert' import got from 'got' import { AddressInfo } from 'net' -import { AuthenticateOptions } from '../AuthenticationRoute' -import Authenticator from '../Authenticator' -import { Strategy } from '../strategies' +import { AuthenticateOptions } from '../src/AuthenticationRoute' +import Authenticator from '../src/Authenticator' +import { Strategy } from '../src/strategies' import { getConfiguredTestServer, getRegisteredTestServer, getTestServer, TestStrategy } from './helpers' const testSuite = (sessionPluginName: string) => { diff --git a/src/test/secure-session-manager.test.ts b/test/secure-session-manager.test.ts similarity index 97% rename from src/test/secure-session-manager.test.ts rename to test/secure-session-manager.test.ts index eefeb0d8..2ae210ae 100644 --- a/src/test/secure-session-manager.test.ts +++ b/test/secure-session-manager.test.ts @@ -1,8 +1,8 @@ import { test, describe, mock } from 'node:test' import assert from 'node:assert' import { FastifyRequest } from 'fastify' -import { SerializeFunction } from '../Authenticator' -import { SecureSessionManager } from '../session-managers/SecureSessionManager' +import { SerializeFunction } from '../src/Authenticator' +import { SecureSessionManager } from '../src/session-managers/SecureSessionManager' describe('SecureSessionManager', () => { test('should throw an Error if no parameter was passed', () => { diff --git a/src/test/secure.key b/test/secure.key similarity index 100% rename from src/test/secure.key rename to test/secure.key diff --git a/src/test/session-isolation.test.ts b/test/session-isolation.test.ts similarity index 100% rename from src/test/session-isolation.test.ts rename to test/session-isolation.test.ts diff --git a/src/test/session-serialization.test.ts b/test/session-serialization.test.ts similarity index 99% rename from src/test/session-serialization.test.ts rename to test/session-serialization.test.ts index 7daab9d2..43316541 100644 --- a/src/test/session-serialization.test.ts +++ b/test/session-serialization.test.ts @@ -2,7 +2,7 @@ import { test, describe, mock } from 'node:test' import assert from 'node:assert' import { FastifyInstance } from 'fastify' import { FastifyRequest } from 'fastify/types/request' -import Authenticator from '../Authenticator' +import Authenticator from '../src/Authenticator' import { getTestServer, TestDatabaseStrategy, TestStrategy } from './helpers' const testSuite = (sessionPluginName: string) => { diff --git a/src/test/session-strategy.test.ts b/test/session-strategy.test.ts similarity index 94% rename from src/test/session-strategy.test.ts rename to test/session-strategy.test.ts index 5d6fd6b2..9ba53417 100644 --- a/src/test/session-strategy.test.ts +++ b/test/session-strategy.test.ts @@ -1,7 +1,7 @@ import { test, describe } from 'node:test' import assert from 'node:assert' -import { SerializeFunction } from '../Authenticator' -import { SessionStrategy } from '../strategies/SessionStrategy' +import { SerializeFunction } from '../src/Authenticator' +import { SessionStrategy } from '../src/strategies/SessionStrategy' describe('SessionStrategy', () => { test('should throw an Error if no parameter was passed', () => { diff --git a/src/test/strategies-integration.test.ts b/test/strategies-integration.test.ts similarity index 100% rename from src/test/strategies-integration.test.ts rename to test/strategies-integration.test.ts diff --git a/src/test/strategy.test.ts b/test/strategy.test.ts similarity index 97% rename from src/test/strategy.test.ts rename to test/strategy.test.ts index a91bbef4..e102136a 100644 --- a/src/test/strategy.test.ts +++ b/test/strategy.test.ts @@ -1,8 +1,8 @@ import { test, describe } from 'node:test' import assert from 'node:assert' -import Authenticator from '../Authenticator' +import Authenticator from '../src/Authenticator' import { getConfiguredTestServer, TestStrategy } from './helpers' -import { Strategy } from '../strategies' +import { Strategy } from '../src/strategies' const testSuite = (sessionPluginName: string) => { describe(`${sessionPluginName} tests`, () => { diff --git a/tsconfig.json b/tsconfig.json index 8922df2c..61128164 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -13,7 +13,7 @@ "noImplicitAny": false, "removeComments": true, "noUnusedLocals": true, - "rootDir": "./src", + "rootDir": ".", "resolveJsonModule": true, "newLine": "lf", "noFallthroughCasesInSwitch": true, @@ -22,5 +22,5 @@ "skipLibCheck": true, "lib": ["ESNext"] }, - "include": ["src"] + "include": ["src", "test"] }