Skip to content

Instantly share code, notes, and snippets.

@rickyalmeidadev
Last active November 1, 2023 10:48
Show Gist options
  • Save rickyalmeidadev/965f639e175267ae0ea4e96bf4c07981 to your computer and use it in GitHub Desktop.
Save rickyalmeidadev/965f639e175267ae0ea4e96bf4c07981 to your computer and use it in GitHub Desktop.
vite + react + @swc/jest
yarn create vite
yarn add --dev @swc/core @swc/jest @testing-library/jest-dom @testing-library/react @types/jest eslint eslint-config-prettier eslint-plugin-jest-dom eslint-plugin-prettier eslint-plugin-react eslint-plugin-react-hooks eslint-plugin-testing-library jest prettier
{
"env": {
"browser": true,
"es2021": true,
"jest": true,
"node": true
},
"extends": [
"eslint:recommended",
"plugin:react/recommended",
"plugin:react-hooks/recommended",
"plugin:testing-library/react",
"plugin:jest-dom/recommended",
"plugin:prettier/recommended"
],
"parserOptions": {
"ecmaFeatures": {
"jsx": true
},
"ecmaVersion": "latest",
"sourceType": "module"
},
"rules": {
"react/react-in-jsx-scope": "off"
},
"settings": {
"react": {
"version": "latest"
}
}
}
{
"arrowParens": "avoid",
"printWidth": 90,
"singleQuote": true,
"semi": false
}
module.exports = {
process: () => "module.exports = 'test-file-stub'",
}
module.exports = {
clearMocks: true,
moduleNameMapper: {
'^~/(.*)$': '<rootDir>/src/$1',
},
setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
testEnvironment: 'jest-environment-jsdom',
transform: {
'^.+\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$':
'<rootDir>/__mocks__/file-transformer.js',
'^.+\\.(css|scss|sass|less)$': '<rootDir>/__mocks__/style-transformer.js',
'^.+\\.(t|j)sx?$': [
'@swc/jest',
{
jsc: {
parser: {
syntax: 'ecmascript',
jsx: true,
},
transform: {
react: {
runtime: 'automatic',
},
},
},
},
],
},
}
import '@testing-library/jest-dom/extend-expect'
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"~/*": ["./src/*"]
}
}
}
{
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"test": "jest",
"test:coverage": "jest --coverage && open coverage/lcov-report/index.html",
"test:watch": "jest --watch"
}
module.exports = {
process: () => 'module.exports = {}',
}
import react from '@vitejs/plugin-react'
import path from 'node:path'
export default {
plugins: [react()],
resolve: {
alias: {
'~': path.resolve(__dirname, 'src'),
},
},
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment