Skip to content

Commit

Permalink
ci(test): adds the test actions
Browse files Browse the repository at this point in the history
Adds the test actions to run on pull requests and pushes to the main branch.

fixes #260
  • Loading branch information
anguspiv committed Dec 24, 2024
1 parent 6d3da67 commit 9bc61cd
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 10 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,39 @@ jobs:
- name: Lint
run: npm run lint

test:
runs-on: ubuntu-latest

permissions:
# Required to checkout the code
contents: read
# Required to put a comment into the pull-request
pull-requests: write

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20.x'

- name: Cache Node.js modules
id: cache-node-modules
uses: actions/cache@v4
with:
path: node_modules
key: ${{ runner.os }}-node-modules-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-modules-
- name: Install dependencies
run: npm install

- name: 'Test'
run: npx vitest

commitlint:
permissions:
contents: read
Expand Down
43 changes: 43 additions & 0 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: 'Pull Request'
on:
pull_request:

jobs:
test:
runs-on: ubuntu-latest

permissions:
# Required to checkout the code
contents: read
# Required to put a comment into the pull-request
pull-requests: write

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20.x'

- name: Cache Node.js modules
id: cache-node-modules
uses: actions/cache@v4
with:
path: node_modules
key: ${{ runner.os }}-node-modules-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-modules-
- name: Install dependencies
run: npm install

- name: 'Test'
run: npx vitest --coverage.enabled true

- name: 'Report Coverage'
# Set if: always() to also generate the report if tests are failing
# Only works if you set `reportOnFailure: true` in your vite config as specified above
if: always()
uses: davelosert/vitest-coverage-report-action@v2
8 changes: 5 additions & 3 deletions astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import { defineConfig } from 'astro/config';
import { vanillaExtractPlugin } from '@vanilla-extract/vite-plugin';
import react from '@astrojs/react';

// https://astro.build/config
export default defineConfig({
export const config = {
integrations: [react()],
vite: {
plugins: [vanillaExtractPlugin({})],
Expand All @@ -14,4 +13,7 @@ export default defineConfig({
},
},
},
});
};

// https://astro.build/config
export default defineConfig(config);
7 changes: 1 addition & 6 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
{
"extends": "astro/tsconfigs/strict",
"include": [".astro/types.d.ts", "**/*"],
"exclude": ["dist"],
"compilerOptions": {
"jsx": "react-jsx",
"jsxImportSource": "react",
"types": ["vitest/globals", "@testing-library/jest-dom"]
}
"exclude": ["dist"]
}
13 changes: 12 additions & 1 deletion vitest.config.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
import { defineConfig } from 'vite';
/// <reference types="vitest/config" />
import { defineConfig } from 'astro/config';
import { config } from './astro.config.mjs';

export default defineConfig({
...config,
// @ts-expect-error - this is a vitest config
test: {
globals: true,
environment: 'jsdom',
setupFiles: './vitest.setup.ts',
coverage: {
// you can include other reporters, but 'json-summary' is required, json is recommended
reporter: ['text', 'json-summary', 'json'],
// If you want a coverage reports even if your tests are failing, include the reportOnFailure option
reportOnFailure: true,
},
typecheck: true,
},
});

0 comments on commit 9bc61cd

Please sign in to comment.