Skip to content

test: added test for playwright-core#184

Closed
mxschmitt wants to merge 2 commits into
vercel:mainfrom
mxschmitt:test/playwright-core
Closed

test: added test for playwright-core#184
mxschmitt wants to merge 2 commits into
vercel:mainfrom
mxschmitt:test/playwright-core

Conversation

@mxschmitt

@mxschmitt mxschmitt commented Apr 12, 2021

Copy link
Copy Markdown
Contributor

This PR adds a test to demonstrate a current issue which was reported here.

TL;DR: The following file does not get added: node_modules/playwright-core/browsers.json

See here for more information and background: microsoft/playwright#5862

The relevant part in the code is the fs.readFileSync which does not get detected. If you use require
instead it works and it does get added.

The following line is the relevant one in Playwright, if it does get changed to require instead, it does pass the test. (change it in node_modules/playwright-core/lib/utils/registry.js for local testing)

https://github.com/microsoft/playwright/blob/e81a3c5901e024f7c41edf023daad60c68ed093d/src/utils/registry.ts#L238

This was probably a recently introduced bug which breaks the usage of Playwright on Vercel serverless functions. It worked a few months ago. On Playwright side a few users faced already into this bug.

@mxschmitt

Copy link
Copy Markdown
Contributor Author

Update: I went through the latest releases until 0.1.7 and it all of them the file was not added. Still not sure if its a bug in that repo or as-designed.

@styfle

styfle commented Apr 13, 2021

Copy link
Copy Markdown
Member

Thanks for digging into this one!

I was able to reproduce the bug. Replacing the readFileSync with require works.

- const browsersJSON = JSON.parse(fs_1.default.readFileSync(path_1.default.join(packagePath, 'browsers.json'), 'utf8'));
+ const browsersJSON = require(path_1.default.join(packagePath, 'browsers.json'));

My first thought is that packagePath is treated as a wild card with require() and its not for readFileSync() because we know both would work with __dirname and a relative path to the current file.

Needs a little more investigation to fix. Would you like to fix it in nft? 🙂

@mxschmitt

Copy link
Copy Markdown
Contributor Author

Yup will take a look, I keep you posted. 👍

@mxschmitt mxschmitt force-pushed the test/playwright-core branch from 861576f to eba8499 Compare April 13, 2021 17:37
@mxschmitt

Copy link
Copy Markdown
Contributor Author

I think I was able to simplify the test-case as small as it can get. Unfortunately I have to give away my notebook today and then get a new one in a few days since I'm switching jobs. Also I tried to dig into it and spend a few hours but was not sure about the internals how the matching works. Would be awesome if you could take over, with the small repro it should be easier to find the root cause. Thanks!


class Foobar {
constructor(packagePath) {
console.log(fs.readFileSync(path.join(packagePath, 'asset1.txt'), 'utf8'))

@styfle styfle Apr 14, 2021

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I tried changing readFileSync to require and that doesn't work either. So there must be something different about the npm package that made it work with require but fail with readFileSync 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants