Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ieedan committed Nov 1, 2024
1 parent cc48256 commit d68170f
Showing 1 changed file with 100 additions and 0 deletions.
100 changes: 100 additions & 0 deletions packages/cli/test/utils/registry/index.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import { describe, expect, it } from "vitest";
import { getItemTargetPath } from "../../../src/utils/registry/index";
import { SITE_BASE_URL } from "../../../src/constants";

const config = {
style: "new-york",
tailwind: {
config: "tailwind.config.js",
css: "src/app.pcss",
baseColor: "zinc",
},
aliases: {
utils: "$lib/utils",
components: "$lib/components",
hooks: "$lib/hooks",
ui: "$lib/components/ui",
},
// not how they will look in the end but works for the tests
resolvedPaths: {
components: "./src/lib/components",
tailwindConfig: "./tailwind.config.js",
tailwindCss: "./src/app.pcss",
utils: "./src/lib/utils",
cwd: "./",
hooks: "./src/lib/hooks",
ui: "./src/lib/components/ui",
},
typescript: true,
registry: `${SITE_BASE_URL}/registry`,
};

describe("getItemTargetPath", () => {
it("returns null if invalid type missing `:`", async () => {
expect(
getItemTargetPath(
config,
{
name: "label",
dependencies: ["bits-ui@next"],
registryDependencies: [],
files: [
//... snip this since it doesn't matter
],
// @ts-expect-error Comes from over the wire in prod
type: "registry",
}
)
).toEqual(null);
});

it("returns null if `item.type` has invalid `:<type>`", async () => {
expect(
getItemTargetPath(
config,
{
name: "label",
dependencies: ["bits-ui@next"],
registryDependencies: [],
files: [
//... snip this since it doesn't matter
],
// @ts-expect-error Comes from over the wire in prod
type: "registry:foo",
}
)
).toEqual(null);
});

it("disallow overrides for `registry:ui`", async () => {
expect(
getItemTargetPath(
config,
{
name: "label",
dependencies: ["bits-ui@next"],
registryDependencies: [],
files: [
//... snip this since it doesn't matter
],
type: "registry:ui",
},
"./override-path"
)
).toEqual("src\\lib\\components\\ui\\label");
});

it("resolves itemTargetPath", async () => {
expect(
getItemTargetPath(config, {
name: "label",
dependencies: ["bits-ui@next"],
registryDependencies: [],
files: [
//... snip this since it doesn't matter
],
type: "registry:ui",
})
).toEqual("src\\lib\\components\\ui\\label");
});
});

0 comments on commit d68170f

Please sign in to comment.