No error output in Nightwatch if the ./scripts/test-site.php produces the "Parse error"

Created on 11 November 2024, 5 months ago

Problem/Motivation

If your testing module produces the "Parse error" on the Drupal install stage, sometimes you don't see this error text in the Nightwatch output.

Steps to reproduce

1. Run a Nightwatch test from Core, eg this one:

yarn test:nightwatch /var/www/html/web/core/tests/Drupal/Nightwatch/Tests/loginTest.js

See that it executes well.

2. Open the file modules/user/src/UserFloodControl.php and make a syntax error there, eg like this:

class UserFloodControl implements UserFloodControlInterface {
asdsad  
  /**

3. Run the Nightwatch test again, and see that Drupal fails to install, but with no error output:

$ yarn test:nightwatch /var/www/html/web/core/tests/Drupal/Nightwatch/Tests/loginTest.js
yarn run v1.22.22
$ node -r dotenv-safe/config ./node_modules/.bin/nightwatch --config ./tests/Drupal/Nightwatch/nightwatch.conf.js /var/www/html/web/core/tests/Drupal/Nightwatch/Tests/loginTest.js

[Tests/Login Test] Test Suite
──────────────────────────────────────────────────────────
β„Ή Connected to selenium-chrome on port 4444 (364ms).
  Using: chrome (129.0.6668.100) on LINUX.

  βœ– NightwatchAssertError
   Command failed: php ./scripts/test-site.php install  --install-profile "nightwatch_testing"  --base-url http://web --db-url mysql://db:db@db/db --json


  Running Test login:

4. Run the install command manually in the console and see the actual error text:

$ php ./scripts/test-site.php install  --install-profile "nightwatch_testing"  --base-url http://web --db-url mysql://db:db@db/db --json
Xdebug: [Step Debug] Could not connect to debugging client. Tried: 127.0.0.1:9003 (fallback through xdebug.client_host/xdebug.client_port).

Parse error: syntax error, unexpected identifier "asdsad", expecting "function" or "const" in /var/www/html/web/core/modules/user/src/UserFloodControl.php on line 17

This happens because for some reason PHP outputs the error to stdout instead of the stderr.

Proposed resolution

When Drupal fails to install, output the stdout to the console as well.

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

πŸ› Bug report
Status

Active

Version

11.0 πŸ”₯

Component

javascript

Created by

πŸ‡¦πŸ‡²Armenia murz Yerevan, Armenia

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @murz
  • πŸ‡¦πŸ‡²Armenia murz Yerevan, Armenia

    I make a fix to print stdout output to the console, if the installation fails, please review.

  • Pipeline finished with Failed
    5 months ago
    Total: 587s
    #337312
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Possible to get simple test coverage to make sure this change catches what we think.

  • πŸ‡¦πŸ‡²Armenia narine_tsaturyan

    I applied the proposed fix for printing stdout during installation failures, and it significantly improved the debugging process for me. I was able to quickly pinpoint and resolve errors that were not previously visible in the Nightwatch test output. This enhancement is definitely a valuable addition for developers working with Drupal installations and testing.
    Thank you for addressing this!

  • πŸ‡¦πŸ‡²Armenia murz Yerevan, Armenia
  • Status changed to Needs work 2 months ago
  • πŸ‡ΊπŸ‡¦Ukraine Joyakas

    Thank you, murz.
    This solution indeed helps identify non-obvious installation issues faster.
    However, in my specific case, the issue was in the response content of the command. It is expected to be valid JSON, but any message from PHP here:

    1. breaks this logic and interrupts the test execution.
    2. hides the true cause of the problem behind the message "Not a valid JSON near...".

    In the logic of the your suggestion, I'd expand an error display for this case.

  • Pipeline finished with Failed
    2 months ago
    Total: 133s
    #423455
  • πŸ‡¦πŸ‡²Armenia murz Yerevan, Armenia

    Yeah, I also pretty often face the Nightwatch errors during the Drupal Profile installation that are very unclear:

    Installing the profile: commercetools_decoupled_locale_test_profile
      βœ– NightwatchAssertError
       Unexpected token W in JSON at position 1

    And
    Unexpected token E in JSON at position 1
    Unexpected token D in JSON at position 1
    Actually, this is because during the lunch of the command php ./scripts/test-site.php install Nightwatch expects the valid JSON output, but if we have errors or warnings in the output - it breaks the parsing of the result.

    In that case, the solution is to output the failed-to-parse JSON to stdout, so your patch works great!

  • Pipeline finished with Failed
    2 months ago
    Total: 157s
    #423798
  • πŸ‡¦πŸ‡²Armenia murz Yerevan, Armenia

    Possible to get simple test coverage to make sure this change catches what we think.

    @smustgrave, I'm not sure about how to cover this by tests, actually, it will be a functional test for the functional test, that is not good.

    This patch just improves outputting the errors to the console, when the Drupal installation fails when installing Drupal for further testing. So, moving to review to get comments about how to make the test coverage, if needed.

  • Pipeline finished with Failed
    2 months ago
    Total: 143s
    #424065
  • Pipeline finished with Failed
    2 months ago
    Total: 145s
    #424076
  • Pipeline finished with Failed
    2 months ago
    Total: 642s
    #424086
  • The Needs Review Queue Bot β†’ tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

    This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

    Consult the Drupal Contributor Guide β†’ to find step-by-step guides for working with issues.

  • πŸ‡¦πŸ‡²Armenia murz Yerevan, Armenia

    Attaching a static patch file for Drupal up to 11.1.x with those changes, to make it possible to use in composer until πŸ› GitLab Merge Requests Unable to Generate Incremental Patch Files Active is resolved.

Production build 0.71.5 2024