mirror of
https://github.com/chenasraf/simple-scaffold.git
synced 2026-05-18 01:29:09 +00:00
49 lines
1.5 KiB
TypeScript
49 lines
1.5 KiB
TypeScript
import { handlebarsParse } from "../src/utils"
|
|
import { ScaffoldConfig } from "../src/types"
|
|
import path from "path"
|
|
|
|
const blankConf: ScaffoldConfig = {
|
|
verbose: 0,
|
|
name: "",
|
|
output: "",
|
|
templates: [],
|
|
data: { name: "test" },
|
|
}
|
|
|
|
describe("Utils", () => {
|
|
describe("handlebarsParse", () => {
|
|
let origSep: any
|
|
describe("windows paths", () => {
|
|
beforeAll(() => {
|
|
origSep = path.sep
|
|
Object.defineProperty(path, "sep", { value: "\\" })
|
|
})
|
|
afterAll(() => {
|
|
Object.defineProperty(path, "sep", { value: origSep })
|
|
})
|
|
test("should work for windows paths", async () => {
|
|
expect(handlebarsParse(blankConf, "C:\\exports\\{{name}}.txt", { isPath: true })).toEqual(
|
|
"C:\\exports\\test.txt"
|
|
)
|
|
})
|
|
})
|
|
describe("non-windows paths", () => {
|
|
beforeAll(() => {
|
|
origSep = path.sep
|
|
Object.defineProperty(path, "sep", { value: "/" })
|
|
})
|
|
afterAll(() => {
|
|
Object.defineProperty(path, "sep", { value: origSep })
|
|
})
|
|
test("should work for non-windows paths", async () => {
|
|
expect(handlebarsParse(blankConf, "/home/test/{{name}}.txt", { isPath: true })).toEqual("/home/test/test.txt")
|
|
})
|
|
})
|
|
test("should not do path escaping on non-path compiles", async () => {
|
|
expect(handlebarsParse(blankConf, "/home/test/{{name}} \\{{escaped}}.txt", { isPath: false })).toEqual(
|
|
"/home/test/test {{escaped}}.txt"
|
|
)
|
|
})
|
|
})
|
|
})
|