-
-
Notifications
You must be signed in to change notification settings - Fork 1
feat: added 'vitest' #1
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
Open
FindMalek
wants to merge
1
commit into
openstatusHQ:main
Choose a base branch
from
FindMalek:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,81 @@ | ||
| # Testing | ||
|
|
||
| How we’ve configured testing in Goat Stack. | ||
|
|
||
| Goat Stack uses Vitest for unit testing. It’s a fast and lightweight testing framework that’s compatible with Jest’s API. Unit tests are run automatically as part of the build task in Turborepo. | ||
|
|
||
| ## Running Tests | ||
|
|
||
| To run tests, simply execute: | ||
|
|
||
| ```bash | ||
| pnpm test | ||
| ``` | ||
|
|
||
| This will run all tests in the `__tests__` folder in each app, however we’ve only written a couple of tests for app project so far. | ||
|
|
||
| ## Adding Tests | ||
|
|
||
| We use Testing Library for our tests. It’s a great library that allows you to test your components in a way that’s close to how a user would interact with them. | ||
|
|
||
| In the `__tests__` folder, create a new file called `[page].test.tsx` (where `[page]` is the name of the page you want to test). Here’s an example of a test for the home page: | ||
|
|
||
| `apps/app/__tests__/home.test.tsx` | ||
|
|
||
| ```typescript | ||
| import { render, screen } from '@testing-library/react'; | ||
| import { expect, test } from 'vitest'; | ||
| import Page from '../app/(unauthenticated)/home/page'; | ||
|
|
||
| test('Home Page', () => { | ||
| render(<Page />); | ||
| expect( | ||
| screen.getByRole('heading', { | ||
| level: 1, | ||
| name: 'Hello, world!', | ||
| }) | ||
| ).toBeDefined(); | ||
| }); | ||
| ``` | ||
|
|
||
| ## Adding Vitest to other apps | ||
|
|
||
| To add Vitest to another app, you’ll need to install the dependencies: | ||
|
|
||
| ```bash | ||
| pnpm install -D vitest @testing-library/react @testing-library/dom --filter [app] | ||
| ``` | ||
|
|
||
| as well as adding the `@goat/testing` package to the `devDependencies` section of the `package.json` file: | ||
|
|
||
| `apps/[app]/package.json` | ||
|
|
||
| ```json | ||
| "devDependencies": { | ||
| "@goat/testing": "workspace:*" | ||
| } | ||
| ``` | ||
|
|
||
| Create a new file called `vitest.config.ts` in the root of the app and add the following: | ||
|
|
||
| `apps/[app]/vitest.config.ts` | ||
|
|
||
| ```typescript | ||
| export { default } from '@goat/testing'; | ||
| ``` | ||
|
|
||
| Then, create a new file in the `__tests__` folder in the relevant app and add a test command to the `package.json` file: | ||
|
|
||
| `apps/[app]/package.json` | ||
|
|
||
| ```json | ||
| { | ||
| "scripts": { | ||
| "test": "vitest" | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| Turborepo will automatically pick up on the new test script and run the tests. | ||
|
|
||
| Then, just follow the instructions above to write tests. |
This file contains hidden or 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,18 @@ | ||
| const path = require('node:path'); | ||
| const react = require('@vitejs/plugin-react'); | ||
| const { defineConfig } = require('vitest/config'); | ||
|
|
||
| const config = defineConfig({ | ||
| plugins: [react()], | ||
| test: { | ||
| environment: 'jsdom', | ||
| }, | ||
| resolve: { | ||
| alias: { | ||
| '@': path.resolve(__dirname, './'), | ||
| '@goat': path.resolve(__dirname, '../../packages'), | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| module.exports = config; |
This file contains hidden or 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,17 @@ | ||
| { | ||
| "name": "@goat/testing", | ||
| "version": "0.0.0", | ||
| "private": true, | ||
| "main": "./index.js", | ||
| "type": "commonjs", | ||
| "scripts": { | ||
| "clean": "git clean -xdf .cache .turbo dist node_modules", | ||
| "typecheck": "tsc --noEmit --emitDeclarationOnly false" | ||
| }, | ||
| "devDependencies": { | ||
| "@goat/typescript-config": "workspace:*", | ||
| "@vitejs/plugin-react": "^4.3.4", | ||
| "vitest": "^3.0.7", | ||
| "typescript": "5.7.3" | ||
| } | ||
| } |
This file contains hidden or 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 @@ | ||
| { | ||
| "extends": "@goat/typescript-config/react-library.json", | ||
| "include": ["src"], | ||
| "exclude": ["dist", "build", "node_modules"] | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think i need to use the
nextjs.json