fix: Test case for multipart request interception
This commit is contained in:
parent
85d1bb940f
commit
f93d1b90e8
|
|
@ -1006,43 +1006,42 @@ it('should support multipart/form-data and keep the order', async function({ con
|
||||||
expect(response.status()).toBe(200);
|
expect(response.status()).toBe(200);
|
||||||
});
|
});
|
||||||
|
|
||||||
it.only('should support intercepting multipart/form-data requests', async function({ context, server }) {
|
it.only('should support intercepting multipart/form-data requests', async function({ context, page, server }) {
|
||||||
const given = {
|
const requestReceived = new Promise<void>(resolve => {
|
||||||
firstName: 'John',
|
|
||||||
lastName: 'Doe',
|
|
||||||
age: 27,
|
|
||||||
};
|
|
||||||
|
|
||||||
const formReceived = new Promise<{error: any, fields: formidable.Fields}>(resolve => {
|
|
||||||
server.setRoute('/empty.html', async (serverRequest, res) => {
|
server.setRoute('/empty.html', async (serverRequest, res) => {
|
||||||
const form = new formidable.IncomingForm();
|
server.serveFile(serverRequest, res);
|
||||||
form.parse(serverRequest, (error, fields, files) => {
|
resolve();
|
||||||
server.serveFile(serverRequest, res);
|
|
||||||
resolve({ error, fields });
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
let bufferIntercepted: Buffer;
|
const bufferInterceptedPromise = new Promise(
|
||||||
|
async resolve => await context.route(
|
||||||
await context.route(
|
/./,
|
||||||
server.EMPTY_PAGE,
|
async (route, request) => {
|
||||||
async (route, request) => {
|
resolve(request.postDataBuffer());
|
||||||
bufferIntercepted = request.postDataBuffer();
|
await route.continue();
|
||||||
await route.continue();
|
},
|
||||||
},
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
const [{ error }, response] = await Promise.all([
|
const [bufferIntercepted] = await Promise.all([
|
||||||
formReceived,
|
bufferInterceptedPromise,
|
||||||
context.request.post(server.EMPTY_PAGE, {
|
requestReceived,
|
||||||
multipart: given,
|
page.evaluate(url => {
|
||||||
}),
|
const formData = new FormData();
|
||||||
|
formData.set('name', 'John');
|
||||||
|
formData.append('name', 'Doe');
|
||||||
|
formData.append('file', new File(['var x = 10;\r\n;console.log(x);'], 'f1.js', { type: 'text/javascript' }));
|
||||||
|
formData.append('file', new File(['hello'], 'f2.txt', { type: 'text/plain' }), 'custom_f2.txt');
|
||||||
|
formData.append('file', new Blob(['boo'], { type: 'text/plain' }));
|
||||||
|
void fetch(url, {
|
||||||
|
method: 'POST',
|
||||||
|
body: formData,
|
||||||
|
});
|
||||||
|
}, server.EMPTY_PAGE),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
expect(error).toBeFalsy();
|
expect(bufferIntercepted.toString()).toEqual(expect.stringMatching(/content-disposition: form-data;/i));
|
||||||
expect(response.status()).toBe(200);
|
|
||||||
expect(bufferIntercepted.toString()).toEqual(expect.stringMatching(/content-disposition: form-data;/));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should support repeating names in multipart/form-data', async function({ context, server }) {
|
it('should support repeating names in multipart/form-data', async function({ context, server }) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue