Skip to content

Commit 2ccd25b

Browse files
improve unit tests
1 parent 9cab2d3 commit 2ccd25b

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed
Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
1+
import path from "node:path";
2+
13
import { describe, expect, it } from "vitest";
24

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

7+
const isWindows = process.platform === "win32";
8+
59
describe("normalizePathForInlineCode", () => {
6-
describe.runIf(process.platform === "win32")("windows", () => {
7-
it("should produce an absolute path ready to be embedded in inlined code", () => {
8-
const code = `const d = require('${normalizePathForInlineCode("/Users/me/projects/cloudflare/index.mjs")}').default;`;
10+
it("should produce an absolute path ready to be embedded in inlined code", () => {
11+
const joined = path.join("/", "Users", "me", "projects", "cloudflare", "index.mjs");
12+
const code = `const d = require('${normalizePathForInlineCode(joined)}').default;`;
13+
if (!isWindows) {
14+
expect(code).toEqual("const d = require('/Users/me/projects/cloudflare/index.mjs').default;");
15+
} else {
916
expect(code).toEqual("const d = require('\\Users\\me\\projects\\cloudflare\\index.mjs').default;");
10-
});
11-
12-
it("should produce a relative path ready to be embedded in inlined code", () => {
13-
const code = `const d = require('${normalizePathForInlineCode("../../tmp/index.mjs")}').default;`;
14-
expect(code).toEqual("const d = require('..\\..\\tmp\\index.mjs').default;");
15-
});
17+
}
1618
});
1719

18-
describe.runIf(process.platform === "linux" || process.platform === "darwin")("linux/mac", () => {
19-
it("should produce an absolute path ready to be embedded in inlined code", () => {
20-
const code = `const d = require('${normalizePathForInlineCode("/Users/me/projects/cloudflare/index.mjs")}').default;`;
21-
expect(code).toEqual("const d = require('/Users/me/projects/cloudflare/index.mjs').default;");
22-
});
23-
24-
it("should produce a relative path ready to be embedded in inlined code", () => {
25-
const code = `const d = require('${normalizePathForInlineCode("../../tmp/index.mjs")}').default;`;
20+
it("should produce a relative path ready to be embedded in inlined code", () => {
21+
const joined = path.join("..", "..", "tmp", "index.mjs");
22+
const code = `const d = require('${normalizePathForInlineCode(joined)}').default;`;
23+
if (!isWindows) {
2624
expect(code).toEqual("const d = require('../../tmp/index.mjs').default;");
27-
});
25+
} else {
26+
expect(code).toEqual("const d = require('..\\..\\tmp\\index.mjs').default;");
27+
}
2828
});
2929
});

0 commit comments

Comments
 (0)