Skip to content

Commit

Permalink
test archetypes
Browse files Browse the repository at this point in the history
  • Loading branch information
goulvenclech committed May 9, 2024
1 parent 9e5d7bd commit c5c6bec
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/astropi/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ interface AstropiUserConfig {
type Archetype = {
name: string
path: string
collection: any
collection: string
type: "blog-content" | "docs-content" | "docs-openapi"
}
// Used by "./virtual-user-config.ts"
Expand Down
42 changes: 37 additions & 5 deletions packages/astropi/utils/archetypes.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,41 @@
import { expect, test } from "vitest"
import { vi } from "vitest"
import { getCurrentArchetype } from "./archetypes"

function sum(a: number, b: number) {
return a + b
}
vi.mock("virtual:astropi-user-config", () => {
const userConfig = {
projectName: "Astropi Project",
archetypes: [
{
name: "Blog",
path: "blog",
collection: "blog",
type: "blog-content",
},
{
name: "Changelog",
path: "changelog",
collection: "changelog",
type: "blog-content",
},
{
name: "Docs",
path: "docs",
collection: "docs",
type: "docs-content",
},
],
}
return { userConfig }
})

test("adds 1 + 2 to equal 3", () => {
expect(sum(1, 2)).toBe(3)
test("Should return the current Archetype for a given URL location", () => {
const location = new URL("https://astro.build/blog")
const archetype = getCurrentArchetype(location)
expect(archetype).toEqual({
name: "Blog",
path: "blog",
collection: "blog",
type: "blog-content",
})
})
10 changes: 10 additions & 0 deletions vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,14 @@ export default defineConfig({
exclude: ["**/*.config.*", "**/config.*", "**/*.workspace.*"],
},
},
plugins: [
{
name: "astropi-user-config",
resolveId(id: any) {
if (id === "virtual:astropi-user-config") {
return "\0virtual:astropi-user-config"
}
},
},
],
})

0 comments on commit c5c6bec

Please sign in to comment.