Page MenuHomePhabricator

WikiLambda unit tests fail with TypeError: Cannot redefine property: window when running on Node 19
Closed, ResolvedPublicBUG REPORT

Description

Steps to replicate the issue (include links if applicable):

What happens?:
The test fails with the following error

FAIL  tests/jest/integration/CancelEditNewFunction.test.js
  ● WikiLambda frontend, function-editor view, on a new function › allows cancelling with no changes

    TypeError: Cannot redefine property: window

      15 |      jest.useFakeTimers();
      16 |
    > 17 |      global.window = Object.create( window );
         |                    ^
      18 |      Object.defineProperty( window, 'location', {
      19 |              value: {
      20 |                      href: 'currentPage'

      at runSetup (tests/jest/integration/helpers/functionEditorTestHelpers.js:17:16)
      at Object.<anonymous> (tests/jest/integration/CancelEditNewFunction.test.js:28:3)

  ● WikiLambda frontend, function-editor view, on a new function › allows cancelling after changes

    TypeError: Cannot redefine property: window

      15 |      jest.useFakeTimers();
      16 |
    > 17 |      global.window = Object.create( window );
         |                    ^
      18 |      Object.defineProperty( window, 'location', {
      19 |              value: {
      20 |                      href: 'currentPage'

      at runSetup (tests/jest/integration/helpers/functionEditorTestHelpers.js:17:16)
      at Object.<anonymous> (tests/jest/integration/CancelEditNewFunction.test.js:28:3)

What should have happened instead?:
Pass the tests without error

Software version (skip for WMF-hosted wikis like Wikipedia):
Node.js 19.7.0
macOS 13.2.1

I think removing all global.window = Object.create( window ); will pass the tests .

Event Timeline

DVrandecic renamed this task from WikiLamda unit tests fail with TypeError: Cannot redefine property: window to WikiLambda unit tests fail with TypeError: Cannot redefine property: window.Mar 14 2023, 6:35 PM
Jdforrester-WMF renamed this task from WikiLambda unit tests fail with TypeError: Cannot redefine property: window to WikiLambda unit tests fail with TypeError: Cannot redefine property: window when running on Node 19.Mar 14 2023, 6:56 PM

Hey there, I can replicate this bug locally on node 19 (as you report), but of course it passes fine on node 14 and 16 (which we use for CI) and I've just tested it as working on node 18 too, so we didn't notice.

Thank you for the fix!

Change 898676 had a related patch set uploaded (by Jforrester; author: Takaharu Nakamura):

[mediawiki/extensions/WikiLambda@master] tests: Don't try to re-create global window, it breaks on Node 19

https://gerrit.wikimedia.org/r/898676

Change 898676 merged by jenkins-bot:

[mediawiki/extensions/WikiLambda@master] tests: Don't try to re-create global window, it breaks on Node 19

https://gerrit.wikimedia.org/r/898676

@Jdforrester-WMF Thank you for reviewing and merging my code.
This is my first time committing to a massive project, so I am breathing a sigh of relief at the successful merging.
I'm interested in participating GSoC23, please keep an eye on my activity!