diff --git a/.github/workflows/_base.yml b/.github/workflows/_base.yml index b9b0d29..ed2a7ac 100644 --- a/.github/workflows/_base.yml +++ b/.github/workflows/_base.yml @@ -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- diff --git a/package.json b/package.json index ff96dc1..6a510c7 100644 --- a/package.json +++ b/package.json @@ -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", @@ -32,6 +36,7 @@ "src/.github", "src/commitlint", "src/eslint", + "src/jest", "src/prettier", "src/semantic-release", "src/tsconfig" diff --git a/src/eslint/rules/base/import.js b/src/eslint/rules/base/import.js index 8795ef8..95f17ec 100644 --- a/src/eslint/rules/base/import.js +++ b/src/eslint/rules/base/import.js @@ -82,7 +82,7 @@ module.exports = { pathGroups: [ { group: 'internal', - pattern: '~/**', + pattern: '@/**', position: 'before', }, ], diff --git a/src/jest/jest.config.base.js b/src/jest/jest.config.base.js new file mode 100644 index 0000000..9f5b41e --- /dev/null +++ b/src/jest/jest.config.base.js @@ -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)$': '/__mocks__/fileMock.js', + }, + setupFilesAfterEnv: ['/jest.setup.js'], + snapshotSerializers: ['@emotion/jest/serializer'], + testEnvironment: 'node', // Default; overridden in project-specific configs + transform: { + '^.+\\.(js|jsx)$': 'babel-jest', + '^.+\\.(ts|tsx)$': 'ts-jest', + }, +}; diff --git a/src/jest/jest.config.node.js b/src/jest/jest.config.node.js new file mode 100644 index 0000000..a1821c0 --- /dev/null +++ b/src/jest/jest.config.node.js @@ -0,0 +1,17 @@ +const baseConfig = require('./jest.config.base.js'); + +module.exports = { + ...baseConfig, + globals: { + 'ts-jest': { + diagnostics: false, + tsconfig: '/tsconfig.spec.json', + }, + }, + moduleNameMapper: { + ...baseConfig.moduleNameMapper, + '^@/(.*)$': '/src/$1', + }, + roots: ['/src'], + testEnvironment: 'node', +}; diff --git a/src/jest/jest.config.react.js b/src/jest/jest.config.react.js new file mode 100644 index 0000000..7a28c5f --- /dev/null +++ b/src/jest/jest.config.react.js @@ -0,0 +1,11 @@ +const baseConfig = require('./jest.config.base.js'); + +module.exports = { + ...baseConfig, + moduleNameMapper: { + ...baseConfig.moduleNameMapper, + '^@/(.*)$': '/src/$1', + }, + roots: ['/src'], + testEnvironment: 'jsdom', +}; diff --git a/src/jest/jest.config.remix.js b/src/jest/jest.config.remix.js new file mode 100644 index 0000000..7de05f6 --- /dev/null +++ b/src/jest/jest.config.remix.js @@ -0,0 +1,11 @@ +const baseConfig = require('./jest.config.base.js'); + +module.exports = { + ...baseConfig, + moduleNameMapper: { + ...baseConfig.moduleNameMapper, + '^@/(.*)$': '/app/$1', + }, + roots: ['/app'], + testEnvironment: 'jsdom', +}; diff --git a/src/prettier/index.js b/src/prettier/index.js index eb1a29a..042e9ab 100644 --- a/src/prettier/index.js +++ b/src/prettier/index.js @@ -6,7 +6,7 @@ module.exports = { arrowParens: 'always', bracketSpacing: true, endOfLine: 'lf', - importOrder: ['', '^~/(.*)$', '^[../]', '^./'], + importOrder: ['', '^@/(.*)$', '^[../]', '^./'], importOrderSeparation: true, importOrderSortSpecifiers: true, jsxSingleQuote: true,