From cfb20692df24a4ad34141e073f1e6fc996bc9987 Mon Sep 17 00:00:00 2001 From: JonLuca DeCaro Date: Tue, 5 Mar 2024 18:33:48 -0800 Subject: [PATCH] reenable browser tests for release, add more absolute path checks --- .github/workflows/CI-CD.yaml | 2 +- lib/util/url.ts | 8 +++++-- test/specs/util/url.spec.ts | 43 +++++++++++++++++++----------------- 3 files changed, 30 insertions(+), 23 deletions(-) diff --git a/.github/workflows/CI-CD.yaml b/.github/workflows/CI-CD.yaml index 2c7e6b44..8f19aa55 100644 --- a/.github/workflows/CI-CD.yaml +++ b/.github/workflows/CI-CD.yaml @@ -106,7 +106,7 @@ jobs: timeout-minutes: 10 needs: - node_tests - # - browser_tests + - browser_tests steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 diff --git a/lib/util/url.ts b/lib/util/url.ts index 1e392fef..bff79576 100644 --- a/lib/util/url.ts +++ b/lib/util/url.ts @@ -191,9 +191,13 @@ export function fromFileSystemPath(path: string) { const posixUpper = projectDirPosixPath.toUpperCase(); const hasProjectDir = upperPath.includes(posixUpper); const hasProjectUri = upperPath.includes(posixUpper); - const isAbsolutePath = win32?.isAbsolute(path); + const isAbsolutePath = + win32?.isAbsolute(path) || + path.startsWith("http://") || + path.startsWith("https://") || + path.startsWith("file://"); - if (!(hasProjectDir || hasProjectUri || isAbsolutePath)) { + if (!(hasProjectDir || hasProjectUri || isAbsolutePath) && !projectDir.startsWith("http")) { path = join(projectDir, path); } path = convertPathToPosix(path); diff --git a/test/specs/util/url.spec.ts b/test/specs/util/url.spec.ts index 4920e171..94d177a2 100644 --- a/test/specs/util/url.spec.ts +++ b/test/specs/util/url.spec.ts @@ -2,6 +2,7 @@ import { afterAll, beforeAll, describe, expect, it, vi } from "vitest"; import * as $url from "../../../lib/util/url.js"; import * as isWin from "../../../lib/util/is-windows"; import convertPathToPosix from "../../../lib/util/convert-path-to-posix"; +import { cwd } from "../../../lib/util/url.js"; describe("Return the extension of a URL", () => { it("should return an empty string if there isn't any extension", async () => { const extension = $url.getExtension("/file"); @@ -18,30 +19,32 @@ describe("Return the extension of a URL", () => { expect(extension).to.equal(".yml"); }); }); -describe("Handle Windows file paths", () => { - beforeAll(function (this: any) { - vi.spyOn(isWin, "isWindows").mockReturnValue(true); - }); - afterAll(function (this: any) { - vi.restoreAllMocks(); - }); +if (!process.env.BROWSER) { + describe("Handle Windows file paths", () => { + beforeAll(function (this: any) { + vi.spyOn(isWin, "isWindows").mockReturnValue(true); + }); - it("should handle absolute paths", async () => { - const result = $url.fromFileSystemPath("Y:\\A\\Random\\Path\\file.json"); - expect(result) - .to.be.a("string") - .and.toSatisfy((msg: string) => msg.startsWith("Y:/A/Random/Path")); - }); + afterAll(function (this: any) { + vi.restoreAllMocks(); + }); - it("should handle relative paths", async () => { - const result = $url.fromFileSystemPath("Path\\file.json"); - const pwd = convertPathToPosix(process.cwd()); - expect(result) - .to.be.a("string") - .and.toSatisfy((msg: string) => msg.startsWith(pwd)); + it("should handle absolute paths", async () => { + const result = $url.fromFileSystemPath("Y:\\A\\Random\\Path\\file.json"); + expect(result) + .to.be.a("string") + .and.toSatisfy((msg: string) => msg.startsWith("Y:/A/Random/Path")); + }); + + it("should handle relative paths", async () => { + const result = $url.fromFileSystemPath("Path\\file.json"); + const pwd = convertPathToPosix(cwd()); + expect(result).to.be.a("string"); + expect(result).toSatisfy((msg: string) => msg.startsWith(pwd)); + }); }); -}); +} describe("Handle Linux file paths", () => { beforeAll(function (this: any) {