Fix multipart boundary mismatch (#540)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Kelvin Del Monte · committed by GitHub · parent dd713b6 · Browse files · 7 files·+64 added−31 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
7 files+64 added−31 removed
- tests:+35 added−28 removed
- other:+29 added−3 removed
Provenance
- Commit
0e9d7bb- Tree
c225476- Author
Kelvin Del Monte <kdelmonten@gmail.com>- Committer
GitHub <noreply@github.com>- Parent
dd713b6
7 files changed+64 added−31 removed
modified:.github/workflows/main.yml+2 added
15 unmodified lines161718192021222324252 unmodified lines15 unmodified lines - uses: actions/setup-node@v3 with: node-version: ${{ matrix.node-version }} - run: npm install - name: Install Playwright Browsers run: npx playwright install --with-deps - run: npm test # TODO: Enable again when https://github.com/istanbuljs/nyc/issues/1287 is fixed. # - uses: codecov/codecov-action@v1 # if: matrix.node-version == 142 unmodified linesmodified:source/core/constants.ts+19 added
123456750 unmodified lines58596061626364656667686970717273747576777879import type {Expect, Equal} from '@type-challenges/utils';import {type HttpMethod, type KyOptionsRegistry} from '../types/options.js';import {type RequestInitRegistry} from '../types/request.js';
export const supportsRequestStreams = (() => { let duplexAccessed = false; let hasContentType = false;50 unmodified lines throwHttpErrors: true, onDownloadProgress: true, fetch: true,};
export const requestOptionsRegistry: RequestInitRegistry = { method: true, headers: true, body: true, mode: true, credentials: true, cache: true, redirect: true, referrer: true, referrerPolicy: true, integrity: true, keepalive: true, signal: true, window: true, dispatcher: true, duplex: true,};added:source/types/request.ts+5 added
12345import {type RequestInit as UndiciRequestInit} from 'undici-types';
type CombinedRequestInit = globalThis.RequestInit & UndiciRequestInit;
export type RequestInitRegistry = {[K in keyof CombinedRequestInit]-?: true};modified:source/utils/options.ts+2 added-2 removed
11234567891010111213142 unmodified linesimport {kyOptionKeys} from '../core/constants.js';import {kyOptionKeys, requestOptionsRegistry} from '../core/constants.js';
export const findUnknownOptions = ( request: Request, options: Record<string, unknown>,): Record<string, unknown> => { const unknownOptions: Record<string, unknown> = {};
for (const key in options) { if (!(key in kyOptionKeys) && !(key in request)) { if (!(key in requestOptionsRegistry) && !(key in kyOptionKeys) && !(key in request)) { unknownOptions[key] = options[key]; } }
2 unmodified linesmodified:test/helpers/with-page.ts+20 added-11 removed
122334567891011910111213141516171213141516171819202122232425262728/* eslint-disable ava/no-ignored-test-files */import process from 'node:process';import type {ExecutionContext, Implementation} from 'ava';import {chromium, type Page} from 'playwright-chromium';import test from 'ava';import {chromium, firefox, webkit, type BrowserType, type Page} from 'playwright';import type {ExecutionContext} from 'ava';
type Run = (t: ExecutionContext, page: Page) => Promise<void>;
const PWDEBUG = Boolean(process.env['PWDEBUG']);const DEFAULT_BROWSERS = [chromium, firefox, webkit];
export const withPage: Implementation<any[]> = async (t: ExecutionContext, run: Run): Promise<void> => { const browser = await chromium.launch({ devtools: PWDEBUG, }); const page = await browser.newPage(); try { await run(t, page); } finally { await browser.close();export const browserTest = (title: string, browserTypes: BrowserType[], run: Run) => { for (const browserType of browserTypes) { test.serial(`${browserType.name()} - ${title}`, async t => { const browser = await browserType.launch({devtools: PWDEBUG}); const page = await browser.newPage(); try { await run(t, page); } finally { await browser.close(); } }); }};
export const defaultBrowsersTest = (title: string, run: Run) => { browserTest(title, DEFAULT_BROWSERS, run);};modified:test/browser.ts+15 added-17 removed
1 import test, {type ExecutionContext} from 'ava';2 import busboy from 'busboy';3 import express from 'express';4-import {type Page} from 'playwright-chromium';4+import {chromium, webkit, type Page} from 'playwright';5 import type ky from '../source/index.js';6 import {createHttpTestServer, type ExtendedHttpTestServer, type HttpServerOptions} from './helpers/create-http-test-server.js';7 import {parseRawBody} from './helpers/parse-body.js';8-import {withPage} from './helpers/with-page.js';8+import {browserTest, defaultBrowsersTest} from './helpers/with-page.js';9 10 declare global {11 // eslint-disable-next-line @typescript-eslint/consistent-type-definitions12 interface Window {32 unmodified lines45 test.afterEach(async () => {46 await server.close();47 });48 49-test.serial('prefixUrl option', withPage, async (t: ExecutionContext, page: Page) => {49+defaultBrowsersTest('prefixUrl option', async (t: ExecutionContext, page: Page) => {50 server.get('/', (_request, response) => {51 response.end('zebra');52 });53 19 unmodified lines73 74 t.deepEqual(results, ['rainbow', 'rainbow', 'rainbow', 'rainbow']);75 });76 77-test.serial('aborting a request', withPage, async (t: ExecutionContext, page: Page) => {77+defaultBrowsersTest('aborting a request', async (t: ExecutionContext, page: Page) => {78 server.get('/', (_request, response) => {79 response.end('meow');80 });81 15 unmodified lines97 98 t.is(errorName, 'AbortError');99 });100 101-test.serial('should copy origin response info when using `onDownloadProgress`', withPage, async (t: ExecutionContext, page: Page) => {101+defaultBrowsersTest('should copy origin response info when using `onDownloadProgress`', async (t: ExecutionContext, page: Page) => {102 const json = {hello: 'world'};103 const status = 202;104 const statusText = 'Accepted';105 server.get('/', (_request, response) => {26 unmodified lines132 data: json,133 });134 });135 136-test.serial('should not copy response body with 204 status code when using `onDownloadProgress` ', withPage, async (t: ExecutionContext, page: Page) => {136+defaultBrowsersTest('should not copy response body with 204 status code when using `onDownloadProgress` ', async (t: ExecutionContext, page: Page) => {137 const status = 204;138 const statusText = 'No content';139 server.get('/', (_request, response) => {140 response.end('meow');40 unmodified lines181 transferredBytes: 0,182 }]);183 });184 185-test.serial('aborting a request with onDonwloadProgress', withPage, async (t: ExecutionContext, page: Page) => {185+browserTest('aborting a request with onDownloadProgress', [chromium], async (t: ExecutionContext, page: Page) => {186 server.get('/', (_request, response) => {187 response.end('meow');188 });189 23 unmodified lines213 // This should be an AbortError like in the 'aborting a request' test, but there is a bug in Chromium214 t.is(error, 'TypeError: Failed to fetch');215 });216 217-test.serial(217+defaultBrowsersTest(218 'throws TimeoutError even though it does not support AbortController',219- withPage,219 async (t: ExecutionContext, page: Page) => {220 server.get('/', (_request, response) => {221 response.end();222 });24 unmodified lines247 t.is(error.request.url, `${server.url}/slow`);248 },249 );250 252-test.serial('onDownloadProgress works', withPage, async (t: ExecutionContext, page: Page) => {251+browserTest('onDownloadProgress works', [chromium, webkit], async (t: ExecutionContext, page: Page) => {252 server.get('/', (_request, response) => {253 response.writeHead(200, {254 'content-length': '4',255 });31 unmodified lines287 ]);288 t.is(result.text, 'meow');289 });290 292-test.serial('throws if onDownloadProgress is not a function', withPage, async (t: ExecutionContext, page: Page) => {291+defaultBrowsersTest('throws if onDownloadProgress is not a function', async (t: ExecutionContext, page: Page) => {292 server.get('/', (_request, response) => {293 response.end();294 });295 7 unmodified lines303 }, server.url);304 t.is(error, 'TypeError: The `onDownloadProgress` option must be a function');305 });306 308-test.serial('throws if does not support ReadableStream', withPage, async (t: ExecutionContext, page: Page) => {307+defaultBrowsersTest('throws if does not support ReadableStream', async (t: ExecutionContext, page: Page) => {308 server.get('/', (_request, response) => {309 response.end();310 });311 8 unmodified lines320 }, server.url);321 t.is(error, 'Error: Streams are not supported in your environment. `ReadableStream` is missing.');322 });323 325-test.serial('FormData with searchParams', withPage, async (t: ExecutionContext, page: Page) => {324+defaultBrowsersTest('FormData with searchParams', async (t: ExecutionContext, page: Page) => {325 t.plan(3);326 327 server.get('/', (_request, response) => {328 response.end();23 unmodified lines352 });353 }, server.url);354 });355 357-test.serial('FormData with searchParams ("multipart/form-data" parser)', withPage, async (t: ExecutionContext, page: Page) => {356+defaultBrowsersTest('FormData with searchParams ("multipart/form-data" parser)', async (t: ExecutionContext, page: Page) => {357 t.plan(3);358 359 server.get('/', (_request, response) => {360 response.end();63 unmodified lines424 });425 }, server.url);426 });427 429-test.serial(428+defaultBrowsersTest(429 'headers are preserved when input is a Request and there are searchParams in the options',431- withPage,430 async (t: ExecutionContext, page: Page) => {431 t.plan(2);432 433 server.get('/', (_request, response) => {22 unmodified lines456 }, server.url);457 },458 );459 462-test.serial('retry with body', withPage, async (t: ExecutionContext, page: Page) => {460+browserTest('retry with body', [chromium, webkit], async (t: ExecutionContext, page: Page) => {461 t.plan(4);462 463 let requestCount = 0;464 24 unmodified linesmodified:package.json+1 added-1 removed
65 unmodified lines66 "delay": "^6.0.0",67 "expect-type": "^0.16.0",68 "express": "^4.18.2",69 "pify": "^6.1.0",70- "playwright-chromium": "^1.37.1",70+ "playwright": "^1.39.0",71 "raw-body": "^2.5.2",72 "ts-node": "^10.9.1",73 "typescript": "^5.2.2",74 "xo": "^0.56.0"38 unmodified lines