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

Fix browser tests (Karma + Webpack setup). #1109

Merged
merged 4 commits into from
Apr 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,3 @@ matrix:
- node_js: "9"
- node_js: "7"
- node_js: "iojs"
- env: KARMA=true TEST=false
7 changes: 1 addition & 6 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,7 @@ module.exports = (config) => {

frameworks: ['mocha', 'sinon', 'chai'],

files: [
'test/_helpers/registerReactWithStylesInterface.js',
'test/_helpers/restoreSinonStubs.js',
'test/utils/*',
'test/components/*',
],
files: ['test/browser-main.js'],

webpack: {
externals: {
Expand Down
6 changes: 0 additions & 6 deletions test/_helpers/ignoreSVGStrings.jsx

This file was deleted.

6 changes: 6 additions & 0 deletions test/browser-main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const requireAll = requireContext => requireContext.keys().forEach(requireContext);

if (typeof window !== 'undefined') {
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'd rather use Mocha's --exclude option (mochajs/mocha#3210) once it lands instead of this.

Copy link
Member

Choose a reason for hiding this comment

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

Mocha has dropped older node versions so we shouldn’t be upgrading too far on it; this approach is fine.

Copy link
Contributor Author

@joaovieira joaovieira Apr 9, 2018

Choose a reason for hiding this comment

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

Fair enough 👍

Edit: Just checking. Mocha supports node >= 4. react-dates has dependencies that only support node >= 4 as well (enzyme-adapter-react-helper > install-peerdeps > has-yarn) - which is causing the iojs tests to fail https://travis-ci.org/airbnb/react-dates/jobs/363589154#L4426).

Copy link
Member

Choose a reason for hiding this comment

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

that is true; but that is something i'm still working on fixing :-)

requireAll(require.context('./_helpers', true, /.jsx?$/));
requireAll(require.context('.', true, /.jsx?$/));
}
4 changes: 2 additions & 2 deletions test/components/DateRangePicker_spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import {
const requiredProps = {
onDatesChange: () => {},
onFocusChange: () => {},
startDateId: 'startDate',
endDateId: 'endDate',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

required

};

describe('DateRangePicker', () => {
Expand Down Expand Up @@ -316,7 +318,6 @@ describe('DateRangePicker', () => {
const wrapper = shallow((
<DateRangePicker
{...requiredProps}
onDateChange={sinon.stub()}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

not used; also onDateChange does not exist for DateRangePicker anymore

onFocusChange={sinon.stub()}
keepFocusOnInput
/>
Expand All @@ -330,7 +331,6 @@ describe('DateRangePicker', () => {
const wrapper = shallow((
<DateRangePicker
{...requiredProps}
onDateChange={sinon.stub()}
onFocusChange={sinon.stub()}
keepFocusOnInput
withFullScreenPortal
Expand Down
8 changes: 4 additions & 4 deletions test/components/DayPickerKeyboardShortcuts_spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ describe('DayPickerKeyboardShortcuts', () => {
});

afterEach(() => {
openKeyboardShortcutsPanelStub.reset();
openKeyboardShortcutsPanelStub.resetHistory();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

sinon.reset() has been deprecated

});

it('onClick calls onShowKeyboardShortcutsButtonClick', () => {
Expand Down Expand Up @@ -205,9 +205,9 @@ describe('DayPickerKeyboardShortcuts', () => {
});

afterEach(() => {
closeKeyboardShortcutsPanelStub.reset();
event.stopPropagation.reset();
event.preventDefault.reset();
closeKeyboardShortcutsPanelStub.resetHistory();
event.stopPropagation.resetHistory();
event.preventDefault.resetHistory();
});

it('onClick calls onShowKeyboardShortcutsButtonClick', () => {
Expand Down
52 changes: 26 additions & 26 deletions test/components/DayPickerRangeController_spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ describe('DayPickerRangeController', () => {
'getStateForNewMonth',
);
const wrapper = shallow(<DayPickerRangeController {...props} focusedInput={null} />);
getStateForNewMonthSpy.reset();
getStateForNewMonthSpy.resetHistory();
wrapper.instance().componentWillReceiveProps({
...props,
focusedInput: START_DATE,
Expand Down Expand Up @@ -162,7 +162,7 @@ describe('DayPickerRangeController', () => {
'getStateForNewMonth',
);
const wrapper = shallow(<DayPickerRangeController {...props} focusedInput={null} />);
getStateForNewMonthSpy.reset();
getStateForNewMonthSpy.resetHistory();
wrapper.instance().componentWillReceiveProps({
...props,
focusedInput: null,
Expand Down Expand Up @@ -216,7 +216,7 @@ describe('DayPickerRangeController', () => {
'getStateForNewMonth',
);
const wrapper = shallow(<DayPickerRangeController {...props} />);
getStateForNewMonthSpy.reset();
getStateForNewMonthSpy.resetHistory();
wrapper.instance().componentWillReceiveProps({
...props,
numberOfMonths: 5,
Expand Down Expand Up @@ -262,7 +262,7 @@ describe('DayPickerRangeController', () => {
it('calls getStateForNewMonth with nextProps', () => {
const getStateForNewMonthSpy = sinon.spy(DayPickerRangeController.prototype, 'getStateForNewMonth');
const wrapper = shallow(<DayPickerRangeController {...props} />);
getStateForNewMonthSpy.reset();
getStateForNewMonthSpy.resetHistory();
wrapper.instance().componentWillReceiveProps({
...props,
enableOutsideDays: true,
Expand Down Expand Up @@ -313,7 +313,7 @@ describe('DayPickerRangeController', () => {
minimumNights={minimumNights}
/>
));
deleteModifierFromRangeSpy.reset();
deleteModifierFromRangeSpy.resetHistory();
wrapper.instance().componentWillReceiveProps({
...props,
startDate: nextStartDate,
Expand Down Expand Up @@ -748,7 +748,7 @@ describe('DayPickerRangeController', () => {
it('does not call isBlocked', () => {
const isBlockedStub = sinon.stub(DayPickerRangeController.prototype, 'isBlocked');
const wrapper = shallow(<DayPickerRangeController {...props} />);
isBlockedStub.reset();
isBlockedStub.resetHistory();
wrapper.instance().componentWillReceiveProps({
...props,
});
Expand All @@ -774,7 +774,7 @@ describe('DayPickerRangeController', () => {
const isBlockedStub = sinon.stub(DayPickerRangeController.prototype, 'isBlocked');
const wrapper = shallow(<DayPickerRangeController {...props} />);
wrapper.setState({ visibleDays });
isBlockedStub.reset();
isBlockedStub.resetHistory();
wrapper.instance().componentWillReceiveProps({
...props,
focusedInput: END_DATE,
Expand Down Expand Up @@ -1578,7 +1578,7 @@ describe('DayPickerRangeController', () => {
wrapper.setState({
hoverDate: null,
});
addModifierSpy.reset();
addModifierSpy.resetHistory();
wrapper.instance().onDayMouseEnter(today);
expect(addModifierSpy.callCount).to.equal(1);
expect(addModifierSpy.getCall(0).args[1]).to.equal(today);
Expand All @@ -1595,7 +1595,7 @@ describe('DayPickerRangeController', () => {
wrapper.setState({
hoverDate: today,
});
deleteModifierSpy.reset();
deleteModifierSpy.resetHistory();
wrapper.instance().onDayMouseEnter(moment().add(10, 'days'));
expect(deleteModifierSpy.callCount).to.equal(1);
expect(deleteModifierSpy.getCall(0).args[1]).to.equal(today);
Expand All @@ -1619,7 +1619,7 @@ describe('DayPickerRangeController', () => {
/>
));
wrapper.setState({ hoverDate });
deleteModifierFromRangeSpy.reset();
deleteModifierFromRangeSpy.resetHistory();
wrapper.instance().onDayMouseEnter(moment().add(10, 'days'));
const hoverSpanCalls = getCallsByModifier(deleteModifierFromRangeSpy, 'hovered-span');
expect(hoverSpanCalls.length).to.equal(1);
Expand All @@ -1644,7 +1644,7 @@ describe('DayPickerRangeController', () => {
/>
));
wrapper.setState({ hoverDate: null });
addModifierToRangeSpy.reset();
addModifierToRangeSpy.resetHistory();
wrapper.instance().onDayMouseEnter(hoverDate);
const hoverSpanCalls = getCallsByModifier(addModifierToRangeSpy, 'hovered-span');
expect(hoverSpanCalls.length).to.equal(1);
Expand All @@ -1670,7 +1670,7 @@ describe('DayPickerRangeController', () => {
/>
));
wrapper.setState({ hoverDate });
deleteModifierFromRangeSpy.reset();
deleteModifierFromRangeSpy.resetHistory();
wrapper.instance().onDayMouseEnter(moment().add(10, 'days'));
expect(deleteModifierFromRangeSpy.callCount).to.equal(1);
expect(deleteModifierFromRangeSpy.getCall(0).args[1]).to.equal(hoverDate);
Expand All @@ -1694,7 +1694,7 @@ describe('DayPickerRangeController', () => {
/>
));
wrapper.setState({ hoverDate: null });
addModifierToRangeSpy.reset();
addModifierToRangeSpy.resetHistory();
wrapper.instance().onDayMouseEnter(hoverDate);
expect(addModifierToRangeSpy.callCount).to.equal(1);
expect(addModifierToRangeSpy.getCall(0).args[1]).to.equal(hoverDate);
Expand All @@ -1717,7 +1717,7 @@ describe('DayPickerRangeController', () => {
minimumNights={minimumNights}
/>
));
deleteModifierFromRangeSpy.reset();
deleteModifierFromRangeSpy.resetHistory();
wrapper.instance().onDayMouseEnter(today);
const afterHoverStartCalls = getCallsByModifier(deleteModifierFromRangeSpy, 'after-hovered-start');
expect(afterHoverStartCalls.length).to.equal(0);
Expand All @@ -1741,7 +1741,7 @@ describe('DayPickerRangeController', () => {
minimumNights={minimumNights}
/>
));
addModifierToRangeSpy.reset();
addModifierToRangeSpy.resetHistory();
wrapper.instance().onDayMouseEnter(startDate);
const afterHoverStartCalls = getCallsByModifier(addModifierToRangeSpy, 'after-hovered-start');
expect(afterHoverStartCalls.length).to.equal(1);
Expand All @@ -1764,7 +1764,7 @@ describe('DayPickerRangeController', () => {
minimumNights={minimumNights}
/>
));
addModifierToRangeSpy.reset();
addModifierToRangeSpy.resetHistory();
wrapper.instance().onDayMouseEnter(today);
const afterHoverStartCalls = getCallsByModifier(addModifierToRangeSpy, 'after-hovered-start');
expect(afterHoverStartCalls.length).to.equal(0);
Expand Down Expand Up @@ -1797,7 +1797,7 @@ describe('DayPickerRangeController', () => {
wrapper.setState({
hoverDate: today,
});
deleteModifierSpy.reset();
deleteModifierSpy.resetHistory();
wrapper.instance().onDayMouseLeave(today);
expect(deleteModifierSpy.callCount).to.equal(1);
expect(deleteModifierSpy.getCall(0).args[1]).to.equal(today);
Expand All @@ -1819,7 +1819,7 @@ describe('DayPickerRangeController', () => {
/>
));
wrapper.setState({ hoverDate });
deleteModifierFromRangeSpy.reset();
deleteModifierFromRangeSpy.resetHistory();
wrapper.instance().onDayMouseLeave(today);
const hoveredSpanCalls = getCallsByModifier(deleteModifierFromRangeSpy, 'hovered-span');
expect(hoveredSpanCalls.length).to.equal(1);
Expand All @@ -1842,7 +1842,7 @@ describe('DayPickerRangeController', () => {
/>
));
wrapper.setState({ hoverDate });
deleteModifierFromRangeSpy.reset();
deleteModifierFromRangeSpy.resetHistory();
wrapper.instance().onDayMouseLeave(today);
expect(deleteModifierFromRangeSpy.callCount).to.equal(1);
expect(deleteModifierFromRangeSpy.getCall(0).args[1]).to.equal(hoverDate);
Expand All @@ -1868,7 +1868,7 @@ describe('DayPickerRangeController', () => {
/>
));
wrapper.setState({ hoverDate: today });
deleteModifierFromRangeSpy.reset();
deleteModifierFromRangeSpy.resetHistory();
wrapper.instance().onDayMouseLeave(startDate);
const afterHoverStartCalls = getCallsByModifier(deleteModifierFromRangeSpy, 'after-hovered-start');
expect(afterHoverStartCalls.length).to.equal(1);
Expand All @@ -1891,7 +1891,7 @@ describe('DayPickerRangeController', () => {
/>
));
wrapper.setState({ hoverDate: today });
deleteModifierFromRangeSpy.reset();
deleteModifierFromRangeSpy.resetHistory();
wrapper.instance().onDayMouseLeave(today);
const afterHoverStartCalls = getCallsByModifier(deleteModifierFromRangeSpy, 'after-hovered-start');
expect(afterHoverStartCalls.length).to.equal(0);
Expand All @@ -1911,7 +1911,7 @@ describe('DayPickerRangeController', () => {
/>
));
wrapper.setState({ hoverDate: today });
deleteModifierFromRangeSpy.reset();
deleteModifierFromRangeSpy.resetHistory();
wrapper.instance().onDayMouseLeave(today);
const afterHoverStartCalls = getCallsByModifier(deleteModifierFromRangeSpy, 'after-hovered-start');
expect(afterHoverStartCalls.length).to.equal(0);
Expand Down Expand Up @@ -1979,7 +1979,7 @@ describe('DayPickerRangeController', () => {
onFocusChange={sinon.stub()}
/>
));
getModifiersSpy.reset();
getModifiersSpy.resetHistory();
wrapper.instance().onPrevMonthClick();
expect(getModifiersSpy.callCount).to.equal(1);
});
Expand Down Expand Up @@ -2061,7 +2061,7 @@ describe('DayPickerRangeController', () => {
onFocusChange={sinon.stub()}
/>
));
getModifiersSpy.reset();
getModifiersSpy.resetHistory();
wrapper.instance().onNextMonthClick();
expect(getModifiersSpy.callCount).to.equal(1);
});
Expand Down Expand Up @@ -2182,7 +2182,7 @@ describe('DayPickerRangeController', () => {
onDatesChange={sinon.stub()}
/>
));
isBlockedStub.reset();
isBlockedStub.resetHistory();
isBlockedStub.returns(true).onCall(8).returns(false);

const firstFocusableDay = wrapper.instance().getFirstFocusableDay(today);
Expand Down Expand Up @@ -2219,7 +2219,7 @@ describe('DayPickerRangeController', () => {
onFocusChange={sinon.stub()}
/>
));
getModifiersForDaySpy.reset();
getModifiersForDaySpy.resetHistory();
wrapper.instance().getModifiers(visibleDays);

expect(getModifiersForDaySpy.callCount).to.equal(visibleDays[monthISO].length);
Expand Down
18 changes: 9 additions & 9 deletions test/components/DayPickerSingleDateController_spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ describe('DayPickerSingleDateController', () => {
it('does not call isBlocked', () => {
const isBlockedStub = sinon.stub(DayPickerSingleDateController.prototype, 'isBlocked');
const wrapper = shallow(<DayPickerSingleDateController {...props} />);
isBlockedStub.reset();
isBlockedStub.resetHistory();
wrapper.instance().componentWillReceiveProps({
...props,
});
Expand All @@ -120,7 +120,7 @@ describe('DayPickerSingleDateController', () => {
const isBlockedStub = sinon.stub(DayPickerSingleDateController.prototype, 'isBlocked');
const wrapper = shallow(<DayPickerSingleDateController {...props} />);
wrapper.setState({ visibleDays });
isBlockedStub.reset();
isBlockedStub.resetHistory();
wrapper.instance().componentWillReceiveProps({
...props,
focused: true,
Expand Down Expand Up @@ -620,7 +620,7 @@ describe('DayPickerSingleDateController', () => {
wrapper.setState({
hoverDate: null,
});
addModifierSpy.reset();
addModifierSpy.resetHistory();
wrapper.instance().onDayMouseEnter(today);
expect(addModifierSpy.callCount).to.equal(1);
expect(addModifierSpy.getCall(0).args[1]).to.equal(today);
Expand All @@ -638,7 +638,7 @@ describe('DayPickerSingleDateController', () => {
wrapper.setState({
hoverDate: today,
});
deleteModifierSpy.reset();
deleteModifierSpy.resetHistory();
wrapper.instance().onDayMouseEnter(moment().add(10, 'days'));
expect(deleteModifierSpy.callCount).to.equal(1);
expect(deleteModifierSpy.getCall(0).args[1]).to.equal(today);
Expand Down Expand Up @@ -670,7 +670,7 @@ describe('DayPickerSingleDateController', () => {
wrapper.setState({
hoverDate: today,
});
deleteModifierSpy.reset();
deleteModifierSpy.resetHistory();
wrapper.instance().onDayMouseLeave(today);
expect(deleteModifierSpy.callCount).to.equal(1);
expect(deleteModifierSpy.getCall(0).args[1]).to.equal(today);
Expand Down Expand Up @@ -736,7 +736,7 @@ describe('DayPickerSingleDateController', () => {
onFocusChange={sinon.stub()}
/>
));
getModifiersSpy.reset();
getModifiersSpy.resetHistory();
wrapper.instance().onPrevMonthClick();
expect(getModifiersSpy.callCount).to.equal(1);
});
Expand Down Expand Up @@ -818,7 +818,7 @@ describe('DayPickerSingleDateController', () => {
onFocusChange={sinon.stub()}
/>
));
getModifiersSpy.reset();
getModifiersSpy.resetHistory();
wrapper.instance().onNextMonthClick();
expect(getModifiersSpy.callCount).to.equal(1);
});
Expand Down Expand Up @@ -883,7 +883,7 @@ describe('DayPickerSingleDateController', () => {
/>
));

isBlockedStub.reset();
isBlockedStub.resetHistory();
isBlockedStub.returns(true);
isBlockedStub.onCall(8).returns(false);
const firstFocusableDay = wrapper.instance().getFirstFocusableDay(today);
Expand Down Expand Up @@ -920,7 +920,7 @@ describe('DayPickerSingleDateController', () => {
onFocusChange={sinon.stub()}
/>
));
getModifiersForDaySpy.reset();
getModifiersForDaySpy.resetHistory();
wrapper.instance().getModifiers(visibleDays);

expect(getModifiersForDaySpy.callCount).to.equal(visibleDays[monthISO].length);
Expand Down