diff --git a/src/adapters/apollo-server/apollo-server-mutation.adapter.ts b/src/adapters/apollo-server/apollo-server-mutation.adapter.ts index ec316ccd..808a11bb 100644 --- a/src/adapters/apollo-server/apollo-server-mutation.adapter.ts +++ b/src/adapters/apollo-server/apollo-server-mutation.adapter.ts @@ -41,12 +41,8 @@ export type ApolloServerMutationAdapterOptions = { * @breadcrumb Adapters / Apollo Server / ApolloServerMutationAdapter * @public */ -export class ApolloServerMutationAdapter< - TEvent, - TContext, - TResponse, - TBaseAdapter extends AdapterContract, -> implements AdapterContract +export class ApolloServerMutationAdapter + implements AdapterContract { //#region Constructor @@ -54,7 +50,11 @@ export class ApolloServerMutationAdapter< * The default constructor */ constructor( - protected readonly baseAdapter: TBaseAdapter, + protected readonly baseAdapter: AdapterContract< + TEvent, + TContext, + TResponse + >, protected readonly options: ApolloServerMutationAdapterOptions, ) {} diff --git a/src/network/response-stream.ts b/src/network/response-stream.ts index 52d06188..3e46985f 100644 --- a/src/network/response-stream.ts +++ b/src/network/response-stream.ts @@ -113,9 +113,12 @@ export class ServerlessStreamResponse extends ServerResponse { endHeaderIndex, ); const headers = parseHeaders(headerData); - log.debug('SERVERLESS_ADAPTER:RESPONSE_STREAM:FRAMEWORK_HEADERS', { - headers, - }); + log.debug( + 'SERVERLESS_ADAPTER:RESPONSE_STREAM:FRAMEWORK_HEADERS', + () => ({ + headers, + }), + ); writesToIgnore = 1; internalWritable = onReceiveHeaders(status, headers); diff --git a/test/adapters/apollo-server/apollo-mutation.adapter.spec.ts b/test/adapters/apollo-server/apollo-mutation.adapter.spec.ts index 3e72a747..9522f6bf 100644 --- a/test/adapters/apollo-server/apollo-mutation.adapter.spec.ts +++ b/test/adapters/apollo-server/apollo-mutation.adapter.spec.ts @@ -1,9 +1,10 @@ import { ApolloServer } from '@apollo/server'; import { describe, expect, it, vitest } from 'vitest'; +import type { SQSEvent } from 'aws-lambda'; import { - AdapterContract, + type AdapterContract, EmptyResponse, - GetResponseAdapterProps, + type GetResponseAdapterProps, ServerlessRequest, ServerlessResponse, createDefaultLogger, @@ -11,7 +12,7 @@ import { } from '../../../src'; import { ApolloServerMutationAdapter, - ApolloServerMutationAdapterOptions, + type ApolloServerMutationAdapterOptions, } from '../../../src/adapters/apollo-server'; import { DynamoDBAdapter, @@ -279,7 +280,7 @@ it('onErrorWhileForwarding: should forward error dealing to base adapter', () => }); const props = { - event: {}, + event: {} as SQSEvent, log: createDefaultLogger(), error: new Error(), delegatedResolver: { fail: vitest.fn(), succeed: vitest.fn() }, diff --git a/test/adapters/aws/alb.adapter.spec.ts b/test/adapters/aws/alb.adapter.spec.ts index e003d0a4..cf3e5294 100644 --- a/test/adapters/aws/alb.adapter.spec.ts +++ b/test/adapters/aws/alb.adapter.spec.ts @@ -1,9 +1,9 @@ import type { ALBEvent, ALBResult } from 'aws-lambda'; import { beforeEach, describe, expect, it, vitest } from 'vitest'; import { - DelegatedResolver, - GetResponseAdapterProps, - ILogger, + type DelegatedResolver, + type GetResponseAdapterProps, + type ILogger, getEventBodyAsBuffer, getFlattenedHeadersMap, getMultiValueHeadersMap, diff --git a/test/adapters/aws/api-gateway-v1.adapter.spec.ts b/test/adapters/aws/api-gateway-v1.adapter.spec.ts index 9832fa67..75536483 100644 --- a/test/adapters/aws/api-gateway-v1.adapter.spec.ts +++ b/test/adapters/aws/api-gateway-v1.adapter.spec.ts @@ -2,9 +2,9 @@ import type { APIGatewayProxyResult } from 'aws-lambda'; import type { APIGatewayProxyEvent } from 'aws-lambda/trigger/api-gateway-proxy'; import { beforeEach, describe, expect, it, vitest } from 'vitest'; import { - DelegatedResolver, - GetResponseAdapterProps, - ILogger, + type DelegatedResolver, + type GetResponseAdapterProps, + type ILogger, ServerlessResponse, getEventBodyAsBuffer, getFlattenedHeadersMap, diff --git a/test/adapters/aws/api-gateway-v2.adapter.spec.ts b/test/adapters/aws/api-gateway-v2.adapter.spec.ts index cf465a07..3c820bee 100644 --- a/test/adapters/aws/api-gateway-v2.adapter.spec.ts +++ b/test/adapters/aws/api-gateway-v2.adapter.spec.ts @@ -2,9 +2,9 @@ import type { APIGatewayProxyEventV2 } from 'aws-lambda'; import type { APIGatewayProxyStructuredResultV2 } from 'aws-lambda/trigger/api-gateway-proxy'; import { beforeEach, describe, expect, it, vitest } from 'vitest'; import { - DelegatedResolver, - GetResponseAdapterProps, - ILogger, + type DelegatedResolver, + type GetResponseAdapterProps, + type ILogger, ServerlessResponse, getEventBodyAsBuffer, getFlattenedHeadersMap, diff --git a/test/adapters/aws/aws-simple-adapter.spec.ts b/test/adapters/aws/aws-simple-adapter.spec.ts index 1aa4557c..d8db9e1a 100644 --- a/test/adapters/aws/aws-simple-adapter.spec.ts +++ b/test/adapters/aws/aws-simple-adapter.spec.ts @@ -1,8 +1,8 @@ import { describe, expect, it, vitest } from 'vitest'; import { - DelegatedResolver, + type DelegatedResolver, EmptyResponse, - ILogger, + type ILogger, createDefaultLogger, getEventBodyAsBuffer, } from '../../../src'; diff --git a/test/adapters/aws/lambda-edge.adapter.spec.ts b/test/adapters/aws/lambda-edge.adapter.spec.ts index 743720a6..4bd6ef8b 100644 --- a/test/adapters/aws/lambda-edge.adapter.spec.ts +++ b/test/adapters/aws/lambda-edge.adapter.spec.ts @@ -9,11 +9,11 @@ import type { } from 'aws-lambda/trigger/cloudfront-request'; import { beforeEach, describe, expect, it, vitest } from 'vitest'; import { - BothValueHeaders, - DelegatedResolver, - ILogger, - MultiValueHeaders, - SingleValueHeaders, + type BothValueHeaders, + type DelegatedResolver, + type ILogger, + type MultiValueHeaders, + type SingleValueHeaders, } from '../../../src'; import { DEFAULT_LAMBDA_EDGE_DISALLOWED_HEADERS, diff --git a/test/adapters/aws/request-lambda-edge.adapter.spec.ts b/test/adapters/aws/request-lambda-edge.adapter.spec.ts index 1b201e7a..35cf48c2 100644 --- a/test/adapters/aws/request-lambda-edge.adapter.spec.ts +++ b/test/adapters/aws/request-lambda-edge.adapter.spec.ts @@ -5,11 +5,11 @@ import type { } from 'aws-lambda/trigger/cloudfront-request'; import { beforeEach, describe, expect, it, vitest } from 'vitest'; import { - BothValueHeaders, - DelegatedResolver, - ILogger, - MultiValueHeaders, - SingleValueHeaders, + type BothValueHeaders, + type DelegatedResolver, + type ILogger, + type MultiValueHeaders, + type SingleValueHeaders, } from '../../../src'; import { DEFAULT_LAMBDA_EDGE_DISALLOWED_HEADERS, diff --git a/test/adapters/azure/http-trigger.adapter.spec.ts b/test/adapters/azure/http-trigger.adapter.spec.ts index 29690542..cfea450c 100644 --- a/test/adapters/azure/http-trigger.adapter.spec.ts +++ b/test/adapters/azure/http-trigger.adapter.spec.ts @@ -1,9 +1,9 @@ import type { Cookie, HttpRequest, HttpResponseSimple } from '@azure/functions'; import { beforeEach, describe, expect, it, vitest } from 'vitest'; import { - DelegatedResolver, - GetResponseAdapterProps, - ILogger, + type DelegatedResolver, + type GetResponseAdapterProps, + type ILogger, getEventBodyAsBuffer, getFlattenedHeadersMap, getPathWithQueryStringParams, @@ -303,7 +303,7 @@ describe(HttpTriggerV4Adapter.name, () => { const log = {} as ILogger; - const resolver: DelegatedResolver = { + const resolver: DelegatedResolver = { fail: vitest.fn(), succeed: vitest.fn(), }; diff --git a/test/adapters/azure/utils/http-trigger.ts b/test/adapters/azure/utils/http-trigger.ts index 989a708f..3b81b5cd 100644 --- a/test/adapters/azure/utils/http-trigger.ts +++ b/test/adapters/azure/utils/http-trigger.ts @@ -1,7 +1,7 @@ import { URL } from 'url'; import type { Context, Form, HttpRequest } from '@azure/functions'; import { vitest } from 'vitest'; -import { BothValueHeaders } from '../../../../src'; +import { type BothValueHeaders } from '../../../../src'; export function createHttpTriggerEvent( method: HttpRequest['method'], diff --git a/test/adapters/digital-ocean/http-function.adapter.spec.ts b/test/adapters/digital-ocean/http-function.adapter.spec.ts index 12780810..d3afb56d 100644 --- a/test/adapters/digital-ocean/http-function.adapter.spec.ts +++ b/test/adapters/digital-ocean/http-function.adapter.spec.ts @@ -1,13 +1,15 @@ import { beforeEach, describe, expect, it, vitest } from 'vitest'; import { - DelegatedResolver, - GetResponseAdapterProps, - ILogger, + type DelegatedResolver, + type GetResponseAdapterProps, + type ILogger, getEventBodyAsBuffer, getPathWithQueryStringParams, } from '../../../src'; -import { DigitalOceanHttpEvent } from '../../../src/@types/digital-ocean'; -import { DigitalOceanHttpResponse } from '../../../src/@types/digital-ocean/digital-ocean-http-response'; +import { + type DigitalOceanHttpEvent, + type DigitalOceanHttpResponse, +} from '../../../src/@types/digital-ocean'; import { HttpFunctionAdapter } from '../../../src/adapters/digital-ocean'; import { createCanHandleTestsForAdapter } from '../utils/can-handle'; import { createHttpFunctionEvent } from './utils/http-function'; diff --git a/test/adapters/digital-ocean/utils/http-function.ts b/test/adapters/digital-ocean/utils/http-function.ts index cb1aad06..1febfde6 100644 --- a/test/adapters/digital-ocean/utils/http-function.ts +++ b/test/adapters/digital-ocean/utils/http-function.ts @@ -1,4 +1,4 @@ -import { DigitalOceanHttpEvent } from '../../../../src/@types/digital-ocean'; +import { type DigitalOceanHttpEvent } from '../../../../src/@types/digital-ocean'; export function createHttpFunctionEvent( method: string, diff --git a/test/adapters/dummy/dummy.adapter.spec.ts b/test/adapters/dummy/dummy.adapter.spec.ts index 4cfb2fef..7a56843a 100644 --- a/test/adapters/dummy/dummy.adapter.spec.ts +++ b/test/adapters/dummy/dummy.adapter.spec.ts @@ -1,6 +1,6 @@ import { beforeEach, describe, expect, it, vitest } from 'vitest'; import { - DelegatedResolver, + type DelegatedResolver, EmptyResponse, createDefaultLogger, } from '../../../src'; diff --git a/test/adapters/huawei/huawei-api-gateway.adapter.spec.ts b/test/adapters/huawei/huawei-api-gateway.adapter.spec.ts index a4e9f28e..5687c4c9 100644 --- a/test/adapters/huawei/huawei-api-gateway.adapter.spec.ts +++ b/test/adapters/huawei/huawei-api-gateway.adapter.spec.ts @@ -1,13 +1,13 @@ import { beforeEach, describe, expect, it, vitest } from 'vitest'; import { - DelegatedResolver, - GetResponseAdapterProps, - ILogger, + type DelegatedResolver, + type GetResponseAdapterProps, + type ILogger, getEventBodyAsBuffer, getFlattenedHeadersMap, getPathWithQueryStringParams, } from '../../../src'; -import { +import type { HuaweiApiGatewayEvent, HuaweiApiGatewayResponse, } from '../../../src/@types/huawei'; diff --git a/test/adapters/huawei/utils/huawei-api-gateway.ts b/test/adapters/huawei/utils/huawei-api-gateway.ts index d27b6801..f1e881e8 100644 --- a/test/adapters/huawei/utils/huawei-api-gateway.ts +++ b/test/adapters/huawei/utils/huawei-api-gateway.ts @@ -1,5 +1,5 @@ -import { BothValueHeaders } from '../../../../src'; -import { +import type { BothValueHeaders } from '../../../../src'; +import type { HuaweiApiGatewayEvent, HuaweiRequestQueryStringParameters, } from '../../../../src/@types/huawei'; diff --git a/test/adapters/utils/can-handle.ts b/test/adapters/utils/can-handle.ts index 54479099..48548f17 100644 --- a/test/adapters/utils/can-handle.ts +++ b/test/adapters/utils/can-handle.ts @@ -1,5 +1,5 @@ import { beforeEach, describe, expect, it } from 'vitest'; -import { AdapterContract, ILogger } from '../../../src'; +import type { AdapterContract, ILogger } from '../../../src'; import { allEvents } from './events'; export function createCanHandleTestsForAdapter< diff --git a/test/core/base-handler.spec.ts b/test/core/base-handler.spec.ts index 73cbe731..cd3396d0 100644 --- a/test/core/base-handler.spec.ts +++ b/test/core/base-handler.spec.ts @@ -1,9 +1,9 @@ import { describe, expect, it, vitest } from 'vitest'; import { - AdapterContract, - AdapterRequest, + type AdapterContract, + type AdapterRequest, BaseHandler, - ILogger, + type ILogger, ServerlessRequest, ServerlessResponse, createDefaultLogger, @@ -11,32 +11,32 @@ import { import { AlbAdapter, SQSAdapter } from '../../src/adapters/aws'; import { createSQSEvent } from '../adapters/aws/utils/sqs'; -class TestHandler< +class TestHandler extends BaseHandler< TApp, - TEvent, + unknown, TContext, TCallback, - TResponse, - TReturn, -> extends BaseHandler { + unknown, + TReturn +> { getHandler = vitest.fn(); /** * {@inheritDoc} */ - public getAdapterByEventAndContext( + public override getAdapterByEventAndContext( event: any, context: any, - adapters: AdapterContract[], + adapters: AdapterContract[], log: ILogger, - ): AdapterContract { + ): AdapterContract { return super.getAdapterByEventAndContext(event, context, adapters, log); } /** * {@inheritDoc} */ - public getServerlessRequestResponseFromAdapterRequest( + public override getServerlessRequestResponseFromAdapterRequest( requestValues: AdapterRequest, ): [request: ServerlessRequest, response: ServerlessResponse] { return super.getServerlessRequestResponseFromAdapterRequest(requestValues); @@ -48,7 +48,11 @@ describe(BaseHandler.name, () => { const handler = new TestHandler(); const testEvent = createSQSEvent(); const eventAdapter = new SQSAdapter(); - const adapters = [eventAdapter, new AlbAdapter()]; + const adapters = [eventAdapter, new AlbAdapter()] as AdapterContract< + any, + any, + any + >[]; const context = {}; const logger = createDefaultLogger(); @@ -89,7 +93,11 @@ describe(BaseHandler.name, () => { it('should throw error when resolve more than one adapter', () => { const handler = new TestHandler(); const testEvent = createSQSEvent(); - const adapters = [new SQSAdapter(), new SQSAdapter()]; + const adapters = [new SQSAdapter(), new SQSAdapter()] as AdapterContract< + any, + any, + any + >[]; const adapterNames = adapters .map(adapter => adapter.getAdapterName()) .join(', '); diff --git a/test/core/headers.spec.ts b/test/core/headers.spec.ts index 5b82ad93..84be2e4f 100644 --- a/test/core/headers.spec.ts +++ b/test/core/headers.spec.ts @@ -1,6 +1,6 @@ import { describe, expect, it } from 'vitest'; import { - BothValueHeaders, + type BothValueHeaders, getFlattenedHeadersMap, getFlattenedHeadersMapAndCookies, getMultiValueHeadersMap, diff --git a/test/core/is-binary.spec.ts b/test/core/is-binary.spec.ts index 52862ee8..b2513c96 100644 --- a/test/core/is-binary.spec.ts +++ b/test/core/is-binary.spec.ts @@ -1,6 +1,6 @@ import { describe, expect, it } from 'vitest'; import { - BothValueHeaders, + type BothValueHeaders, DEFAULT_BINARY_CONTENT_TYPES, DEFAULT_BINARY_ENCODINGS, getContentType, diff --git a/test/core/logger.spec.ts b/test/core/logger.spec.ts index eaa29da0..658e3528 100644 --- a/test/core/logger.spec.ts +++ b/test/core/logger.spec.ts @@ -1,7 +1,7 @@ /* eslint-disable @typescript-eslint/unbound-method */ import { - SpyInstance, + type MockInstance, afterEach, beforeEach, describe, @@ -10,14 +10,14 @@ import { vitest, } from 'vitest'; import { - LogLevels, + type LogLevels, NO_OP, createDefaultLogger, isInternalLogger, } from '../../src'; describe('createDefaultLogger', () => { - const mocks: SpyInstance[] = []; + const mocks: MockInstance[] = []; beforeEach(() => { const mockMethods: (keyof Console)[] = [ diff --git a/test/core/utils/stream.ts b/test/core/utils/stream.ts index 9abbbfe5..a438d25d 100644 --- a/test/core/utils/stream.ts +++ b/test/core/utils/stream.ts @@ -1,7 +1,7 @@ // credits to: https://github.com/b4nst/stream-mock/pull/64/files#diff-52aee274967f2fcfa3ffa78ebba2f510dd23d176aa92ccf8c0ad4843373f5ce7 -import { Readable, ReadableOptions } from 'node:stream'; -import { IReadableMock } from 'stream-mock'; +import { Readable, type ReadableOptions } from 'node:stream'; +import type { IReadableMock } from 'stream-mock'; /** * ErrorReadableMock is a readable stream that mocks error. @@ -34,7 +34,7 @@ export default class ErrorReadableMock private expectedError: Error; // tslint:disable-next-line:function-name Not responsible of this function name - public _read() { + public override _read() { this.destroy(this.expectedError); } } diff --git a/test/frameworks/apollo-server.framework.spec.ts b/test/frameworks/apollo-server.framework.spec.ts index 6d2f0468..3100d33a 100644 --- a/test/frameworks/apollo-server.framework.spec.ts +++ b/test/frameworks/apollo-server.framework.spec.ts @@ -8,12 +8,12 @@ import { waitForStreamComplete, } from '../../src'; import { - ApolloServerContextArguments, + type ApolloServerContextArguments, ApolloServerFramework, - DefaultServerlessApolloServerContext, + type DefaultServerlessApolloServerContext, } from '../../src/frameworks/apollo-server'; import { JsonBodyParserFramework } from '../../src/frameworks/body-parser'; -import { TestRouteBuilderMethods } from './utils'; +import { type TestRouteBuilderMethods } from './utils'; export const frameworkTestOptions: [ method: TestRouteBuilderMethods, diff --git a/test/frameworks/express.framework.spec.ts b/test/frameworks/express.framework.spec.ts index cbcd4567..59a0147f 100644 --- a/test/frameworks/express.framework.spec.ts +++ b/test/frameworks/express.framework.spec.ts @@ -1,7 +1,7 @@ -import express, { Express } from 'express'; +import express, { type Express } from 'express'; import { describe } from 'vitest'; import { ExpressFramework } from '../../src/frameworks/express'; -import { TestRouteBuilderHandler, createTestSuiteFor } from './utils'; +import { type TestRouteBuilderHandler, createTestSuiteFor } from './utils'; function createHandler( method: 'get' | 'post' | 'delete' | 'put', diff --git a/test/frameworks/fastify.framework.spec.ts b/test/frameworks/fastify.framework.spec.ts index a00778c3..94d7f872 100644 --- a/test/frameworks/fastify.framework.spec.ts +++ b/test/frameworks/fastify.framework.spec.ts @@ -1,7 +1,7 @@ -import fastify, { FastifyInstance } from 'fastify'; +import fastify, { type FastifyInstance } from 'fastify'; import { describe } from 'vitest'; import { FastifyFramework } from '../../src/frameworks/fastify'; -import { TestRouteBuilderHandler, createTestSuiteFor } from './utils'; +import { type TestRouteBuilderHandler, createTestSuiteFor } from './utils'; function createHandler( method: 'get' | 'post' | 'delete' | 'put', diff --git a/test/frameworks/hapi.framework.spec.ts b/test/frameworks/hapi.framework.spec.ts index 9742c23c..9445d33e 100644 --- a/test/frameworks/hapi.framework.spec.ts +++ b/test/frameworks/hapi.framework.spec.ts @@ -1,7 +1,7 @@ import { Server } from '@hapi/hapi'; import { describe } from 'vitest'; import { HapiFramework } from '../../src/frameworks/hapi'; -import { TestRouteBuilderHandler, createTestSuiteFor } from './utils'; +import { type TestRouteBuilderHandler, createTestSuiteFor } from './utils'; function createHandler( method: 'GET' | 'POST' | 'DELETE' | 'PUT', diff --git a/test/frameworks/http-deepkit.framework.spec.ts b/test/frameworks/http-deepkit.framework.spec.ts index 6c278b85..22e9cb85 100644 --- a/test/frameworks/http-deepkit.framework.spec.ts +++ b/test/frameworks/http-deepkit.framework.spec.ts @@ -1,6 +1,6 @@ import { App } from '@deepkit/app'; import { - HttpBody, + type HttpBody, HttpKernel, HttpModule, HttpRequest, @@ -14,7 +14,7 @@ import { waitForStreamComplete, } from '../../src'; import { HttpDeepkitFramework } from '../../src/frameworks/deepkit'; -import { TestRouteBuilderHandler } from './utils'; +import { type TestRouteBuilderHandler } from './utils'; export function createDeepkitHandler( method: 'get' | 'post' | 'delete' | 'put', diff --git a/test/frameworks/koa.framework.spec.ts b/test/frameworks/koa.framework.spec.ts index 61c954b6..4a372e4b 100644 --- a/test/frameworks/koa.framework.spec.ts +++ b/test/frameworks/koa.framework.spec.ts @@ -1,11 +1,11 @@ -import Application, { Context } from 'koa'; +import Application, { type Context } from 'koa'; import { describe } from 'vitest'; import { NO_OP } from '../../src'; import { KoaFramework } from '../../src/frameworks/koa'; -import { TestRouteBuilderHandler, createTestSuiteFor } from './utils'; +import { type TestRouteBuilderHandler, createTestSuiteFor } from './utils'; function createHandler(): TestRouteBuilderHandler { - return (app, path, handler) => { + return (app, _, handler) => { app.use((ctx: Context) => { const [statusCode, resultBody, headers] = handler(ctx.headers, NO_OP); diff --git a/test/frameworks/lazy.framework.spec.ts b/test/frameworks/lazy.framework.spec.ts index ac9a4a28..67f5a3f4 100644 --- a/test/frameworks/lazy.framework.spec.ts +++ b/test/frameworks/lazy.framework.spec.ts @@ -1,6 +1,6 @@ import { describe, expect, it, vitest } from 'vitest'; import { - ILogger, + type ILogger, ServerlessRequest, ServerlessResponse, waitForStreamComplete, diff --git a/test/frameworks/trpc.framework.spec.ts b/test/frameworks/trpc.framework.spec.ts index c184c1ea..b31075e1 100644 --- a/test/frameworks/trpc.framework.spec.ts +++ b/test/frameworks/trpc.framework.spec.ts @@ -1,5 +1,5 @@ import * as trpc from '@trpc/server'; -import { AnyRouter } from '@trpc/server'; +import { type AnyRouter } from '@trpc/server'; import { describe, expect, it } from 'vitest'; import { NO_OP, @@ -10,10 +10,10 @@ import { } from '../../src'; import { BufferToJSObjectTransformer, - TrpcAdapterContext, + type TrpcAdapterContext, TrpcFramework, } from '../../src/frameworks/trpc'; -import { TestRouteBuilderHandler, frameworkTestOptions } from './utils'; +import { type TestRouteBuilderHandler, frameworkTestOptions } from './utils'; type TrpcContext = TrpcAdapterContext; diff --git a/test/frameworks/utils.ts b/test/frameworks/utils.ts index f97b9b9d..d60161b1 100644 --- a/test/frameworks/utils.ts +++ b/test/frameworks/utils.ts @@ -1,6 +1,6 @@ import { expect, it } from 'vitest'; import { - FrameworkContract, + type FrameworkContract, NO_OP, ServerlessRequest, ServerlessResponse, diff --git a/test/handlers/aws-stream.handler.spec.ts b/test/handlers/aws-stream.handler.spec.ts index d1c5c4bd..af871d4b 100644 --- a/test/handlers/aws-stream.handler.spec.ts +++ b/test/handlers/aws-stream.handler.spec.ts @@ -3,7 +3,7 @@ import { join } from 'path'; import express from 'express'; import { WritableMock } from 'stream-mock/lib/writable'; import { afterEach, beforeEach, describe, expect, it, vitest } from 'vitest'; -import { ILogger, getCurrentInvoke } from '../../src'; +import { type ILogger, getCurrentInvoke } from '../../src'; import { ApiGatewayV2Adapter } from '../../src/adapters/aws'; import { ExpressFramework } from '../../src/frameworks/express'; import { AwsStreamHandler } from '../../src/handlers/aws'; @@ -48,7 +48,7 @@ describe('AwsStreamHandler', () => { const app = express(); const file = readFileSync(join(__dirname, 'bitcoin.pdf')); - app.get('/', (req, res) => { + app.get('/', (_, res) => { const readable = createReadStream(join(__dirname, 'bitcoin.pdf')); res.statusCode = 200; @@ -86,7 +86,7 @@ describe('AwsStreamHandler', () => { it('should return the correct bytes of json', async () => { const app = express(); - app.get('/', (req, res) => { + app.get('/', (_, res) => { return res.json({ test: 'true' }); }); @@ -117,10 +117,10 @@ describe('AwsStreamHandler', () => { expect(finalBuffer.toString()).toBe(JSON.stringify({ test: 'true' })); }); - it('should handle redirects', async () => { + it('should handle redirect with status 304', async () => { const app = express(); - app.get('/', (req, res) => { + app.get('/', (_, res) => { return res.redirect(304, '/test'); }); @@ -154,47 +154,129 @@ describe('AwsStreamHandler', () => { expect(finalBuffer.toString()).toBe(''); }); - it('should handle no content', async () => { - const app = express(); + for (const statusCode of [300, 301, 302, 303, 305, 306, 307, 308]) { + it(`should handle redirect with status ${statusCode}`, async () => { + const app = express(); + + app.get('/', (_, res) => { + return res.redirect(statusCode, '/test'); + }); + + const expressFramework = new ExpressFramework(); + + const handler = awsStreamHandler.getHandler( + app, + expressFramework, + adapters, + resolver, + binarySettings, + respondWithErrors, + logger, + ); + + const event = createApiGatewayV2('GET', '/', undefined); + const context = { test: Symbol('unique') }; + + const writable = new WritableMock(); + const write = vitest.spyOn(writable, 'write'); - app.get('/', (req, res) => { - return res.status(204).end(); + await handler(event, writable, context); + + expect(getCurrentInvoke()).toHaveProperty('event', event); + expect(getCurrentInvoke()).toHaveProperty('context', context); + + expect(write).toHaveBeenCalled(); + + const finalBuffer = Buffer.concat(writable.data); + + expect(finalBuffer.toString()).toContain( + 'Redirecting to /test', + ); }); + } - const expressFramework = new ExpressFramework(); + for (const statusCode of [200, 201, 202, 203, 204, 400, 401, 403, 404]) { + it(`should handle no content with status ${statusCode}`, async () => { + const app = express(); - const handler = awsStreamHandler.getHandler( - app, - expressFramework, - adapters, - resolver, - binarySettings, - respondWithErrors, - logger, - ); + app.get('/', (_, res) => { + return res.status(statusCode).end(); + }); - const event = createApiGatewayV2('GET', '/', undefined); - const context = { test: Symbol('unique') }; + const expressFramework = new ExpressFramework(); - const writable = new WritableMock(); - const write = vitest.spyOn(writable, 'write'); + const handler = awsStreamHandler.getHandler( + app, + expressFramework, + adapters, + resolver, + binarySettings, + respondWithErrors, + logger, + ); - await handler(event, writable, context); + const event = createApiGatewayV2('GET', '/', undefined); + const context = { test: Symbol('unique') }; - expect(getCurrentInvoke()).toHaveProperty('event', event); - expect(getCurrentInvoke()).toHaveProperty('context', context); + const writable = new WritableMock(); + const write = vitest.spyOn(writable, 'write'); - expect(write).toHaveBeenCalledWith(''); + await handler(event, writable, context); - const finalBuffer = Buffer.concat(writable.data); + expect(getCurrentInvoke()).toHaveProperty('event', event); + expect(getCurrentInvoke()).toHaveProperty('context', context); - expect(finalBuffer.toString()).toBe(''); - }); + expect(write).toHaveBeenCalledWith(''); + + const finalBuffer = Buffer.concat(writable.data); + + expect(finalBuffer.toString()).toBe(''); + }); + } + + for (const statusCode of [200, 201, 202, 203, 204, 400, 401, 403, 404]) { + it(`should handle writeHead with no content and status ${statusCode}`, async () => { + const app = express(); + + app.get('/', (_, res) => { + return res.writeHead(statusCode).end(); + }); + + const expressFramework = new ExpressFramework(); + + const handler = awsStreamHandler.getHandler( + app, + expressFramework, + adapters, + resolver, + binarySettings, + respondWithErrors, + logger, + ); + + const event = createApiGatewayV2('GET', '/', undefined); + const context = { test: Symbol('unique') }; + + const writable = new WritableMock(); + const write = vitest.spyOn(writable, 'write'); + + await handler(event, writable, context); + + expect(getCurrentInvoke()).toHaveProperty('event', event); + expect(getCurrentInvoke()).toHaveProperty('context', context); + + expect(write).toHaveBeenCalledWith(''); + + const finalBuffer = Buffer.concat(writable.data); + + expect(finalBuffer.toString()).toBe(''); + }); + } it('should handle HEAD requests', async () => { const app = express(); - app.head('/', (req, res) => { + app.head('/', (_, res) => { return res.set(200).end(); }); @@ -231,7 +313,7 @@ describe('AwsStreamHandler', () => { it('should handle correctly the cookies', async () => { const app = express(); - app.get('/', (req, res) => { + app.get('/', (_, res) => { res.setHeader('set-cookie', 'test=1'); res.json({ ok: true }); }); @@ -274,7 +356,7 @@ describe('AwsStreamHandler', () => { it('should handle correctly the cookies array', async () => { const app = express(); - app.get('/', (req, res) => { + app.get('/', (_, res) => { res.setHeader('set-cookie', ['test=1', 'test2=3']); res.json({ ok: true }); }); diff --git a/test/handlers/azure.handler.spec.ts b/test/handlers/azure.handler.spec.ts index 7250b360..5584f3a7 100644 --- a/test/handlers/azure.handler.spec.ts +++ b/test/handlers/azure.handler.spec.ts @@ -1,5 +1,6 @@ import { describe, expect, it, vitest } from 'vitest'; -import { ILogger, createDefaultLogger } from '../../src'; +import type { HttpRequest } from '@azure/functions'; +import { type ILogger, createDefaultLogger } from '../../src'; import { HttpTriggerV4Adapter } from '../../src/adapters/azure'; import { AzureHandler } from '../../src/handlers/azure'; import { DefaultHandler } from '../../src/handlers/default'; @@ -11,7 +12,13 @@ import { import { FrameworkMock } from '../mocks/framework.mock'; describe(AzureHandler.name, () => { - const azureHandlerFactory = new AzureHandler(); + const azureHandlerFactory = new AzureHandler< + null, + HttpRequest, + any, + any, + any + >(); const app = null; const response = { batata: true }; @@ -121,7 +128,7 @@ describe(AzureHandler.name, () => { log, ] as const; - const azureHandler = new AzureHandler({ + const azureHandler = new AzureHandler({ useContextLogWhenInternalLogger: false, }).getHandler(...getHandlerArguments); diff --git a/test/handlers/default.handler.spec.ts b/test/handlers/default.handler.spec.ts index f00af6bb..f1dbd6a2 100644 --- a/test/handlers/default.handler.spec.ts +++ b/test/handlers/default.handler.spec.ts @@ -1,5 +1,10 @@ import { describe, expect, it, vitest } from 'vitest'; -import { ILogger, NO_OP, getCurrentInvoke } from '../../src'; +import { + type AdapterContract, + type ILogger, + NO_OP, + getCurrentInvoke, +} from '../../src'; import { ApiGatewayV2Adapter } from '../../src/adapters/aws'; import { DefaultHandler } from '../../src/handlers/default'; import { PromiseResolver } from '../../src/resolvers/promise'; @@ -12,11 +17,11 @@ describe('DefaultHandler', () => { const app = null; const response = { batata: true }; const apiGatewayAdapter = new ApiGatewayV2Adapter(); - const adapters = [apiGatewayAdapter]; + const adapters = [apiGatewayAdapter] as AdapterContract[]; const resolver = new PromiseResolver(); const binarySettings = { contentEncodings: [], contentTypes: [] }; const respondWithErrors = true; - const executeLog = (m, fn) => typeof fn === 'function' && fn(); + const executeLog = (_, fn) => typeof fn === 'function' && fn(); const logger: ILogger = { debug: vitest.fn(executeLog), error: vitest.fn(executeLog), diff --git a/test/handlers/digital-ocean.handler.spec.ts b/test/handlers/digital-ocean.handler.spec.ts index 02865766..9ca1390a 100644 --- a/test/handlers/digital-ocean.handler.spec.ts +++ b/test/handlers/digital-ocean.handler.spec.ts @@ -1,14 +1,20 @@ import { describe, expect, it, vitest } from 'vitest'; -import { ILogger } from '../../src'; +import { type ILogger } from '../../src'; import { HttpFunctionAdapter } from '../../src/adapters/digital-ocean'; import { DefaultHandler } from '../../src/handlers/default'; import { DigitalOceanHandler } from '../../src/handlers/digital-ocean'; import { PromiseResolver } from '../../src/resolvers/promise'; -import { createHttpTriggerEvent } from '../adapters/azure/utils/http-trigger'; import { FrameworkMock } from '../mocks/framework.mock'; +import { createHttpFunctionEvent } from '../adapters/digital-ocean/utils/http-function'; +import type { DigitalOceanHttpEvent } from '../../src/@types/digital-ocean'; describe(DigitalOceanHandler.name, () => { - const azureHandlerFactory = new DigitalOceanHandler(); + const azureHandlerFactory = new DigitalOceanHandler< + null, + DigitalOceanHttpEvent, + any, + any + >(); const app = null; const response = { batata: true }; @@ -44,7 +50,7 @@ describe(DigitalOceanHandler.name, () => { const azureHandler = azureHandlerFactory.getHandler(...getHandlerArguments); - const event = createHttpTriggerEvent('GET', '/'); + const event = createHttpFunctionEvent('GET', '/'); expect(azureHandler(event)).resolves.toBe(response); diff --git a/test/handlers/gcp.handler.spec.ts b/test/handlers/gcp.handler.spec.ts index 409998e2..06058d07 100644 --- a/test/handlers/gcp.handler.spec.ts +++ b/test/handlers/gcp.handler.spec.ts @@ -1,11 +1,11 @@ import type { IncomingMessage, ServerResponse } from 'http'; import { describe, expect, it, vitest } from 'vitest'; -import { FrameworkContract } from '../../src'; +import { type FrameworkContract } from '../../src'; import { GCPHandler } from '../../src/handlers/gcp'; import { FrameworkMock } from '../mocks/framework.mock'; class TestGCPHandler extends GCPHandler { - public onRequestCallback( + public override onRequestCallback( app: TApp, framework: FrameworkContract, ): (req: IncomingMessage, res: ServerResponse) => void | Promise { diff --git a/test/handlers/http-firebase.handler.spec.ts b/test/handlers/http-firebase.handler.spec.ts index 700e3f98..08290d3d 100644 --- a/test/handlers/http-firebase.handler.spec.ts +++ b/test/handlers/http-firebase.handler.spec.ts @@ -1,6 +1,7 @@ import { describe, expect, it, vitest } from 'vitest'; +import type { Request, Response } from 'express'; import { - FrameworkContract, + type FrameworkContract, ServerlessRequest, ServerlessResponse, waitForStreamComplete, @@ -10,7 +11,7 @@ import { FrameworkMock } from '../mocks/framework.mock'; describe(HttpFirebaseHandler.name, () => { it('should forward correctly the request to framework', async () => { - const handlerFactory = new HttpFirebaseHandler(); + const handlerFactory = new HttpFirebaseHandler(); const method = 'POST'; const url = '/users/batata'; @@ -36,7 +37,7 @@ describe(HttpFirebaseHandler.name, () => { const handler = handlerFactory.getHandler(null, framework); - handler(request, response); + handler(request as Request, response as unknown as Response); await waitForStreamComplete(response); @@ -72,7 +73,7 @@ describe(HttpFirebaseHandler.name, () => { // eslint-disable-next-line @typescript-eslint/no-misused-promises sendRequest: vitest.fn( async ( - app: null, + _app: null, req: ServerlessRequest, res: ServerlessResponse, ) => { @@ -94,7 +95,7 @@ describe(HttpFirebaseHandler.name, () => { const handler = handlerFactory.getHandler(null, framework); - handler(request, response); + handler(request as Request, response as unknown as Response); } }); }); diff --git a/test/handlers/huawei.handler.spec.ts b/test/handlers/huawei.handler.spec.ts index 02212983..dbc8cbac 100644 --- a/test/handlers/huawei.handler.spec.ts +++ b/test/handlers/huawei.handler.spec.ts @@ -1,7 +1,7 @@ import { type Server, createServer } from 'node:http'; import supertest from 'supertest'; import { describe, expect, it, vitest } from 'vitest'; -import { ILogger } from '../../src'; +import { type ILogger } from '../../src'; import { DummyAdapter } from '../../src/adapters/dummy'; import { DEFAULT_HUAWEI_LISTEN_PORT, diff --git a/test/mocks/framework.mock.ts b/test/mocks/framework.mock.ts index 1d7c3ae3..d0ba6aec 100644 --- a/test/mocks/framework.mock.ts +++ b/test/mocks/framework.mock.ts @@ -2,7 +2,7 @@ import type { IncomingMessage, ServerResponse } from 'http'; import { ObjectReadableMock } from 'stream-mock'; -import { FrameworkContract } from '../../src'; +import { type FrameworkContract } from '../../src'; //#endregion @@ -29,7 +29,7 @@ export class FrameworkMock implements FrameworkContract { */ public sendRequest( _: null, - request: IncomingMessage, + _request: IncomingMessage, response: ServerResponse, ): void { const writableOutput = new ObjectReadableMock( diff --git a/test/network/response.spec.ts b/test/network/response.spec.ts index 6d56c1a4..3ef5a7ef 100644 --- a/test/network/response.spec.ts +++ b/test/network/response.spec.ts @@ -204,7 +204,7 @@ describe('ServerlessResponse', () => { it('should write headers correctly in object when call writeHead', () => { class MockServerlessResponse extends ServerlessResponse { - public callNativeWriteHead( + public override callNativeWriteHead( statusCode: number, statusMessage?: string | any | any[], obj?: any | any[], diff --git a/test/resolvers/aws-context.resolver.spec.ts b/test/resolvers/aws-context.resolver.spec.ts index dc6238cc..bf2b2d1e 100644 --- a/test/resolvers/aws-context.resolver.spec.ts +++ b/test/resolvers/aws-context.resolver.spec.ts @@ -1,6 +1,6 @@ import type { Context } from 'aws-lambda'; import { beforeEach, describe, expect, it, vitest } from 'vitest'; -import { +import type { AdapterContract, ILogger, OnErrorProps, diff --git a/test/resolvers/callback.resolver.spec.ts b/test/resolvers/callback.resolver.spec.ts index fa71c3a3..486049ee 100644 --- a/test/resolvers/callback.resolver.spec.ts +++ b/test/resolvers/callback.resolver.spec.ts @@ -1,5 +1,5 @@ import { beforeEach, describe, expect, it, vitest } from 'vitest'; -import { +import type { AdapterContract, ILogger, OnErrorProps, @@ -7,7 +7,7 @@ import { } from '../../src'; import { CallbackResolver, - ServerlessCallback, + type ServerlessCallback, } from '../../src/resolvers/callback'; describe(CallbackResolver.name, () => { diff --git a/test/resolvers/promise.resolver.spec.ts b/test/resolvers/promise.resolver.spec.ts index 1c89b59e..e7d77bb5 100644 --- a/test/resolvers/promise.resolver.spec.ts +++ b/test/resolvers/promise.resolver.spec.ts @@ -1,6 +1,6 @@ import { beforeEach, describe, expect, it, vitest } from 'vitest'; import type { Context } from 'aws-lambda'; -import { +import type { AdapterContract, ILogger, OnErrorProps, diff --git a/test/serverless-adapter.spec.ts b/test/serverless-adapter.spec.ts index 9d9507e7..30130a43 100644 --- a/test/serverless-adapter.spec.ts +++ b/test/serverless-adapter.spec.ts @@ -1,9 +1,9 @@ import { describe, expect, it, vitest } from 'vitest'; import { - BinarySettings, + type BinarySettings, DEFAULT_BINARY_CONTENT_TYPES, DEFAULT_BINARY_ENCODINGS, - HandlerContract, + type HandlerContract, NO_OP, ServerlessAdapter, createDefaultLogger,