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

Update: Move some components to single test runner #4132

Merged
merged 9 commits into from
Mar 18, 2016
7 changes: 0 additions & 7 deletions client/components/accordion/Makefile

This file was deleted.

10 changes: 4 additions & 6 deletions client/components/accordion/test/index.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/* eslint-disable vars-on-top */
require( 'lib/react-test-env-setup' )();

/**
* External dependencies
*/
Expand All @@ -9,14 +6,15 @@ var expect = require( 'chai' ).expect,
React = require( 'react' ),
TestUtils = require( 'react-addons-test-utils' );

require( 'react-tap-event-plugin' )();

/**
* Internal dependencies
*/
var Accordion = require( '../' );

describe( 'Accordion', function() {
describe( 'index', function() {
require( 'react-tap-event-plugin' )();
require( 'test/helpers/use-fake-dom' )();

afterEach( function() {
ReactDom.unmountComponentAtNode( document.body );
} );
Expand Down
10 changes: 0 additions & 10 deletions client/components/bulk-select/Makefile

This file was deleted.

6 changes: 2 additions & 4 deletions client/components/bulk-select/test/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@

require( 'lib/react-test-env-setup' )();

/**
* External dependencies
*/
Expand All @@ -14,7 +11,8 @@ import noop from 'lodash/noop';
*/
import BulkSelect from '../index';

describe( 'BulkSelect', function() {
describe( 'index', function() {
require( 'test/helpers/use-fake-dom' )();
it( 'should have BulkSelect class', function() {
const bulkSelect = shallow( <BulkSelect selectedElements={ 0 } totalElements={ 3 } onToggle={ noop } /> );
assert.equal( 1, bulkSelect.find( '.bulk-select' ).length );
Expand Down
8 changes: 0 additions & 8 deletions client/components/data/media-list-data/Makefile

This file was deleted.

3 changes: 0 additions & 3 deletions client/components/data/media-list-data/test/index.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var expect = require( 'chai' ).expect;
/**
* Internal dependencies
*/
var utils = require( '../../utils' );
var utils = require( '../utils' );

describe( 'utils', function() {
describe( '#getMimeBaseTypeFromFilter()', function() {
Expand Down
7 changes: 0 additions & 7 deletions client/components/drop-zone/Makefile

This file was deleted.

35 changes: 12 additions & 23 deletions client/components/drop-zone/test/index.jsx
Original file line number Diff line number Diff line change
@@ -1,31 +1,18 @@
/* eslint-disable vars-on-top */
require( 'lib/react-test-env-setup' )( '<html><body><div id="container"></div></body></html>' );

/**
* External dependencies
*/
var expect = require( 'chai' ).expect,
ReactDom = require( 'react-dom' ),
React = require( 'react' ),
TestUtils = require( 'react-addons-test-utils' ),
sinon = require( 'sinon' );

/**
* Internal dependencies
*/
var DropZone = require( '../' );

/**
* Module variables
*/
var Wrapper = React.createClass( {
render: function() {
return <div>{ this.props.children }</div>;
}
} );
sinon = require( 'sinon' ),
DropZone = require( '../' ),
Wrapper = React.createClass( {
render: function() {
return <div>{ this.props.children }</div>;
}
} );

describe( 'DropZone', function() {
describe( 'index', function() {
var container, sandbox;
require( 'test/helpers/use-fake-dom' )( '<html><body><div id="container"></div></body></html>' );

before( function() {
DropZone.prototype.__reactAutoBindMap.translate = sinon.stub().returnsArg( 0 );
Expand All @@ -37,7 +24,9 @@ describe( 'DropZone', function() {
} );

after( function() {
delete window.MutationObserver;
if ( global.window && global.window.MutationObserver ) {
Copy link
Member

Choose a reason for hiding this comment

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

Not related to this PR, but maybe we should improve the way clean window document in useFakeDom helper to avoid manual cleaning?

/cc @aduth @blowery

Copy link
Contributor

Choose a reason for hiding this comment

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

Why did we have to do this in the first place? cleanup lets go of window, which holds MutationObserver...

Copy link
Contributor

Choose a reason for hiding this comment

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

It was needed in the original test, but I agree, with use-fake-dom performing the cleanup in after, this shouldn't be necessary.

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 know that window gets cleaned up and this won't get executed at all; it was semi-conscious decision to clean something up the test created explicitly.

We're kind of used to not cleaning up the tests since they used to live in different processes; I wanted this to be a good example that cleans up after itself.

Another argument might be that the consumer of use-fake-dom doesn't have to know which variables we are exposing and cleaning up; and should clean up the globals they've introduced.

I'm not feeling wrong strong with either, though.

Copy link
Contributor

Choose a reason for hiding this comment

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

ok, whew, i thought you had to do it for some odd reason.

I'd be wary of leaving stuff like this in there, just because someone coming across it later might think it was strictly necessary and spent a bunch of time and energy trying to figure out why it was done. But maybe not. 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@blowery Oh no. Definitely the reverse effect of what I intended. If that's the effect you had, we should definitely remove that.

delete global.window.MutationObserver;
}
delete DropZone.prototype.__reactAutoBindMap.translate;
} );

Expand Down
13 changes: 0 additions & 13 deletions client/components/forms/counted-textarea/Makefile

This file was deleted.

2 changes: 1 addition & 1 deletion client/components/forms/counted-textarea/test/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var React = require( 'react' ),
*/
var i18n = require( 'lib/mixins/i18n' );

describe( 'CountedTextarea', function() {
describe( 'index', function() {
var CountedTextarea, renderer;

before( function() {
Expand Down
7 changes: 0 additions & 7 deletions client/components/forms/form-toggle/Makefile

This file was deleted.

8 changes: 4 additions & 4 deletions client/components/forms/form-toggle/test/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@ var FormToggle = require( 'components/forms/form-toggle' ),
*/
var Wrapper = React.createClass( {
render: function() {
return <div>{this.props.children}</div>;
return <div>{ this.props.children }</div>;
}
} );

require( 'lib/react-test-env-setup' )();

describe( 'CompactFormToggle', function() {
describe( 'index', function() {
require( 'test/helpers/use-fake-dom' )();
describe( 'rendering', function() {
it( 'should have is-compact class', function() {
var toggle = TestUtils.renderIntoDocument( <CompactFormToggle /> ),
Expand All @@ -37,6 +36,7 @@ describe( 'CompactFormToggle', function() {
} );

describe( 'FormToggle', function() {
require( 'test/helpers/use-fake-dom' )();
afterEach( function() {
ReactDom.unmountComponentAtNode( document.body );
} );
Expand Down
7 changes: 0 additions & 7 deletions client/components/forms/multi-checkbox/Makefile

This file was deleted.

16 changes: 4 additions & 12 deletions client/components/forms/multi-checkbox/test/index.jsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,15 @@
require( 'lib/react-test-env-setup' )();

/**
* External dependencies
*/
var assert = require( 'assert' ),
ReactDom = require( 'react-dom' ),
React = require( 'react' ),
TestUtils = require( 'react-addons-test-utils' );

/**
* Internal dependencies
*/
var MultiCheckbox = require( '../' );
TestUtils = require( 'react-addons-test-utils' ),
MultiCheckbox = require( '../' );

describe( 'MultiCheckbox', function() {
describe( 'index', function() {
var options = [
{ value: 1, label: 'One' },
{ value: 2, label: 'Two' }
];
require( 'test/helpers/use-fake-dom' )();

afterEach( function() {
ReactDom.unmountComponentAtNode( document.body );
Expand Down
7 changes: 0 additions & 7 deletions client/components/forms/range/Makefile

This file was deleted.

9 changes: 4 additions & 5 deletions client/components/forms/range/test/index.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require( 'lib/react-test-env-setup' )();

/**
* External dependencies
*/
Expand All @@ -13,7 +11,8 @@ var expect = require( 'chai' ).expect,
*/
var FormRange = require( '../' );

describe( 'Range', function() {
describe( 'index', function() {
require( 'test/helpers/use-fake-dom' )();
afterEach( function() {
ReactDom.unmountComponentAtNode( document.body );
} );
Expand All @@ -28,7 +27,7 @@ describe( 'Range', function() {
content = TestUtils.scryRenderedDOMComponentsWithClass( range, 'range__content' );

expect( content ).to.have.length( 1 );
expect( content[0].props.className ).to.contain( 'is-min' );
expect( content[0].getAttribute( 'class' ) ).to.contain( 'is-min' );
} );

it( 'should render ending content if passed a `maxContent` prop', function() {
Expand All @@ -41,7 +40,7 @@ describe( 'Range', function() {
content = TestUtils.scryRenderedDOMComponentsWithClass( range, 'range__content' );

expect( content ).to.have.length( 1 );
expect( content[0].props.className ).to.contain( 'is-max' );
expect( content[0].getAttribute( 'class' ) ).to.contain( 'is-max' );
} );

it( 'should render a value label if passed a truthy `showValueLabel` prop', function() {
Expand Down
28 changes: 28 additions & 0 deletions client/tests.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,34 @@
"domain-suggestion": {
"test": [ "index" ]
}
},
"accordion": {
"test": [ "index" ]
},
"bulk-select": {
"test": [ "index" ]
},
"data": {
"media-list-data": {
"test": [ "utils" ]
}
},
"drop-zone": {
"test": [ "index" ]
},
"forms": {
"counted-textarea": {
"test": [ "index" ]
},
"form-toggle": {
"test": [ "index" ]
},
"multi-checkbox": {
"test": [ "index" ]
},
"range": {
"test": [ "index" ]
}
}
},
"lib": {
Expand Down