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

Prepared tests and all utilities to support both unit and integrations tests #6

Merged
merged 2 commits into from
Dec 11, 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
20 changes: 18 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
module.exports = {
root: true,
extends: ["next/core-web-vitals"],
plugins: ["testing-library"],
extends: [
"next/core-web-vitals",
"eslint:recommended",
"plugin:@typescript-eslint/recommended"
],
plugins: ["testing-library", "@typescript-eslint"],
parser: "@typescript-eslint/parser",
overrides: [
{
files: ["**/__tests__/**/*.[jt]s?(x)", "**/?(*.)+(spec|test).[jt]s?(x)"],
extends: ["plugin:testing-library/react"],
},
{
files: ["packages/**/*", "apps/api/**/*"],
extends: [
"eslint:recommended",
"plugin:@typescript-eslint/recommended"
],
rules: {
"@typescript-eslint/no-explicit-any": "error",
"@typescript-eslint/explicit-module-boundary-types": "error"
}
}
],
};
57 changes: 57 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Tests

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
# Allow manual triggering
workflow_dispatch:

jobs:
test:
runs-on: ubuntu-latest

env:
GITHUB_TOKEN: ${{ secrets.TEST_GITHUB_TOKEN }}
GITHUB_TEST_OWNER: ${{ secrets.TEST_OWNER }}
GITHUB_TEST_REPO: ${{ secrets.TEST_REPO }}
DATABASE_URL: ${{ secrets.TEST_DATABASE_URL }}
NODE_ENV: test
# Add this for local testing
CI: true

steps:
- uses: actions/checkout@v3

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '20.10.0'

# Simplified pnpm setup for local testing
- name: Install pnpm
run: |
if ! command -v pnpm &> /dev/null; then
npm install -g [email protected]
fi

- name: Install dependencies
run: pnpm install --no-frozen-lockfile

- name: Run type check
run: pnpm type-check

- name: Run tests
run: pnpm test

# Only run coverage upload in CI, not locally
- name: Upload coverage
if: ${{ !env.ACT }}
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage/lcov.info
flags: unittests
name: codecov-umbrella
fail_ci_if_error: true
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,5 @@ yarn-error.log*

