Skip to content

Commit

Permalink
Merge pull request #58 from Bricks666/feature/36-add-integration-and-…
Browse files Browse the repository at this point in the history
…unit-tests

Feature/36 add integration and unit tests
  • Loading branch information
Bricks666 authored Nov 24, 2024
2 parents 19f53e4 + 7a85eb3 commit d82ed98
Show file tree
Hide file tree
Showing 278 changed files with 27,867 additions and 4,914 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
BASE_CLIENT_URL=http://localhost:3000
API_HOST=http://localhost:5000/api
VITE_API_HOST=http://localhost:3000
1 change: 1 addition & 0 deletions .env.test
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
BASE_CLIENT_URL=http://localhost:3000
API_HOST=http://localhost:5000/api
VITE_API_HOST=http://localhost:3000
69 changes: 68 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@
"error",
{
"patterns": [
{
"message": "Tests specific imports are prohibited, use it only in tests",
"group": ["~/**"]
},
{
"message": "Private imports are prohibited, use public imports instead",
"group": ["@/app/**"]
Expand Down Expand Up @@ -215,5 +219,68 @@
"@typescript-eslint/no-empty-interface": ["off"],
"@typescript-eslint/no-explicit-any": "warn"
},
"ignorePatterns": ["templates/**/*", "*.css.d.ts", "configs/*", "e2e", "*.config.*"]
"overrides": [
{
"files": ["*.spec.tsx", "*.spec.ts"],
"rules": {
"import/no-extraneous-dependencies": "off",
"no-restricted-imports": [
"error",
{
"patterns": [
{
"message": "Private imports are prohibited, use public imports instead",
"group": ["@/app/**"]
},
{
"message": "Private imports are prohibited, use public imports instead",
"group": ["@/pages/*/**"]
},
{
"message": "Private imports are prohibited, use public imports instead",
"group": ["@/widgets/*/**"]
},
{
"message": "Private imports are prohibited, use public imports instead",
"group": ["@/features/*/**"]
},
{
"message": "Private imports are prohibited, use public imports instead",
"group": ["@/entities/*/**"]
},
{
"message": "Private imports are prohibited, use public imports instead",
"group": ["@/shared/*/*/**"]
},
{
"message": "Prefer absolute imports instead of relatives (for root modules)",
"group": ["../**/app"]
},
{
"message": "Prefer absolute imports instead of relatives (for root modules)",
"group": ["../**/pages"]
},
{
"message": "Prefer absolute imports instead of relatives (for root modules)",
"group": ["../**/widgets"]
},
{
"message": "Prefer absolute imports instead of relatives (for root modules)",
"group": ["../**/features"]
},
{
"message": "Prefer absolute imports instead of relatives (for root modules)",
"group": ["../**/entities"]
},
{
"message": "Prefer absolute imports instead of relatives (for root modules)",
"group": ["../**/shared"]
}
]
}
]
}
}
],
"ignorePatterns": ["*.css.d.ts", "configs/*", "e2e", "*.config.*"]
}
37 changes: 37 additions & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: 'Run tests'

on:
push:
branches: ['main', 'develop']
pull_request:

jobs:
test:
runs-on: ubuntu-latest

permissions:
contents: read
pull-requests: write

steps:
- name: Checkout branch
uses: actions/checkout@v4

- name: Install Node
uses: actions/setup-node@v4
with:
node-version: '20.x'
cache: 'npm'

- name: Install deps
run: npm ci

- name: Run tests
run: npm run test:coverage

- name: "Report Coverage"
if: always()
uses: davelosert/vitest-coverage-report-action@v2
with:
json-summary-path: coverage/coverage-summary.json
json-final-path: coverage/coverage-final.json
4 changes: 4 additions & 0 deletions .lintstagedrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,9 @@
"*.ts(x)?": [
"prettier --write --ignore-unknown --config ./.prettierrc",
"eslint --fix -c ./.eslintrc.json"
],
"*.css": [
"prettier --write --ignore-unknown --config ./.prettierrc --ignore-path ./.prettierignore",
"stylelint --fix -c ./configs/styles/.stylelintrc.json"
]
}
4 changes: 4 additions & 0 deletions .projections.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"src/**/*.tsx": { "alternate": "src/{}.spec.tsx" },
"src/**/*.ts": { "alternate": "src/{}.spec.ts" }
}
27 changes: 27 additions & 0 deletions .stylelintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"extends": ["stylelint-config-clean-order"],
"plugins": [
"stylelint-color-format",
"stylelint-use-nesting",
"stylelint-z-index-value-constraint",
"stylelint-no-nested-media",
"stylelint-high-performance-animation",
"stylelint-css-modules"
],
"rules": {
"color-format/format": {
"format": "hsl"
},
"media-feature-range-notation": "prefix",

"plugin/z-index-value-constraint": {
"min": -1,
"max": 10000
},

"pitcher/no-nested-media": true,

"plugin/no-low-performance-animation-properties": true
},
"ignoreFiles": ["**/*.[jt]sx?", "**/third-party/*", "**/PlanEditor/*"]
}
3 changes: 3 additions & 0 deletions configs/tests/global-setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const setup = () => {
process.env.TZ = 'UTC';
};
39 changes: 39 additions & 0 deletions configs/tests/setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { expect, afterEach, beforeAll, afterAll, vi } from 'vitest';
import { cleanup } from '@testing-library/react';
import * as matchers from '@testing-library/jest-dom/matchers';
import {
matchMedia,
MediaQueryListEvent,
cleanup as cleanupMatchMedia,
} from 'mock-match-media';
import { server } from '~/test-utils';

expect.extend(matchers);

vi.mock('@/shared/configs/i18n/index.ts');

vi.mock('@farfetched/core', async (importOriginal) => {
const module = await importOriginal<typeof import('@farfetched/core')>();

return {
...module,
keepFresh: vi.fn(),
};
});

beforeAll(() => {
server.listen();
});

afterEach(() => {
cleanup();
server.resetHandlers();
cleanupMatchMedia();
});

afterAll(() => {
server.close();
});

window.MediaQueryListEvent = MediaQueryListEvent;
window.matchMedia = matchMedia;
Loading

0 comments on commit d82ed98

Please sign in to comment.