-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* test: add vitest and istanbul * test archetypes * test collections * changeset
- Loading branch information
1 parent
eb0edff
commit b5be9dc
Showing
10 changed files
with
642 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@goulvenclech/astropi": patch | ||
--- | ||
|
||
Add tests for collections and archetypes public functions. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,9 @@ dist/ | |
# generated types | ||
.astro/ | ||
|
||
# generated by Vitest UI | ||
coverage/ | ||
|
||
# dependencies | ||
node_modules/ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { describe, expect, it } from "vitest" | ||
import { vi } from "vitest" | ||
import { getCurrentArchetype } from "./archetypes" | ||
|
||
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 } | ||
}) | ||
|
||
describe("getCurrentArchetype", () => { | ||
it("should return the current archetype based on the 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", | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Test packages/astropi/utils/collections.ts exported functions | ||
import { describe, it, expect, vi } from "vitest" | ||
import { generateCollections } from "./collections" | ||
|
||
describe("generateCollections", () => { | ||
it("should generate collections based on the user's configuration", () => { | ||
const archetypes: Archetype[] = [ | ||
{ | ||
name: "blog", | ||
path: "blog", | ||
collection: "blog", | ||
type: "blog-content", | ||
}, | ||
{ | ||
name: "docs", | ||
path: "docs", | ||
collection: "docs", | ||
type: "docs-content", | ||
}, | ||
{ | ||
name: "docs-reference", | ||
path: "reference", | ||
collection: "reference", | ||
type: "docs-openapi", | ||
}, | ||
] | ||
const injectRoute = vi.fn() | ||
generateCollections(injectRoute, archetypes) | ||
expect(injectRoute).toHaveBeenCalledTimes(6) | ||
expect(injectRoute).toHaveBeenCalledWith({ | ||
pattern: "/blog", | ||
entrypoint: "@goulvenclech/astropi/pages/blog.astro", | ||
prerender: true, | ||
}) | ||
expect(injectRoute).toHaveBeenCalledWith({ | ||
pattern: "/blog/[...slug]", | ||
entrypoint: "@goulvenclech/astropi/pages/[...blog].astro", | ||
prerender: true, | ||
}) | ||
expect(injectRoute).toHaveBeenCalledWith({ | ||
pattern: "/docs", | ||
entrypoint: "@goulvenclech/astropi/pages/docs-content.astro", | ||
prerender: true, | ||
}) | ||
expect(injectRoute).toHaveBeenCalledWith({ | ||
pattern: "/docs/[...slug]", | ||
entrypoint: "@goulvenclech/astropi/pages/[...docs-content].astro", | ||
prerender: true, | ||
}) | ||
expect(injectRoute).toHaveBeenCalledWith({ | ||
pattern: "/reference", | ||
entrypoint: "@goulvenclech/astropi/pages/docs-openapi.astro", | ||
prerender: true, | ||
}) | ||
expect(injectRoute).toHaveBeenCalledWith({ | ||
pattern: "/reference/[...slug]", | ||
entrypoint: "@goulvenclech/astropi/pages/[...docs-openapi].astro", | ||
prerender: true, | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.