Skip to content

Commit 57056e9

Browse files
committed
Setup Jest and Storybook for component-drive development of NewBookForm
1 parent ec1a584 commit 57056e9

30 files changed

+53111
-6711
lines changed

.eslintrc.js

+7-14
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,23 @@ module.exports = {
22
parser: 'babel-eslint',
33
env: {
44
browser: true,
5-
es2021: true,
5+
es2021: true
66
},
7-
extends: [
8-
'eslint:recommended',
9-
'plugin:react/recommended',
10-
'plugin:@typescript-eslint/recommended',
11-
'prettier',
12-
'plugin:react/jsx-runtime',
13-
'next',
14-
],
7+
extends: ['eslint:recommended', 'plugin:react/recommended', 'plugin:@typescript-eslint/recommended', 'prettier', 'plugin:react/jsx-runtime', 'next', 'plugin:storybook/recommended'],
158
parser: '@typescript-eslint/parser',
169
parserOptions: {
1710
ecmaFeatures: {
1811
jsx: true,
19-
tsx: true,
12+
tsx: true
2013
},
2114
ecmaVersion: 'latest',
22-
sourceType: 'module',
15+
sourceType: 'module'
2316
},
2417
plugins: ['react', 'react-hooks', '@typescript-eslint', 'prettier'],
2518
rules: {
2619
'no-console': 'warn',
2720
'prettier/prettier': 'error',
2821
'@typescript-eslint/no-explicit-any': 'off',
29-
'react-hooks/exhaustive-deps': 'warn',
30-
},
31-
};
22+
'react-hooks/exhaustive-deps': 'warn'
23+
}
24+
};

.storybook/main.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module.exports = {
2+
"stories": [
3+
"../src/**/*.stories.mdx",
4+
"../src/**/*.stories.@(js|jsx|ts|tsx)"
5+
],
6+
"addons": [
7+
"@storybook/addon-links",
8+
"@storybook/addon-essentials",
9+
"@storybook/addon-interactions"
10+
],
11+
"framework": "@storybook/react",
12+
"core": {
13+
"builder": "@storybook/builder-webpack5"
14+
}
15+
}

.storybook/preview.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export const parameters = {
2+
actions: { argTypesRegex: "^on[A-Z].*" },
3+
controls: {
4+
matchers: {
5+
color: /(background|color)$/i,
6+
date: /Date$/,
7+
},
8+
},
9+
}

jest.config.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const nextJest = require('next/jest')
2+
3+
const createJestConfig = nextJest({
4+
dir: './',
5+
})
6+
7+
const customJestConfig = {
8+
setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
9+
moduleDirectories: ['node_modules', '<rootDir>/'],
10+
testEnvironment: 'jest-environment-jsdom',
11+
moduleNameMapper: {
12+
'^@/components/(.*)$': '<rootDir>/components/$1',
13+
'^@/hooks/(.*)$': '<rootDir>/hooks/$1',
14+
'^@/services/(.*)$': '<rootDir>/services/$1',
15+
'^@/pages/(.*)$': '<rootDir>/pages/$1',
16+
'^@/helpers/(.*)$': '<rootDir>/helpers/$1',
17+
}
18+
}
19+
20+
// createJestConfig is exported this way to ensure that next/jest can load the Next.js config which is async
21+
module.exports = createJestConfig(customJestConfig)

jest.setup.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import '@testing-library/jest-dom/extend-expect'

next.config.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
const clientUrl = process.env.NEXT_PUBLIC_CLIENT_URL;
44

5-
if (clientUrl === null || clientUrl === undefined) {
5+
const isNotTestEnvironemtn = process.env.NODE_ENV !== 'test';
6+
7+
if ((clientUrl === null || clientUrl === undefined) && isNotTestEnvironemtn) {
68
throw Error('Required variable NEXT_PUBLIC_CLIENT_URL was not defined');
79
}
810

0 commit comments

Comments
 (0)