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

Upgrade JS syn to v0.15.0 #358

Merged
merged 2 commits into from
Feb 26, 2023
Merged

Upgrade JS syn to v0.15.0 #358

merged 2 commits into from
Feb 26, 2023

Conversation

mvorisek
Copy link
Contributor

@mvorisek mvorisek commented Oct 16, 2022

syn.js downloaded by npm install syn and moved from node_modules/syn/dist/global/syn.js (no local compilation, only non-minified version is available, thankfully, as it is much better for debugging)

replaces #333

fixes #279 and maybe also #20

@mvorisek mvorisek force-pushed the upgrade_syn_015 branch 4 times, most recently from 6ffe75a to cfb81e9 Compare October 16, 2022 22:11
@codecov
Copy link

codecov bot commented Oct 16, 2022

Codecov Report

Merging #358 (0405fe7) into master (5d15043) will increase coverage by 0.60%.
The diff coverage is 100.00%.

@@             Coverage Diff              @@
##             master     #358      +/-   ##
============================================
+ Coverage     90.02%   90.62%   +0.60%     
  Complexity      150      150              
============================================
  Files             1        1              
  Lines           421      448      +27     
============================================
+ Hits            379      406      +27     
  Misses           42       42              
Impacted Files Coverage Δ
src/Selenium2Driver.php 90.62% <100.00%> (+0.60%) ⬆️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@@ -222,25 +222,29 @@ protected function withSyn()
/**
* Creates some options for key events
*
* @param string $char the character or code
* @param string $modifier one of 'shift', 'alt', 'ctrl' or 'meta'
* @param string|int $char the character or code
Copy link
Member

Choose a reason for hiding this comment

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

why adding support for integers there ? This looks like a new feature

Copy link
Contributor Author

Choose a reason for hiding this comment

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

see #358 (comment), the method is called from Selenium2Driver::keyXxx() methods, so this is a phpdoc fix to match 1:1 the possible input types

Copy link
Member

Choose a reason for hiding this comment

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

This method is protected and not tagged as @internal. So someone extending the class (and I know some people do extend this class) could rely on it.

Copy link
Member

Choose a reason for hiding this comment

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

Well, it is not only a phpdoc fix. You also change the code to implement it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

#358 (comment) resolved, the phpdoc is changed correctly and int can/is passed by the testing suite

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@stof can this PR be merged or is there anything else to address?

As the upgraded syn.js lib might cause edge case incompatibilities please tag with increased minor version, ie. 1.7.0.

Copy link
Member

Choose a reason for hiding this comment

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

if integers are passed without being handled explicitly here, how did it work before ? Were we dispatching broken events (in which case it mean that this is not actually tested by the driver testsuite as it was passing) or was the old version of Syn fixing this for us ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

@stof , I can confirm, that:

  • \Behat\Mink\Driver\DriverInterface::keyPress method PhpDoc has @param string|int $char ...;
  • implementation of that interface method \Behat\Mink\Driver\Selenium2Driver::keyPress is passing that $char parameter to the \Behat\Mink\Driver\Selenium2Driver::charToOptions method (changed below).

I agree with the made PhpDoc change, but I don't agree with the is_numeric change into is_int as this could be a BC break.

Copy link
Member

Choose a reason for hiding this comment

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

After a thorough investigation, I longer consider this a BC break and agree with a merge.

@@ -204,7 +204,7 @@ public static function getDefaultCapabilities()
protected function withSyn()
{
$hasSyn = $this->wdSession->execute(array(
'script' => 'return typeof window["Syn"]!=="undefined" && typeof window["Syn"].trigger!=="undefined"',
'script' => 'return typeof window.syn !== \'undefined\' && typeof window.syn.trigger !== \'undefined\'',
Copy link
Member

Choose a reason for hiding this comment

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

Replacing typeof ... !== \'undefined\' constructs with ... !== undefined would also work.

Copy link
Contributor Author

@mvorisek mvorisek Oct 20, 2022

Choose a reason for hiding this comment

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

@@ -222,25 +222,29 @@ protected function withSyn()
/**
* Creates some options for key events
*
* @param string $char the character or code
* @param string $modifier one of 'shift', 'alt', 'ctrl' or 'meta'
* @param string|int $char the character or code
Copy link
Member

Choose a reason for hiding this comment

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

@stof , I can confirm, that:

  • \Behat\Mink\Driver\DriverInterface::keyPress method PhpDoc has @param string|int $char ...;
  • implementation of that interface method \Behat\Mink\Driver\Selenium2Driver::keyPress is passing that $char parameter to the \Behat\Mink\Driver\Selenium2Driver::charToOptions method (changed below).

I agree with the made PhpDoc change, but I don't agree with the is_numeric change into is_int as this could be a BC break.

Comment on lines +232 to 237
if (is_int($char)) {
$charCode = $char;
$char = chr($charCode);
} else {
$charCode = ord($char);
}
Copy link
Member

Choose a reason for hiding this comment

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

Please revert this code fragment, because it could potentially lead to the BC break when is_int($char) and is_numeric($char) yields different results.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@aik099 for ex. when 1 char/string is passed, I expect 1 to be pressed, is_numeric was wrong here, also all tests pass

Copy link
Member

Choose a reason for hiding this comment

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

That's an interesting observation. Never thought that number (e.g. 1, 7) could also be interpreted as a symbol and not a char code. Need to look closely at these tests you're talking about.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@aik099 please merge minkphp/driver-testsuite#61 test for it, also adds a test for capital letter key press

Copy link
Member

Choose a reason for hiding this comment

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

@stof , I've debugged the original (prior to this PR) version of the \Behat\Mink\Driver\Selenium2Driver::charToOptions method and the results are as follows:

  • When a letter is given as input, then it's converted into an ASCII code
  • When a number is given (as a string or as an integer) it's interpreted as an ASCII code itself

This behavior partially matches the DocBlock on the \Behat\Mink\Driver\DriverInterface::keyPress:

* @param string|int $char     could be either char ('b') or char-code (98)

Due to the usage of the is_numeric function (in implementation), a digit from '0' to '9' passed in as a string was interpreted as an ASCII code as well, which is a bug.

To overcome this developers likely had to pass in the ASCII code of these digits. Tests for the such case were missing, but now they're added via minkphp/driver-testsuite#61 .

@aik099
Copy link
Member

aik099 commented Nov 18, 2022

@mvorisek , I've rerun the builds and they seem to pass with a new test.

@mvorisek
Copy link
Contributor Author

@aik099 yes, please merge this PR as well and close the 3 mentioned #/issues in the description then.

@aik099
Copy link
Member

aik099 commented Nov 18, 2022

@aik099 yes, please merge this PR as well and close the 3 mentioned #/issues in the description then.

I'll wait for @stof to see if he has anything to add.

@mvorisek
Copy link
Contributor Author

Hi @stof, this PR is approved but Alex wants your feedback as well, can you please give this PR a green light?

@mvorisek
Copy link
Contributor Author

@stof @aik099 can this PR be merged? Thank you.

@aik099
Copy link
Member

aik099 commented Feb 24, 2023

@mvorisek , I guess you need to add a line to the changelog explaining the bug, that was fixed with this PR: the numbers from 0 to 9 passed as strings were treated as ASCII codes.

After that, I'll try to merge this PR.

@mvorisek
Copy link
Contributor Author

@aik099 CHANGELOG added

@aik099 aik099 merged commit affb7ea into minkphp:master Feb 26, 2023
@aik099
Copy link
Member

aik099 commented Feb 26, 2023

Merged. Thank you @mvorisek .

@mvorisek mvorisek deleted the upgrade_syn_015 branch February 26, 2023 17:59
@mvorisek mvorisek mentioned this pull request Mar 1, 2023
@mvorisek
Copy link
Contributor Author

mvorisek commented Mar 1, 2023

@aik099 Thank you, would it be possible to tag a new release please?

@aik099
Copy link
Member

aik099 commented May 11, 2023

How that would help you?

@mvorisek
Copy link
Contributor Author

mvorisek commented May 11, 2023

I no longer need it as I desided to fork this repo..

But I would like to get my changes still merged, especially #359. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Queries re use of Syn library
3 participants