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

Increase test coverage #451

Merged
merged 30 commits into from
Apr 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
6364992
Migrate to jest and increase test coverage
Apr 29, 2020
4f65d2a
Remove not used methods from Carousel
Apr 29, 2020
aa6f1bd
Generate lcov report
Apr 29, 2020
a2c385c
Add coverage badge
Apr 29, 2020
7028a6d
Fix CI config
Apr 29, 2020
f42780b
Update yarn.lock
Apr 29, 2020
35abb74
Update test/unit/carousel.test.js
Apr 30, 2020
f959adb
toEqual(true) -> toBeTruthy();
Apr 30, 2020
8c5a37b
Merge remote-tracking branch 'origin/fix/increase-test-coverage' into…
Apr 30, 2020
4b8c039
Update test/unit/carousel.test.js
Apr 30, 2020
38231d3
Update test/unit/carousel.test.js
Apr 30, 2020
c287545
Update test/unit/carousel.test.js
Apr 30, 2020
e4307e8
Update test/unit/carousel.test.js
Apr 30, 2020
e01d13a
Update test/unit/carousel.test.js
Apr 30, 2020
0b8609c
Update test/unit/carousel.test.js
Apr 30, 2020
ee618aa
Update test/unit/carousel.test.js
Apr 30, 2020
d36b62e
Update test/unit/carousel.test.js
Apr 30, 2020
910d4be
Update test/unit/carousel.test.js
Apr 30, 2020
49bb9d0
Update test/unit/carousel.test.js
Apr 30, 2020
f130910
Update test/unit/carousel.test.js
Apr 30, 2020
6210c26
Update test/unit/carousel.test.js
Apr 30, 2020
5ad9446
Update test/unit/carousel.test.js
Apr 30, 2020
4855f82
Update test/unit/carousel.test.js
Apr 30, 2020
6219a47
Update test/unit/carousel.test.js
Apr 30, 2020
5c9be25
Update test/unit/carousel.test.js
Apr 30, 2020
1e225fd
Update test/unit/carousel.test.js
Apr 30, 2020
65aeeec
Update test/unit/carousel.test.js
Apr 30, 2020
14ee0fb
Update test/unit/carousel.test.js
Apr 30, 2020
2b20850
Update test/unit/carousel.test.js
Apr 30, 2020
4c6119f
Update test/unit/carousel.test.js
Apr 30, 2020
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
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
- checkout
- run: yarn install --non-interactive
- run: yarn lint
- run: yarn test:unit:coverage:ci
- run: yarn test:unit:coverage
- run:
name: Generate coveralls config
command: "echo repo_token: $COVERALLS_REPO_TOKEN > ./.coveralls.yml"
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](http://makeapullrequest.com)
[![Renovate enabled](https://img.shields.io/badge/renovate-enabled-brightgreen.svg)](https://renovatebot.com/)

[![Coveralls github](https://img.shields.io/coveralls/github/brainhubeu/react-carousel.svg)](https://coveralls.io/github/brainhubeu/react-carousel?branch=master)
[![Downloads](https://img.shields.io/npm/dm/@brainhubeu/react-carousel?color=blue)](https://www.npmjs.com/package/@brainhubeu/react-carousel)
[![Activity](https://img.shields.io/github/commit-activity/m/brainhubeu/react-carousel.svg)](https://github.com/brainhubeu/react-carousel/commits/master)
[![Minified](https://img.shields.io/bundlephobia/min/@brainhubeu/react-carousel?label=minified)](https://www.npmjs.com/package/@brainhubeu/react-carousel)
Expand Down
13 changes: 13 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
testEnvironment: 'node',
testMatch: ['<rootDir>/test/unit/**.test.js'],
moduleNameMapper: { '\\.(css|scss)$': '<rootDir>/test/unit/__mocks__/styleMock.js' },
setupFilesAfterEnv: [
'<rootDir>/jest.setup.js',
],
coverageReporters: [
'text',
['lcov', {
projectRoot: './',
}]],
};
4 changes: 4 additions & 0 deletions jest.setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { configure } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';

configure({ adapter: new Adapter() });
9 changes: 3 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@
"build": "node tools/build.js",
"cypress:open": "cypress open",
"cypress:run": "cypress run",
"test:unit": "mocha tools/testSetup.js \"./test/unit/*.js\" --exit",
"test:unit": "jest",
"test:e2e": "start-server-and-test start-test-app http://localhost:8000 cypress:run",
"test-dockerized:e2e": "docker-compose -f ./docker-compose.e2e.yml up --build --exit-code-from e2e-test",
"test:unit:coverage": "nyc --reporter=text-summary yarn test:unit",
"test:unit:coverage:ci": "nyc --reporter=lcov --reporter=text-summary yarn test:unit",
"test:unit:coverage": "yarn jest --coverage",
"start-test-app": "yarn --cwd docs-www develop",
"precommit": "npm run lint"
},
Expand Down Expand Up @@ -59,9 +58,9 @@
"html-webpack-plugin": "^4.2.0",
"husky": "^4.2.5",
"isparta": "^4.1.1",
"jest": "^25.4.0",
"jsdom": "^16.2.2",
"lodash": "^4.17.15",
"mocha": "^7.1.1",
"node-sass": "^4.13.1",
"nyc": "^15.0.1",
"postcss-loader": "^3.0.0",
Expand All @@ -71,8 +70,6 @@
"react-test-renderer": "^16.13.1",
"rimraf": "3.0.2",
"sass-loader": "^8.0.2",
"sinon": "^9.0.2",
"sinon-chai": "^3.5.0",
"start-server-and-test": "^1.11.0",
"style-loader": "^1.1.4",
"uglifyjs-webpack-plugin": "^2.2.0",
Expand Down
30 changes: 0 additions & 30 deletions src/components/Carousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,19 +232,6 @@ class Carousel extends Component {
? this.getCurrentSlideIndex() + this.getClonesLeft() * this.getChildren().length
: this.getCurrentSlideIndex();

/* infinite calculations */
getSlidesBounds = (customValue = null) => {
const value = isNil(customValue) ? this.getCurrentValue() : customValue;
const length = this.getChildren().length;
const times = ((value + 1) / length);
const ceil = Math.ceil(times);

return {
low: (ceil - 1) * length,
high: ceil * length - 1,
};
};

getTargetMod = (customValue = null) => {
const value = isNil(customValue) ? this.getCurrentValue() : customValue;
const length = this.getChildren().length;
Expand Down Expand Up @@ -330,23 +317,6 @@ class Carousel extends Component {
}));
};

/**
* Function handling touch move if drag has started. Sets dragOffset in the state.
* @param {event} e event
*/
onTouchMove = e => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are these removed methods unneeded?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested the deployed version and it seems it works as expected. Also tests e2e are passing so I guess everything works all right

if (Math.abs(this.state.dragOffset) > this.props.minDraggableOffset) {
e.preventDefault();
e.stopPropagation();
}
const { changedTouches } = e;
if (this.state.dragStart !== null) {
this.setState(previousState => ({
dragOffset: this.getProp('rtl') ? previousState.dragStart - changedTouches[0].pageX : changedTouches[0].pageX - previousState.dragStart,
}));
}
};

/**
* Function handling end of touch or mouse drag. If drag was long it changes current slide to the nearest one,
* if drag was short (or it was just a click) it changes slide to the clicked (or touched) one.
Expand Down
8 changes: 0 additions & 8 deletions test/.eslintrc

This file was deleted.

1 change: 1 addition & 0 deletions test/unit/__mocks__/styleMock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = {};
Loading