Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unit tests #12

Merged
merged 1 commit into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 47 additions & 27 deletions .github/workflows/website.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,37 +18,57 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
- uses: actions/setup-node@v4
with:
node-version: lts/*
- uses: actions/cache@v3

- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"

- name: Cache yarn
uses: actions/cache@v3
id: yarn-cache
with:
path: ~/.cache/yarn
key: ${{ runner.os }}-yarn-${{ hashFiles('website/**/yarn.lock') }}
path: |
${{ steps.yarn-cache-dir-path.outputs.dir }}
~/.cache/yarn
key: ${{ runner.os }}-yarn-${{ hashFiles('variation/**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-

- name: Install dependencies
run: yarn install --frozen-lockfile
run: yarn --immutable

- name: Check format
run: yarn run lint

# unitTests:
# name: Unit Tests
# timeout-minutes: 10
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v4
# - uses: actions/setup-node@v4
# with:
# node-version: lts/*
# - name: Cache .npm
# uses: actions/cache@v3
# with:
# path: ~/.npm
# key: ${{ runner.os }}-node-${{ hashFiles('variation/**/package-lock.json') }}
# - name: Install dependencies
# run: npm ci
# - name: Run tests
# run: npm run test
#
run: yarn lint

unitTests:
name: Unit Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: lts/*

- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"

- name: Cache yarn
uses: actions/cache@v3
id: yarn-cache
with:
path: |
${{ steps.yarn-cache-dir-path.outputs.dir }}
~/.cache/yarn
key: ${{ runner.os }}-yarn-${{ hashFiles('variation/**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-

- name: Install dependencies
run: yarn --immutable

- name: Run tests
run: yarn test
9 changes: 7 additions & 2 deletions website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,32 @@
"build": "next build",
"start": "next start",
"lint": "next lint",
"format": "prettier --write '*/**/*.{js,jsx,ts,tsx,json,css,md}'"
"format": "prettier --write '*/**/*.{js,jsx,ts,tsx,json,css,md}'",
"test": "vitest"
},
"dependencies": {
"next": "14.0.4",
"react": "^18",
"react-dom": "^18"
},
"devDependencies": {
"@testing-library/react": "^14.1.2",
"@types/node": "^20",
"@types/react": "^18",
"@types/react-dom": "^18",
"@typescript-eslint/eslint-plugin": "^6.18.1",
"@typescript-eslint/parser": "^6.18.1",
"@vitejs/plugin-react": "^4.2.1",
"autoprefixer": "^10.0.1",
"eslint": "^8",
"eslint-config-next": "14.0.4",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.1.3",
"jsdom": "^24.0.0",
"postcss": "^8",
"prettier": "^3.1.1",
"tailwindcss": "^3.3.0",
"typescript": "^5"
"typescript": "^5",
"vitest": "^1.2.2"
}
}
8 changes: 8 additions & 0 deletions website/src/__tests__/page.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { expect, test } from 'vitest';
import { render, screen } from '@testing-library/react';
import Home from '../app/page';

test('Home', () => {
render(<Home />);
expect(screen.getByRole('heading', { level: 1, name: 'Variation study' })).toBeDefined();
});
2 changes: 1 addition & 1 deletion website/src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export default function Home() {
return (
<main className='flex min-h-screen flex-col items-center justify-between p-24'>
<div>Variation study</div>
<h1>Variation study</h1>
</main>
);
}
9 changes: 9 additions & 0 deletions website/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { defineConfig } from 'vitest/config';
import react from '@vitejs/plugin-react';

export default defineConfig({
plugins: [react()],
test: {
environment: 'jsdom',
},
});
Loading
Loading