Skip to content

Commit b38fa71

Browse files
implement simple unit tetsts
1 parent 4c7ef4c commit b38fa71

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

packages/cloudflare/src/cli/build/utils/normalize-path-for-inline-code.spec.ts

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,27 @@ import { describe, expect, it } from "vitest";
33
import { normalizePathForInlineCode } from "./normalize-path-for-inline-code";
44

55
describe("normalizePathForInlineCode", () => {
6-
it("should extract production env vars", () => {
7-
const result = normalizePathForInlineCode("TODO");
8-
expect(result).toBeFalsy();
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;`;
9+
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+
});
16+
});
17+
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;`;
26+
expect(code).toEqual("const d = require('../../tmp/index.mjs').default;");
27+
});
928
});
1029
});

0 commit comments

Comments
 (0)