tests: Adopt private require() for skins.minerva.scripts (take 2)

Resubmission of Ib68f45d93a (548e94da98), which caused an error due
to `require('../../`)` not working outside the module base directory.
This is fixed with regression test in T373065.

Further confirmed in this repo by viewing
`/wiki/Special:CreateAccount?campaign=loginCTA&useskin=minerva`
with this patch applied. Without the T373065 fix, the console warns:
> Error: Cannot require undefined file …/ToggleList.js

-------

Support for private require() in tests is available since MW 1.41:
https://mediawiki.org/wiki/RL/PKG#Private_export_and_import
https://mediawiki.org/wiki/RL/PKG#Virtual_files_in_traditional_modules

This fixes a confusing assertion in page-issues/index.test.js,
where for "insertBannersOrNotice()" it was asserting that the HTML
contain "⧼skin-minerva-issue-learn-more⧽", where the ⧼ character
indicates the message is not found (i.e. an error).

The test had to be written this way in order to pass, because
the skins.minerva.scripts module was not actually loaded, and thus
its templates and messages are not present either. This lack was
filled in by index.js for mw.templates, but not mw.messages.

By adopting private require(), these workarounds can all be removed.

== Motivation ==

In change I3a4024ccf90e505581, I'm working on improving the testrunner
config to enforce uselang=qqx on all tests. This is passing except
for GrowthExperiments and Minerva, both of which have the above
workarounds in place that caused a message to be undefined, and then
kept in the assertion expectation. When using uselang=qqx, values are
returned as (key) instead of ⧼key⧽, which exposes these message
existence errors.

By removing this workaround, the test will simply import the module
in the test as normal, thus the messages will exist, and thus it
will expect (key), and thus it will continue to pass even after
enforcing uselang=qqx.

Bug: T373482
Depends-On: I777f2c12e845a738edeac00e19818d4c939a1ef1
Change-Id: I6348e5ae00776c2c01d91fa90a431b6ffe3da25d
This commit is contained in:
Timo Tijhof 2024-08-23 05:25:52 +01:00 committed by Jdlrobson
parent a9fe1ac572
commit 4ca4febd89
10 changed files with 77 additions and 103 deletions

View file

@ -46,7 +46,9 @@ function init() {
);
}
init();
if ( !window.QUnit ) {
init();
}
module.exports = {
// Version number allows breaking changes to be detected by other extensions

View file

@ -522,6 +522,8 @@
]
},
"skins.minerva.scripts": {
"localBasePath": "resources/skins.minerva.scripts",
"remoteSkinPath": "MinervaNeue/resources/skins.minerva.scripts",
"dependencies": [
"skins.minerva.mainMenu.icons",
"skins.minerva.mainMenu.styles",
@ -561,40 +563,40 @@
"mobile-frontend-redirected-from"
],
"styles": [
"resources/skins.minerva.scripts/styles.less"
"styles.less"
],
"templates": {
"IssueNotice.mustache": "resources/skins.minerva.scripts/page-issues/overlay/IssueNotice.mustache"
"IssueNotice.mustache": "page-issues/overlay/IssueNotice.mustache"
},
"packageFiles": [
"resources/skins.minerva.scripts/setup.js",
"resources/skins.minerva.scripts/reportIfNightModeWasDisabledOnPage.js",
"resources/skins.minerva.scripts/addPortletLink.js",
"resources/skins.minerva.scripts/initMobile.js",
"resources/skins.minerva.scripts/searchSuggestReveal.js",
"resources/skins.minerva.scripts/drawers.js",
"resources/skins.minerva.scripts/ctaDrawers.js",
"resources/skins.minerva.scripts/menu.js",
"resources/skins.minerva.scripts/preInit.js",
"resources/skins.minerva.scripts/downloadPageAction.js",
"resources/skins.minerva.scripts/page-issues/parser.js",
"resources/skins.minerva.scripts/AB.js",
"resources/skins.minerva.scripts/page-issues/overlay/IssueNotice.js",
"resources/skins.minerva.scripts/page-issues/overlay/IssueList.js",
"resources/skins.minerva.scripts/page-issues/overlay/pageIssuesOverlay.js",
"resources/skins.minerva.scripts/page-issues/page/PageIssueLearnMoreLink.js",
"resources/skins.minerva.scripts/page-issues/page/PageIssueLink.js",
"resources/skins.minerva.scripts/page-issues/page/pageIssueFormatter.js",
"resources/skins.minerva.scripts/page-issues/index.js",
"resources/skins.minerva.scripts/UriUtil.js",
"resources/skins.minerva.scripts/TitleUtil.js",
"includes/Skins/ToggleList/ToggleList.js",
"resources/skins.minerva.scripts/TabScroll.js",
"resources/skins.minerva.scripts/Toolbar.js",
"resources/skins.minerva.scripts/mobileRedirect.js",
"resources/skins.minerva.scripts/search.js",
"resources/skins.minerva.scripts/references.js",
"resources/skins.minerva.scripts/watchstar.js"
"setup.js",
"reportIfNightModeWasDisabledOnPage.js",
"addPortletLink.js",
"initMobile.js",
"searchSuggestReveal.js",
"drawers.js",
"ctaDrawers.js",
"menu.js",
"preInit.js",
"downloadPageAction.js",
"page-issues/parser.js",
"AB.js",
"page-issues/overlay/IssueNotice.js",
"page-issues/overlay/IssueList.js",
"page-issues/overlay/pageIssuesOverlay.js",
"page-issues/page/PageIssueLearnMoreLink.js",
"page-issues/page/PageIssueLink.js",
"page-issues/page/pageIssueFormatter.js",
"page-issues/index.js",
"UriUtil.js",
"TitleUtil.js",
"../../includes/Skins/ToggleList/ToggleList.js",
"TabScroll.js",
"Toolbar.js",
"mobileRedirect.js",
"search.js",
"references.js",
"watchstar.js"
]
},
"skins.minerva.messageBox.styles": {
@ -620,39 +622,26 @@
}
},
"QUnitTestModule": {
"localBasePath": "",
"remoteSkinPath": "MinervaNeue",
"localBasePath": "tests/qunit/skins.minerva.scripts",
"remoteSkinPath": "MinervaNeue/tests/qunit/skins.minerva.scripts",
"dependencies": [
"mediawiki.cookie",
"skins.minerva.messageBox.styles",
"skins.minerva.scripts",
"mobile.startup",
"mediawiki.user",
"mediawiki.experiments",
"mediawiki.Uri"
],
"packageFiles": [
"tests/qunit/skins.minerva.scripts/index.js",
"tests/qunit/skins.minerva.scripts/integration.test.js",
"resources/skins.minerva.scripts/page-issues/parser.js",
"resources/skins.minerva.scripts/downloadPageAction.js",
"resources/skins.minerva.scripts/AB.js",
"resources/skins.minerva.scripts/page-issues/overlay/IssueNotice.js",
"resources/skins.minerva.scripts/page-issues/overlay/IssueList.js",
"resources/skins.minerva.scripts/page-issues/overlay/pageIssuesOverlay.js",
"resources/skins.minerva.scripts/page-issues/page/PageIssueLearnMoreLink.js",
"resources/skins.minerva.scripts/page-issues/page/PageIssueLink.js",
"resources/skins.minerva.scripts/page-issues/page/pageIssueFormatter.js",
"resources/skins.minerva.scripts/page-issues/index.js",
"resources/skins.minerva.scripts/UriUtil.js",
"resources/skins.minerva.scripts/TitleUtil.js",
"resources/skins.minerva.scripts/watchstar.js",
"tests/qunit/skins.minerva.scripts/downloadPageAction.test.js",
"tests/qunit/skins.minerva.scripts/page-issues/parser.test.js",
"tests/qunit/skins.minerva.scripts/AB.test.js",
"tests/qunit/skins.minerva.scripts/page-issues/index.test.js",
"tests/qunit/skins.minerva.scripts/UriUtil.test.js",
"tests/qunit/skins.minerva.scripts/TitleUtil.test.js",
"tests/qunit/skins.minerva.scripts/watchstar.test.js"
"scripts": [
"integration.test.js",
"downloadPageAction.test.js",
"page-issues/parser.test.js",
"AB.test.js",
"page-issues/index.test.js",
"UriUtil.test.js",
"TitleUtil.test.js",
"watchstar.test.js"
]
},
"ServiceWiringFiles": [

View file

@ -1,6 +1,6 @@
( function () {
const AB = require( '../../../resources/skins.minerva.scripts/AB.js' );
const AB = require( 'skins.minerva.scripts/AB.js' );
const defaultConfig = {
testName: 'WME.MinervaABTest',
samplingRate: 0.5,

View file

@ -1,5 +1,5 @@
( function () {
const TitleUtil = require( '../../../resources/skins.minerva.scripts/TitleUtil.js' );
const TitleUtil = require( 'skins.minerva.scripts/TitleUtil.js' );
const mwUriOrg = mw.Uri;
QUnit.module( 'Minerva TitleUtil', QUnit.newMwEnvironment( {

View file

@ -1,5 +1,5 @@
( function () {
const UriUtil = require( '../../../resources/skins.minerva.scripts/UriUtil.js' );
const UriUtil = require( 'skins.minerva.scripts/UriUtil.js' );
const mwUriOrg = mw.Uri;
QUnit.module( 'Minerva UriUtil', {

View file

@ -7,7 +7,7 @@
const Deferred = $.Deferred;
const windowChrome = { chrome: true };
const windowNotChrome = {};
const downloadAction = require( '../../../resources/skins.minerva.scripts/downloadPageAction.js' );
const downloadAction = require( 'skins.minerva.scripts/downloadPageAction.js' );
const onClick = downloadAction.test.onClick;
const isAvailable = downloadAction.test.isAvailable;

View file

@ -1,14 +0,0 @@
// Since tests.minerva.scripts does
// not pull in the entire module skins.minerva.scripts
// we have to stub certain templates to make it appear like its been loaded.
mw.template.add( 'skins.minerva.scripts', 'IssueNotice.mustache', '' );
module.exports = [
require( './integration.test.js' ),
require( './downloadPageAction.test.js' ),
require( './page-issues/parser.test.js' ),
require( './AB.test.js' ),
require( './page-issues/index.test.js' ),
require( './UriUtil.test.js' ),
require( './TitleUtil.test.js' ),
require( './watchstar.test.js' )
];

View file

@ -1,31 +1,28 @@
( function () {
const
mobile = require( 'mobile.startup' ),
pageIssues = require( '../../../../resources/skins.minerva.scripts/page-issues/index.js' ),
insertBannersOrNotice = pageIssues.test.insertBannersOrNotice,
PageHTMLParser = mobile.PageHTMLParser,
overlayManager = mobile.getOverlayManager(),
$mockContainer = $(
'<div id=\'bodyContent\'>' +
'<table class=\'ambox ambox-content\'>' +
'<tbody class=\'mbox-text\'>' +
'<tr><td><span class=\'mbox-text-span\'> ambox text span </span></td></tr>' +
QUnit.module( 'Minerva pageIssues', () => {
const mobile = require( 'mobile.startup' );
const pageIssues = require( 'skins.minerva.scripts/page-issues/index.js' );
const insertBannersOrNotice = pageIssues.test.insertBannersOrNotice;
const PageHTMLParser = mobile.PageHTMLParser;
const overlayManager = mobile.getOverlayManager();
const $mockContainer = $(
'<div id="bodyContent">' +
'<table class="ambox ambox-content">' +
'<tbody class="mbox-text">' +
'<tr><td><span class="mbox-text-span"> ambox text span </span></td></tr>' +
'</tbody>' +
'</table>' +
'</div>'
),
labelText = 'label text',
inline = true,
SECTION = '0',
processedAmbox = insertBannersOrNotice(
);
const labelText = 'label text';
const inline = true;
const SECTION = '0';
const processedAmbox = insertBannersOrNotice(
new PageHTMLParser( $mockContainer ),
labelText, SECTION, inline, overlayManager
).ambox;
QUnit.module( 'Minerva pageIssues' );
QUnit.test( 'insertBannersOrNotice() should add a "learn more" message', ( assert ) => {
assert.true( /⧼skin-minerva-issue-learn-more⧽/.test( processedAmbox.html() ) );
assert.true( /(skin-minerva-issue-learn-more)/.test( processedAmbox.html() ) );
} );
QUnit.test( 'insertBannersOrNotice() should add an icon', ( assert ) => {
@ -35,4 +32,4 @@
processedAmbox.click();
assert.strictEqual( window.location.hash, '#/issues/' + SECTION );
} );
}() );
} );

View file

@ -1,6 +1,6 @@
( function () {
const iconElement = document.createElement( 'div' ),
pageIssuesParser = require( '../../../../resources/skins.minerva.scripts/page-issues/parser.js' ),
pageIssuesParser = require( 'skins.minerva.scripts/page-issues/parser.js' ),
extractMessage = pageIssuesParser.extract;
iconElement.classList.add( 'minerva-icon--issue-generic-defaultColor', 'minerva-ambox-icon' );

View file

@ -1,6 +1,6 @@
/* eslint-disable no-jquery/no-class-state */
( function () {
const watchstar = require( '../../../resources/skins.minerva.scripts/watchstar.js' );
const watchstar = require( 'skins.minerva.scripts/watchstar.js' );
const toggleClasses = watchstar.test.toggleClasses;
const WATCHED_CLASS = watchstar.test.WATCHED_ICON_CLASS;
const TEMP_WATCHED_CLASS = watchstar.test.TEMP_WATCHED_ICON_CLASS;