Skip to content

Commit

Permalink
feat: add jest annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
apurv-wednesday committed Apr 26, 2024
1 parent 2a52566 commit 851349c
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 29 deletions.
30 changes: 27 additions & 3 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"plugin:@typescript-eslint/recommended",
"next/core-web-vitals"
],
"plugins": ["react", "@typescript-eslint"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaFeatures": {
Expand All @@ -18,17 +19,17 @@
"ecmaVersion": "latest",
"sourceType": "module"
},
"plugins": ["react", "@typescript-eslint"],
"rules": {
"react/prop-types": "off",
"react/react-in-jsx-scope": "off",
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/no-inferrable-types": "error",
"react-hooks/rules-of-hooks": "error",
"react-hooks/exhaustive-deps": "warn",
"import/prefer-default-export": "off",
"import/prefer-default-export": "off", // check for relevance here
"eslint-comments/no-use": 0,
"import/no-cycle": "off",
"no-multi-assign": "off",
// "prettier/prettier": "error",
"no-console": 1,
"import/no-extraneous-dependencies": "off",
"import/no-unresolved": "error",
Expand All @@ -45,6 +46,29 @@
{
"patterns": ["@mui/*/*/*"]
}
],
"max-lines-per-function": ["error", 250],
"max-params": ["error", 3],
"complexity": ["error", 5],
"max-lines": ["error", 350],
"no-else-return": "error",
"require-jsdoc": [
"error",
{
"require": {
"FunctionDeclaration": true,
"MethodDefinition": false,
"ClassDeclaration": false,
"ArrowFunctionExpression": false,
"FunctionExpression": false
}
}
],
"no-shadow": "error",
"no-empty": "error",
"import/order": [
"error",
{ "groups": [["builtin", "external", "internal", "parent", "sibling", "index"]] }
]
}
}
41 changes: 41 additions & 0 deletions .github/workflows/jest-coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Jest Coverage Report with Annotations (CI)
on:
pull_request:
branches: [main]
push:
branches: [main]
jobs:
coverage_report:
name: Jest Coverage Report
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [20.x]

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
cache: 'yarn'

# could not find the threshold value in jest.config.js
# therefore hardcoded for now
# - name: Get Threshold
# id: threshold
# uses: notiz-dev/github-action-json-property@release
# with:
# path: 'jest.config.js'
# prop_path: 'coverageThreshold.global.statements'

- name: Install dependencies
run: yarn

- name: Test and generate coverage report
uses: artiomtr/[email protected]
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
# threshold: ${{steps.threshold.outputs.prop}}
package-manager: yarn
custom-title: Jest Coverage Report
46 changes: 23 additions & 23 deletions jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ const createJestConfig = nextJest({ dir: "./" });
const jestConfig: Config = {
preset: "ts-jest",
testEnvironment: "jsdom",
collectCoverageFrom: [
"./common/**/*.{js,jsx,ts,tsx}",
"./containers/**/*.{js,jsx,ts,tsx}",
"./features/**/*.{js,jsx,ts,tsx}",
"./pages/**/*.{js,jsx,ts,tsx}",
"./store/**/*.{js,jsx,ts,tsx}",
"./styles/**/*.{js,jsx,ts,tsx}",
"./themes/**/*.{js,jsx,ts,tsx}",
"./utils/**/*.{js,jsx,ts,tsx}",
],
// comment coverage for now, to make the CI pipeline green
// coverageThreshold: {
// global: {
// statements: 90,
// branches: 90,
// functions: 90,
// lines: 90,
// },
// },
collectCoverageFrom: ["./src/**/*.{js,jsx,ts,tsx}"],
reporters: [
"default",
[
Expand All @@ -42,19 +42,19 @@ const jestConfig: Config = {
// Handle image imports
// https://jestjs.io/docs/webpack#handling-static-assets
"^.+\\.(jpg|jpeg|png|gif|webp|avif|svg)$": `<rootDir>/__mocks__/fileMock.js`,
"@styles(.*)": "<rootDir>/styles",
"@logger(.*)": "<rootDir>/logger",
"@constants(.*)": "<rootDir>/constants",
"services(.*)": "<rootDir>/services",
"^@features(.*)": "<rootDir>/features/$1",
"^@store(.*)": "<rootDir>/store/$1",
"^@containers(.*)": "<rootDir>/containers/$1",
"^@hooks(.*)": "<rootDir>/hooks/$1",
"^@shared(.*)": "<rootDir>/features/sharedComponents/$1",
"^@themes(.*)": "<rootDir>/themes/$1",
"^@utils(.*)": "<rootDir>/utils/$1",
"^@slices(.*)": "<rootDir>/store/slices/$1",
"^@app(.*)": "<rootDir>/$1",
"@styles(.*)": "<rootDir>/src/styles",
"@logger(.*)": "<rootDir>/src/logger",
"@constants(.*)": "<rootDir>/src/constants",
"services(.*)": "<rootDir>/src/services",
"^@features(.*)": "<rootDir>/src/features/$1",
"^@store(.*)": "<rootDir>/src/store/$1",
"^@containers(.*)": "<rootDir>/src/containers/$1",
"^@hooks(.*)": "<rootDir>/src/hooks/$1",
"^@shared(.*)": "<rootDir>/src/features/sharedComponents/$1",
"^@themes(.*)": "<rootDir>/src/themes/$1",
"^@utils(.*)": "<rootDir>/src/utils/$1",
"^@slices(.*)": "<rootDir>/src/store/slices/$1",
"^@app(.*)": "<rootDir>/src/$1",
},
setupFilesAfterEnv: ["<rootDir>/jest.setup.js"],
testPathIgnorePatterns: [
Expand Down
6 changes: 3 additions & 3 deletions sonar-project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ sonar.projectKey=wednesday-solutions_next-bulletproof-ts_AY6yu6eKB2n8RRmGoUz4
sonar.language=ts

# Source directory
sonar.sources=.
sonar.sources=src

# Test directory
sonar.tests=src
Expand All @@ -21,7 +21,7 @@ sonar.test.inclusions=**/*.test.tsx,**/*.test.js,**/*.test.ts
sonar.sourceEncoding=UTF-8

# Coverage report path
sonar.javascript.lcov.reportPaths=coverage/lcov.info
sonar.typescript.lcov.reportPaths=.coverage/lcov.info

# Test execution report path
sonar.testExecutionReportPaths=./reports/test-report.xml
sonar.testExecutionReportPaths=.reports/test-report.xml

0 comments on commit 851349c

Please sign in to comment.