# Turborepo
.turbo
.secrets
.actrc
2 changes: 1 addition & 1 deletion apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"dev": "ts-node-dev --respawn --transpile-only src/index.ts",
"build": "tsc",
"start": "node dist/index.js",
"lint": "eslint src --ext .ts",
"lint": "eslint .",
"test": "jest"
},
"dependencies": {
Expand Down
30 changes: 29 additions & 1 deletion apps/web/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,31 @@
{
"extends": ["next/core-web-vitals", "next/typescript"]
"extends": ["next/core-web-vitals"],
"rules": {
"prefer-const": "error",
"@typescript-eslint/no-namespace": ["error", { "allowDeclarations": true }],
"@typescript-eslint/no-explicit-any": "warn",
"@typescript-eslint/no-unused-vars": ["error", {
"argsIgnorePattern": "^_|^(req|request|res|response|next|props|user)$",
"varsIgnorePattern": "^(React|_|NextAuth|JWT|Link|Alert|AlertDescription|AlertTitle|AlertCircle|cn|signIn|Github|CardDescription|session|handleSignOut|clientSecret)$",
"ignoreRestSiblings": true
}]
},
"overrides": [
{
"files": ["**/__tests__/**/*.ts", "**/__tests__/**/*.tsx"],
"rules": {
"@typescript-eslint/no-namespace": "off",
"@typescript-eslint/no-unused-vars": "off",
"@typescript-eslint/no-explicit-any": "off"
}
},
{
"files": ["**/route.ts"],
"rules": {
"@typescript-eslint/no-unused-vars": ["error", {
"argsIgnorePattern": "^(req|request|res|response|next)$"
}]
}
}
]
}
16 changes: 10 additions & 6 deletions apps/web/babel.config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
module.exports = {
presets: [
['@babel/preset-env', {
targets: {
node: 'current'
}
['@babel/preset-env', { targets: { node: 'current' } }],
'@babel/preset-typescript',
],
plugins: [
['@babel/plugin-transform-runtime', {
corejs: 3,
helpers: true,
regenerator: true,
useESModules: false,
}],
'@babel/preset-typescript'
]
],
};
25 changes: 13 additions & 12 deletions apps/web/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,21 @@ module.exports = {
coverageReporters: ['text', 'lcov'],
verbose: true,
transform: {
'^.+\\.(ts|tsx|js|jsx)$': [
'babel-jest',
{
presets: [
['@babel/preset-env', {
targets: { node: 'current' }
}],
'@babel/preset-typescript'
]
}
]
'^.+\\.(ts|tsx)$': ['babel-jest', { configFile: './babel.config.js' }]
},
transformIgnorePatterns: [
'/node_modules/(?!(@octokit|@babel/runtime|@babel/runtime-corejs3|universal-user-agent|before-after-hook|is-plain-object|node-fetch|once|wrappy|tr46|whatwg-url|webidl-conversions)/)'
],
setupFilesAfterEnv: [
'<rootDir>/src/lib/github/__tests__/setup.ts'
],
moduleNameMapper: {
'^@/(.*)$': '<rootDir>/src/$1'
},
setupFiles: ['<rootDir>/src/lib/github/__tests__/setup.ts']
globals: {
'ts-jest': {
isolatedModules: true
}
},
testTimeout: 10000
};
49 changes: 29 additions & 20 deletions apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,41 @@
"build": "next build",
"start": "next start",
"lint": "next lint",
"test": "jest",
"type-check": "tsc --noEmit"
"test": "jest"
},
"dependencies": {
"@babel/runtime": "^7.24.0",
"@octokit/graphql": "^7.0.2",
"@octokit/plugin-paginate-rest": "^9.2.0",
"@octokit/plugin-rest-endpoint-methods": "^10.2.0",
"@octokit/request-error": "^6.1.5",
"@octokit/rest": "^21.0.2",
"@octokit/types": "^12.4.0"
"@babel/runtime-corejs3": "^7.23.6",
"@octokit/plugin-rest-endpoint-methods": "^10.0.0",
"@octokit/rest": "^20.0.2",
"@octokit/webhooks-types": "^7.3.1",
"@prisma/client": "^5.22.0",
"lucide-react": "^0.468.0",
"next": "14.0.4",
"next-auth": "^4.24.5",
"react": "^18",
"react-dom": "^18"
},
"devDependencies": {
"@babel/core": "^7.24.0",
"@babel/preset-env": "^7.24.0",
"@babel/core": "^7.23.6",
"@babel/plugin-transform-runtime": "^7.23.6",
"@babel/preset-env": "^7.23.6",
"@babel/preset-typescript": "^7.23.3",
"@babel/plugin-transform-modules-commonjs": "^7.24.0",
"@babel/plugin-transform-runtime": "^7.24.0",
"@jest/globals": "^29.7.0",
"@types/jest": "^29.5.0",
"@octokit/types": "^13.6.2",
"@types/jest": "^29.5.11",
"@types/node": "^20",
"@types/react": "^18",
"@types/react-dom": "^18",
"autoprefixer": "^10.0.1",
"babel-jest": "^29.7.0",
"babel-plugin-transform-import-meta": "^2.2.1",
"jest": "^29.5.0",
"jest-environment-node": "^29.7.0",
"msw": "1.3.2",
"typescript": "^5.3.2",
"whatwg-fetch": "^3.6.20"
"eslint": "^8",
"eslint-config-next": "14.0.4",
"jest": "^29.7.0",
"msw": "^2.0.11",
"postcss": "^8",
"prisma": "^5.22.0",
"tailwindcss": "^3.3.0",
"ts-jest": "^29.1.1",
"typescript": "^5"
}
}
Loading
Loading