Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix: fix URL path for childProcess.fork when using Pleasantest from ESM #726

Merged
merged 2 commits into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions .changeset/calm-windows-retire.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'pleasantest': minor
---

Fix fork URL for ESM use
13 changes: 0 additions & 13 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,19 +91,6 @@ function bundlePlugin() {

return resolved;
},
resolveFileUrl({ relativePath, format }) {
return format === 'es'
? `new URL('${relativePath}', import.meta.url).href`
: `require('path').join(__dirname,'${relativePath}')`;
},
resolveImportMeta(property, { format }) {
if (property === 'url' && format === 'cjs') {
// eslint-disable-next-line no-template-curly-in-string
return '`file://${__filename}`';
}

return null;
},
async load(id) {
if (!id.startsWith('\0bundle:')) return;
id = id.slice(8);
Expand Down
11 changes: 7 additions & 4 deletions src/connect-to-browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,13 @@ export const connectToBrowser = async (
return connectedBrowser;
}

const subprocess = childProcess.fork(startDisownedBrowserPath, {
detached: true,
stdio: 'ignore',
});
const subprocess = childProcess.fork(
fileURLToPath(startDisownedBrowserPath),
{
detached: true,
stdio: 'ignore',
},
);
const wsEndpoint = await new Promise<string>((resolve, reject) => {
subprocess.send({ browser, headless });
subprocess.on('message', (msg: any) => {
Expand Down