Skip to content

Commit dfa0152

Browse files
committed
refactor(project): add tests and other things
1 parent be92888 commit dfa0152

File tree

12 files changed

+2165
-265
lines changed

12 files changed

+2165
-265
lines changed

.eslintrc.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,16 @@ module.exports = {
22
env: {
33
browser: true,
44
es2020: true,
5+
'jest/globals': true
6+
},
7+
globals: {
8+
JestMockFn: true,
59
},
610
extends: [
711
'plugin:react/recommended',
812
'airbnb',
913
'plugin:prettier/recommended',
14+
'plugin:jest/recommended'
1015
],
1116
parserOptions: {
1217
ecmaFeatures: {
@@ -15,7 +20,7 @@ module.exports = {
1520
ecmaVersion: 11,
1621
sourceType: 'module',
1722
},
18-
plugins: ['react', 'react-hooks', 'prettier'],
23+
plugins: ['jest', 'react', 'react-hooks', 'prettier'],
1924
settings: {
2025
'import/resolver': {
2126
node: {

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,5 @@ yarn-debug.log*
2222
yarn-error.log*
2323

2424
.vercel
25+
26+
coverage

.versionrc.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module.exports = {
2+
types: [
3+
{type: 'feat', section: 'Features'},
4+
{type: 'fix', section: 'Bug Fixes'},
5+
{type: 'test', section: 'Tests'},
6+
{type: 'docs', section: 'Documentation'},
7+
{type: 'build', section: 'Build System'},
8+
{type: 'perf', section: 'Performance Issues'},
9+
{type: 'style', section: 'Styling'},
10+
{type: 'ci', section: 'Pipelines'},
11+
{type: 'refactor', section: 'Refactors'},
12+
],
13+
};

README.md

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88

99
---
1010

11+
| Statements | Branches | Functions | Lines |
12+
| --------------------------------------------------------------------- | ------------------------------------------------------------------- | -------------------------------------------------------------------- | ---------------------------------------------------------------- |
13+
| ![Statements](https://img.shields.io/badge/Coverage-64.65%25-red.svg) | ![Branches](https://img.shields.io/badge/Coverage-59.38%25-red.svg) | ![Functions](https://img.shields.io/badge/Coverage-57.58%25-red.svg) | ![Lines](https://img.shields.io/badge/Coverage-64.44%25-red.svg) |
14+
1115
## Table of Contents
1216

1317
- [Running example](#running-example)
@@ -20,9 +24,9 @@
2024

2125
## Running example
2226

23-
| Plain |
24-
| ------------------------------- |
25-
| ![Example](./assets/readme.gif) |
27+
| Plain |
28+
| --------------------------------------------------------------- |
29+
| ![Example](./assets/readme.gif) |
2630
| [Preview!](https://codesandbox.io/s/react-use-downloader-0zzoq) |
2731

2832
---
@@ -38,8 +42,8 @@ npm install --save react-use-downloader
3842
## Usage
3943

4044
```jsx
41-
import React from "react";
42-
import useDownloader from "react-use-downloader";
45+
import React from 'react';
46+
import useDownloader from 'react-use-downloader';
4347

4448
export default function App() {
4549
const {
@@ -49,21 +53,21 @@ export default function App() {
4953
download,
5054
cancel,
5155
error,
52-
isInProgress
56+
isInProgress,
5357
} = useDownloader();
5458

55-
const fileUrl = "https://olavoparno.github.io/saywololo/sounds/Wololo1.wav";
59+
const fileUrl =
60+
'https://upload.wikimedia.org/wikipedia/commons/4/4d/%D0%93%D0%BE%D0%B2%D0%B5%D1%80%D0%BB%D0%B0_%D1%96_%D0%9F%D0%B5%D1%82%D1%80%D0%BE%D1%81_%D0%B2_%D0%BF%D1%80%D0%BE%D0%BC%D1%96%D0%BD%D1%8F%D1%85_%D0%B2%D1%80%D0%B0%D0%BD%D1%96%D1%88%D0%BD%D1%8C%D0%BE%D0%B3%D0%BE_%D1%81%D0%BE%D0%BD%D1%86%D1%8F.jpg';
61+
const filename = 'beautiful-carpathia.jpg';
5662

5763
return (
5864
<div className="App">
5965
<p>Download is in {isInProgress ? 'in progress' : 'stopped'}</p>
60-
<button onClick={() => download(fileUrl, "filename")}>
66+
<button onClick={() => download(fileUrl, filename)}>
6167
Click to download the file
6268
</button>
6369
<button onClick={() => cancel()}>Cancel the download</button>
64-
<p>
65-
Download size in bytes {size}
66-
</p>
70+
<p>Download size in bytes {size}</p>
6771
<label for="file">Downloading progress:</label>
6872
<progress id="file" value={percentage} max="100" />
6973
<p>Elapsed time in seconds {elapsed}</p>
@@ -93,14 +97,14 @@ export default function App() {
9397

9498
```jsx
9599
const {
96-
size,
97-
elapsed,
98-
percentage,
99-
download,
100-
cancel,
101-
error,
102-
isInProgress
103-
} = useDownloader();
100+
size,
101+
elapsed,
102+
percentage,
103+
download,
104+
cancel,
105+
error,
106+
isInProgress,
107+
} = useDownloader();
104108
```
105109

106110
---

babel.config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = {
2+
presets: ["@babel/preset-env"],
3+
plugins: ["@babel/plugin-transform-runtime"]
4+
};

jest.config.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = {
2+
transform: {
3+
"^.+\\.(js|jsx)$": "babel-jest"
4+
},
5+
coverageReporters: [
6+
"json-summary"
7+
],
8+
};

0 commit comments

Comments
 (0)