Problem/Motivation

core/tests/Drupal/Nightwatch/Tests/claroAutocompleteTest.js passes in our Nightwatch job on GitLab.
Yet, when we look at it's console log in the saved artifact after the test, we see:
"http://localhost/subdirectory/form-test/autocomplete-1?q=123 - Failed to load resource: the server responded with a status of 404 (Not Found)"

The original IS below already found the solution for the 404 problem:

In core/modules/system/tests/modules/form_test/form_test.routing.yml, how is it possible that these invalid route definitions (use of controller: with no underscore instead of _controller:) don't cause test failures when form_test is used in general and when the autocomplete test is performed in particular?

The test itself isn't affected by the 404. Since it's only testing the layout of the "processing" phase of the autocomplete, it doesn't need a response. In fact this situation is beneficial, since the "processing" phase is currently endless, due to the lack of any response that would end it.

Nevertheless, this is not code we want to have as an example in core.
Also, this form might be used elsewhere someday, by somebody expecting it to actually works.

So let's fix it.

Steps to reproduce

Go to the Nightwatch job of a GitLab CI run, browse the Job artifacts and under nightwatch_output/consoleLogs/Tests/claroAutocompleteTest find the JSON file.
It will contain the key message with value "http://localhost/subdirectory/form-test/autocomplete-1?q=123 - Failed to load resource: the server responded with a status of 404 (Not Found)".
I've attached an example JSON from a random run to the issue.

Proposed resolution

- Fix the invalid route definitions
- Test the return of the autocomplete in claroAutocompleteTest
- Add some comments in claroAutocompleteTest to explain what's actually being tested.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Issue fork drupal-2651798

Command icon 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

TR created an issue. See original summary.

cilefen’s picture

cilefen’s picture

Poking around, it looks as though no tests ever try those routes:

drupal8x (8.1.x *%=)$ ack 'form-test/autocomplete-1' core/
core/modules/system/src/Tests/Form/ElementTest.php
151:    $result = $this->xpath('//input[@id="edit-autocomplete-1" and contains(@data-autocomplete-path, "form-test/autocomplete-1")]');
163:    $result = $this->xpath('//input[@id="edit-autocomplete-1" and contains(@data-autocomplete-path, "form-test/autocomplete-1")]');

core/modules/system/tests/modules/form_test/form_test.routing.yml
58:  path: '/form-test/autocomplete-1'
drupal8x (8.1.x *%=)$ ack 'form-test/autocomplete-2' core/
core/modules/system/src/Tests/Form/ElementTest.php
153:    $result = $this->xpath('//input[@id="edit-autocomplete-2" and contains(@data-autocomplete-path, "form-test/autocomplete-2/value")]');
165:    $result = $this->xpath('//input[@id="edit-autocomplete-2" and contains(@data-autocomplete-path, "form-test/autocomplete-2/value")]');

core/modules/system/tests/modules/form_test/form_test.routing.yml
65:  path: '/form-test/autocomplete-2/{param}'

drupal8x (8.1.x *%=)$ ack form_test.autocomplete_1 core/
core/modules/system/tests/modules/form_test/form_test.routing.yml
57:form_test.autocomplete_1:

core/modules/system/tests/modules/form_test/src/FormTestAutocompleteForm.php
32:      '#autocomplete_route_name' => 'form_test.autocomplete_1',
drupal8x (8.1.x *%=)$ ack form_test.autocomplete_2 core/
core/modules/system/tests/modules/form_test/form_test.routing.yml
64:form_test.autocomplete_2:

core/modules/system/tests/modules/form_test/src/FormTestAutocompleteForm.php
37:      '#autocomplete_route_name' => 'form_test.autocomplete_2',
cilefen’s picture

Priority: Normal » Minor
Status: Active » Needs review
Issue tags: +Quick fix, +Trivial patch of the month
StatusFileSize
new951 bytes

