Skip to content

Commit e81bf99

Browse files
fix: coverage reporting (SSENSE#413)
* chore: mixin coverage now 100% * chore: fix coverage reporting for .vue files * tests: add test for index.js * tests: add test for debounce util
1 parent 2091431 commit e81bf99

12 files changed

+1254
-587
lines changed

Diff for: babel.config.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
module.exports = (api) => {
2+
const isTest = api.env('test');
3+
4+
const config = {
5+
presets: [
6+
["@babel/preset-env", {
7+
targets: {
8+
"browsers": ["last 2 versions", "IE 11"]
9+
},
10+
useBuiltIns: "usage"
11+
}],
12+
],
13+
};
14+
15+
if(isTest) {
16+
api.cache.never();
17+
}
18+
19+
return config;
20+
};
21+

Diff for: jest.babelrc

-11
This file was deleted.

Diff for: package.json

+7-1
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,17 @@
3838
"regenerator-runtime": "^0.12.1",
3939
"vue": "^2.5.17"
4040
},
41+
"resolutions": {
42+
"babel-core": "7.0.0-bridge.0"
43+
},
4144
"devDependencies": {
4245
"@babel/core": "^7.0.0",
4346
"@babel/polyfill": "^7.0.0",
4447
"@babel/preset-env": "^7.0.0",
4548
"@vue/test-utils": "^1.0.0-beta.26",
49+
"babel-jest": "^24.5.0",
4650
"babel-loader": "^8.0.1",
51+
"babel-plugin-istanbul": "^5.1.1",
4752
"coveralls": "^3.0.1",
4853
"css-loader": "^1.0.0",
4954
"eslint": "^3.19.0",
@@ -59,14 +64,15 @@
5964
"husky": "^0.12.0",
6065
"isparta": "^4.0.0",
6166
"isparta-loader": "^2.0.0",
62-
"jest": "^23.5.0",
67+
"jest": "^24.5.0",
6368
"jest-serializer-vue": "^2.0.2",
6469
"lint-staged": "^8.1.0",
6570
"prettier": "^1.10.2",
6671
"prettier-eslint": "^8.8.1",
6772
"prettier-eslint-cli": "^4.7.0",
6873
"shelljs": "^0.7.5",
6974
"uglifyjs-webpack-plugin": "^1.3.0",
75+
"vue-jest": "^3.0.4",
7076
"vue-loader": "^15.3.0",
7177
"vue-play": "^3.2.1",
7278
"vue-play-cli": "^1.1.1",

Diff for: tests/client.jest.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
"verbose": true,
33
"rootDir": "../",
44
"transform": {
5-
".*\\.(js|vue)$": "<rootDir>/tests/preprocessor.js"
5+
"^.+\\.js?$": "babel-jest",
6+
"^.+\\.vue$": "vue-jest"
67
},
78
"snapshotSerializers": [
89
"jest-serializer-vue"
@@ -12,8 +13,7 @@
1213
"/debug/"
1314
],
1415
"collectCoverageFrom": [
15-
"src/*.vue",
16-
"src/mixins/*.js"
16+
"src/**/*.{vue,js}"
1717
],
1818
"moduleFileExtensions": [
1919
"node",
@@ -22,7 +22,7 @@
2222
"js"
2323
],
2424
"testRegex": ".*\\.spec.js$",
25-
"coverageDirectory": "<rootDir>/coverage/client",
25+
"coverageDirectory": "<rootDir>/coverage",
2626
"coverageReporters": [
2727
"json",
2828
"html",

Diff for: tests/client/components/carousel.spec.js

+25-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
/* eslint-disable */
22

33
import { mount, shallowMount } from '@vue/test-utils';
4-
5-
const Carousel = require('../../../src/Carousel.vue');
6-
const Slide = require('../../../src/Slide.vue');
7-
4+
import Carousel from '../../../src/Carousel.vue';
5+
import Slide from '../../../src/Slide.vue';
6+
87
describe('Carousel component', () => {
98
describe('Default mounting properties', () => {
109
it('should mount successfully', () => {
@@ -155,6 +154,27 @@ describe('Carousel component', () => {
155154
});
156155
});
157156

157+
it('should call start and pause when restarting autoplay', done => {
158+
const wrapper = mount(Carousel, {
159+
propsData: {
160+
perPage: 1,
161+
autoplay: true,
162+
autoplayHoverPause: false,
163+
autoplayDirection: 'test'
164+
},
165+
slots: {
166+
default: [Slide, Slide]
167+
}
168+
});
169+
170+
const spy = jest.spyOn(wrapper.vm, 'advancePage');
171+
wrapper.vm.autoplayAdvancePage();
172+
expect(spy).toHaveBeenCalledWith('test');
173+
174+
spy.mockRestore();
175+
done()
176+
});
177+
158178
it('should reset autoplay when switching slide without autoplayHoverPause', done => {
159179
const wrapper = mount(Carousel, {
160180
propsData: {
@@ -936,3 +956,4 @@ describe('Carousel component', () => {
936956
});
937957
});
938958
});
959+

Diff for: tests/client/components/navigation.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { shallowMount } from '@vue/test-utils';
22

3-
const Navigation = require('../../../src/Navigation');
3+
import Navigation from '../../../src/Navigation.vue';
44

55
describe('Navigation', () => {
66
let carousel;

Diff for: tests/client/components/slide.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { shallowMount } from '@vue/test-utils';
22

3-
const Slide = require('../../../src/Slide.vue');
3+
import Slide from '../../../src/Slide.vue';
44

55
describe('Slide', () => {
66
let carousel;

Diff for: tests/client/index.spec.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import index, { Carousel, Slide } from '../../src/index.js';
2+
import { createLocalVue } from '@vue/test-utils';
3+
4+
describe('index', () => {
5+
it('should export a slide component', () => {
6+
expect(Slide).toBeDefined()
7+
})
8+
9+
it('should export a Carousel component', () => {
10+
expect(Carousel).toBeDefined();
11+
});
12+
13+
it('Installs the defauly export as a plugin', () => {
14+
const vue = createLocalVue();
15+
vue.use(index);
16+
expect(vue.options.components.carousel).toBeDefined();
17+
expect(vue.options.components.slide).toBeDefined();
18+
})
19+
});

Diff for: tests/client/utils/.debounce.spec.js.swp

12 KB
Binary file not shown.

Diff for: tests/client/utils/debounce.spec.js

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import debounce from '../../../src/utils/debounce.js';
2+
3+
jest.useFakeTimers();
4+
5+
describe('debounce', () => {
6+
it('immediately calls the passed function if call now is true and no timeout is passed', () => {
7+
const testfn = jest.fn();
8+
const db = debounce(testfn, 0, true);
9+
db();
10+
expect(testfn).toHaveBeenCalled();
11+
});
12+
13+
it('calls the method in the passed amount of time', () => {
14+
const testfn = jest.fn();
15+
const db = debounce(testfn, 10000, false);
16+
db();
17+
jest.advanceTimersByTime(5000);
18+
expect(testfn).not.toBeCalled();
19+
20+
jest.advanceTimersByTime(5000);
21+
expect(testfn).toHaveBeenCalled();
22+
})
23+
});

Diff for: tests/preprocessor.js

-65
This file was deleted.

0 commit comments

Comments
 (0)