Skip to content
Merged
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
33 changes: 33 additions & 0 deletions packages/puppeteer-cloudflare/utils/generate_worker_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,38 @@ function tracingTempDirectoryPlugin() {
};
}

// Browser Run accepts DOM.setFileInputFiles paths only under its download
// directory. The files don't need to exist: these tests only check the name,
// type and events of the File that the page gets.
function uploadDirectoryPlugin() {
const downloadDir = '/tmp/browser-run-downloads';
return {
name: 'upload-directory',
enforce: 'pre',
transform(code, id) {
if (!id.endsWith('/input.test.ts')) {
return;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💬 SUGGESTION · Code Quality

The .replace/.replaceAll rewrites in uploadDirectoryPlugin do nothing, and say nothing, if the upstream test text changes

This replacement matches an exact multi-line string, including newlines and two-space indentation. If upstream input.test.ts reformats the FILE_TO_UPLOAD declaration, nothing gets rewritten and the tests fail again with the DOM.setFileInputFiles protocol error, with no hint that this plugin is the cause. You could throw when the transformed code still contains '/../assets/file-to-upload.txt', or use a regex that tolerates whitespace, so that drift shows up at build time.

@ruifigueira ruifigueira Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

beep-boop-rui-agent-🤖 Fixed in cc553dc. Each rewrite in uploadDirectoryPlugin now throws if its pattern is not in input.test.ts. If upstream changes this text, the test build fails with the missing pattern.

I did not add the suggested check for '/../assets/file-to-upload.txt'. The upstream test "should not accept multiple files for single-file input" uses this path on purpose, so the check would always fail. A test with a changed pattern made the build fail with this message:

upload-directory: "'file-does-not-exist.txt'" not found in .../submodules/puppeteer/test/src/input.test.ts

// Fail the build if upstream changes this text. Otherwise the tests
// fail at run time with a protocol error that doesn't point here.
const rewrite = (src, from, to) => {
const out = src.replaceAll(from, to);
if (out === src) {
throw new Error(`upload-directory: ${JSON.stringify(from)} not found in ${id}`);
}
return out;
};
code = rewrite(
code,
"const FILE_TO_UPLOAD = path.join(\n import.meta.dirname,\n '/../assets/file-to-upload.txt',\n);",
`const FILE_TO_UPLOAD = '${downloadDir}/file-to-upload.txt';`,
);
code = rewrite(code, 'path.relative(process.cwd(), FILE_TO_UPLOAD)', 'FILE_TO_UPLOAD');
return rewrite(code, "'file-does-not-exist.txt'", `'${downloadDir}/file-does-not-exist.txt'`);
},
};
}

function remoteTestServerPlugin() {
return {
name: 'remote-test-server',
Expand Down Expand Up @@ -211,6 +243,7 @@ ${[...testFiles, ...cloudflareTestFiles]
plugins: [
setTestFilePlugin(),
tracingTempDirectoryPlugin(),
uploadDirectoryPlugin(),
remoteTestServerPlugin(),
],
root: sourceTestsDir,
Expand Down
Loading