-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Conversation
@@ -18,6 +18,8 @@ import { | |||
const requiredProps = { | |||
onDatesChange: () => {}, | |||
onFocusChange: () => {}, | |||
startDateId: 'startDate', | |||
endDateId: 'endDate', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
required
@@ -316,7 +318,6 @@ describe('DateRangePicker', () => { | |||
const wrapper = shallow(( | |||
<DateRangePicker | |||
{...requiredProps} | |||
onDateChange={sinon.stub()} |
There was a problem hiding this comment.
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
@@ -117,7 +117,7 @@ describe('DayPickerKeyboardShortcuts', () => { | |||
}); | |||
|
|||
afterEach(() => { | |||
openKeyboardShortcutsPanelStub.reset(); | |||
openKeyboardShortcutsPanelStub.resetHistory(); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, this is amazing. Just the one comment.
test/mocha.opts
Outdated
@@ -2,3 +2,4 @@ | |||
--compilers js:babel-register,jsx:babel-register | |||
--require airbnb-js-shims | |||
--recursive | |||
test/_helpers test/**/*_spec* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file needs a trailing newline; separately, the spec dir shouldn’t go here - i should be able to run mocha path/to/file
and not run every test (and I’d prefer ever file inside “test” get treated as a spec, not just ones following a naming convention)
eb9ba62
to
89986db
Compare
@@ -1,6 +0,0 @@ | |||
// Don't load svg strings into tests | |||
require.extensions['.svg'] = (obj) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
require.extensions
is node.js specific (does not work in webpack/browser). Though, it also seems it's not necessary anymore as enzyme fixed support for SVGs (enzymejs/enzyme#375)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The enzyme bug was on svg elements being present; this file makes svg files requirable in node, which is a different thing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for clarifying. Then isn't what this is doing as well https://github.com/airbnb/react-dates/blob/master/.babelrc#L6? The .svg
imports won't get to node.js - they'll be transformed before that in babel.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we weren't using the inline-svg plugin when this was first written so it's probable that it's no longer necessary.
@@ -0,0 +1,6 @@ | |||
const requireAll = requireContext => requireContext.keys().forEach(requireContext); | |||
|
|||
if (typeof window !== 'undefined') { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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 :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is really really great! :D Thank you so much for this clean-up.
@@ -1,6 +0,0 @@ | |||
// Don't load svg strings into tests | |||
require.extensions['.svg'] = (obj) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we weren't using the inline-svg plugin when this was first written so it's probable that it's no longer necessary.
TD;LR
This has the same problem as enzymejs/enzyme#1318. Solved using enzymejs/enzyme#1318 (comment).
This also:
mocha.opts
Explanation
When using a files array, each file is fed into the webpack config creating an isolated bundle. When a bundle executes it is independent from other bundles (i.e. even if we load
tests/enzymeSetup.js
it only sets up the adapter for that bundle) - or so it seems.Having a single bundle is also more efficient as webpack only needs to build once and there's no duplication.
The new entrypoint file is loading the tests the same way as mocha:
test/_helpers
*_spec
files intests