Thanks to visit codestin.com
Credit goes to github.com

Skip to content

chore: align test-server PATH with npx playwright test#671

Merged
Skn0tt merged 8 commits into
microsoft:mainfrom
Skn0tt:webserver
Aug 28, 2025
Merged

chore: align test-server PATH with npx playwright test#671
Skn0tt merged 8 commits into
microsoft:mainfrom
Skn0tt:webserver

Conversation

@Skn0tt

@Skn0tt Skn0tt commented Aug 22, 2025

Copy link
Copy Markdown
Member

We recommend running Playwright via npx, which brings all project dependencies into PATH. This means that in a webserver config, serve build will run the binary from node_modules/.bin/serve. Some projects in the wild make use of this (https://github.com/DerYeger/yeger, https://github.com/louislam/uptime-kuma), and so our extension fails spinning up a webserver that works just fine with npx playwright test.

To fix this, this PR adds env that resembles npx, loosely based on https://github.com/sindresorhus/npm-run-path/blob/main/index.js.

@Skn0tt Skn0tt requested a review from dgozman August 22, 2025 10:38
@Skn0tt Skn0tt changed the title feat: start test-server via npx to align behaviour with CLI chore: align test-server PATH with npx playwright test Aug 22, 2025
@Skn0tt

Skn0tt commented Aug 25, 2025

Copy link
Copy Markdown
Member Author

turning into draft until I figured out the CI.

@Skn0tt Skn0tt marked this pull request as draft August 25, 2025 11:56
@Skn0tt

Skn0tt commented Aug 25, 2025

Copy link
Copy Markdown
Member Author

This seems to be the wrong approach. It's really hard to make this work under windows, because npx isn't a binary but a batch script there. I'll look at assembling PATH myself, like in https://github.com/sindresorhus/npm-run-path/blob/main/index.js.

@pavelfeldman

Copy link
Copy Markdown
Member

This would be a substantial slowdown, especially on Windows. Is there a bug filed for this?

@Skn0tt

Skn0tt commented Aug 26, 2025

Copy link
Copy Markdown
Member Author

There's no bug filed for this, it's something I noticed while going through open source repos. I pushed a different approach that works by manually extending PATH. That should also incur a lot less slowdown.

@Skn0tt Skn0tt marked this pull request as ready for review August 26, 2025 09:33
@Skn0tt Skn0tt self-assigned this Aug 26, 2025
Comment thread src/extension.ts
if (error.location) {
const document = await this._vscode.workspace.openTextDocument(error.location.file);
const position = new this._vscode.Position(error.location.line - 1, error.location.column - 1);
const position = new this._vscode.Position(Math.max(0, error.location.line - 1), error.location.column - 1);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

These changes seem unrelated.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

They're unrelated, but I stumbled into weird errors here while working on this change. The Position constructor threw because of -1 being passed. Let me try reproing them.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

There's several places where Playwright emits line: 0, column: 0: https://github.com/search?q=repo%3Amicrosoft%2Fplaywright%20line%3A%200&type=code
I'll kepp this in.

Comment thread src/utils.ts
let currentPath = path.resolve(cwd);
let previousPath;
while (previousPath !== currentPath) {
newPath.push(path.join(currentPath, 'node_modules', '.bin'));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Shouldn't we check that node_modules/.bin exists? Looks kinda wasteful to add all of them.

@Skn0tt Skn0tt Aug 28, 2025

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'm not sure! My hunch is that the system that resolves PATH is very optimised and much faster at checking path existence than our code. And because FS operations come at a premium under Windows, leaving the actual checks to the OS would be faster. This is all speculation though - do you happen to know more about this?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No, I don't. I see that's what the other project does. Let's keep it as is.

@Skn0tt Skn0tt merged commit 44eb9e2 into microsoft:main Aug 28, 2025
6 checks passed
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.

3 participants