Skip to content
Myr

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

7 files+64 added−31 removed

modified:.github/workflows/main.yml+2 added
modified:source/core/constants.ts+19 added
added:source/types/request.ts+5 added
modified:source/utils/options.ts+2 added-2 removed
modified:test/helpers/with-page.ts+20 added-11 removed
modified:test/browser.ts+15 added-17 removed
1import test, {type ExecutionContext} from 'ava';2import busboy from 'busboy';3import express from 'express';4import {type Page} from 'playwright-chromium';4import {chromium, webkit, type Page} from 'playwright';5import type ky from '../source/index.js';6import {createHttpTestServer, type ExtendedHttpTestServer, type HttpServerOptions} from './helpers/create-http-test-server.js';7import {parseRawBody} from './helpers/parse-body.js';8import {withPage} from './helpers/with-page.js';8import {browserTest, defaultBrowsersTest} from './helpers/with-page.js';910declare global {11 // eslint-disable-next-line @typescript-eslint/consistent-type-definitions12 interface Window {
32 unmodified lines
45test.afterEach(async () => {46 await server.close();47});4849test.serial('prefixUrl option', withPage, async (t: ExecutionContext, page: Page) => {49defaultBrowsersTest('prefixUrl option', async (t: ExecutionContext, page: Page) => {50 server.get('/', (_request, response) => {51 response.end('zebra');52 });53
19 unmodified lines
7374 t.deepEqual(results, ['rainbow', 'rainbow', 'rainbow', 'rainbow']);75});7677test.serial('aborting a request', withPage, async (t: ExecutionContext, page: Page) => {77defaultBrowsersTest('aborting a request', async (t: ExecutionContext, page: Page) => {78 server.get('/', (_request, response) => {79 response.end('meow');80 });81
15 unmodified lines
9798 t.is(errorName, 'AbortError');99});100101test.serial('should copy origin response info when using `onDownloadProgress`', withPage, async (t: ExecutionContext, page: Page) => {101defaultBrowsersTest('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 lines
132 data: json,133 });134});135136test.serial('should not copy response body with 204 status code when using `onDownloadProgress` ', withPage, async (t: ExecutionContext, page: Page) => {136defaultBrowsersTest('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 lines
181 transferredBytes: 0,182 }]);183});184185test.serial('aborting a request with onDonwloadProgress', withPage, async (t: ExecutionContext, page: Page) => {185browserTest('aborting a request with onDownloadProgress', [chromium], async (t: ExecutionContext, page: Page) => {186 server.get('/', (_request, response) => {187 response.end('meow');188 });189
23 unmodified lines
213 // 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});216217test.serial(217defaultBrowsersTest(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 lines
247 t.is(error.request.url, `${server.url}/slow`);248 },249);250252test.serial('onDownloadProgress works', withPage, async (t: ExecutionContext, page: Page) => {251browserTest('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 lines
287 ]);288 t.is(result.text, 'meow');289});290292test.serial('throws if onDownloadProgress is not a function', withPage, async (t: ExecutionContext, page: Page) => {291defaultBrowsersTest('throws if onDownloadProgress is not a function', async (t: ExecutionContext, page: Page) => {292 server.get('/', (_request, response) => {293 response.end();294 });295
7 unmodified lines
303 }, server.url);304 t.is(error, 'TypeError: The `onDownloadProgress` option must be a function');305});306308test.serial('throws if does not support ReadableStream', withPage, async (t: ExecutionContext, page: Page) => {307defaultBrowsersTest('throws if does not support ReadableStream', async (t: ExecutionContext, page: Page) => {308 server.get('/', (_request, response) => {309 response.end();310 });311
8 unmodified lines
320 }, server.url);321 t.is(error, 'Error: Streams are not supported in your environment. `ReadableStream` is missing.');322});323325test.serial('FormData with searchParams', withPage, async (t: ExecutionContext, page: Page) => {324defaultBrowsersTest('FormData with searchParams', async (t: ExecutionContext, page: Page) => {325 t.plan(3);326327 server.get('/', (_request, response) => {328 response.end();
23 unmodified lines
352 });353 }, server.url);354});355357test.serial('FormData with searchParams ("multipart/form-data" parser)', withPage, async (t: ExecutionContext, page: Page) => {356defaultBrowsersTest('FormData with searchParams ("multipart/form-data" parser)', async (t: ExecutionContext, page: Page) => {357 t.plan(3);358359 server.get('/', (_request, response) => {360 response.end();
63 unmodified lines
424 });425 }, server.url);426});427429test.serial(428defaultBrowsersTest(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);432433 server.get('/', (_request, response) => {
22 unmodified lines
456 }, server.url);457 },458);459462test.serial('retry with body', withPage, async (t: ExecutionContext, page: Page) => {460browserTest('retry with body', [chromium, webkit], async (t: ExecutionContext, page: Page) => {461 t.plan(4);462463 let requestCount = 0;464
24 unmodified lines
modified:package.json+1 added-1 removed
65 unmodified lines
66 "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