From 49377d2663259cb292f8b968a101fd52f42665d1 Mon Sep 17 00:00:00 2001 From: kakkokari-gtyih <67428053+kakkokari-gtyih@users.noreply.github.com> Date: Wed, 30 Sep 2026 23:55:39 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=B8=80=E5=BA=A6=E8=A8=AD=E5=AE=9A?= =?UTF-8?q?=E3=81=97=E3=81=9F=E3=82=AA=E3=83=97=E3=82=B7=E3=83=A7=E3=83=B3?= =?UTF-8?q?=E3=81=8C=E3=81=82=E3=81=A8=E3=81=AE=E5=91=BC=E3=81=B3=E5=87=BA?= =?UTF-8?q?=E3=81=97=E3=81=AB=E5=BC=95=E3=81=8D=E7=B6=99=E3=81=8C=E3=82=8C?= =?UTF-8?q?=E3=82=8B=E5=95=8F=E9=A1=8C=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/index.ts | 5 ++++- test/index.test.ts | 21 ++++++++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index 75036ac6..27060006 100644 --- a/src/index.ts +++ b/src/index.ts @@ -81,7 +81,10 @@ export const version = _VERSION_ as string; export const summaly = async (url: string, options?: SummalyOptions): Promise => { if (options?.agent) setAgent(options.agent); - const opts = Object.assign(summalyDefaultOptions, options); + const opts: SummalyOptions = { + ...summalyDefaultOptions, + ...options, + }; const plugins = builtinPlugins.concat(opts.plugins || []); diff --git a/test/index.test.ts b/test/index.test.ts index 4786eeb6..409746a0 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -15,7 +15,7 @@ import { Agent as httpAgent } from 'node:http'; import { Agent as httpsAgent } from 'node:https'; import { expect, test, describe, beforeEach, afterEach } from 'vitest'; import fastify, { type FastifyInstance } from 'fastify'; -import { summaly } from '@/index.js'; +import { summaly, summalyDefaultOptions } from '@/index.js'; import { StatusError } from '@/utils/status-error.js'; const _filename = fileURLToPath(import.meta.url); @@ -692,6 +692,25 @@ describe('local tests', () => { }); }); + describe('options', () => { + test('指定したオプションが以降の呼び出しに引き継がれないこと', async () => { + const content = fs.readFileSync(_dirname + '/htmls/basic.html'); + const defaults = { ...summalyDefaultOptions }; + + app = fastify(); + app.get('/', (request, reply) => { + reply.header('content-length', content.byteLength); + reply.header('content-type', 'text/html'); + return reply.send(content); + }); + await app.listen({ port }); + + await expect(summaly(host, { contentLengthLimit: content.byteLength - 1, userAgent: 'test-ua' })).rejects.toThrow(); + expect(summalyDefaultOptions).toEqual(defaults); + expect(await summaly(host)).toBeDefined(); + }); + }); + describe('content-length limit', () => { test('content-lengthの上限以内であればエラーが起こらないこと', async () => { const content = fs.readFileSync(_dirname + '/htmls/basic.html');