Skip to content

Commit

Permalink
feat: add tests, storybook, babel, linters, ci\cd
Browse files Browse the repository at this point in the history
  • Loading branch information
TomatoVan committed Nov 12, 2023
1 parent b4a321a commit fd673da
Show file tree
Hide file tree
Showing 54 changed files with 1,895 additions and 11,644 deletions.
86 changes: 61 additions & 25 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,20 @@
"react-hooks",
"@typescript-eslint"
],
"overrides": [{ "files": [
".js",
".ts",
".jsx",
".tsx",
"**/*.spec.js",
"**/*.test.ts",
"**/*.test.tsx",
"**/*.spec.tsx"
] }],
"overrides": [
{
"files": [
".js",
".ts",
".jsx",
".tsx",
"**/*.spec.js",
"**/*.test.ts",
"**/*.test.tsx",
"**/*.spec.tsx"
]
}
],
"rules": {
"prettier/prettier": [
"error",
Expand Down Expand Up @@ -80,9 +84,33 @@
"consistent-return": "off",
"padding-line-between-statements": [
"error",
{ "blankLine": "always", "prev": "*", "next": "return"},
{ "blankLine": "always", "prev": ["const", "let", "var"], "next": "*"},
{ "blankLine": "any", "prev": ["const", "let", "var"], "next": ["const", "let", "var"]}
{
"blankLine": "always",
"prev": "*",
"next": "return"
},
{
"blankLine": "always",
"prev": [
"const",
"let",
"var"
],
"next": "*"
},
{
"blankLine": "any",
"prev": [
"const",
"let",
"var"
],
"next": [
"const",
"let",
"var"
]
}
],
"no-shadow": "off",
"no-debugger": "error",
Expand All @@ -98,13 +126,16 @@
}
],
"no-use-before-define": "off",
"no-param-reassign": ["error", {
"props": true,
"ignorePropertyModificationsFor": [
"state",
"self"
]
}],
"no-param-reassign": [
"error",
{
"props": true,
"ignorePropertyModificationsFor": [
"state",
"self"
]
}
],
"react/display-name": "off",
"react/react-in-jsx-scope": "off",
"react/require-default-props": "off",
Expand All @@ -126,10 +157,15 @@
"unnamedComponents": "arrow-function"
}
],
"react/jsx-props-no-spreading": [0, {
"html": "ignore"
}],
"@typescript-eslint/no-unused-vars": ["warn"],
"react/jsx-props-no-spreading": [
0,
{
"html": "ignore"
}
],
"@typescript-eslint/no-unused-vars": [
"warn"
],
"@typescript-eslint/explicit-function-return-type": "off"
},
"settings": {
Expand All @@ -147,4 +183,4 @@
}
}
}
}
}
46 changes: 46 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: linting, testing, building
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
pipeline:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [ 17.x ]

steps:
- uses: actions/checkout@v2
- name: Staring Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}

- name: install modules
run: npm install

- name: build production project
if: always()
run: npm run build

- name: linting typescript
if: always()
run: npm run lint:ts

- name: linting css
if: always()
run: npm run lint:scss

- name: unit testing
if: always()
run: npm run test:unit

- name: build storybook
if: always()
run: npm run storybook:build




6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
/node_modules
/.pnp
.pnp.js
yarn.lock
./yarn.lock
/yarn.lock
.yarn.lock
.storybook-static
/storybook-static

# testing
/coverage
Expand Down
7 changes: 7 additions & 0 deletions .stylelintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "stylelint-config-standard-scss",
"rules": {
"indentation": [4],
"selector-class-pattern": null
}
}
13 changes: 13 additions & 0 deletions babel.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"presets": [
"@babel/preset-env",
"@babel/preset-typescript",
[
"@babel/preset-react",
{
"runtime": "automatic"
}
]
],
"plugins": []
}
175 changes: 175 additions & 0 deletions config/jest/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
/*
* For a detailed explanation regarding each configuration property and type check, visit:
* https://jestjs.io/docs/configuration
*/

import path from 'path';

