Skip to content

Conversation

@nicolad
Copy link
Member

@nicolad nicolad commented Nov 14, 2018

Description

Replaced pressWithModifier method from e2e test utils with modifiers from keycodes package.
Added missing JSDocs in test utils files.

How has this been tested?

Testing will be done with TravisCI

Types of changes

Enhancements

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.

@gziolo gziolo added [Type] Automated Testing Testing infrastructure changes impacting the execution of end-to-end (E2E) and/or unit tests. [Type] Code Quality Issues or PRs that relate to code quality labels Nov 14, 2018
Copy link
Member Author

@nicolad nicolad left a comment

Choose a reason for hiding this comment

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

Hi @gziolo, based on this modifierMapping
const SELECT_WORD_MODIFIER_KEYS = process.platform === 'darwin' ? [ 'Shift', 'Alt' ] : [ 'Shift', 'Control' ];
from this file https://github.com/WordPress/gutenberg/blob/master/test/e2e/specs/links.test.js#L18
I have updated this modifier:
https://github.com/WordPress/gutenberg/blob/master/packages/keycodes/src/index.js#L56
This change caused this test to fail:
https://github.com/WordPress/gutenberg/blob/master/packages/edit-post/src/components/keyboard-shortcut-help-modal/test/index.js
What's your thought on this, should I updated the test or should I change back keycodes package ?

@gziolo gziolo requested review from ellatrix and talldan November 15, 2018 12:42
@gziolo gziolo added the [Type] Enhancement A suggestion for improvement. label Nov 15, 2018
@gziolo gziolo requested a review from mcsf November 15, 2018 12:48
@gziolo
Copy link
Member

gziolo commented Nov 15, 2018

I think @talldan have the most experience with Keyboard shortcuts modal so I would defer it to him.

I see also a lot of failing e2e tests because of:

Unknown key: "Ctrl"

In general, I like the direction where this PR is heading. It would be awesome if we could land those changes as it will allow us to reuse existing utilities rather than duplicate them for all tests.

