Skip to content

Commit cfb2069

Browse files
committed
reenable browser tests for release, add more absolute path checks
1 parent 510112e commit cfb2069

File tree

3 files changed

+30
-23
lines changed

3 files changed

+30
-23
lines changed

.github/workflows/CI-CD.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ jobs:
106106
timeout-minutes: 10
107107
needs:
108108
- node_tests
109-
# - browser_tests
109+
- browser_tests
110110
steps:
111111
- uses: actions/checkout@v4
112112
- uses: actions/setup-node@v4

lib/util/url.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,13 @@ export function fromFileSystemPath(path: string) {
191191
const posixUpper = projectDirPosixPath.toUpperCase();
192192
const hasProjectDir = upperPath.includes(posixUpper);
193193
const hasProjectUri = upperPath.includes(posixUpper);
194-
const isAbsolutePath = win32?.isAbsolute(path);
194+
const isAbsolutePath =
195+
win32?.isAbsolute(path) ||
196+
path.startsWith("http://") ||
197+
path.startsWith("https://") ||
198+
path.startsWith("file://");
195199

196-
if (!(hasProjectDir || hasProjectUri || isAbsolutePath)) {
200+
if (!(hasProjectDir || hasProjectUri || isAbsolutePath) && !projectDir.startsWith("http")) {
197201
path = join(projectDir, path);
198202
}
199203
path = convertPathToPosix(path);

test/specs/util/url.spec.ts

+23-20
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { afterAll, beforeAll, describe, expect, it, vi } from "vitest";
22
import * as $url from "../../../lib/util/url.js";
33
import * as isWin from "../../../lib/util/is-windows";
44
import convertPathToPosix from "../../../lib/util/convert-path-to-posix";
5+
import { cwd } from "../../../lib/util/url.js";
56
describe("Return the extension of a URL", () => {
67
it("should return an empty string if there isn't any extension", async () => {
78
const extension = $url.getExtension("/file");
@@ -18,30 +19,32 @@ describe("Return the extension of a URL", () => {
1819
expect(extension).to.equal(".yml");
1920
});
2021
});
21-
describe("Handle Windows file paths", () => {
22-
beforeAll(function (this: any) {
23-
vi.spyOn(isWin, "isWindows").mockReturnValue(true);
24-
});
2522

26-
afterAll(function (this: any) {
27-
vi.restoreAllMocks();
28-
});
23+
if (!process.env.BROWSER) {
24+
describe("Handle Windows file paths", () => {
25+
beforeAll(function (this: any) {
26+
vi.spyOn(isWin, "isWindows").mockReturnValue(true);
27+
});
2928

30-
it("should handle absolute paths", async () => {
31-
const result = $url.fromFileSystemPath("Y:\\A\\Random\\Path\\file.json");
32-
expect(result)
33-
.to.be.a("string")
34-
.and.toSatisfy((msg: string) => msg.startsWith("Y:/A/Random/Path"));
35-
});
29+
afterAll(function (this: any) {
30+
vi.restoreAllMocks();
31+
});
3632

37-
it("should handle relative paths", async () => {
38-
const result = $url.fromFileSystemPath("Path\\file.json");
39-
const pwd = convertPathToPosix(process.cwd());
40-
expect(result)
41-
.to.be.a("string")
42-
.and.toSatisfy((msg: string) => msg.startsWith(pwd));
33+
it("should handle absolute paths", async () => {
34+
const result = $url.fromFileSystemPath("Y:\\A\\Random\\Path\\file.json");
35+
expect(result)
36+
.to.be.a("string")
37+
.and.toSatisfy((msg: string) => msg.startsWith("Y:/A/Random/Path"));
38+
});
39+
40+
it("should handle relative paths", async () => {
41+
const result = $url.fromFileSystemPath("Path\\file.json");
42+
const pwd = convertPathToPosix(cwd());
43+
expect(result).to.be.a("string");
44+
expect(result).toSatisfy((msg: string) => msg.startsWith(pwd));
45+
});
4346
});
44-
});
47+
}
4548

4649
describe("Handle Linux file paths", () => {
4750
beforeAll(function (this: any) {

0 commit comments

Comments
 (0)