Skip to content

Commit

Permalink
feat(config): adds jest config (#19) (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
csantiago132 authored Oct 3, 2024
1 parent 3518db0 commit 449c977
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/_base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
- name: Cache pnpm store
uses: actions/cache@v3
with:
path: ~/.pnpm-store # Path to pnpm store
path: ./.pnpm-store
key: ${{ runner.os }}-pnpm-${{ hashFiles('pnpm-lock.yaml') }} # Cache key based on OS and lockfile hash
restore-keys: |
${{ runner.os }}-pnpm-
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
},
"license": "MPL-2.0",
"exports": {
"./jest/base": "./src/jest/jest.config.base.js",
"./jest/node": "./src/jest/jest.config.node.js",
"./jest/react": "./src/jest/jest.config.react.js",
"./jest/remix": "./src/jest/jest.config.remix.js",
"./commitlint": "./src/commitlint/index.js",
"./semantic-release": "./src/semantic-release/index.js",
"./eslint/base": "./src/eslint/eslint.base.js",
Expand All @@ -32,6 +36,7 @@
"src/.github",
"src/commitlint",
"src/eslint",
"src/jest",
"src/prettier",
"src/semantic-release",
"src/tsconfig"
Expand Down
2 changes: 1 addition & 1 deletion src/eslint/rules/base/import.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ module.exports = {
pathGroups: [
{
group: 'internal',
pattern: '~/**',
pattern: '@/**',
position: 'before',
},
],
Expand Down
25 changes: 25 additions & 0 deletions src/jest/jest.config.base.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module.exports = {
collectCoverage: true,
collectCoverageFrom: [
'**/*.{js,jsx,ts,tsx}',
'!**/node_modules/**',
'!**/vendor/**',
'!**/dist/**',
'!**/build/**',
'!**/__mocks__/**',
'!**/__tests__/**',
],
coverageReporters: ['text', 'lcov'],
moduleFileExtensions: ['js', 'jsx', 'ts', 'tsx'],
moduleNameMapper: {
'\\.(css|less|scss|sass)$': 'identity-obj-proxy',
'\\.(gif|ttf|eot|svg)$': '<rootDir>/__mocks__/fileMock.js',
},
setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
snapshotSerializers: ['@emotion/jest/serializer'],
testEnvironment: 'node', // Default; overridden in project-specific configs
transform: {
'^.+\\.(js|jsx)$': 'babel-jest',
'^.+\\.(ts|tsx)$': 'ts-jest',
},
};
17 changes: 17 additions & 0 deletions src/jest/jest.config.node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const baseConfig = require('./jest.config.base.js');

module.exports = {
...baseConfig,
globals: {
'ts-jest': {
diagnostics: false,
tsconfig: '<rootDir>/tsconfig.spec.json',
},
},
moduleNameMapper: {
...baseConfig.moduleNameMapper,
'^@/(.*)$': '<rootDir>/src/$1',
},
roots: ['<rootDir>/src'],
testEnvironment: 'node',
};
11 changes: 11 additions & 0 deletions src/jest/jest.config.react.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const baseConfig = require('./jest.config.base.js');

module.exports = {
...baseConfig,
moduleNameMapper: {
...baseConfig.moduleNameMapper,
'^@/(.*)$': '<rootDir>/src/$1',
},
roots: ['<rootDir>/src'],
testEnvironment: 'jsdom',
};
11 changes: 11 additions & 0 deletions src/jest/jest.config.remix.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const baseConfig = require('./jest.config.base.js');

module.exports = {
...baseConfig,
moduleNameMapper: {
...baseConfig.moduleNameMapper,
'^@/(.*)$': '<rootDir>/app/$1',
},
roots: ['<rootDir>/app'],
testEnvironment: 'jsdom',
};
2 changes: 1 addition & 1 deletion src/prettier/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = {
arrowParens: 'always',
bracketSpacing: true,
endOfLine: 'lf',
importOrder: ['<THIRD_PARTY_MODULES>', '^~/(.*)$', '^[../]', '^./'],
importOrder: ['<THIRD_PARTY_MODULES>', '^@/(.*)$', '^[../]', '^./'],
importOrderSeparation: true,
importOrderSortSpecifiers: true,
jsxSingleQuote: true,
Expand Down

0 comments on commit 449c977

Please sign in to comment.