|
| 1 | +import path from "node:path"; |
| 2 | + |
1 | 3 | import { describe, expect, it } from "vitest"; |
2 | 4 |
|
3 | 5 | import { normalizePathForInlineCode } from "./normalize-path-for-inline-code"; |
4 | 6 |
|
| 7 | +const isWindows = process.platform === "win32"; |
| 8 | + |
5 | 9 | 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 { |
9 | 16 | 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 | + } |
16 | 18 | }); |
17 | 19 |
|
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) { |
26 | 24 | 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 | + } |
28 | 28 | }); |
29 | 29 | }); |
0 commit comments