Skip to content

Commit

Permalink
test: add jest (#14)
Browse files Browse the repository at this point in the history
- Add jest and some additional core test dependencies
- Add the beginnings of a test, which does nothing at this point other than make jest happy that at least 1 test exists
- Update CI to include tests
  • Loading branch information
dylants authored Jan 23, 2024
1 parent 0d1e0a7 commit 3b2b6d4
Show file tree
Hide file tree
Showing 5 changed files with 2,458 additions and 80 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/ci.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ jobs:
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: "yarn"
cache: 'yarn'
- name: Install dependencies
run: yarn --frozen-lockfile
- name: Run lint
run: yarn lint
- name: Run tests
run: yarn test
- name: Run build
run: yarn build
20 changes: 20 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import type { Config } from 'jest';
import nextJest from 'next/jest.js';

const createJestConfig = nextJest({
// Provide the path to your Next.js app to load next.config.js and .env files in your test environment
dir: './',
});

// Add any custom config to be passed to Jest
const config: Config = {
collectCoverageFrom: ['src/**/*.ts*'],
coveragePathIgnorePatterns: ['src/components/*'],
coverageProvider: 'v8',
testEnvironment: 'jsdom',
// Add more setup options before each test is run
// setupFilesAfterEnv: ['<rootDir>/jest.setup.ts'],
};

// createJestConfig is exported this way to ensure that next/jest can load the Next.js config which is async
export default createJestConfig(config);
10 changes: 9 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
"dev": "next dev",
"eslint": "next lint",
"lint": "yarn eslint && yarn check-types",
"start": "next start"
"start": "next start",
"test": "jest --coverage",
"test:watch": "jest --watch"
},
"dependencies": {
"@prisma/client": "5.8.1",
Expand All @@ -26,6 +28,9 @@
"tailwindcss-animate": "1.0.7"
},
"devDependencies": {
"@testing-library/jest-dom": "6.2.1",
"@testing-library/react": "14.1.2",
"@types/jest": "29.5.11",
"@types/node": "^20",
"@types/react": "^18",
"@types/react-dom": "^18",
Expand All @@ -34,10 +39,13 @@
"eslint-config-next": "14.0.4",
"eslint-config-prettier": "9.1.0",
"eslint-plugin-prettier": "5.1.3",
"jest": "29.7.0",
"jest-environment-jsdom": "29.7.0",
"postcss": "^8",
"prettier": "3.2.4",
"prisma": "5.8.1",
"tailwindcss": "^3.3.0",
"ts-node": "10.9.2",
"typescript": "^5"
}
}
5 changes: 5 additions & 0 deletions src/lib/search/external/useExternalBookSearch.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
describe('useExternalBookSearch', () => {
it('should work', () => {
expect(true).toEqual(true);
});
});
Loading

0 comments on commit 3b2b6d4

Please sign in to comment.