From cc553dc13cbcc9ab99beae7f739d7ab885d92b36 Mon Sep 17 00:00:00 2001 From: Rui Figueira Date: Mon, 23 Nov 2026 23:57:50 +0000 Subject: [PATCH] test(puppeteer): upload test files from the Browser Run download directory MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Browser Run accepts DOM.setFileInputFiles paths only under /tmp/browser-run-downloads. The input tests used client-side paths, so 5 tests failed with a protocol error. The test build now rewrites the paths in input.test.ts to this directory. The files do not need to exist. The tests only check the name, type and events of the File that the page gets. Each rewrite throws if its pattern is not in input.test.ts. If upstream changes this text, the test build fails with the missing pattern. beep-boop-🤖 --- .../utils/generate_worker_tests.js | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/packages/puppeteer-cloudflare/utils/generate_worker_tests.js b/packages/puppeteer-cloudflare/utils/generate_worker_tests.js index 32c351d80..04aa7051c 100644 --- a/packages/puppeteer-cloudflare/utils/generate_worker_tests.js +++ b/packages/puppeteer-cloudflare/utils/generate_worker_tests.js @@ -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; + } + // 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', @@ -211,6 +243,7 @@ ${[...testFiles, ...cloudflareTestFiles] plugins: [ setTestFilePlugin(), tracingTempDirectoryPlugin(), + uploadDirectoryPlugin(), remoteTestServerPlugin(), ], root: sourceTestsDir,