export const rawShortcut = mapValues( modifiers, ( modifier ) => {
return ( character, _isApple = isAppleOS ) => {
return [ ...modifier( _isApple ), character.toLowerCase() ].join( '+' );
return [ ...modifier( _isApple ), character.toLowerCase() ].filter( ( key ) => key !== '' ).join( '+' );
Copy link
Member

Choose a reason for hiding this comment

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

What was the reason that filtering is introduced?

Copy link
Member Author

@nicolad nicolad Nov 15, 2018

Choose a reason for hiding this comment

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

This is because when we are passing second argument to pressWithModifier there is no need to pass it to rawShortcut also, because key is used only in here await page.keyboard.press( key )

Copy link
Contributor

@talldan talldan Nov 15, 2018

Choose a reason for hiding this comment

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

I think it might be tidier to export the modifiers const from keycodes, and write a function that maps the keys exactly as they're needed within the e2e/utils (instead of using rawShortcut in tests).

That would also allow the possibility of adding extra combinations to the list of modifiers that are only used in tests (e.g. the shift+control word selection modifiers) and the production implementation wouldn't need to be touched.

Copy link
Member Author

Choose a reason for hiding this comment

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

Agree, have adjusted this, also had swapped ctrl, because in tests it was used as Control. Also shiftAlt is overwritten in pressWithModifier to align with tests prior usage.

For some reasons Travis has cached META_KEY and SELECT_WORD_MODIFIER_KEYS, which is causing tests to fail, is there a way to clean cache in Travis ?

Copy link
Contributor

@talldan talldan left a comment

Choose a reason for hiding this comment

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

Hey @vadimnicolai - thanks for the changes!

I've added a couple of comments for things that I think need to be addressed.

export const rawShortcut = mapValues( modifiers, ( modifier ) => {
return ( character, _isApple = isAppleOS ) => {
return [ ...modifier( _isApple ), character.toLowerCase() ].join( '+' );
return [ ...modifier( _isApple ), character.toLowerCase() ].filter( ( key ) => key !== '' ).join( '+' );
Copy link
Contributor

@talldan talldan Nov 15, 2018

Choose a reason for hiding this comment

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

I think it might be tidier to export the modifiers const from keycodes, and write a function that maps the keys exactly as they're needed within the e2e/utils (instead of using rawShortcut in tests).

That would also allow the possibility of adding extra combinations to the list of modifiers that are only used in tests (e.g. the shift+control word selection modifiers) and the production implementation wouldn't need to be touched.

@gziolo
Copy link
Member

gziolo commented Nov 16, 2018

I will try to clear caches on Travis and restart build.

Copy link
Member

@gziolo gziolo left a comment

Choose a reason for hiding this comment

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

This is looking very good, it still needs some adjustments.

There are some issues to resolve:

[0] [0] /home/travis/build/WordPress/gutenberg/test/e2e/specs/links.test.js
[0] [0] 391:28 error 'META_KEY' is not defined no-undef
[0] [0] 461:28 error 'SELECT_WORD_MODIFIER_KEYS' is not defined no-undef
[0] [0]
[0] [0] /home/travis/build/WordPress/gutenberg/test/e2e/specs/undo.test.js
[0] [0] 25:28 error 'META_KEY' is not defined no-undef
[0] [0] 34:28 error 'META_KEY' is not defined no-undef
[0] [0] 39:28 error 'META_KEY' is not defined no-undef
[0] [0]
[0] [0] ✖ 8 problems (5 errors, 3 warnings)

There are still references to the removed constants:

ReferenceError: META_KEY is not defined
  389 | 
  390 | 		// Press Cmd+K to insert a link
> 391 | 		await pressWithModifier( META_KEY, 'K' );
      | 		                         ^
  392 | 
  393 | 		// Wait for the URL field to auto-focus
  394 | 		await waitForAutoFocus();
  at Object.META_KEY (test/e2e/specs/links.test.js:391:28)
  at tryCatch (node_modules/regenerator-runtime/runtime.js:62:40)
  at Generator.invoke [as _invoke] (node_modules/regenerator-runtime/runtime.js:288:22)
  at Generator.prototype.(anonymous function) [as next] (node_modules/regenerator-runtime/runtime.js:114:21)
  at asyncGeneratorStep (test/e2e/specs/links.test.js:15:103)
  at _next (test/e2e/specs/links.test.js:17:194)

● Links › link popover remains visible after a mouse drag event
ReferenceError: SELECT_WORD_MODIFIER_KEYS is not defined
459 |
460 | // Select some text
> 461 | await pressWithModifier( SELECT_WORD_MODIFIER_KEYS, 'ArrowLeft' );
| ^
462 |
463 | // Click on the Link button
464 | await page.click( 'button[aria-label="Link"]' );
at Object.SELECT_WORD_MODIFIER_KEYS (test/e2e/specs/links.test.js:461:28)
at tryCatch (node_modules/regenerator-runtime/runtime.js:62:40)
at Generator.invoke [as _invoke] (node_modules/regenerator-runtime/runtime.js:288:22)
at Generator.prototype.(anonymous function) [as next] (node_modules/regenerator-runtime/runtime.js:114:21)
at asyncGeneratorStep (test/e2e/specs/links.test.js:15:103)
at _next (test/e2e/specs/links.test.js:17:194)
FAIL test/e2e/specs/undo.test.js (6.534s)
● undo › should undo typing after a pause
ReferenceError: META_KEY is not defined
23 | expect( await getEditedPostContent() ).toMatchSnapshot();
24 |
> 25 | await pressWithModifier( META_KEY, 'z' );
| ^
26 |
27 | expect( await getEditedPostContent() ).toMatchSnapshot();
28 | } );
at Object.META_KEY (test/e2e/specs/undo.test.js:25:28)
at tryCatch (node_modules/regenerator-runtime/runtime.js:62:40)
at Generator.invoke [as _invoke] (node_modules/regenerator-runtime/runtime.js:288:22)
at Generator.prototype.(anonymous function) [as next] (node_modules/regenerator-runtime/runtime.js:114:21)
at asyncGeneratorStep (test/e2e/specs/undo.test.js:9:103)
at _next (test/e2e/specs/undo.test.js:11:194)
● undo › should undo typing after non input change
ReferenceError: META_KEY is not defined
32 |
33 | await page.keyboard.type( 'before keyboard ' );
> 34 | await pressWithModifier( META_KEY, 'b' );
| ^
35 | await page.keyboard.type( 'after keyboard' );
36 |
37 | expect( await getEditedPostContent() ).toMatchSnapshot();
at Object.META_KEY (test/e2e/specs/undo.test.js:34:28)
at tryCatch (node_modules/regenerator-runtime/runtime.js:62:40)
at Generator.invoke [as _invoke] (node_modules/regenerator-runtime/runtime.js:288:22)
at Generator.prototype.(anonymous function) [as next] (node_modules/regenerator-runtime/runtime.js:114:21)
at asyncGeneratorStep (test/e2e/specs/undo.test.js:9:103)
at _next (test/e2e/specs/undo.test.js:11:194)

@nicolad
Copy link
Member Author

nicolad commented Nov 16, 2018

Is the Travis environment the same as the container in which e2e tests are runned locally ?
screen shot 2018-11-16 at 18 30 11

@gziolo
Copy link
Member

gziolo commented Nov 17, 2018

It should be very close to what you have locally if you use Docker instance provided with the repository.

FAIL test/e2e/specs/links.test.js (41.536s)

There are 9 tests failing in this suite. Everything else passes. Maybe shiftAlt behaves differently on Travis?

https://github.com/WordPress/gutenberg/pull/11855/files#diff-3d57671ff8af77f3854ff531c06ba975R39

...modifiers,
shiftAlt: ( _isApple ) => _isApple ? [ SHIFT, ALT ] : [ SHIFT, CTRL ],
};
const mappedModifiers = overWrittenModifiers[ modifier ]( isAppleOS );
Copy link
Member

Choose a reason for hiding this comment

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

I think I found what's causing issues. isAppleOS should be called here. It is passed down as function and that's why shiftAlt is always [ SHIFT, ALT ].

Copy link
Member

Choose a reason for hiding this comment

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

Actually, it should be inside shiftAlt. It's not easy to debug using GitHub UI :)

Copy link
Member Author

Choose a reason for hiding this comment

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

You have an eye of the 🐯

@gziolo gziolo added this to the 4.5 milestone Nov 17, 2018
@gziolo gziolo dismissed talldan’s stale review November 17, 2018 11:06

Feedback was addressed :)

@nicolad
Copy link
Member Author

nicolad commented Nov 17, 2018

Is it ok if I will add missing JSDocs in a separate PR ?

@gziolo
Copy link
Member

gziolo commented Nov 17, 2018

Yes, sure thing. Another nice refactor, thanks for all your help with making e2e test utils better 🙇

@gziolo gziolo merged commit 3b16e5f into WordPress:master Nov 17, 2018
raquelmsmith pushed a commit to raquelmsmith/gutenberg that referenced this pull request Nov 20, 2018
gziolo pushed a commit that referenced this pull request Nov 21, 2018
* Add e2e tests for the format API

* Fixes some whitespace issues

* Update format-api.test.js

* Add missing dependencies to the script registration

* Add snapshot to test

* Check for custom button, remove extra lines

* Change modifier keys used

From #11855
@nicolad nicolad self-assigned this Sep 29, 2019
*
* @type {string}
*/
const SELECT_WORD_MODIFIER_KEYS = process.platform === 'darwin' ? [ 'Shift', 'Alt' ] : [ 'Shift', 'Control' ];
Copy link
Member

Choose a reason for hiding this comment

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

The JSDoc comment on the preceding comment existed to complement this line of code. With this line of code removed, that JSDoc should have been removed as well.

See: #21297

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Type] Automated Testing Testing infrastructure changes impacting the execution of end-to-end (E2E) and/or unit tests. [Type] Code Quality Issues or PRs that relate to code quality [Type] Enhancement A suggestion for improvement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants