Skip to content

Commit

Permalink
reenable browser tests for release, add more absolute path checks
Browse files Browse the repository at this point in the history
  • Loading branch information
jonluca committed Mar 6, 2024
1 parent 510112e commit cfb2069
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/CI-CD.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions lib/util/url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
43 changes: 23 additions & 20 deletions test/specs/util/url.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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) {
Expand Down

0 comments on commit cfb2069

Please sign in to comment.