Skip to content

Commit

Permalink
improve unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dario-piotrowicz committed Dec 27, 2024
1 parent 9cab2d3 commit 2ccd25b
Showing 1 changed file with 18 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
import path from "node:path";

import { describe, expect, it } from "vitest";

import { normalizePathForInlineCode } from "./normalize-path-for-inline-code";

const isWindows = process.platform === "win32";

describe("normalizePathForInlineCode", () => {
describe.runIf(process.platform === "win32")("windows", () => {
it("should produce an absolute path ready to be embedded in inlined code", () => {
const code = `const d = require('${normalizePathForInlineCode("/Users/me/projects/cloudflare/index.mjs")}').default;`;
it("should produce an absolute path ready to be embedded in inlined code", () => {
const joined = path.join("/", "Users", "me", "projects", "cloudflare", "index.mjs");
const code = `const d = require('${normalizePathForInlineCode(joined)}').default;`;
if (!isWindows) {
expect(code).toEqual("const d = require('/Users/me/projects/cloudflare/index.mjs').default;");
} else {
expect(code).toEqual("const d = require('\\Users\\me\\projects\\cloudflare\\index.mjs').default;");
});

it("should produce a relative path ready to be embedded in inlined code", () => {
const code = `const d = require('${normalizePathForInlineCode("../../tmp/index.mjs")}').default;`;
expect(code).toEqual("const d = require('..\\..\\tmp\\index.mjs').default;");
});
}
});

describe.runIf(process.platform === "linux" || process.platform === "darwin")("linux/mac", () => {
it("should produce an absolute path ready to be embedded in inlined code", () => {
const code = `const d = require('${normalizePathForInlineCode("/Users/me/projects/cloudflare/index.mjs")}').default;`;
expect(code).toEqual("const d = require('/Users/me/projects/cloudflare/index.mjs').default;");
});

it("should produce a relative path ready to be embedded in inlined code", () => {
const code = `const d = require('${normalizePathForInlineCode("../../tmp/index.mjs")}').default;`;
it("should produce a relative path ready to be embedded in inlined code", () => {
const joined = path.join("..", "..", "tmp", "index.mjs");
const code = `const d = require('${normalizePathForInlineCode(joined)}').default;`;
if (!isWindows) {
expect(code).toEqual("const d = require('../../tmp/index.mjs').default;");
});
} else {
expect(code).toEqual("const d = require('..\\..\\tmp\\index.mjs').default;");
}
});
});

0 comments on commit 2ccd25b

Please sign in to comment.