export default {
globals: {
__IS_DEV__: true,
},
clearMocks: true,
testEnvironment: 'jsdom',
coveragePathIgnorePatterns: ['\\\\node_modules\\\\'],
moduleFileExtensions: ['js', 'jsx', 'ts', 'tsx', 'json', 'node'],
moduleDirectories: ['node_modules'],
modulePaths: ['<rootDir>src'],
testMatch: [
// Обнаружил разницу между МАК ОС и ВИНДОУС!!!
'<rootDir>src/**/*(*.)@(spec|test).[tj]s?(x)',
],
rootDir: '../../',
setupFilesAfterEnv: ['<rootDir>config/jest/setupTests.ts'],
moduleNameMapper: {
'\\.s?css$': 'identity-obj-proxy',
'\\.svg': path.resolve(__dirname, 'jestEmptyComponent.tsx'),
'.+\\.(css|styl|less|sass|scss|png|jpg|ttf|woff|woff2)$': 'identity-obj-proxy',
},
// Indicates whether the coverage information should be collected while executing the test
// collectCoverage: false,

// An array of glob patterns indicating a set of files for which coverage information should be collected
// collectCoverageFrom: undefined,

// The directory where Jest should output its coverage files
// coverageDirectory: undefined,

// An array of regexp pattern strings used to skip coverage collection

// Indicates which provider should be used to instrument code for coverage
// coverageProvider: "babel",

// A list of reporter names that Jest uses when writing coverage reports
// coverageReporters: [
// "json",
// "text",
// "lcov",
// "clover"
// ],

// An object that configures minimum threshold enforcement for coverage results
// coverageThreshold: undefined,

// A path to a custom dependency extractor
// dependencyExtractor: undefined,

// Make calling deprecated APIs throw helpful error messages
// errorOnDeprecated: false,

// Force coverage collection from ignored files using an array of glob patterns
// forceCoverageMatch: [],

// A path to a module which exports an async function that is triggered once before all test suites
// globalSetup: undefined,

// A path to a module which exports an async function that is triggered once after all test suites
// globalTeardown: undefined,

// A set of global variables that need to be available in all test environments
// globals: {},

// The maximum amount of workers used to run your tests. Can be specified as % or a number. E.g. maxWorkers: 10% will use 10% of your CPU amount + 1 as the maximum worker number. maxWorkers: 2 will use a maximum of 2 workers.
// maxWorkers: "50%",

// An array of directory names to be searched recursively up from the requiring module's location

// An array of file extensions your modules use

// A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
// moduleNameMapper: {},

// An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
// modulePathIgnorePatterns: [],

// Activates notifications for test results
// notify: false,

// An enum that specifies notification mode. Requires { notify: true }
// notifyMode: "failure-change",

// A preset that is used as a base for Jest's configuration
// preset: undefined,

// Use this configuration option to add custom reporters to Jest
// reporters: undefined,

// Automatically reset mock state before every test
// resetMocks: false,

// Reset the module registry before running each individual test
// resetModules: false,

// Automatically restore mock state and implementation before every test
// restoreMocks: false,

// The root directory that Jest should scan for tests and modules within

// A list of paths to directories that Jest should use to search for files in
// roots: [
// "<rootDir>"
// ],

// Allows you to use a custom runner instead of Jest's default test runner
// runner: "jest-runner",

// The paths to modules that run some code to configure or set up the testing environment before each test
// setupFiles: [],

// A list of paths to modules that run some code to configure or set up the testing framework before each test
// setupFilesAfterEnv: [],

// The number of seconds after which a test is considered as slow and reported as such in the results.
// slowTestThreshold: 5,

// A list of paths to snapshot serializer modules Jest should use for snapshot testing
// snapshotSerializers: [],

// The test environment that will be used for testing

// Options that will be passed to the testEnvironment
// testEnvironmentOptions: {},

// Adds a location field to test results
// testLocationInResults: false,

// The glob patterns Jest uses to detect test files

// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
// testPathIgnorePatterns: [
// "\\\\node_modules\\\\"
// ],

// The regexp pattern or array of patterns that Jest uses to detect test files
// testRegex: [],

// This option allows the use of a custom results processor
// testResultsProcessor: undefined,

// This option allows use of a custom test runner
// testRunner: "jest-circus/runner",

// This option sets the URL for the jsdom environment. It is reflected in properties such as location.href
// testURL: "http://localhost",

// Setting this value to "fake" allows the use of fake timers for functions such as "setTimeout"
// timers: "real",

// A map from regular expressions to paths to transformers
// transform: undefined,

// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
// transformIgnorePatterns: [
// "\\\\node_modules\\\\",
// "\\.pnp\\.[^\\\\]+$"
// ],

// Indicates whether each individual test should be reported during the run
// verbose: undefined,

// An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode
// watchPathIgnorePatterns: [],

// Whether to use watchman for file crawling
// watchman: true,
};
5 changes: 5 additions & 0 deletions config/jest/jestEmptyComponent.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const jestEmptyComponent = function () {
return <div />;
};

export default jestEmptyComponent;
3 changes: 3 additions & 0 deletions config/jest/setupTests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Такой файл вы могли наблюдать при create-react-app
import '@testing-library/jest-dom';
import 'regenerator-runtime/runtime';
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { ReactNode } from 'react';

import { Provider } from 'react-redux';

import { store } from '../../../../src/app/store';

export const ProviderDecorator = (story: () => ReactNode) => (
<Provider store={store}>{story()}</Provider>
);
Loading

0 comments on commit fd673da

Please sign in to comment.