Skip to content

Commit

Permalink
test(component): Add bio unit test
Browse files Browse the repository at this point in the history
Check whether the component is rendered as expected.
  • Loading branch information
5ouma committed Nov 8, 2024
1 parent 67463b4 commit 2690508
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 2 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,31 @@ jobs:
- name: 🏞️ Biome Check
run: bun run check:biome

test:
name: 🧪 Test
runs-on: Ubuntu-Latest

steps:
- name: 🚚 Checkout Repository
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

- name: 🍞 Setup Bun with Cache
uses: ./.github/actions/setup-bun-with-cache

- name: 🧪 Run Tests
run: bun run test:cov

- name: ☂️ Upload Coverage
uses: codecov/codecov-action@b9fd7d16f6d7d1b5d2bec1a2887e65ceed900238 # v4.6.0
with:
token: ${{ secrets.CODECOV_TOKEN }}

- name: ☂️ Upload Test Results
if: ${{ !cancelled() }}
uses: codecov/test-results-action@9739113ad922ea0a9abb4b2c0f8bf6a4aa8ef820 # v1.0.1
with:
token: ${{ secrets.CODECOV_TOKEN }}

build-check:
name: 🛠️ Build Check
runs-on: Ubuntu-Latest
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
node_modules/
dist/
.astro/
coverage/
junit.xml
Binary file modified bun.lockb
Binary file not shown.
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
"build": "astro build",
"preview": "astro preview",
"check:astro": "astro check",
"check:biome": "biome check"
"check:biome": "biome check",
"test": "vitest run",
"test:cov": "vitest run --coverage"
},
"dependencies": {
"astro": "4.16.10",
Expand All @@ -18,6 +20,8 @@
"@astrojs/check": "0.9.4",
"@biomejs/biome": "1.9.4",
"@types/node": "22.9.0",
"astrobook": "0.5.1"
"@vitest/coverage-v8": "2.1.4",
"astrobook": "0.5.1",
"vitest": "2.1.4"
}
}
18 changes: 18 additions & 0 deletions src/components/Bio/Bio.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { experimental_AstroContainer as AstroContainer } from "astro/container";
import { describe, expect, test } from "vitest";

import Bio from "./Bio.astro";
import * as stories from "./story.ts";

describe("Bio", () => {
for (const [name, props] of Object.entries(stories)) {
test(name, async () => {
const container: AstroContainer = await AstroContainer.create();
const result: string = await container.renderToString(Bio, { props });

expect(result).toContain(`>${props.name}</span>`);
expect(result).toContain(`>${props.description}</span>`);
expect(result).toContain(`<img src="${props.icon}"`);
});
}
});
10 changes: 10 additions & 0 deletions vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/// <reference types="vitest" />

import { getViteConfig } from "astro/config";

export default getViteConfig({
test: {
reporters: ["verbose", ["junit", { suiteName: "Component Tests" }]],
outputFile: "junit.xml",
},
});

0 comments on commit 2690508

Please sign in to comment.