Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
Toolbar is not very well tested.
Steps to reproduce
Proposed resolution
Add as much tests as possible.
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
Comment | File | Size | Author |
---|
Issue fork drupal-3255809
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
nod_Not sure what is going on with the tests
Comment #4
SpokjeTests should come back green now after #3255836: Test fails due to Composer 2.2 solved the unrelated test failure.
Comment #6
nod_Adding a patch because the MR is a pain.
Comment #7
lauriiiI think overall this looks good. Totally looking forward to having this test coverage in core. Sorry for basically a nitpick only review:
Should we rename this to something else than
BackboneShimTest
?I think this comment needs to be updated too.
Needs a full stop 😅
s/url/URL
Nit: needs a full stop.
Nit: this line needs to be split
These also need a full stop.
Comment #8
nod_here you go, edited the interdiff for readability.
Comment #10
lauriiiAwesome, thank you @nod_! Adding credit for @hooroomoo since they worked on this.
Comment #11
bnjmnmVery happy to see this getting test coverage! This will make future changes to Toolbar much safer. I spotted a few small things:
Shouldn't the click event happen outside the timeout? It seems like the point of the timeout is to provide a small wait after the click event to ensure the expected changes have completed even when the test environment is running a little slow.
expectedTrue
is missing several of the properties fromtoReturn
. For this and other uses of theexpectedTrue
pattern, include a check thatexpectedTrue.length === result.value.length
, and the tests will catch any omissions.Is there a specific reason for visiting to /user then /admin immediately after?
This class is added via JavaScript in
ToolbarVisualView
, it seems like there's a risk of the test running before this element is rendered. Even it's unlikely, it can be protected against by running a browser.waitForElementPresent() for that selector beforebrowser.executeAsync()
is called.This scenario where the overlap is a concern is when the toolbar tray is horizontal to be useful. Lets add a check for that so if this fails as part of a future change the feedback is more useful.
Ah right, we've never had Nightwatch tests in a module. This is a good place for them!
Comment #12
nod_Thanks :)
Comment #13
lauriiiChecked that all feedback from #11 was addressed. Great catches @bnjmnm!
Comment #17
bnjmnmCommitted to 10.0.x and cherry picked to 9.4.x and 9.3.x as this is noninvasive as it only introduces test coverage that verifies the status quo.
This should make toolbar related issues much easier to work on, as there's now an easy way to know if a change caused unexpected results elsewhere in toolbar's logic.
The one change outside of adding these tests is to commit-code-check.sh, which correctly adds in-module Nightwatch tests to the js files that don't need to be checked for .es6.js equivalents.
Comment #21
xjmUnfortunately this introduced a random fail (probably a race condition) that is happening at a very high rate. See for example:
So, I've reverted it from all three branches. When we debug similar race conditions in functional JS tests, we often make the random fail happen consistently by adding a sleep or such to prove there is a race condition, and the fix is usually to change to functionality that waits on the element to be available to click. Hopefully Nightwatch supports similar functionality.
Comment #22
nod_The problem is during setup when assigning permission to the created user. If the user is not properly created then all the tests are going to fail because the toolbar doesnt show up.
Comment #24
nod_Trying with a MR this time
Comment #25
nod_Comment #26
nod_All right think I got it. Added a clear cache before trying to go to the permission page to create a new role. Probably an underlying issue somewhere else but it seems to be reliable now
Comment #27
nod_lol, no.
Comment #28
nod_The failure above is because Drupal 10 doesn't work on php 7.4, not because the tests has a problem
Comment #29
nod_One failure for the previous test run, added a bunch more here see if that helps.
Comment #30
nod_Ok, seems like it's holding up. There are 50 runs for each test file, so 100 installs and calls to drupalCreateRole that could fail. Ran that 3 times so we had 300 opportunities to fail, and we didn't get one failure :)
(I know I posted that before all test runs came back, but I'm optimistic :D)
I think we're good to go now :)
Comment #31
lauriiiThe solution for the random failure looks good for me! Thank you for confirming that this actually resolves the random failure.
Would be good to have change record for this since it's a new API. I opened follow-up for using this new API in other tests: #3264940: Add optional parameter to Nightwatch drupalInstallModule command to enable module dependencies.
Comment #32
nod_CR created: https://www.drupal.org/node/3264978
Comment #36
bnjmnmImpressive work by @nod_ on tracking down the race condition causing intermittent failures on the prior commit. Nightwatch isn't great with modules that have dependencies, and this significantly improved DX.
The commits just above & below #29 run the toolbar tests 100 consecutive times without a failure.
Committed to 10.0.x/9.4.x and backported to 9.3.x since this it is non-disruptive and the tests are confirming the status quo.
Comment #37
xjmNice work!