Problem/Motivation

In developing a mechanism for contrib to run nightwatch.js tests, we discovered that when it attempts to write out the filename for the console logs, some directories are not created, because the testname can sometimes have '/''s in it.

Proposed resolution

Properly clean up the testname to convert spaces to dashes, and slashes to underscores.

Remaining tasks

User interface changes

API changes

Data model changes

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Mixologic created an issue. See original summary.

Mixologic’s picture

Status: Active » Needs review
FileSize
1.24 KB
Mixologic’s picture

Adding a blocked drupalci issue.

dawehner’s picture

Thank you @mixologic for this patch! I'm curious why you haven't used .replace(/[\s/]+/g, '-'), am I missing something?

GrandmaGlassesRopeMan’s picture

@dawehner Nice one. I always forget about [ ] in regex.

Mixologic’s picture

FileSize
1.23 KB
697 bytes

Mostly because the slack convo sorta just ended up with that. just so the filename separated the module name from the test name. It could be just dashes too.

Tests_autodrop-JSTest_PASSED_Tue-May-22-2018-14:53:52-GMT+0000-(UTC)_console.json

vs

Tests-autodrop-JSTest_PASSED_Tue-May-22-2018-14:53:52-GMT+0000-(UTC)_console.json

maybe just the underscores separating the filenames from the status from date are all thats needed.

Your suggestion, I think, makes for simpler code vs whats there.

GrandmaGlassesRopeMan’s picture

Status: Needs review » Needs work
  1. +++ b/core/tests/Drupal/Nightwatch/globals.js
    @@ -32,7 +32,6 @@ module.exports = {
           let testName = browser.currentTest.name || browser.currentTest.module;
    

    Since testName is never reassigned, you can use const now.

  2. +++ b/core/tests/Drupal/Nightwatch/globals.js
    @@ -40,7 +39,7 @@ module.exports = {
    +          fs.writeFileSync(`${resultPath}/${testName.replace(/[\s\/]+/g, '-')}_${status}_${now}_console.json`, browserlog);
    

    You could also replace testName here with (browser.currentTest.name || browser.currentTest.module)

Mixologic’s picture

Status: Needs work » Needs review
FileSize
1.31 KB

Feedback incorporated, and a browserlog to browserLog fix incorporated.

Not interdiffing since its mostly the same size as the patch.

Mixologic’s picture

FileSize
1.4 KB
815 bytes

One more bit of feedback incorporated : if we're cleaning strings of unwanted chars, lets do it all in the same style. Since we're cleaning both slashes and spaces out of one string, the split/join method seemed repetitive and verbose, so I opted to change the other to a regex replace.

The downside is regex readability, and "move all the things into one line". I'll leave this up to the JS maintainers to ultimately decide style choices - Im not informed enough in JS to decide one way or the other.

In any case this fix will unblock nightwatch testing in core and contrib. Right now nightwatch isnt producing any log data, so jenkins cant process the results, so although the tests are running, and you can see their results in the console log, drupalci cannot pass or fail the tests based on the outcome.

Mixologic’s picture

Dang. I reversed my interdiff -> patch is going from splits to regexes.

justafish’s picture

Status: Needs review » Reviewed & tested by the community

👍

alexpott’s picture

Crediting @dawehner and @drpal for reviews on the issue and crediting @justafish for discussions that took place in #javascript Drupal slack.

alexpott’s picture

Status: Reviewed & tested by the community » Needs review

There's a JS style issue.

/Volumes/devdisk/dev/drupal/core/tests/Drupal/Nightwatch/globals.js
  41:114  error  Unnecessary escape character: \/  no-useless-escape

✖ 1 problem (1 error, 0 warnings)

I think /[\s\/]+/g can be /[\s/]+/g

dawehner’s picture

Oh yeah this one is always getting me. It just not obvious at all that you can skip the escaping.

Mixologic’s picture

I wasnt sure if we were linting those files yet. On the testbots we've got

/var/lib/drupalci/workspace/jenkins-drupal_patches-59273/source/core/tests/Drupal/Nightwatch/globals.js
line 0
File ignored because of a matching ignore pattern. Use "--no-ignore" to override.

So perhaps something needs to change in the .eslintignore?

Heres a patch that fixes the escaping.

justafish’s picture

FileSize
3.17 KB
3.17 KB

This error wasn't getting picked up when running any of the scripts in package.json as it was only running on .es6.js files

justafish’s picture

Oops, will open up a follow up for the rogue || exit 0 stuff

GrandmaGlassesRopeMan’s picture

Status: Needs review » Needs work
Issue tags: +JavaScript
  1. +++ b/core/package.json
    @@ -12,9 +12,9 @@
    +    "lint:core-js": "node ./node_modules/eslint/bin/eslint.js . || exit 0",
    

    Makes sense to drop the --ext option here since we have this handled in the .eslintignore file.

  2. +++ b/core/tests/Drupal/Nightwatch/globals.js
    @@ -31,16 +31,14 @@ module.exports = {
    +          fs.writeFileSync(`${resultPath}/${(browser.currentTest.name || browser.currentTest.module).replace(/[\s/]+/g, '-')}_${status}_${now}_console.json`, browserLog);
    

    We should either create the variables outside this string, or move now into this and avoid creating a variable. Either way is fine with me, but lets be consistent.

Mixologic’s picture

After fighting for seconds with these changes, I finally have a fix.

Mixologic’s picture

Status: Needs work » Needs review

I dont know how to use the tools I help maintain.

GrandmaGlassesRopeMan’s picture

Status: Needs review » Reviewed & tested by the community

👍 Looks good to me.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 2e75397 and pushed to 8.6.x. Thanks!

  • alexpott committed 2e75397 on 8.6.x
    Issue #2974553 by Mixologic, justafish, drpal, dawehner: Nightwatch...

Status: Fixed » Closed (fixed)

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