Skip to content

Commit

Permalink
Chore: Upgrade ESLint to the latest version (6.1.0) (#16921)
Browse files Browse the repository at this point in the history
* Chore: Upgrade ESLint to the latest version (6.1.0)

* Refactor tests to use native describe.each functionality

* Enable jest/valid-describe rule again

* Use describe.each in more places

* Write describe name on one line

* Disable jest/valid-describe individually for special cases

* Fix typo

* Remove unused import

* Remove unnecessary nested describe

* Run npm install

* Chore: Fix package-lock.json file

* Fix failing e2e tests for navigable toolbar

* Fix JSDoc rule in ESLint plugin
  • Loading branch information
gziolo committed Aug 29, 2019
1 parent c6b57c3 commit 16ad2e1
Show file tree
Hide file tree
Showing 28 changed files with 633 additions and 407 deletions.
737 changes: 488 additions & 249 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
"deep-freeze": "0.0.1",
"doctrine": "2.1.0",
"enzyme": "3.9.0",
"eslint-plugin-jest": "21.5.0",
"eslint-plugin-jest": "22.14.1",
"espree": "4.0.0",
"fast-glob": "2.2.7",
"fbjs": "0.8.17",
Expand Down
4 changes: 2 additions & 2 deletions packages/block-editor/src/components/block-list/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ function BlockListBlock( {
// jsx-a11y/no-static-element-interactions:
// - Each block can be selected by clicking on it

/* eslint-disable jsx-a11y/mouse-events-have-key-events, jsx-a11y/no-static-element-interactions, jsx-a11y/onclick-has-role, jsx-a11y/click-events-have-key-events */
/* eslint-disable jsx-a11y/mouse-events-have-key-events, jsx-a11y/no-static-element-interactions, jsx-a11y/click-events-have-key-events */

return (
<IgnoreNestedEvents
Expand Down Expand Up @@ -618,7 +618,7 @@ function BlockListBlock( {
) }
</IgnoreNestedEvents>
);
/* eslint-enable jsx-a11y/mouse-events-have-key-events, jsx-a11y/no-static-element-interactions, jsx-a11y/onclick-has-role, jsx-a11y/click-events-have-key-events */
/* eslint-enable jsx-a11y/mouse-events-have-key-events, jsx-a11y/no-static-element-interactions, jsx-a11y/click-events-have-key-events */
}

const applyWithSelect = withSelect(
Expand Down
4 changes: 2 additions & 2 deletions packages/block-library/src/audio/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class AudioEdit extends Component {
);
}

/* eslint-disable jsx-a11y/no-static-element-interactions, jsx-a11y/onclick-has-role, jsx-a11y/click-events-have-key-events */
/* eslint-disable jsx-a11y/no-static-element-interactions, jsx-a11y/click-events-have-key-events */
return (
<>
<BlockControls>
Expand Down Expand Up @@ -210,7 +210,7 @@ class AudioEdit extends Component {
</figure>
</>
);
/* eslint-enable jsx-a11y/no-static-element-interactions, jsx-a11y/onclick-has-role, jsx-a11y/click-events-have-key-events */
/* eslint-enable jsx-a11y/no-static-element-interactions, jsx-a11y/click-events-have-key-events */
}
}
export default compose( [
Expand Down
4 changes: 2 additions & 2 deletions packages/block-library/src/image/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@ export class ImageEdit extends Component {
);

// Disable reason: Each block can be selected by clicking on it
/* eslint-disable jsx-a11y/no-static-element-interactions, jsx-a11y/onclick-has-role, jsx-a11y/click-events-have-key-events */
/* eslint-disable jsx-a11y/no-static-element-interactions, jsx-a11y/click-events-have-key-events */
return (
<>
{ controls }
Expand Down Expand Up @@ -924,7 +924,7 @@ export class ImageEdit extends Component {
{ mediaPlaceholder }
</>
);
/* eslint-enable jsx-a11y/no-static-element-interactions, jsx-a11y/onclick-has-role, jsx-a11y/click-events-have-key-events */
/* eslint-enable jsx-a11y/no-static-element-interactions, jsx-a11y/click-events-have-key-events */
}
}

Expand Down
4 changes: 2 additions & 2 deletions packages/block-library/src/video/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ class VideoEdit extends Component {
}
const videoPosterDescription = `video-block__poster-image-description-${ instanceId }`;

/* eslint-disable jsx-a11y/no-static-element-interactions, jsx-a11y/onclick-has-role, jsx-a11y/click-events-have-key-events */
/* eslint-disable jsx-a11y/no-static-element-interactions, jsx-a11y/click-events-have-key-events */
return (
<>
<BlockControls>
Expand Down Expand Up @@ -314,7 +314,7 @@ class VideoEdit extends Component {
</figure>
</>
);
/* eslint-enable jsx-a11y/no-static-element-interactions, jsx-a11y/onclick-has-role, jsx-a11y/click-events-have-key-events */
/* eslint-enable jsx-a11y/no-static-element-interactions, jsx-a11y/click-events-have-key-events */
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/block-serialization-default-parser/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ import { jsTester, phpTester } from '@wordpress/block-serialization-spec-parser/
*/
import { parse } from '../src';

describe( 'block-serialization-default-parser-js', jsTester( parse ) );
describe( 'block-serialization-default-parser-js', jsTester( parse ) ); // eslint-disable-line jest/valid-describe

phpTester( 'block-serialization-default-parser-php', path.join( __dirname, 'test-parser.php' ) );
2 changes: 1 addition & 1 deletion packages/block-serialization-spec-parser/shared-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ const hasPHP = 'test' === process.env.NODE_ENV ? ( () => {
// skipping if `php` isn't available to us, such as in local dev without it
// skipping preserves snapshots while commenting out or simply
// not injecting the tests prompts `jest` to remove "obsolete snapshots"
// eslint-disable-next-line jest/no-disabled-tests
// eslint-disable-next-line jest/no-disabled-tests, jest/valid-describe
const makeTest = hasPHP ? ( ...args ) => describe( ...args ) : ( ...args ) => describe.skip( ...args );

export const phpTester = ( name, filename ) => makeTest(
Expand Down
2 changes: 1 addition & 1 deletion packages/block-serialization-spec-parser/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ import path from 'path';
import { parse } from '../';
import { jsTester, phpTester } from '../shared-tests';

describe( 'block-serialization-spec-parser-js', jsTester( parse ) );
describe( 'block-serialization-spec-parser-js', jsTester( parse ) ); // eslint-disable-line jest/valid-describe

phpTester( 'block-serialization-spec-parser-php', path.join( __dirname, 'test-parser.php' ) );
2 changes: 0 additions & 2 deletions packages/blocks/src/api/test/utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable react/forbid-elements2 */

/**
* External dependencies
*/
Expand Down
4 changes: 2 additions & 2 deletions packages/components/src/autocomplete/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ export class Autocomplete extends Component {
const activeId = isExpanded ? `components-autocomplete-item-${ instanceId }-${ selectedKey }` : null;

// Disable reason: Clicking the editor should reset the autocomplete when the menu is suppressed
/* eslint-disable jsx-a11y/no-static-element-interactions, jsx-a11y/onclick-has-role, jsx-a11y/click-events-have-key-events */
/* eslint-disable jsx-a11y/no-static-element-interactions, jsx-a11y/click-events-have-key-events */
return (
<div
ref={ this.bindNode }
Expand Down Expand Up @@ -487,7 +487,7 @@ export class Autocomplete extends Component {
) }
</div>
);
/* eslint-enable jsx-a11y/no-static-element-interactions, jsx-a11y/onclick-has-role, jsx-a11y/click-events-have-key-events */
/* eslint-enable jsx-a11y/no-static-element-interactions, jsx-a11y/click-events-have-key-events */
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export default createHigherOrderComponent(
} );

// Disable reason: Clicking the editor should dismiss the regions focus style
/* eslint-disable jsx-a11y/no-static-element-interactions, jsx-a11y/onclick-has-role, jsx-a11y/click-events-have-key-events */
/* eslint-disable jsx-a11y/no-static-element-interactions, jsx-a11y/click-events-have-key-events */
return (
<div ref={ this.bindContainer } className={ className } onClick={ this.onClick }>
<KeyboardShortcuts
Expand All @@ -76,7 +76,7 @@ export default createHigherOrderComponent(
<WrappedComponent { ...this.props } />
</div>
);
/* eslint-enable jsx-a11y/no-static-element-interactions, jsx-a11y/onclick-has-role, jsx-a11y/click-events-have-key-events */
/* eslint-enable jsx-a11y/no-static-element-interactions, jsx-a11y/click-events-have-key-events */
}
};
}, 'navigateRegions'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe( 'withSpokenMessages', () => {
render( <DumpComponent /> );

// Unrendered element.
expect( testSpeak ).toBeCalledWith( true );
expect( testDebouncedSpeak ).toBeCalledWith( true );
expect( testSpeak ).toHaveBeenCalledWith( true );
expect( testDebouncedSpeak ).toHaveBeenCalledWith( true );
} );
} );
9 changes: 5 additions & 4 deletions packages/components/src/slot-fill/test/slot.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,9 @@ describe( 'Slot', () => {
expect( testRenderer.toJSON() ).toMatchSnapshot();
} );

[ false, true ].forEach( ( bubblesVirtually ) => {
describe( 'bubblesVirtually ' + bubblesVirtually, () => {
describe.each( [ false, true ] )(
'bubblesVirtually %p',
( bubblesVirtually ) => {
it( 'should subsume another slot by the same name', () => {
const testRenderer = ReactTestRenderer.create(
<Provider>
Expand Down Expand Up @@ -251,6 +252,6 @@ describe( 'Slot', () => {

expect( testRenderer.getInstance().slots ).toHaveProperty( 'egg' );
} );
} );
} );
}
);
} );
4 changes: 2 additions & 2 deletions packages/data/src/components/with-dispatch/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe( 'withDispatch', () => {
return {
increment: () => {
const actionReturnedFromDispatch = Promise.resolve( _dispatch( 'counter' ).increment( count ) );
expect( actionReturnedFromDispatch ).resolves.toEqual(
return expect( actionReturnedFromDispatch ).resolves.toEqual(
{
type: 'increment',
count,
Expand Down Expand Up @@ -166,7 +166,7 @@ describe( 'withDispatch', () => {
const actionReturnedFromDispatch = Promise.resolve(
_dispatch( 'counter' ).update( innerCount + 1 )
);
expect( actionReturnedFromDispatch ).resolves.toEqual( {
return expect( actionReturnedFromDispatch ).resolves.toEqual( {
type: 'update',
count: innerCount + 1,
} );
Expand Down
8 changes: 3 additions & 5 deletions packages/data/src/namespace-store/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe( 'controls', () => {
} );

registry.dispatch( 'store2' ).action2();
expect( action1 ).toBeCalled();
expect( action1 ).toHaveBeenCalled();
} );
} );

Expand Down Expand Up @@ -107,8 +107,7 @@ describe( 'controls', () => {
expect( registry.select( 'store' ).getItems.hasResolver ).toBe( false );
} );
} );
describe( 'various action types have expected response and resolve as ' +
'expected with controls middleware', () => {
describe( 'various action types have expected response and resolve as expected with controls middleware', () => {
const actions = {
*withPromise() {
yield { type: 'SOME_ACTION' };
Expand Down Expand Up @@ -164,8 +163,7 @@ describe( 'controls', () => {
.toEqual( { type: 'NORMAL' } );
} );
} );
describe( 'action type resolves as expected with just promise ' +
'middleware', () => {
describe( 'action type resolves as expected with just promise middleware', () => {
const actions = {
normal: () => ( { type: 'NORMAL' } ),
withPromiseAndAction: () => new Promise(
Expand Down
4 changes: 2 additions & 2 deletions packages/data/src/test/registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -438,10 +438,10 @@ describe( 'createRegistry', () => {
} );

expect( registry.select( 'reducer1' ).selector1() ).toEqual( 'result1' );
expect( selector1 ).toBeCalledWith( store.getState() );
expect( selector1 ).toHaveBeenCalledWith( store.getState() );

expect( registry.select( 'reducer1' ).selector2() ).toEqual( 'result2' );
expect( selector2 ).toBeCalledWith( store.getState() );
expect( selector2 ).toHaveBeenCalledWith( store.getState() );
} );

it( 'should run the registry selectors properly', () => {
Expand Down
51 changes: 24 additions & 27 deletions packages/e2e-tests/specs/navigable-toolbar.test.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
/**
* External dependencies
*/
import { forEach } from 'lodash';

/**
* WordPress dependencies
*/
import { createNewPost, pressKeyWithModifier } from '@wordpress/e2e-test-utils';

describe( 'block toolbar', () => {
forEach( {
unified: true,
contextual: false,
}, ( isUnifiedToolbar, label ) => {
describe.each( [ [ 'unified', true ], [ 'contextual', false ] ] )(
'block toolbar (%s: %p)',
( label, isUnifiedToolbar ) => {
beforeEach( async () => {
await createNewPost();

Expand All @@ -25,24 +18,28 @@ describe( 'block toolbar', () => {
}, isUnifiedToolbar );
} );

const isInBlockToolbar = () => page.evaluate( () => (
!! document.activeElement.closest( '.block-editor-block-toolbar' )
) );
const isInBlockToolbar = () => page.evaluate( ( _isUnifiedToolbar ) => {
if ( _isUnifiedToolbar ) {
return !! document.activeElement
.closest( '.edit-post-header-toolbar' )
.querySelector( '.block-editor-block-toolbar' );
}
return !! document.activeElement.closest( '.block-editor-block-toolbar' );
}, isUnifiedToolbar );

describe( label, () => {
it( 'navigates in and out of toolbar by keyboard (Alt+F10, Escape)', async () => {
// Assumes new post focus starts in title. Create first new
// block by ArrowDown.
await page.keyboard.press( 'ArrowDown' );
it( 'navigates in and out of toolbar by keyboard (Alt+F10, Escape)', async () => {
// Assumes new post focus starts in title. Create first new
// block by ArrowDown.
await page.keyboard.press( 'ArrowDown' );

// [TEMPORARY]: A new paragraph is not technically a block yet
// until starting to type within it.
await page.keyboard.type( 'Example' );
// [TEMPORARY]: A new paragraph is not technically a block yet
// until starting to type within it.
await page.keyboard.type( 'Example' );

// Upward
await pressKeyWithModifier( 'alt', 'F10' );
expect( await isInBlockToolbar() ).toBe( true );
} );
// Upward
await pressKeyWithModifier( 'alt', 'F10' );
expect( await isInBlockToolbar() ).toBe( true );
} );
} );
} );
}
);

36 changes: 21 additions & 15 deletions packages/e2e-tests/specs/publishing.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ import {
} from '@wordpress/e2e-test-utils';

describe( 'Publishing', () => {
[ 'post', 'page' ].forEach( ( postType ) => {
let werePrePublishChecksEnabled;
describe( `a ${ postType }`, () => {
describe.each( [ 'post', 'page' ] )(
'a %s',
( postType ) => {
let werePrePublishChecksEnabled;

beforeEach( async () => {
await createNewPost( postType );
werePrePublishChecksEnabled = await arePrePublishChecksEnabled();
Expand Down Expand Up @@ -43,12 +45,14 @@ describe( 'Publishing', () => {
// The post-publishing panel is not visible anymore.
expect( await page.$( '.editor-post-publish-panel' ) ).toBeNull();
} );
} );
} );
}
);

describe.each( [ 'post', 'page' ] )(
'a %s with pre-publish checks disabled',
( postType ) => {
let werePrePublishChecksEnabled;

[ 'post', 'page' ].forEach( ( postType ) => {
let werePrePublishChecksEnabled;
describe( `a ${ postType } with pre-publish checks disabled`, () => {
beforeEach( async () => {
await createNewPost( postType );
werePrePublishChecksEnabled = await arePrePublishChecksEnabled();
Expand All @@ -75,12 +79,14 @@ describe( 'Publishing', () => {
// The post-publishing panel should have been not shown.
expect( await page.$( '.editor-post-publish-panel' ) ).toBeNull();
} );
} );
} );
}
);

describe.each( [ 'post', 'page' ] )(
'a %s in small viewports',
( postType ) => {
let werePrePublishChecksEnabled;

[ 'post', 'page' ].forEach( ( postType ) => {
let werePrePublishChecksEnabled;
describe( `a ${ postType } in small viewports`, () => {
beforeEach( async () => {
await createNewPost( postType );
werePrePublishChecksEnabled = await arePrePublishChecksEnabled();
Expand All @@ -101,6 +107,6 @@ describe( 'Publishing', () => {
expect( await page.$( '.editor-post-publish-panel__toggle' ) ).not.toBeNull();
expect( await page.$( '.editor-post-publish-button' ) ).toBeNull();
} );
} );
} );
}
);
} );
Loading

0 comments on commit 16ad2e1

Please sign in to comment.