Page MenuHomePhabricator

JavaScript test reports global variable pluralRuleParser
Closed, ResolvedPublic

Description

When running the whole JavaScript test with the flag noglobals it reports:

mediawiki.jqueryMsg: formatnum (2, 14, 16)

    Introduced global variable(s): pluralRuleParser

When rerun the problematic test the error does not occur.

Event Timeline

Fomafix raised the priority of this task from to Needs Triage.
Fomafix updated the task description. (Show Details)
Fomafix subscribed.
gerritbot subscribed.

Change 190446 had a related patch set uploaded (by Gerrit Patch Uploader):
Use mw.libs.pluralRuleParser directly

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

Patch-For-Review

The test complains because the global appears half-way through the test suite, long after all source dependencies have been loaded. That is the problem.

The check indicates an unknown global appeared within the test execution. That can mean either, 1) a new variable was created and accidentally let to be global due to omission of a var statement), or 2) It was meant to be global, but created too late.

In this case it's case #2. This code very intentionally (window means global) makes it a global variable. The problem is merely it appearing too late (tests shouldn't create new global variables).

Note that this check is optional and not enabled at the moment (QUnit: checkbox "Check for globals"). It'd be nice, but not a major issue.

When rerun the problematic test the error does not occur.

When QUnit re-runs tests, it remembers which failed last time and runs those first.

Since this global is likely introduced by an asynchronous request, the individual assertion that first noticed this global probably isn't loading the global itself. As such, when re-running only that one test, the global doesn't appear. When re-running all tests, it appears again.

Change 190446 abandoned by Nikerabbit:
Use mw.libs.pluralRuleParser directly

Reason:
This issue needs different approach. See the bug for more details. This patch has not moved for a long time.

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

I can't reproduce this anymore. It was most likely fixed due to ensuring dependencies load in the right order, thus pluralRuleParser now exists before QUnit creates the snapshot of "allowed" globals, as it should.