Skip to content

Commit ff8fb9a

Browse files
authored
Merge pull request #90 from bad4iz/feature/vitest-coverage-file-without-test_#89
#89: exaple coverage without test
2 parents 17afa47 + fde1422 commit ff8fb9a

File tree

4 files changed

+71
-9
lines changed

4 files changed

+71
-9
lines changed

.github/workflows/test-pr.yml

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: 'Test'
1+
name: Test
22
on:
33
pull_request:
44

@@ -7,9 +7,7 @@ jobs:
77
runs-on: ubuntu-latest
88

99
permissions:
10-
# Required to checkout the code
1110
contents: read
12-
# Required to put a comment into the pull-request
1311
pull-requests: write
1412

1513
steps:
@@ -18,10 +16,16 @@ jobs:
1816
uses: actions/setup-node@v2
1917
with:
2018
node-version: '18.x'
19+
# - name: Fetch develop branch
20+
# run: git fetch origin develop
21+
# - name: develop branch
22+
# run: git branch develop origin/develop
23+
# - name: Git diff
24+
# run: git diff --name-only origin/develop HEAD
2125
- name: 'Install Deps'
2226
run: npm install
2327
- name: 'Test'
24-
run: npx vitest --coverage
28+
run: npx vitest --coverage.enabled --changed
2529
- name: 'Report Coverage'
26-
if: always() # Also generate the report if tests are failing
30+
if: always()
2731
uses: davelosert/vitest-coverage-report-action@v1

src/component/SelectCert.Copy.tsx

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import React, { FC, ReactElement, useEffect, useState } from 'react';
2+
3+
/* eslint-disable */
4+
import Select from './Select';
5+
import { ISelectCertProps, ThumbprintType, ValueSelectI } from './types';
6+
import { useDoCertsList } from './utils/hooks';
7+
8+
/**
9+
* Селектор выбора сертификата подписи.
10+
* @param {ISelectCertProps} props - Props.
11+
* @param {ISelectCertProps.setThumbprint} props.setThumbprint - Функция прокидывания подписи.
12+
* @param {ISelectCertProps.Component} props.Component - Select для.
13+
* @param {ISelectCertProps.callbackError} props.callbackError - Callback error - для перехвата ошибок.
14+
* @param {ISelectCertProps.value} props.value - Значения.
15+
* @returns {FC} A.
16+
*/
17+
const SelectCert: FC<ISelectCertProps> = ({
18+
setThumbprint = () => {},
19+
Component = Select,
20+
callbackError = () => {},
21+
value,
22+
}): ReactElement => {
23+
const [listCert, setListCert] = useState<ValueSelectI[]>([
24+
{ value: 'подпись', label: 'подпись' },
25+
]);
26+
27+
const [selectItem, setSelectItem] = useState<ThumbprintType | null>(null);
28+
29+
useDoCertsList()
30+
.then(setListCert)
31+
.catch((e) => callbackError(String(e)));
32+
33+
useEffect(() => {
34+
if (selectItem) {
35+
setThumbprint(selectItem);
36+
} else {
37+
setThumbprint(listCert[0].value);
38+
}
39+
}, [selectItem, listCert, setThumbprint]);
40+
41+
const onChange = (value: ThumbprintType) => {
42+
callbackError();
43+
setSelectItem(value);
44+
};
45+
46+
return (
47+
<Component
48+
defaultValue={listCert[0].value}
49+
label="Выберите сертификат"
50+
name="thumbprint"
51+
onChange={onChange}
52+
options={listCert}
53+
value={value}
54+
/>
55+
);
56+
};
57+
58+
export default SelectCert;

src/component/utils/b64toBlob.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
* @param b64Data - Blob data.
44
* @param contentType - Content type.
55
* @param sliceSize - Size of the slice.
6-
* @returns Конвертируемые данные в Blob.
7-
* @example ---
6+
* @returns Конвертируемые данные в Blob.
7+
* @example -----
88
* const sign = await certsApi.signBase64(thumbprint, sBase64Data);
99
* const contentType = type.split(':')[1]
1010
* const blob = b64toBlob(sign, contentType)

vitest.config.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ import { defineConfig } from 'vitest/config';
33

44
export default defineConfig({
55
test: {
6-
environment: 'happy-dom', // or 'jsdom', 'node'
76
coverage: {
87
// you can include other reporters, but 'json-summary' is required, json is recommended
8+
all: false,
99
reporter: ['json-summary', 'text', 'html', 'json', 'cobertura'],
10-
all: true,
1110
},
11+
environment: 'happy-dom', // or 'jsdom', 'node'
1212
},
1313
});

0 commit comments

Comments
 (0)