-
Notifications
You must be signed in to change notification settings - Fork 354
Conversation
Note: requires the bug fixes from: microsoft/vscode-chrome-debug-core#449 before the tests will pass. |
bf6adff
to
3b4cdc4
Compare
What problem did you have with vscode-uri and file:// URIs? |
Replaced URI with node's URL class, as it correctly handles file:/// urls out of the box
56993d5
to
5fa09cc
Compare
Here's what I found: Executing the following code: import { URI } from 'vscode-uri';
import { URL } from 'url';
// case: converting Windows file path to file url
const windows = 'file:///C:\\blub\\blubb.js';
// case: converting Windows file path to file url, only two slashes after the protocol (should add the correct number of slashes)
const windows2 = 'file://C:\\blub\\blubb.js';
// case: Windows file path to file url with extra invalid chars we want to encode
const spacesAndTabs = 'file:///C:\\blub with spaces and \ttabs\\blubb.js';
// case: Unix file path with too few slashes after the protocol
const unixFewSlashes = 'file:/blub/blab/bleeb.js';
// case: Unix file path with extra slashes after the protocol
const unixExtraSlashes = 'file://///blub/blab/bleeb.js';
printUrl(windows);
printUrl(windows2);
printUrl(spacesAndTabs);
printUrl(unixFewSlashes);
printUrl(unixExtraSlashes);
function printUrl(urlString: string) {
console.log(`For string: "${urlString}"`);
try { console.log(`With vscode-uri: "${URI.parse(urlString).toString()}"`); } catch (err) { console.log('Throws: ' + err.message); }
try { console.log(`With vscode-uri (no encode): "${URI.parse(urlString).toString(true)}"`); } catch (err) { console.log('Throws: ' + err.message); }
console.log(`With node URL: "${new URL(urlString).href}"\n`);
} We get:
The main problem is creating a file:/// url from a file path in a cross-platform way. The solution we were using before in resourceIdentifier.ts was encoding the entire string before replacing backslashes (which is what vscode-uri is doing by default), which causes issues in Windows paths. What needs to happen is we have to replace the backslashes with forward slashes, and then ulrEncode each chunk. Alternatively, on Mac/Linux, the file path usually starts with a /, which means that we would need to add special handling to intelligently apply the slashes cross-platform. We had been hoping to use the built in I also noticed that we already have an existing |
@@ -65,4 +65,14 @@ export class LaunchWebServer implements IFixture { | |||
public toString(): string { | |||
return `LaunchWebServer`; | |||
} | |||
} | |||
|
|||
export class ProvideStaticUrl implements IFixture { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd either move this to a different file, or rename this file to some other name that encompass both launch web server + provide static url.
* @param bpLabel | ||
* @param trigger | ||
*/ | ||
genericBreakpointTest(description: string, waitSelector: string, bpLabel: string, trigger: (page: puppeteer.Page) => Promise<void>) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rename this to something else like testBreakpointHitsOnPageAction
genericBreakpointTest doesn't give me a lot of information about what the test is actually doing
await page.waitForSelector(`${waitSelector}`); | ||
await setBreakpoint(this.suiteContext.debugClient, location); | ||
const triggerPromise = trigger(page); | ||
await this.suiteContext.debugClient.assertStoppedLocation('breakpoint', location); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to have a race condition here if the stopped event gets sent while we are on line 147?
The problem is that Not sure what the problem is exactly, maybe you are talking about the %5C in the file URI, but those are not an issue. Example of how vscode-uri preserves the slash direction and how it formats uris:
|
How are they not an issue? For the instance here, where I'm using the URL class to build a file url for the launch.json for the tests, Chrome can't resolve a url like file:///C%3A%5Cblub%5Cblub.js to the file C:\blub\blub.js on disk, that's one issue. Using vscode-uri with a Windows path builds a file url that I can't use in the launch.json. Now, as for using vscode-uri in the rest of the test code, because of the encoding, vscode-uri was changing the colon in file:///C:/etc to a %3A. Chrome can resolve that URL just fine, but because of the way we're setting breakpoints in v2 (via regex instead of just by URL) we're unable to set a breakpoint and it's failing the inline script tests. I added a bug to track this issue, because it is something that needs to be fixed in V2, but I think it's logically separate from the inline scripts stuff, and can be addressed later. I think we have more pressing stuff to fix in the core functionality for V2. IMO, the fact that vscode-uri encodes the colon is a bug, as "file:///c:/blub/blub.js" is a completely valid URI, per https://tools.ietf.org/html/rfc8089 Also found a few other cases where vscode-uri differs from URL, it handles the obscure "vertical pipe" syntax (section E.2.2. "Vertical Line Character" of the RFC), and it resolves relative paths as well.
I can definitely understand wanting to use vscode-uri to more closely match what vscode does with URIs, but node's URL class seems to much more closely mimic what Chrome does with URLs, which seems like it might be more useful for our use cases. But I think that's part of a larger discussion, and outside the scope of this PR. |
I think that vscode-uri really wants I'm not sure why the colon is uri-encoded, the spec does explicitly call out that case. I will file a bug for it. vscode-uri also has the |
Also, vscode-uri normalizes the drive letter to lowercase, which may or may not be an issue. Drive letter case between vscode and Chrome and internally has been a huge issue in the past. |
Filed microsoft/vscode#75027. For now of course you should do whatever unblocks you... |
- Renamed 'generigBreakpointTest' to 'testBreakpointHitsOnPageAction' - Rewrote 'testBreakpointHitsOnPageAction' to use the breakpoint wizard to avoid race conditions - Add source dir to 'fromTestPath' to allow setting custom src dir
2908848
to
f620450
Compare
Adding tests for inline scripts (e.g. <script> blocks in an html page)