Issue 1:
System info

Playwright Version: [v1.34.3]

Operating System: [macOS 13.2.1]

Browser: [Chromium, Firefox]

Source code

I provided exact source code that allows reproducing the issue locally.

When I use newContext() and post() api to send multipart form which includes a file, I get the error apiRequestContext.post: Unexpected buffer type of 'data.file'.

I have this fixture:

import { test as base, APIRequestContext, request } from '@playwright/test';

export const test = base.extend({
apiRequest: async ({apiBaseURL}, use) => {
const apiRequestContext = await request.newContext({
baseURL: process.env.REACT_APP_API_URL
})
await use(apiRequestContext);
await apiRequestContext.dispose();
},
post: async ({ apiRequest }, use) => {
await use(async ({ url, options, context }) => {
if (options && options.data) {
options.data = snakecaseKeys(options.data, { exclude: options.exclude || [] });
}

if (options && options.multipart) {
options.multipart = snakecaseKeys(options.multipart, { exclude: options.exclude || [] });
}

const response = await apiRequest.post(url, options);

return camelcaseKeys(await response.json(), { deep: true });
});
},
});

Also, second fixture which uses post that relies on newContext() (this is not working, getting error from the title):

import { faker } from '@faker-js/faker';
import { tests as base } from '@fixtures/util/util.fixture.ts';
import snakecaseKeys from 'snakecase-keys';

export const fileTest = base.extend({
submitFile: async ({ post }, use) => {
await use(async (data, token) => {
const { orderId } = data;
const file = {
name: 'file.pdf',
mimeType: 'application/pdf',
buffer: Buffer.from('file content'),
};

const payload = snakecaseKeys({
orderId
});

return post(
{
url: someUrl,
options: {
multipart: {
...payload,
file,
},
headers: {
'api-token': token,
},
exclude: ['mimeType']
},
}
);
});
},
});

The same fixture is working if I use context to call post (I would prefer to use newContext() since I don't have to repeat baseUrl every time):

import { faker } from '@faker-js/faker';
import { tests as base } from '@fixtures/util/util.fixture.ts';
import snakecaseKeys from 'snakecase-keys';

export const fileTest = base.extend({
submitFile: async ({ context }, use) => {
await use(async (data, token) => {
const { orderId } = data;
const file = {
name: 'file.pdf',
mimeType: 'application/pdf',
buffer: Buffer.from('file content'),
};

const payload = snakecaseKeys({
orderId
});

return context.request.post(
url: process.env.REACT_APP_API_URL + someUrl,
options: {
multipart: {
...payload,
file,
},
headers: {
'api-token': token,
},
},
);
});
},
});

So, it seems newContext() have some issues with multipart form and Buffer.

Expected

Expected multipart form data to be submitted when using newContext()

Actual

Getting the error Error: apiRequestContext.post: Unexpected buffer type of 'data.file' on the line which points to post method in my first fixture.

Issue 2:
System info

Playwright Version: [v1.XX]: 1.32.3

Operating System: [All, Windows 11, Ubuntu 20, macOS 13.2, etc.]: Windows 10

Browser: [All, Chromium, Firefox, WebKit]: Chromium

Other info:

Source code

I provided exact source code that allows reproducing the issue locally.

Link to the GitHub repository with the repro

[https://github.com/your_profile/playwright_issue_title]

or

Config file

// playwright-ct.config.ts
// @ts-check
import { defineConfig, devices } from '@playwright/experimental-ct-react';
import { resolve } from "path";

/**
* @see https://playwright.dev/docs/test-configuration
*/
module.exports = defineConfig({
retries: 1,
testDir: './tests/component',
timeout: 30 * 1000,
// fullyParallel: true,
use: {
trace: 'on-first-retry',
ctPort: 3100,
ctViteConfig: {
resolve: {
alias: {
'@': resolve(__dirname, './src'),
'@/*': resolve(__dirname, './src'),
}
}
}
},
/* Configure projects for major browsers */
projects: [
{
name: 'chromium',
use: { ...devices['Desktop Chrome'] }
},
]
});

Test file (self-contained)

it('should check the box using setChecked', async ({ page }) => {
await page.setContent(`<input id='checkbox' type='checkbox'></input>`);
await page.getByRole('checkbox').check();
await expect(page.getByRole('checkbox')).toBeChecked();
});

Steps

execute command cross-env PW_EXPERIMENTAL_TS_ESM=1 playwright test --ui -c playwright-ct.config.ts

run specific one test on left side from UI

wait for complete test

rerun this test again

i am getting error below

Expected

Should be able to rerun same test in UI.

Actual

Since I opened GUI, first test always gets working, but every time after first attempt I am being blocked by below error:

vite v4.2.2 building for production...
transforming (1) playwright\index.htmlError when using sourcemap for reporting an error: Can't resolve original location of error.
✓ 3 modules transformed.
✓ built in 67ms
Identifier '__pwReact' has already been declared (Note that you need plugins to import files that are not JavaScript)
file: C:/dev/tester/frontend/playwright/index.ts:139:12
137: // This file is injected into the registry as text, no dependencies are allowed.
138:
139: import * as __pwReact from 'react';
^
140: import { createRoot as __pwCreateRoot } from 'react-dom/client';
RollupError: Identifier '__pwReact' has already been declared (Note that you need plugins to import files that are not JavaScript)

at error (C:\dev\tester\frontend\node_modules\vite\node_modules\rollup\dist\es\shared\node-entry.js:2125:30)
at Module.error (C:\dev\tester\frontend\node_modules\vite\node_modules\rollup\dist\es\shared\node-entry.js:13334:16)
at Module.tryParse (C:\dev\tester\frontend\node_modules\vite\node_modules\rollup\dist\es\shared\node-entry.js:14011:25)
at Module.setSource (C:\dev\tester\frontend\node_modules\vite\node_modules\rollup\dist\es\shared\node-entry.js:13621:39)
at ModuleLoader.addModuleSource (C:\dev\tester\frontend\node_modules\vite\node_modules\rollup\dist\es\shared\node-entry.js:23586:20)
RollupError: Identifier '__pwReact' has already been declared (Note that you need plugins to import files that are not JavaScript)
at error (C:\dev\tester\frontend\node_modules\vite\node_modules\rollup\dist\es\shared\node-entry.js:2125:30)
at Module.error (C:\dev\tester\frontend\node_modules\vite\node_modules\rollup\dist\es\shared\node-entry.js:13334:16)
at Module.tryParse (C:\dev\tester\frontend\node_modules\vite\node_modules\rollup\dist\es\shared\node-entry.js:14011:25)
at Module.setSource (C:\dev\tester\frontend\node_modules\vite\node_modules\rollup\dist\es\shared\node-entry.js:13621:39)
at ModuleLoader.addModuleSource (C:\dev\tester\frontend\node_modules\vite\node_modules\rollup\dist\es\shared\node-entry.js:23586:20)