Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev2 #87

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open

Dev2 #87

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added .eslintignore
Empty file.
13 changes: 13 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
env: {
browser: true,
es2021: true,
},
extends: "plugin:react/recommended",
parser: "@typescript-eslint/parser",
parserOptions: {
ecmaVersion: "latest",
},
plugins: ["@typescript-eslint", "react"],
rules: {},
};
11 changes: 11 additions & 0 deletions .github/workflows/commitlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: Lint Commit Messages
on: [push]

jobs:
commitlint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: wagoid/commitlint-github-action@v5
20 changes: 20 additions & 0 deletions .github/workflows/testpr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Test PR and lint
on:
pull_request:
branches:
- "main"
jobs:
unint-tests:
runs-on: ubuntu-22.04
steps:
- name: Get repo code
uses: actions/checkout@v3
- name: Install dependencies
run: npm ci
- name: Start unit-tests
run: |
for commit in $(git rev-list ${{ github.base_ref }}..${{ github.head_ref }}); do
git checkout $commit
npm run lint
npm test
done
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
1. Добавил `config` файлы для commitlint и добавил workflows для github [commitlint.yml](https://github.com/AparinAA/unit-demo-cra/blob/dev1/.github/workflows/commitlint.yml) . Делать коммит для проверки через с именем `'refactor: commitText'` , либо в любов виде: соглашаения о коммитах.
2. Добавил [testpr.yml](https://github.com/AparinAA/unit-demo-cra/blob/dev1/.github/workflows/testpr.yml) для тестирования и проверки линтером pull requests

В этом репозитории находится пример приложения с тестами:

- [e2e тесты](e2e/example.spec.ts)
- [unit тесты](src/example.test.tsx)
- [e2e тесты](e2e/example.spec.ts)
- [unit тесты](src/example.test.tsx)

Для запуска примеров необходимо установить [NodeJS](https://nodejs.org/en/download/) 16 или выше.

Expand Down
1 change: 1 addition & 0 deletions commitlint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = { extends: ['@commitlint/config-conventional'] };
310 changes: 180 additions & 130 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
"eject": "react-scripts eject",
"test": "react-scripts test",
"e2e": "playwright test --project=chromium && playwright show-report",
"test-ci": "CI=true npm test -- --reporters=\"default\" --reporters=\"jest-html-reporter\" --reporters=\"jest-teamcity\""
"test-ci": "CI=true npm test -- --reporters=\"default\" --reporters=\"jest-html-reporter\" --reporters=\"jest-teamcity\"",
"lint": "./node_modules/.bin/eslint src/"
},
"eslintConfig": {
"extends": [
Expand Down Expand Up @@ -59,6 +60,7 @@
"devDependencies": {
"@playwright/test": "^1.28.0",
"@types/react-helmet": "^6.1.5",
"eslint": "^8.45.0",
"jest-html-reporter": "^3.7.0"
}
}
50 changes: 25 additions & 25 deletions src/example.test.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable react/react-in-jsx-scope */
import { it, expect } from "@jest/globals";
import { render } from "@testing-library/react";
import events from "@testing-library/user-event";
Expand All @@ -10,37 +11,36 @@ import { initStore } from "./store";
import { Application } from "./Application";

it('по адресу /about должна открываться страница "о проекте"', () => {
const store = initStore();
const application = (
<MemoryRouter initialEntries={["/about"]} initialIndex={0}>
<Provider store={store}>
<Application />
</Provider>
</MemoryRouter>
);

const { getByTestId } = render(application);

expect(getByTestId("page-title").textContent).toEqual("About");
const store = initStore();
const application = (
<MemoryRouter initialEntries={["/about"]} initialIndex={0}>
<Provider store={store}>
<Application />
</Provider>
</MemoryRouter>
);

const { getByTestId } = render(application);
expect(getByTestId("page-title").textContent).toEqual("About");
});

it("если добавить элемент, он появляется в списке", async () => {
const store = initStore();
const application = (
<BrowserRouter>
<Provider store={store}>
<Application />
</Provider>
</BrowserRouter>
);
const store = initStore();
const application = (
<BrowserRouter>
<Provider store={store}>
<Application />
</Provider>
</BrowserRouter>
);

const { getByTestId, getAllByTestId } = render(application);
const { getByTestId, getAllByTestId } = render(application);

await events.type(getByTestId("input-add"), "Сделать домашку");
await events.type(getByTestId("input-add"), "Сделать домашку");

await events.click(getByTestId("button-add"));
await events.click(getByTestId("button-add"));

const items = getAllByTestId("list-item");
const items = getAllByTestId("list-item");

expect(items.map((el) => el.textContent)).toContain("Сделать домашку");
expect(items.map((el) => el.textContent)).toContain("Сделать домашку");
});
18 changes: 9 additions & 9 deletions src/pages/About.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import { FC } from "react";
import { Helmet } from "react-helmet";

export const About: FC = () => {
return (
<>
<Helmet>
<title>About page</title>
</Helmet>
<h1 data-testid="page-title">About</h1>
<p>This is an example application.</p>
</>
);
return (
<>
<Helmet>
<title>About page</title>
</Helmet>
<h1 data-testid="page-title">About</h1>
<p>This is an example application.</p>
</>
);
};
20 changes: 10 additions & 10 deletions src/pages/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import { Helmet } from "react-helmet";
import { TodoList } from "../components/TodoList";

export const Home: FC = () => {
return (
<>
<Helmet>
<title>Home page</title>
</Helmet>
<h1 data-testid="page-title">Home</h1>
<p>This is the list.</p>
<TodoList />
</>
);
return (
<>
<Helmet>
<title>Home page</title>
</Helmet>
<h1 data-testid="page-title">Home</h1>
<p>This is the list.</p>
<TodoList />
</>
);
};