Well if we bother patching unused test code (see #3), here it is...

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

surbz’s picture

Status: Needs review » Reviewed & tested by the community

Patch applies clean on 8.2.x-dev.

alexpott’s picture

Priority: Minor » Normal
Status: Reviewed & tested by the community » Needs work
Issue tags: -Quick fix, -Trivial patch of the month +JavaScript

Well the routes are used:

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) {
    $form['autocomplete_1'] = array(
      '#type' => 'textfield',
      '#title' => 'Autocomplete 1',
      '#autocomplete_route_name' => 'form_test.autocomplete_1',
    );
    $form['autocomplete_2'] = array(
      '#type' => 'textfield',
      '#title' => 'Autocomplete 2',
      '#autocomplete_route_name' => 'form_test.autocomplete_2',
      '#autocomplete_route_parameters' => array('param' => 'value'),
    );

    return $form;
  }

So they should be working - in fact maybe the test should be changed to a FunctionalJavascriptTest so we can test the auto complete calling beyond just the existence of the links and autocomplete.js being loaded.

I think we should do that here instead so the trivial fix is actually tested.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

tr’s picture

Version: 8.9.x-dev » 9.3.x-dev
Issue tags: -JavaScript +JavaScript

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

quietone’s picture

Tests were asked for n 2016, adding tag.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

spokje’s picture

Closed #3412895: claroAutocompleteTest passes, but log shows a 404 as a duplicate and going to repurpose this issue to preserve the original credits.

spokje’s picture

Title: form_test routes improperly defined, why doesn't this fail? » claroAutocompleteTest passes, but log shows a 404
Issue summary: View changes
StatusFileSize
new284 bytes
spokje’s picture

Component: forms system » javascript
Assigned: Unassigned » spokje
Issue summary: View changes
Issue tags: -JavaScript
spokje’s picture

spokje’s picture

Issue summary: View changes

spokje’s picture

Issue summary: View changes
spokje’s picture

So they should be working - in fact maybe the test should be changed to a FunctionalJavascriptTest so we can test the auto complete calling beyond just the existence of the links and autocomplete.js being loaded.

I think we should do that here instead so the trivial fix is actually tested.

@alexpott in #7

I disagree.

I would _love_ to convert every Nightwatch test to a FunctionalJavascriptTest, and drop Nightwatch altogether, but that's not very feasible.

Basically, we're a bit spoiled by FunctionalJavascriptTests, which not only test the (JS)-Frontend, but also look at backend errors.
Nightwatch doesn't. If the webserver spews errors in the range from 500 to 911, is on fire and with its last dying breath serves a page that meets the assertations, it's perfectly happy.

That's why claroAutocompleteTest doesn't care about the invalid routes, it only asserts certain specific layout features of a autocomplete which is in progress. The result of the autocomplete is irrelevant and as proven, not even necessary.
The test is not about the inner workings of autocomplete, nor dependent on it even working.

Like it or not, somebody somewhere decided to use a Nightwatch test for this, and I think we should stick with that.

Having said that: We should fix the routing, make the autocomplete work and test this in the Nightwatch test itself.
The latter part didn't exist in the test until now and is added.

I hope this explanation makes any kind of sense?

spokje’s picture

Assigned: spokje » Unassigned
Status: Needs work » Needs review
Issue tags: -Needs tests
smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Confirmed the issue by going by going to the last ticket merged

https://git.drupalcode.org/issue/drupal-3409587/-/jobs/505831/artifacts/...(Coordinated-Universal-Time)_console.json

Checked this MR https://git.drupalcode.org/issue/drupal-2651798/-/jobs/587545/artifacts/...(Coordinated-Universal-Time)_console.json

And no issue.

alexpott’s picture

Version: 11.x-dev » 10.2.x-dev
Status: Reviewed & tested by the community » Fixed

Committed and pushed a4d53f09f6 to 11.x and e265a01324 to 10.2.x. Thanks!

Backported to 10.2.x since this only involved tests.

  • alexpott committed e265a013 on 10.2.x
    Issue #2651798 by Spokje, cilefen, TR, smustgrave: claroAutocompleteTest...

  • alexpott committed a4d53f09 on 11.x
    Issue #2651798 by Spokje, cilefen, TR, smustgrave: claroAutocompleteTest...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.