Problem/Motivation

#2918868: [policy, no patch] Use a deprecation process for JavaScript similar to what we use for PHP code decided on a standard for documenting deprecated JavaScript code: https://www.drupal.org/core/deprecation#javascript.

The next step is to document a consistent way to trigger deprecation notifications on JavaScript deprecations to notify developers that deprecated code is being used. The error should be clearly visible to developers, and there most likely should be a way to silence the notifications on production environment.

Proposed resolution

Provide Drupal.deprecationWarning and Drupal.deprecateProperty functions for marking classes, methods and properties as deprecated. Provide new Drupal setting suppressDeprecationWarnings for suppressing JavaScript deprecation warnings.

Remaining tasks

  1. Agree how to trigger errors JavaScript maintainer @justafish signed off on this in #11 + #13.
  2. Document that on the Drupal core deprecation policy

API changes

Three API additions:

  1. drupalSettings.suppressDeprecationErrors, which defaults to true. This ensures JS deprecation errors are not triggered on production sites. Can be modified using hook_js_settings_alter()
  2. Drupal.deprecationError, to trigger a deprecation error when they're not suppressed. For use in JS functions.
  3. Drupal.deprecatedProperty, to decorate properties that are deprecated, to allow Drupal.deprecationError to be called automatically when deprecation errors are not suppressed.

The second and third are what developers writing JS should use to deprecate.

The first is what developers can use to either surface or suppress deprecation errors.

Release notes snippet

JavaScript code can now also trigger deprecation errors using newly added APIs (Drupal.deprecationError and Drupal.deprecatedProperty). JavaScript deprecation errors are exposed using console.warn. By default, JavaScript deprecation errors are suppressed. See https://www.drupal.org/core/deprecation#javascript for more details.

CommentFileSizeAuthor
#68 3070521-77.patch24.82 KBtedbow
#68 interdiff-66-67.txt759 bytestedbow
#66 3070521-66.patch24.75 KBtedbow
#66 interdiff-63-66.txt739 bytestedbow
#63 3070521-63.patch24.69 KBtedbow
#63 interdiff-59-63.txt4.5 KBtedbow
#58 3070521-58.patch24.81 KBtedbow
#57 3070521-57.patch24.8 KBtedbow
#57 intdiff-52-57.txt7.53 KBtedbow
#52 interdiff-46-52.txt598 bytestedbow
#52 3070521-52.patch24.67 KBtedbow
#46 interdiff.txt4.07 KBlauriii
#46 3070521-46.patch24.08 KBlauriii
#44 interdiff.txt1.04 KBlauriii
#44 3070521-44.patch23.51 KBlauriii
#42 interdiff.txt1.23 KBlauriii
#42 3070521-42.patch22.47 KBlauriii
#39 interdiff.txt12.85 KBlauriii
#39 3070521-39.patch21.97 KBlauriii
#36 interdiff.txt825 byteslauriii
#36 3070521-36.patch23.19 KBlauriii
#35 interdiff.txt2.58 KBlauriii
#35 3070521-35.patch23.02 KBlauriii
#33 3070521-33.patch24.55 KBtedbow
#33 interdiff-22-33.txt14.44 KBtedbow
#22 interdiff.txt1.71 KBlauriii
#22 3070521-19.patch10.11 KBlauriii
#19 interdiff.txt855 byteslauriii
#19 3070521-17.patch10.25 KBlauriii
#17 interdiff.txt855 byteslauriii
#17 3070521-17.patch10.25 KBlauriii
#12 interdiff.txt9.56 KBlauriii
#12 3070521-12.patch10.26 KBlauriii
#7 interdiff.txt6.86 KBlauriii
#7 3070521-6.patch8.73 KBlauriii
#3 3070521-3.patch8.77 KBlauriii
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

lauriii created an issue. See original summary.

lauriii’s picture

Title: Trigger deprecation notifications on JavaScript deprecations to notify developers that deprecated code is being used. » Trigger deprecation notifications on JavaScript deprecations to notify developers that deprecated code is being used
lauriii’s picture

Issue summary: View changes
Status: Active » Needs review
FileSize
8.77 KB
Wim Leers’s picture

Issue summary: View changes
Wim Leers’s picture

This looks like a great start! 😃

