Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,12 @@
export const summaly = async (url: string, options?: SummalyOptions): Promise<SummalyResult> => {
if (options?.agent) setAgent(options.agent);

const opts = Object.assign(summalyDefaultOptions, options);
const opts: SummalyOptions = {
...summalyDefaultOptions,
...options,
};

const plugins = builtinPlugins.concat(opts.plugins || []);

Check warning on line 89 in src/index.ts

View workflow job for this annotation

GitHub Actions / lint (22.23.2)

typescript(prefer-nullish-coalescing)

src/index.ts:89:53: Prefer using nullish coalescing operator (`??`) instead of a logical or (`||`), as it is a safer operator.

let actualUrl = url;
if (opts.followRedirects) {
Expand Down
21 changes: 20 additions & 1 deletion test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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');
Expand Down
Loading