testcafe icon indicating copy to clipboard operation
testcafe copied to clipboard

fix: prevent Invalid URL error in prepareBaseUrl for http/https baseUrl

Open yasinkocak opened this issue 4 months ago • 1 comments

What does this PR do?

Fixes an Invalid URL error that occurs when using baseUrl with http or https values in TestCafe 3.7.1+ on Node.js 20.18+.

Current behavior

The current implementation of prepareBaseUrl applies path.join to the provided baseUrl.
For web URLs, this produces invalid results:

  • Input: "http://devexpress.github.io"
  • Result after path.join: "http:/devexpress.github.io/"
  • new URL("http:/devexpress.github.io/") → throws TypeError: Invalid URL

This breaks .page(...) and config-based baseUrl when using standard web URLs.

Expected behavior

  • baseUrl is always treated as a web URL if it starts with http:// or https://.
  • File system paths should still resolve correctly to file://.

How does this PR fix the problem?

  • Detects and preserves http:// and https:// URLs (adds trailing slash if missing).
  • Allows explicit file:// URLs.
  • Falls back to converting absolute/relative file system paths via pathToFileURL.

Related issue

Fixes #8364

yasinkocak avatar Aug 19 '25 13:08 yasinkocak

Thank you for your contribution to TestCafe. When a member of the TestCafe team becomes available, they will review this PR.

github-actions[bot] avatar Aug 21 '25 09:08 github-actions[bot]