Points 1 and 2 review the key parts of what #3 proposes, the other points look at the impact of those points and the bigger picture.

  1. +++ b/core/misc/drupal.es6.js
    @@ -541,6 +541,51 @@ window.Drupal = { behaviors: {}, locale: {} };
    +  Drupal.deprecationWarning = function(message) {
    

    A method for triggering a deprecation warning using the console.

    There is a suppression mechanism, which is turned on by default.

    👍 Seems reasonable.

    🤔 Primary question: why "deprecation warning" and not "deprecation error"? That's what it's called everywhere else.

  2. +++ b/core/misc/drupal.es6.js
    @@ -541,6 +541,51 @@ window.Drupal = { behaviors: {}, locale: {} };
    +  Drupal.deprecateProperty = (target, deprecatedProp, message) => {
    

    This then is a helper to make it easy to declare deprecated properties, because they me be declared in places where that declaration cannot be followed by a function call (to Drupal.deprecationWarning()).

    👍 Makes sense.

    🤔 I think Drupal.deprecatedProperty() makes slightly more sense? What is your reasoning for this naming?

  3. +++ b/core/misc/ajax.es6.js
    @@ -1118,20 +1122,24 @@
    -  Drupal.theme.ajaxWrapperNewContent = ($newContent, ajax, response) =>
    ...
    +  Drupal.theme.ajaxWrapperNewContent = ($newContent, ajax, response) => {
    

    🤔🤓 I'm wondering if we want a proxy-based approach just like you have for the property, because that would allow us to not have to reformat (indent) existing function definitions?

  4. +++ b/core/misc/drupal.es6.js
    @@ -541,6 +541,51 @@ window.Drupal = { behaviors: {}, locale: {} };
    +   * @see https://www.drupal.org/core/deprecation
    

    🤔 IMHO this should link to https://www.drupal.org/core/deprecation#javascript

  5. +++ b/core/modules/system/system.module
    @@ -788,6 +788,7 @@ function system_js_settings_alter(&$settings, AttachedAssetsInterface $assets) {
    +  $settings['suppressDeprecationWarnings'] = TRUE;
    

    🤔 It's very important here to turn on deprecation warnings (errors?) when it makes sense.

    I'm sure that's something for a future patch iteration.

Status: Needs review » Needs work

The last submitted patch, 3: 3070521-3.patch, failed testing. View results

lauriii’s picture

Status: Needs work » Needs review
FileSize
8.73 KB
6.86 KB

Thanks for the review! ✌️

#5.1 Interesting observation! I feel like deprecation warning is more accurate since these are not actual errors, but warnings that deprecated code is being called. I did very non-scientific research by using Google to search for "deprecation error" which found 9000 results, as well as for "deprecation warning" which found over 200 000 results leading into believe that deprecation warning is a more commonly used term. However, since we're already using the deprecation error term more frequently in core, I changed these to deprecation error.

#5.2 The proposal makes sense. The function isn't actually deprecating anything but it's helping to mark it as deprecated so that the warning can be triggered.

#5.3 In my opinion, it's better to directly call the function to trigger a warning whenever possible since it results in simpler code. If you look at the compiled code, you can see how minimal the change actually is.

#5.4 👍

#5.5 I actually just hardcoded the value since I wasn't sure what should be the rule to turn deprecation warnings on. Should it be something that a module could override or should there be a configuration in core to turn off the suppression?

Wim Leers’s picture

In my opinion, it's better to directly call the function to trigger a warning whenever possible since it results in simpler code

Yep, that's fair. I only thought of it because there is a helper method for properties, so we might want one for functions too. Then again, for properties it's necessary (for the reasons I provided), for functions it's not.

Should it be something that a module could override or should there be a configuration in core to turn off the suppression?

Yeah, good question. I'm inclined to say "if PHP assertions are turned on, you want this to be turned on too". But that's not necessarily true: PHP assertions matter to back end developers, JS deprecations matter to front end developers, you only want both if you're working on both ends simultaneously.

I'm afraid this goes back to #1537198: Add a Production/Development Toggle To Core, which has been an unsolved problem for more years than I'd like to know 🙃

zrpnr’s picture

These methods for logging warnings in the console seem like an ideal approach. I did some research into how React displays warnings in strict mode, and how other js libraries handle deprecations. Logging to the console is standard since there isn't a native feature of the language. Typically with a React app where there is a compile step the "production" build won't display these kind of developer notices. That's not an option for Drupal though since the compiled files are the ones that get loaded and used.

I'm inclined to say "if PHP assertions are turned on, you want this to be turned on too". But that's not necessarily true: PHP assertions matter to back end developers, JS deprecations matter to front end developers, you only want both if you're working on both ends simultaneously.

I agree that php assertions and js deprecations shouldn't be connected, but what about something more user friendly like the "Logging and Errors" config? I think it's system.logging.error_level.

+++ b/core/modules/system/system.module
@@ -788,6 +788,7 @@ function system_js_settings_alter(&$settings, AttachedAssetsInterface $assets) {
+  $settings['suppressDeprecationErrors'] = TRUE;

This could just be TRUE only for error_level: hide so that the warnings would always appear unless deliberately suppressed.
We want developers to notice these warnings, but to be easily suppressed by setting this option to "none" on production.
I think most developers or site builders would think to go here (admin/config/development/logging) first if they wanted to hide those console warnings.

+++ b/core/misc/drupal.js
@@ -173,6 +173,23 @@ window.Drupal = { behaviors: {}, locale: {} };
+  Drupal.deprecatedProperty = function (target, deprecatedProp, message) {
+    return new Proxy(target, {

I was curious to see how the compiler handled this, but it is still using Proxy. I don't think Proxy is supported by IE 11 since it is an ES6 feature of javascript.

Likewise:

+++ b/core/misc/drupal.js
@@ -173,6 +173,23 @@ window.Drupal = { behaviors: {}, locale: {} };
+        return Reflect.get.apply(Reflect, arguments);

Reflect is also not supported in IE11.

justafish’s picture

justafish’s picture

This is cool 👍

Is there a reason deprecationError is a regular function() and deprecatedProperty is an arrow function?

You could also use console.trace instead of console.warn, so it's easier to find where the message was triggered and doesn't mean you need to rely so much on the error message text.

I prefer to pass objects through to functions in JavaScript, it's much more flexible if you want to expand later. I'd also set default values where possible.

Drupal.deprecationError = function({ message: "Function deprecated" }) {
  if (
     drupalSettings.suppressDeprecationErrors === false &&
     typeof console !== 'undefined' &&
     console.trace
   ) {
     console.trace(`[Deprecation] ${message}`);
   }
};
Drupal.deprecatedProperty = ({ target, deprecatedProp, message = "Deprecated property" }) => {
  return new Proxy(target, {
    get(target, key) {
      if (key === deprecatedProp) {
        Drupal.deprecationError(message);
      }
      return Reflect.get(...arguments);
    },
  });
};
lauriii’s picture

I disabled this when Proxy or Reflect isn't supported which seems fine to me since this is a developer-facing feature so it might be safe to assume that they're not running IE 11.

Is there a reason deprecationError is a regular function() and deprecatedProperty is an arrow function?

There was no reason. I was supposed to convert both of them into arrow functions but somehow got just into half way with that 🤣 I converted all functions to use arrow functions.

You could also use console.trace instead of console.warn, so it's easier to find where the message was triggered and doesn't mean you need to rely so much on the error message text.

I would prefer using console.warn because it makes deprecations much more visible. Also, some browsers provide trace even for warnings 😇

I prefer to pass objects through to functions in JavaScript, it's much more flexible if you want to expand later.

👍

I'd also set default values where possible.

I don't think we can set reasonable default values. Drupal has this whole document about the format of deprecation warning messages. Setting a default value could encourage people to break that pattern 🤠

justafish’s picture

Status: Needs review » Reviewed & tested by the community

Looks good (assuming the tests pass)! 💃

Wim Leers’s picture

Status: Reviewed & tested by the community » Needs work

Yay! Thanks, @justafish! :)

I agree that the JS side of things here looks ready, but I think we should consider implementing @zrpnr's suggestion too:

I'm inclined to say "if PHP assertions are turned on, you want this to be turned on too". But that's not necessarily true: PHP assertions matter to back end developers, JS deprecations matter to front end developers, you only want both if you're working on both ends simultaneously.

I agree that php assertions and js deprecations shouldn't be connected, but what about something more user friendly like the "Logging and Errors" config? I think it's system.logging.error_level.

+++ b/core/modules/system/system.module
@@ -788,6 +788,7 @@ function system_js_settings_alter(&$settings, AttachedAssetsInterface $assets) {
+  $settings['suppressDeprecationErrors'] = TRUE;

This could just be TRUE only for error_level: hide so that the warnings would always appear unless deliberately suppressed.
We want developers to notice these warnings, but to be easily suppressed by setting this option to "none" on production.
I think most developers or site builders would think to go here (admin/config/development/logging) first if they wanted to hide those console warnings.

Or if we don’t, at least open a follow-up for it.

lauriii’s picture

I'm not sure if we should use the "Error messages to display" configuration for this since it explicitly mentions displaying them. If we do decide to use it, I think we should add mention to the UI that the setting affects JavaScript deprecations warnings displayed in the console as well. We were planning to use that setting #2987444: Ajax errors are not communicated through the UI but it's slightly different since it actually displays errors in the UI.

Wim Leers’s picture

Priority: Normal » Major
Status: Needs work » Reviewed & tested by the community
Issue tags: +Needs followup

So we still need a follow-up to determine a smarter default for suppressDeprecationErrors. But since this issue is at least major (or is it critical?), we should go ahead and get this committed ASAP.

lauriii’s picture

Adjusted one of the deprecation warning messages.

zrpnr’s picture

Issue tags: -Needs followup

I disabled this when Proxy or Reflect isn't supported which seems fine to me since this is a developer-facing feature so it might be safe to assume that they're not running IE 11.

That's a good point, very unlikely developers would be working using IE11, but the additional check you added is an improvement and an additional safeguard if warnings were accidentally left enabled on production.

+1 for passing objects to the functions, and using arrow functions everywhere!

Should we remove the @todo Add deprecation warning after it is possible from the docblock above Drupal.theme.ajaxWrapperNewContent and Drupal.theme.ajaxWrapperMultipleRootElements as part of this patch?

we still need a follow-up to determine a smarter default for suppressDeprecationErrors. But since this issue is at least major (or is it critical?), we should go ahead and get this committed ASAP.

Created #3082404: Follow-up to #3070521 Provide option to enable javascript deprecation warnings
I agree that this feature should not block this issue.

This is still RTBC since the latest patch was a small change and tests pass, nice work @lauriii !

lauriii’s picture

Status: Reviewed & tested by the community » Needs review
FileSize
10.25 KB
855 bytes

Moved setting the suppressDeprecationErrors default value to core.libraries.yml to allow modules to use the alter function to override this. I also rengerated the compiled JS because it seems like I forgot to do that for #17.

lauriii’s picture

I also opened change records for this.

Wim Leers’s picture

Status: Needs review » Needs work

Moved setting the suppressDeprecationErrors default value to core.libraries.yml to […]

👍 WHY DID I NOT THINK OF THIS!?

But … it's not in the patch?

lauriii’s picture

Status: Needs work » Needs review
FileSize
10.11 KB
1.71 KB

Ignore patch in #19, this is the right patch.

Wim Leers’s picture

Status: Needs review » Reviewed & tested by the community
Related issues: +#2382557: Change JS settings into a separate asset type

Perfect.

I think I even worked on adding the default drupalSettings to core.libraries.yml way back when … yep: #2382557: Change JS settings into a separate asset type. This looks perfect now.

xjm’s picture

I wonder if it would be best to merge the two change records for this? I think the information on how to suppress the messages could be added at the end of https://www.drupal.org/node/3082634.

larowlan’s picture

Status: Reviewed & tested by the community » Needs review

For #24

lauriii’s picture

The reason for splitting them into separate change records was that the information on these change records is targeted to different groups of people. I'm fine with moving them into a single change record if other people prefer that approach.

lauriii’s picture

Status: Needs review » Reviewed & tested by the community

I discussed this with @xjm and as a result, I merged the change records. Moving back to RTBC.

xjm’s picture

Status: Reviewed & tested by the community » Needs work

I still need my release note. :)

xjm’s picture

Issue tags: +Needs release note
xjm’s picture

Probably we should tick all the boxes here since this significantly blah blah blah. :) Lauri has already signed off so I didn't add that tag.

Wim Leers’s picture

Assigned: Unassigned » lauriii
Issue summary: View changes
larowlan’s picture

I'm happy with this - I reviewed it back in #25 and only had questions about the change records. But I realise I didn't actually say 'this looks good' or anything like that.

tedbow’s picture

Status: Needs work » Needs review
FileSize
14.44 KB
24.55 KB

I chatted with lauri and he suggested we needed a way to get deprecation messages in our FunctionJavascript phpunit tests if deprecated JS functions are called.

Here is a try at that.

This starts from some work lauri had done after #22

tedbow’s picture

  1. +++ b/core/modules/system/tests/modules/js_deprecation_log_test/js/js_deprecation_log.es6.js
    @@ -0,0 +1,21 @@
    +      localStorage.setItem(
    +        'js_deprecation_log_test.warnings',
    +        JSON.stringify(warnings),
    +      );
    

    We store the warning in localstorage because there may be calls on previous pages and we need to be able evaluate at the end of the test if any JS deprecated calls were made.

  2. +++ b/core/tests/Drupal/FunctionalJavascriptTests/JavascriptDeprecationTest.php
    @@ -0,0 +1,25 @@
    +  /**
    +   * @expectedDeprecation Javascript Deprecation: Here be llamas.
    +   */
    +  public function testJavascriptDeprecation() {
    

    Here we test for a know deprecation message

  3. +++ b/core/tests/Drupal/FunctionalJavascriptTests/WebDriverTestBase.php
    @@ -17,6 +17,11 @@
    +  /**
    +   * {@inheritdoc}
    +   */
    +  public static $modules = ['js_deprecation_log_test'];
    

    We have to always have this test module enabled because it intercepts the calls to console.warn() to ensure that for all calls across across all page loads in test we will detect deprecated JS calls.

  4. +++ b/core/tests/Drupal/Nightwatch/Assertions/consoleMessageExists.js
    @@ -0,0 +1,19 @@
    diff --git a/core/tests/Drupal/Nightwatch/Tests/jsDeprecationTest.js b/core/tests/Drupal/Nightwatch/Tests/jsDeprecationTest.js
    
    diff --git a/core/tests/Drupal/Nightwatch/Tests/jsDeprecationTest.js b/core/tests/Drupal/Nightwatch/Tests/jsDeprecationTest.js
    new file mode 100644
    
    new file mode 100644
    index 0000000000..2f50de2131
    
    index 0000000000..2f50de2131
    --- /dev/null
    
    --- /dev/null
    +++ b/core/tests/Drupal/Nightwatch/Tests/jsDeprecationTest.js
    
    +++ b/core/tests/Drupal/Nightwatch/Tests/jsDeprecationTest.js
    +++ b/core/tests/Drupal/Nightwatch/Tests/jsDeprecationTest.js
    @@ -0,0 +1,26 @@
    

    @lauriii made all the changes to the nightwatch stuff so I will let him explain those.

  5. If are calling other deprecated JS code in other test then a lot of other tests should fail.
lauriii’s picture

We will still have to make the Nightwatch tests use the new test module to follow deprecation warnings in a more consistent way. This should fix some of the test failures. The patch also still contains some code from #3084698: Add console logs to all Nightwatch tests to make debugging easier.

lauriii’s picture

Since we haven't silenced any deprecations as part of this, I assume some of the JavaScript deprecations we add here should actually be triggered. Let's see if this helps.

Wim Leers’s picture

+++ a/core/package.json
@@ -26,7 +26,7 @@
+    "chromedriver": "^75.1.0",
-    "chromedriver": "^77.0.0",

+++ a/core/yarn.lock
@@ -1233,10 +1233,10 @@
+chromedriver@^75.1.0:
+  version "75.1.0"
...
-chromedriver@^77.0.0:
-  version "77.0.0"

👎Why these changes? this was in #35, but fixed in #36 :)

Status: Needs review » Needs work

The last submitted patch, 36: 3070521-36.patch, failed testing. View results

lauriii’s picture

Assigned: lauriii » Unassigned
Status: Needs work » Needs review
Issue tags: +Needs followup
FileSize
21.97 KB
12.85 KB

Added new assertion to Nighwatch to check if deprecations have been triggered. ✌️For now, this has to be manually run in every test case but we could add it to afterEach if we wanted to.

Let's move deprecating actual production code to follow-up to make sure we have at least this in prior to 8.8.0-alpha1.

Wim Leers’s picture

Let's move deprecating actual production code to follow-up to make sure we have at least this in prior to 8.8.0-alpha1.

I think this is the right call. 👍

  1. +++ b/core/modules/system/tests/modules/js_deprecation_test/js/js_deprecation_test.es6.js
    @@ -0,0 +1,22 @@
    +  const deprecatedFunction = () => {
    +    deprecationError({ message: 'This function is deprecated for testing purposes.' });
    +  };
    

    ✅ Sample deprecated JS function.

  2. +++ b/core/modules/system/tests/modules/js_deprecation_test/js/js_deprecation_test.es6.js
    @@ -0,0 +1,22 @@
    +  const objectWithDeprecatedProperty = deprecatedProperty({
    

    ✅ Sample deprecated JS property.

  3. +++ b/core/modules/system/tests/modules/js_deprecation_test/js/js_deprecation_test.es6.js
    @@ -0,0 +1,22 @@
    +  behaviors.testDeprecations = {
    +    attach: () => {
    +      deprecatedFunction();
    +      const deprecatedProperty =
    +        objectWithDeprecatedProperty.deprecatedProperty;
    +    },
    +  };
    +})(Drupal);
    

    ✅ Using both deprecated pieces of code. This triggers the deprecation errors.

  4. +++ b/core/modules/system/tests/modules/js_deprecation_test/js_deprecation_test.module
    @@ -0,0 +1,13 @@
    +  $settings['suppressDeprecationErrors'] = FALSE;
    

    ✅ This allows the JS deprecation errors to actually show up.

  5. +++ b/core/profiles/testing/testing.info.yml
    @@ -9,3 +9,4 @@ install:
    +  - js_deprecation_log_test
    

    🤔 Ohhhh! I did not expect this. But I think it might make sense. 👍 We need JS deprecation errors to be surfaced in all our functional tests, just like PHP deprecation errors.

    Worth nothing: this means that this won't work in other install profiles, like standard, demo_umami, or Drupal distributions like Thunder or Lightning. Do we believe that's okay?

    Shouldn't we move this to \Drupal\FunctionalJavascriptTests\WebDriverTestBase instead?

    Why is that not possible?

  6. +++ b/core/tests/Drupal/FunctionalJavascriptTests/JavascriptDeprecationTest.php
    @@ -0,0 +1,26 @@
    +  public static $modules = ['js_deprecation_test'];
    

    🤓 Übernit: Missing doc.

  7. +++ b/core/tests/Drupal/FunctionalJavascriptTests/JavascriptDeprecationTest.php
    @@ -0,0 +1,26 @@
    +   * @expectedDeprecation Javascript Deprecation: This function is deprecated for testing purposes.
    +   * @expectedDeprecation Javascript Deprecation: This property is deprecated for testing purposes.
    

    ✅ This proves deprecations are surfaced in tests 🥳

  8. +++ b/core/tests/Drupal/FunctionalJavascriptTests/WebDriverTestBase.php
    @@ -108,6 +108,13 @@ protected function tearDown() {
    +      $warnings = $this->getSession()->evaluateScript("JSON.parse(localStorage.getItem('js_deprecation_log_test.warnings') || JSON.stringify([]))");
    +      foreach ($warnings as $warning) {
    +        if (strpos($warning, '[Deprecation]') === 0) {
    +          @trigger_error('Javascript Deprecation:' . substr($warning, 13), E_USER_DEPRECATED);
    +        }
    +      }
    

    ✅ This maps JS deprecation errors to PHP deprecation errors, so our existing testing infrastructure can surface it! 👏

  9. +++ b/core/tests/Drupal/Nightwatch/Assertions/deprecationErrorExists.js
    --- /dev/null
    +++ b/core/tests/Drupal/Nightwatch/Assertions/noDeprecationErrors.js
    
    +++ b/core/tests/Drupal/Nightwatch/Tests/loginTest.js
    @@ -18,6 +18,7 @@ module.exports = {
    +      .assert.noDeprecationErrors();
    

    ✅ And this allows nightwatch JS tests to ensure there are no deprecation errors either.

I would have RTBC'd this, but I think point 5 needs more discussion still.

lauriii’s picture

Shouldn't we move this to \Drupal\FunctionalJavascriptTests\WebDriverTestBase instead?

Why is that not possible?

We need that for Nighwatch tests as well, which doesn't use \Drupal\FunctionalJavascriptTests\WebDriverTestBase. Maybe we should install it in both, \Drupal\FunctionalJavascriptTests\WebDriverTestBase and testing installation profile.

lauriii’s picture

Here's code for what I suggested in #41 and this should also fix the failing test.

Status: Needs review » Needs work

The last submitted patch, 42: 3070521-42.patch, failed testing. View results

lauriii’s picture

Status: Needs work » Needs review
FileSize
23.51 KB
1.04 KB
Wim Leers’s picture

Maybe we should install it in both, \Drupal\FunctionalJavascriptTests\WebDriverTestBase and testing installation profile.

+1

So we need it in testing to make it work for Nightwatch tests. We need it in WebDriverTestBase so that it works in all functional JS tests.

Arguably, we shouldn't add it to testing, and instead add a nightwatch_testing install profile instead. Because it's possible and even likely that there are more customizations necessary for Nightwatch tests. Furthermore, arguably it does not make sense to have the page_cache and dynamic_page_cache modules installed for Nightwatch tests, since Nightwatch tests are solely about client side testing, not about server-side responses and their cacheability.

Together, that means I'm implicitly proposing nightwatch_testing.info.yml to look like this:

name: Nightwatch Testing
type: profile
description: 'Minimal profile for running Nightwatch tests. Includes absolutely required modules only.'
version: VERSION
core: 8.x
hidden: true
install:
  - js_deprecation_log_test
lauriii’s picture

Addressing #45.

Wim Leers’s picture

Status: Needs review » Reviewed & tested by the community
  1. +++ b/core/profiles/nightwatch_testing/nightwatch_testing.info.yml
    @@ -0,0 +1,8 @@
    +name: Nightwatch Testing
    ...
    +  - js_deprecation_log_test
    
    +++ b/core/tests/Drupal/Nightwatch/Commands/drupalInstall.js
    @@ -25,7 +25,7 @@ exports.command = function drupalInstall({ setupFile = '' } = {}, callback) {
    -        `php ./scripts/test-site.php install ${setupFile} --base-url ${process.env.DRUPAL_TEST_BASE_URL} ${dbOption} --json`,
    +        `php ./scripts/test-site.php install ${setupFile} --install-profile nightwatch_testing --base-url ${process.env.DRUPAL_TEST_BASE_URL} ${dbOption} --json`,
    

    🥳 This ensures that Nightwatch tests install Drupal with this new nightwatch_testing install profile. 👍

  2. +++ b/core/tests/Drupal/FunctionalJavascriptTests/JavascriptDeprecationTest.php
    @@ -0,0 +1,26 @@
    +  public static $modules = ['js_deprecation_test'];
    

    🤓 Still the same nit as in #40.6.

  3. +++ b/core/tests/Drupal/Nightwatch/Tests/jsDeprecationTest.js
    @@ -0,0 +1,28 @@
    +    browser.drupalInstall().drupalLoginAsAdmin(() => {
    +      browser
    +        .drupalRelativeURL('/admin/modules')
    +        .setValue('input[type="search"]', 'JS Deprecation test')
    +        .waitForElementVisible(
    +          'input[name="modules[js_deprecation_test][enable]"]',
    +          1000,
    +        )
    +        .click('input[name="modules[js_deprecation_test][enable]"]')
    +        .click('input[type="submit"]'); // Submit module form.
    +    });
    

    This is no longer necessary AFAICT? 😊 Ah no, the install profile installs js_deprecation_log_test (which results in the logging), this is installing js_deprecation_test which intentionally triggers deprecation errors so we can test it. 👍

  4. +++ b/core/tests/Drupal/Nightwatch/Tests/loginTest.js
    @@ -17,7 +17,8 @@ module.exports = {
    +      .waitForElementVisible('body', 1000)
    

    🤔 Why do we need to add this wait now? This seems like a debug leftover? Oh … this is to allow the JS deprecation errors to have been triggered prior to us asserting there are no JS deprecation errors. 👍

Wim Leers’s picture

Wim Leers’s picture

Issue summary: View changes
Issue tags: -Needs release note

Issue summary updated:

  1. Consensus documented. Credited @justafish.
  2. API additions documented.
  3. Release note added.

Credited @zrpnr for his review in helping validate the approach. Also credited @tedbow for his crucial help in writing test coverage for this.

Wim Leers’s picture

Change record added: https://www.drupal.org/node/3085933

EDIT: d'oh that already existed at https://www.drupal.org/node/3082634. Merged my text into @lauriii's. Keeping it around for now, to retain the history. Once Lauri's is published, mine can be deleted. 🤓

Wim Leers’s picture

tedbow’s picture

#46 failed because the tests switch to stark from classy and there was 1 css selector that didn't exist anymore.

Fixed

lauriii’s picture

Issue tags: +Needs change record

This brings up a concern that this might break contrib / custom tests given that we're changing the testing theme. I grepped contrib projects to make sure that this doesn't break anything there, and I couldn't find any usages of Nighwatch there. A change record probably wouldn't hurt anyway.

Wim Leers’s picture

larowlan’s picture

Status: Reviewed & tested by the community » Needs review
+++ b/core/tests/Drupal/FunctionalJavascriptTests/WebDriverTestBase.php
@@ -108,6 +109,13 @@ protected function tearDown() {
+      $warnings = $this->getSession()->evaluateScript("JSON.parse(localStorage.getItem('js_deprecation_log_test.warnings') || JSON.stringify([]))");
+      foreach ($warnings as $warning) {
+        if (strpos($warning, '[Deprecation]') === 0) {
+          @trigger_error('Javascript Deprecation:' . substr($warning, 13), E_USER_DEPRECATED);
+        }

ChromeDriver has a very long-lived cache (in my experience), should we be removing the items from localStorage after each test to prevent pollution of subsequent tests?

Wim Leers’s picture

should we be removing the items from localStorage after each test to prevent pollution of subsequent tests

Oh, that's a very interesting remark!

Can't we just use sessionStorage instead? That is cleared for every new tab and window by definition :)

tedbow’s picture

  1. Changing to use Session storage
  2. +++ b/core/modules/system/tests/modules/js_deprecation_log_test/js/js_deprecation_log.es6.js
    @@ -0,0 +1,21 @@
    +      let warnings = JSON.parse(
    

    this should be const

  3. +++ b/core/modules/system/tests/modules/js_deprecation_test/js/js_deprecation_test.es6.js
    @@ -0,0 +1,22 @@
    +    deprecationError({ message: 'This function is deprecated for testing purposes.' });
    

    This line is update when I run yarn prettier. Maybe I didn't run it on last patch?

    Ran prettier.

  4. +++ b/core/tests/Drupal/Nightwatch/Assertions/deprecationErrorExists.js
    @@ -0,0 +1,22 @@
    +    return this.api.execute(function() {
    

    This be a arrow function

  5. +++ b/core/tests/Drupal/Nightwatch/Assertions/noDeprecationErrors.js
    @@ -0,0 +1,22 @@
    +    return this.api.execute(function() {
    

    This should be an arrow function

tedbow’s picture

my #57.3 & 4 changes broke the tests. I will defer @lauriii on this and assume his version was actually correct.

Wim Leers’s picture

Status: Needs review » Reviewed & tested by the community

Hurray! :)

larowlan’s picture

+1 RTBC

catch’s picture

Issue tags: -Needs release manager review +needs documentation updates

Can't really do a meaningful review of the js here as such, but the change record looks good to me, and fine with the nightwatch switching to stark change.

Explicitly tagging with 'needs documentation updates' which should happen asap once this is committed (or could probably happen just before too).

larowlan’s picture

Status: Reviewed & tested by the community » Needs review

The pre-commit hooks complain about this patch

$ cross-env BABEL_ENV=legacy node ./scripts/js/babel-es6-build.js --check --file /Volumes/files/code/git/core/drupal/core/misc/drupal.es6.js
[08:39:16] '/Volumes/files/code/git/core/drupal/core/misc/drupal.es6.js' is being checked.
✨  Done in 1.05s.

/Volumes/files/code/git/core/drupal/core/misc/drupal.es6.js
  592:37  error  Expected property shorthand  object-shorthand

✖ 1 problem (1 error, 0 warnings)
  1 error, 0 warnings potentially fixable with the `--fix` option.

$ cross-env BABEL_ENV=legacy node ./scripts/js/babel-es6-build.js --check --file /Volumes/files/code/git/core/drupal/core/misc/drupal.es6.js
[08:39:19] '/Volumes/files/code/git/core/drupal/core/misc/drupal.es6.js' is being checked.
✨  Done in 0.57s.

/Volumes/files/code/git/core/drupal/core/misc/drupal.es6.js
  592:37  error  Expected property shorthand  object-shorthand

✖ 1 problem (1 error, 0 warnings)
  1 error, 0 warnings potentially fixable with the `--fix` option.

$ cross-env BABEL_ENV=legacy node ./scripts/js/babel-es6-build.js --check --file /Volumes/files/code/git/core/drupal/core/modules/system/tests/modules/js_deprecation_log_test/js/js_deprecation_log.es6.js
[08:39:21] '/Volumes/files/code/git/core/drupal/core/modules/system/tests/modules/js_deprecation_log_test/js/js_deprecation_log.es6.js' is being checked.
✨  Done in 0.49s.

$ cross-env BABEL_ENV=legacy node ./scripts/js/babel-es6-build.js --check --file /Volumes/files/code/git/core/drupal/core/modules/system/tests/modules/js_deprecation_log_test/js/js_deprecation_log.es6.js
[08:39:22] '/Volumes/files/code/git/core/drupal/core/modules/system/tests/modules/js_deprecation_log_test/js/js_deprecation_log.es6.js' is being checked.
✨  Done in 0.52s.

$ cross-env BABEL_ENV=legacy node ./scripts/js/babel-es6-build.js --check --file /Volumes/files/code/git/core/drupal/core/modules/system/tests/modules/js_deprecation_test/js/js_deprecation_test.es6.js
[08:39:24] '/Volumes/files/code/git/core/drupal/core/modules/system/tests/modules/js_deprecation_test/js/js_deprecation_test.es6.js' is being checked.
[08:39:24] '/Volumes/files/code/git/core/drupal/core/modules/system/tests/modules/js_deprecation_test/js/js_deprecation_test.es6.js' is not updated.
error Command failed with exit code 1.

$ cross-env BABEL_ENV=legacy node ./scripts/js/babel-es6-build.js --check --file /Volumes/files/code/git/core/drupal/core/modules/system/tests/modules/js_deprecation_test/js/js_deprecation_test.es6.js
[08:39:26] '/Volumes/files/code/git/core/drupal/core/modules/system/tests/modules/js_deprecation_test/js/js_deprecation_test.es6.js' is being checked.
[08:39:26] '/Volumes/files/code/git/core/drupal/core/modules/system/tests/modules/js_deprecation_test/js/js_deprecation_test.es6.js' is not updated.
error Command failed with exit code 1.

/Volumes/files/code/git/core/drupal/core/tests/Drupal/Nightwatch/Assertions/deprecationErrorExists.js
   4:38  error  Unexpected block statement surrounding arrow body; move the returned value immediately after the `=>`  arrow-body-style
  11:51  error  Unexpected block statement surrounding arrow body; move the returned value immediately after the `=>`  arrow-body-style
  16:47  error  Unexpected block statement surrounding arrow body; move the returned value immediately after the `=>`  arrow-body-style
  20:30  error  Unexpected block statement surrounding arrow body; move the returned value immediately after the `=>`  arrow-body-style
  21:29  error  Unexpected function expression                                                                         prefer-arrow-callback

✖ 5 problems (5 errors, 0 warnings)
  5 errors, 0 warnings potentially fixable with the `--fix` option.


/Volumes/files/code/git/core/drupal/core/tests/Drupal/Nightwatch/Assertions/noDeprecationErrors.js
   4:38  error  Unexpected block statement surrounding arrow body; move the returned value immediately after the `=>`  arrow-body-style
  11:51  error  Unexpected block statement surrounding arrow body; move the returned value immediately after the `=>`  arrow-body-style
  16:47  error  Unexpected block statement surrounding arrow body; move the returned value immediately after the `=>`  arrow-body-style
  20:30  error  Unexpected block statement surrounding arrow body; move the returned value immediately after the `=>`  arrow-body-style
  21:29  error  Unexpected function expression                                                                         prefer-arrow-callback

✖ 5 problems (5 errors, 0 warnings)
  5 errors, 0 warnings potentially fixable with the `--fix` option.
tedbow’s picture

@larowlan sorry about that.

I did

yarn lint:core-js-passing --fix (this fix a bunch of files I discarded the ones not changed in this patch)
yarn build:js
yarn prettier

prettier didn't make any changes

Hope this passes

Wim Leers’s picture

Status: Needs review » Reviewed & tested by the community

14 times

File ignored because of a matching ignore pattern. Use "--no-ignore" to override.

caused this test to be marked as Build successful despite all tests passing. This is a pre-existing and known issue with DrupalCI + eslint tooling.

If I try to commit #63 locally with d8githooks, it does pass all tests:

$ git ci -am 63
Installing or updating dependencies...
> Drupal\Core\Composer\Composer::ensureComposerVersion
Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Nothing to install or update
Package phpunit/phpunit-mock-objects is abandoned, you should avoid using it. No replacement was suggested.
Generating autoload files
> Drupal\Core\Composer\Composer::preAutoloadDump
> Drupal\Core\Composer\Composer::ensureHtaccess
    Skipped installation of bin bin/composer for package composer/composer: file not found in package
yarn install v1.17.3
[1/5] 🔍  Validating package.json...
[2/5] 🔍  Resolving packages...
success Already up-to-date.
✨  Done in 0.33s.


Checking changed files...
PHPCS: core/core.libraries.yml passed
yarn run v1.17.3
$ cross-env BABEL_ENV=legacy node ./scripts/js/babel-es6-build.js --check --file /Users/wim.leers/Work/d8/core/misc/drupal.es6.js
[10:10:53] '/Users/wim.leers/Work/d8/core/misc/drupal.es6.js' is being checked.
✨  Done in 0.97s.
yarn run v1.17.3
$ cross-env BABEL_ENV=legacy node ./scripts/js/babel-es6-build.js --check --file /Users/wim.leers/Work/d8/core/misc/drupal.es6.js
[10:10:55] '/Users/wim.leers/Work/d8/core/misc/drupal.es6.js' is being checked.
✨  Done in 0.41s.
yarn run v1.17.3
$ cross-env BABEL_ENV=legacy node ./scripts/js/babel-es6-build.js --check --file /Users/wim.leers/Work/d8/core/modules/system/tests/modules/js_deprecation_log_test/js/js_deprecation_log.es6.js
[10:10:56] '/Users/wim.leers/Work/d8/core/modules/system/tests/modules/js_deprecation_log_test/js/js_deprecation_log.es6.js' is being checked.
✨  Done in 0.33s.
yarn run v1.17.3
$ cross-env BABEL_ENV=legacy node ./scripts/js/babel-es6-build.js --check --file /Users/wim.leers/Work/d8/core/modules/system/tests/modules/js_deprecation_log_test/js/js_deprecation_log.es6.js
[10:10:58] '/Users/wim.leers/Work/d8/core/modules/system/tests/modules/js_deprecation_log_test/js/js_deprecation_log.es6.js' is being checked.
✨  Done in 0.35s.
PHPCS: core/modules/system/tests/modules/js_deprecation_log_test/js_deprecation_log_test.info.yml passed
PHPCS: core/modules/system/tests/modules/js_deprecation_log_test/js_deprecation_log_test.libraries.yml passed
PHPCS: core/modules/system/tests/modules/js_deprecation_log_test/js_deprecation_log_test.module passed
yarn run v1.17.3
$ cross-env BABEL_ENV=legacy node ./scripts/js/babel-es6-build.js --check --file /Users/wim.leers/Work/d8/core/modules/system/tests/modules/js_deprecation_test/js/js_deprecation_test.es6.js
[10:10:59] '/Users/wim.leers/Work/d8/core/modules/system/tests/modules/js_deprecation_test/js/js_deprecation_test.es6.js' is being checked.
✨  Done in 0.35s.
yarn run v1.17.3
$ cross-env BABEL_ENV=legacy node ./scripts/js/babel-es6-build.js --check --file /Users/wim.leers/Work/d8/core/modules/system/tests/modules/js_deprecation_test/js/js_deprecation_test.es6.js
[10:11:00] '/Users/wim.leers/Work/d8/core/modules/system/tests/modules/js_deprecation_test/js/js_deprecation_test.es6.js' is being checked.
✨  Done in 0.36s.
PHPCS: core/modules/system/tests/modules/js_deprecation_test/js_deprecation_test.info.yml passed
PHPCS: core/modules/system/tests/modules/js_deprecation_test/js_deprecation_test.libraries.yml passed
PHPCS: core/modules/system/tests/modules/js_deprecation_test/js_deprecation_test.module passed
PHPCS: core/modules/system/tests/modules/js_deprecation_test/js_deprecation_test.routing.yml passed
PHPCS: core/modules/system/tests/modules/js_deprecation_test/src/Controller/JsDeprecationTestController.php passed
PHPCS: core/profiles/nightwatch_testing/config/optional/locale.settings.yml passed
PHPCS: core/profiles/nightwatch_testing/nightwatch_testing.info.yml passed
PHPCS: core/tests/Drupal/FunctionalJavascriptTests/JavascriptDeprecationTest.php passed
PHPCS: core/tests/Drupal/FunctionalJavascriptTests/WebDriverTestBase.php passed
Committed <a href="https://git.drupalcode.org/project/drupal/commit/844e295">844e295</a> and pushed to 8.8.x. Thanks!

*** Does it need a change record? ***
*** Should it be in the release notes? ***
[8.8.x 844e295269] 63
 27 files changed, 422 insertions(+), 12 deletions(-)
 create mode 100644 core/modules/system/tests/modules/js_deprecation_log_test/js/js_deprecation_log.es6.js
 create mode 100644 core/modules/system/tests/modules/js_deprecation_log_test/js/js_deprecation_log.js
 create mode 100644 core/modules/system/tests/modules/js_deprecation_log_test/js_deprecation_log_test.info.yml
 create mode 100644 core/modules/system/tests/modules/js_deprecation_log_test/js_deprecation_log_test.libraries.yml
 create mode 100644 core/modules/system/tests/modules/js_deprecation_log_test/js_deprecation_log_test.module
 create mode 100644 core/modules/system/tests/modules/js_deprecation_test/js/js_deprecation_test.es6.js
 create mode 100644 core/modules/system/tests/modules/js_deprecation_test/js/js_deprecation_test.js
 create mode 100644 core/modules/system/tests/modules/js_deprecation_test/js_deprecation_test.info.yml
 create mode 100644 core/modules/system/tests/modules/js_deprecation_test/js_deprecation_test.libraries.yml
 create mode 100644 core/modules/system/tests/modules/js_deprecation_test/js_deprecation_test.module
 create mode 100644 core/modules/system/tests/modules/js_deprecation_test/js_deprecation_test.routing.yml
 create mode 100644 core/modules/system/tests/modules/js_deprecation_test/src/Controller/JsDeprecationTestController.php
 create mode 100644 core/profiles/nightwatch_testing/config/optional/locale.settings.yml
 create mode 100644 core/profiles/nightwatch_testing/nightwatch_testing.info.yml
 create mode 100644 core/tests/Drupal/FunctionalJavascriptTests/JavascriptDeprecationTest.php
 create mode 100644 core/tests/Drupal/Nightwatch/Assertions/deprecationErrorExists.js
 create mode 100644 core/tests/Drupal/Nightwatch/Assertions/noDeprecationErrors.js
 create mode 100644 core/tests/Drupal/Nightwatch/Tests/jsDeprecationTest.js
alexpott’s picture

Status: Reviewed & tested by the community » Needs work
00:59:31.733    SyntaxError: Error while running "noDeprecationErrors" command: Unexpected token o in JSON at position 1
00:59:31.733        at JSON.parse (<anonymous>)
00:59:31.733        at AssertionInstance.value.result [as value] (/var/www/html/core/tests/Drupal/Nightwatch/Assertions/noDeprecationErrors.js:6:40)
00:59:31.733        at <anonymous>
00:59:31.733        at process._tickCallback (internal/process/next_tick.js:189:7)
00:59:31.734 
00:59:31.734 FAILED: 1 errors and  2 passed (135ms)
00:59:31.734    SyntaxError: Error while running "noDeprecationErrors" command: Unexpected token o in JSON at position 1
00:59:31.734        at JSON.parse (<anonymous>)
00:59:31.734        at AssertionInstance.value.result [as value] (/var/www/html/core/tests/Drupal/Nightwatch/Assertions/noDeprecationErrors.js:6:40)
00:59:31.734        at <anonymous>
00:59:31.734        at process._tickCallback (internal/process/next_tick.js:189:7)
00:59:31.878 
00:59:31.878 [Js Deprecation Test] Test Suite
00:59:31.878 ================================
00:59:37.132 ✔ Element <input[name="modules[js_deprecation_test][enable]"]> was visible after 540 milliseconds.
00:59:38.493 Running:  Test JavaScript deprecations
00:59:38.493 
00:59:38.593 ✔ Element <body> was visible after 27 milliseconds.
00:59:38.624 ✔ Testing if element <h1> contains text: "JsDeprecationTest"  - 31 ms.
00:59:38.638 
00:59:38.638 OK. 2 assertions passed. (145ms)
00:59:38.983 
00:59:38.983 [Login Test] Test Suite
00:59:38.983 =======================
00:59:42.270 Running:  Test login
00:59:42.270 
00:59:43.697 ✔ Expected element <.user-role-form .machine-name-value> to be visible in 2000ms - condition was met in 538ms
00:59:45.614 ✔ User "user" was created successfully  - 36 ms.
00:59:46.058 ✔ Passed [equal]: The user "user" was logged in.
00:59:46.146 ✔ Element <body> was visible after 26 milliseconds.
00:59:46.181 ✔ Testing if element <h1> contains text: "Reports"  - 35 ms.
00:59:46.187 
00:59:46.187 OK. 5 assertions passed. (3.917s)
00:59:46.482 
00:59:46.482 [States Test] Test Suite
00:59:46.482 ========================
00:59:51.745 ✔ Element <input[name="modules[form_test][enable]"]> was visible after 544 milliseconds.
00:59:54.033 Running:  Test form with state API
00:59:54.033 
00:59:54.132 ✔ Element <body> was visible after 26 milliseconds.
00:59:54.157 ✔ Element <input[name="textfield"]> was not visible after 25 milliseconds.
00:59:54.164 
00:59:54.164 OK. 2 assertions passed. (132ms)
00:59:54.491 _________________________________________________
00:59:54.491 
00:59:54.491 TEST FAILURE: 1 error during execution 0 assertions failed, 15 passed. 26.871s
00:59:54.491 
00:59:54.491  ✖ exampleTest
00:59:54.491  – Page objects test page (135ms)
00:59:54.491 
00:59:54.491   SyntaxError: Error while running "noDeprecationErrors" command: Unexpected token o in JSON at position 1
00:59:54.491        at JSON.parse (<anonymous>)
00:59:54.491        at AssertionInstance.value.result [as value] (/var/www/html/core/tests/Drupal/Nightwatch/Assertions/noDeprecationErrors.js:6:40)
00:59:54.491        at <anonymous>
00:59:54.491        at process._tickCallback (internal/process/next_tick.js:189:7)

So nightwatch tests are broken. Not the nicest reporting from DrupalCI :(

tedbow’s picture

Status: Needs work » Needs review
FileSize
739 bytes
24.75 KB

Sorry all. Was having some issue with linting breaking the tests.

+++ b/core/tests/Drupal/Nightwatch/Assertions/noDeprecationErrors.js
@@ -0,0 +1,23 @@
+  this.command = callback =>
+    this.api.execute(
+      () => window.sessionStorage.getItem('js_deprecation_log_test.warnings'),
+      callback,
+    );

We can't use an arrow function here. So I excluded this line from linting

Wim Leers’s picture

Status: Needs review » Needs work

Lots of errors like this reported by DrupalCI:

space/jenkins-drupal_patches-12602/source/core/misc/drupal.es6.js ✗ 1 more
line 0	File ignored because of a matching ignore pattern. Use "--no-ignore" to override.
/var/lib/drupalci/workspace/jenkins-drupal_patches-12602/source/core/misc/drupal.js ✗ 1 more
0	File ignored because of a matching ignore pattern. Use "--no-ignore" to override.
/var/lib/drupalci/workspace/j

Ran nightwatch tests locally. They do not pass. 😭 I'm getting a mysterious error. It passes for @lauriii and @tedbow. So we got on a call together, and discovered this:

  • On DrupalCI, #58:
    00:58:05.336 [Js Deprecation Test] Test Suite
    00:58:05.336 ================================
    00:58:10.629 ✔ Element <input[name="modules[js_deprecation_test][enable]"]> was visible after 542 milliseconds.
    00:58:11.947 Running:  Test JavaScript deprecations
    00:58:11.947 
    00:58:12.046 ✔ Element <body> was visible after 26 milliseconds.
    00:58:12.077 ✔ Testing if element <h1> contains text: "JsDeprecationTest"  - 30 ms.
    00:58:12.084 ✔ Testing if "This function is deprecated for testing purposes." deprecation error has been triggered  - 7 ms.
    00:58:12.091 ✔ Testing if "This property is deprecated for testing purposes." deprecation error has been triggered  - 5 ms.
    00:58:12.094 
    00:58:12.094 OK. 4 assertions passed. (147ms)
    
  • And #66:
    00:58:26.141 [Js Deprecation Test] Test Suite
    00:58:26.141 ================================
    00:58:31.361 ✔ Element <input[name="modules[js_deprecation_test][enable]"]> was visible after 539 milliseconds.
    00:58:32.666 Running:  Test JavaScript deprecations
    00:58:32.666 
    00:58:32.760 ✔ Element <body> was visible after 25 milliseconds.
    00:58:32.791 ✔ Testing if element <h1> contains text: "JsDeprecationTest"  - 30 ms.
    00:58:32.804 
    00:58:32.804 OK. 2 assertions passed. (138ms)
    

    2 assertions, should be 4! This is also happening for Lauri & Ted.

Ted is momentarily going to upload a new patch that fixes the problem!

tedbow’s picture

Status: Needs work » Needs review
FileSize
759 bytes
24.82 KB
+++ b/core/tests/Drupal/Nightwatch/Assertions/noDeprecationErrors.js
@@ -16,8 +16,8 @@ module.exports.assertion = function() {
-    this.api.execute(
-      () => window.sessionStorage.getItem('js_deprecation_log_test.warnings'),
-      callback,
-    );
+    // eslint-disable-next-line prefer-arrow-callback
+    this.api.execute(function() {
+      return window.sessionStorage.getItem('js_deprecation_log_test.warnings');
+    }, callback);

This exact change needed to happen in core/tests/Drupal/Nightwatch/Assertions/deprecationErrorExists.js also

lauriii’s picture

Status: Needs review » Reviewed & tested by the community

Nightwatch--

#68 should address this problem. 🙏 This is something I run into when I was working on building these assertions in the first place. Moving this back to the RTBC queue. 🚢

Wim Leers’s picture

RTBC confirmed, #68 passes locally for me 🥳

larowlan’s picture

larowlan’s picture

Status: Reviewed & tested by the community » Fixed

Committed 1b0c006 and pushed to 9.0.x. Thanks!

c/p to 8.8 and 8.9

  • larowlan committed 1b0c006 on 9.0.x
    Issue #3070521 by lauriii, tedbow, Wim Leers, larowlan, justafish, zrpnr...

  • larowlan committed fdfd477 on 8.9.x
    Issue #3070521 by lauriii, tedbow, Wim Leers, larowlan, justafish, zrpnr...

  • larowlan committed 557d2dd on 8.8.x
    Issue #3070521 by lauriii, tedbow, Wim Leers, larowlan, justafish, zrpnr...
larowlan’s picture

Oh: reminder - can we get those documentation updates please kind folks?

xjm’s picture

Status: Fixed » Needs work
Issue tags: +8.8.0 release notes

piles on as the third committer asking for docs updates

Yes please!

Also, this and the original new coding standard for JS deprecations should go in the release notes (together).

Wim Leers’s picture

Status: Needs work » Fixed
Issue tags: -needs documentation updates

@larowlan & @xjm: I already did that more than a week ago, see #51 :)

EDIT: ah, @catch tagged this needs documentation updates in #61, 4 days after I already did it. That's why the tag was still here.

xjm’s picture

Status: Fixed » Needs work

https://www.drupal.org/core/deprecation#javascript actually still is incomplete, so setting NW so that we don't lose track of it.

lauriii’s picture

Status: Needs work » Fixed

Status: Fixed » Closed (fixed)

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