Skip to content

Commit

Permalink
T346029 ES Module (#481)
Browse files Browse the repository at this point in the history
* Module

* Deepmerge

* Module

* *.conf.js

* Basic Convert

* Basic Convert

* Fix import

* Fix import

* Fix config import

* Fix exec import

* Directory

* Undo

* Lint

* Test

* Test

* T347117 Repo Nuke Test flaky (#480)

* fix: make nuke test wait for jobs

* fix: assert instead of return

* fix: individual vars for clarity

* Import Fixes

* Filter

* Blazegraph import

* Imports

* imports

* readFileEncoding

* page.js

* default-functions.js

* defaultFunctions

* fix: image upload test

* Formatting

* Function

* Refactor

* Passing

* Passing CJS

* Working MJS

* Engines

* WDIO Patch

---------

Co-authored-by: rti <rti@users.noreply.github.com>
Co-authored-by: roti <robert.timm@wikimedia.de>
  • Loading branch information
3 people authored Oct 5, 2023
1 parent 3ab3bb8 commit 845f7e4
Show file tree
Hide file tree
Showing 64 changed files with 483 additions and 526 deletions.
5 changes: 5 additions & 0 deletions test/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
"wikimedia/selenium",
"wikimedia/language/es2019"
],
"parserOptions": {
"sourceType": "module",
"allowImportExportEverywhere": true,
"ecmaVersion": "latest"
},
"rules": {
"mocha/no-setup-in-describe": "warn"
}
Expand Down
8 changes: 3 additions & 5 deletions test/helpers/WDIOMediawikiScreenshotPatch.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
'use strict';

/**
* Patches the use of `browser.config` in the screenshot-related code in
* https://gerrit.wikimedia.org/r/plugins/gitiles/mediawiki/core/+/refs/heads/wmf/1.40.0-wmf.24/tests/selenium/wdio-mediawiki/index.js
* TODO: Update wdio-mediawiki, remove this file.
* See https://phabricator.wikimedia.org/T347137
*/

const fs = require( 'fs' );
const { makeFilenameDate } = require( 'wdio-mediawiki' );
import fs from 'fs';
import { makeFilenameDate } from 'wdio-mediawiki';

/**
* @since 1.1.0
Expand Down Expand Up @@ -52,4 +50,4 @@ function saveScreenshot( screenshotPath, title ) {
return path;
}

module.exports = saveScreenshot;
export default saveScreenshot;
8 changes: 3 additions & 5 deletions test/helpers/WDIOWikibaseApiPatch.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
'use strict';

const MWBot = require( 'mwbot' );
const request = require( 'request' );
import MWBot from 'mwbot';
import request from 'request';

/**
* Patches the use of `browser.config` in
Expand Down Expand Up @@ -163,4 +161,4 @@ class WikibaseApiPatch {
}
}

module.exports = new WikibaseApiPatch();
export default new WikibaseApiPatch();
10 changes: 2 additions & 8 deletions test/helpers/blazegraph.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
'use strict';
import lodash from 'lodash';

const lodash = require( 'lodash' );

const getElementByURI = function ( uri, bindings ) {
export const getElementByURI = function ( uri, bindings ) {
const index = lodash.findIndex( bindings, function ( binding ) {
return binding.p.value === uri;
} );
return index === -1 ? [] : bindings[ index ];
};

module.exports = {
getElementByURI: getElementByURI
};
45 changes: 23 additions & 22 deletions test/helpers/default-functions.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
'use strict';
import axios from 'axios';
import assert from 'assert';
import { exec } from 'child_process';
import lodash from 'lodash';
import WikibaseApi from './WDIOWikibaseApiPatch.js';

const axios = require( 'axios' );
const assert = require( 'assert' );
const exec = require( 'child_process' ).exec;
const lodash = require( 'lodash' );
const WikibaseApi = require( './WDIOWikibaseApiPatch' );

const defaultFunctions = function () {
export function defaultFunctions() {
/**
* Make a get request to get full request response
* Returns a Promise
Expand Down Expand Up @@ -258,18 +256,21 @@ const defaultFunctions = function () {
}
);
} );
};

module.exports = {
init: defaultFunctions,
skipIfExtensionNotPresent: ( test, extension ) => {
const installedExtensions = browser.options.installed_extensions;
if ( !installedExtensions || installedExtensions.length === 0 ) {
return;
} else if ( installedExtensions && installedExtensions.includes( 'WikibaseRepository' ) && installedExtensions.includes( extension ) ) {
return;
} else {
test.skip();
}
}

export async function skipIfExtensionNotPresent( test, extension ) {
const installedExtensions = await browser.getInstalledExtensions(
process.env.MW_SERVER
);
if ( !installedExtensions || installedExtensions.length === 0 ) {
return;
} else if (
installedExtensions &&
installedExtensions.includes( 'WikibaseRepository' ) &&
installedExtensions.includes( extension )
) {
return;
} else {
test.skip();
}
};
}
22 changes: 0 additions & 22 deletions test/helpers/fetchSuite.js

This file was deleted.

18 changes: 9 additions & 9 deletions test/helpers/json-reporter.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
'use strict';

const fs = require( 'fs' );
const reporter = require( '@wdio/reporter' );

class JsonReporter extends reporter.default {
import fs from 'fs';
import reporter from '@wdio/reporter';

class JsonReporter extends reporter {
constructor( options ) {
// make reporter to write to the output stream by default
options = Object.assign( options, { stdout: true } );
Expand Down Expand Up @@ -59,9 +56,12 @@ class JsonReporter extends reporter.default {
}
}

fs.writeFileSync( this.resultFilePath, JSON.stringify( result, null, 2 ), 'utf-8' );
fs.writeFileSync(
this.resultFilePath,
JSON.stringify( result, null, 2 ),
'utf-8'
);
}

}

module.exports = JsonReporter;
export default JsonReporter;
22 changes: 14 additions & 8 deletions test/helpers/pages/SuiteLoginPage.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
'use strict';

const Page = require( './WDIOMediawikiPagePatch' );
import Page from './WDIOMediawikiPagePatch.js';

// This is a replacement for `wdio-mediawiki/LoginPage`
// which as of version 2.2.0 does not properly await WDIO elements
// causing failures and otherwise unpredictable results.
// TODO: Fix upstream code in `wdio-mediawiki/LoginPage`
// See https://gerrit.wikimedia.org/r/plugins/gitiles/mediawiki/core/+/refs/heads/wmf/1.40.0-wmf.24/tests/selenium/wdio-mediawiki/LoginPage.js
class SuiteLoginPage extends Page {
get username() { return $( '#wpName1' ); }
get password() { return $( '#wpPassword1' ); }
get loginButton() { return $( '#wpLoginAttempt' ); }
get userPage() { return $( '#pt-userpage' ); }
get username() {
return $( '#wpName1' );
}
get password() {
return $( '#wpPassword1' );
}
get loginButton() {
return $( '#wpLoginAttempt' );
}
get userPage() {
return $( '#pt-userpage' );
}

open() {
return super.openTitle( 'Special:UserLogin' );
Expand All @@ -38,4 +44,4 @@ class SuiteLoginPage extends Page {
}
}

module.exports = new SuiteLoginPage();
export default new SuiteLoginPage();
14 changes: 6 additions & 8 deletions test/helpers/pages/WDIOMediawikiPagePatch.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
'use strict';

const querystring = require( 'querystring' );
const Page = require( 'wdio-mediawiki/Page' );
import querystring from 'querystring';
import Page from 'wdio-mediawiki/Page.js';

/**
* Patches the use of `browser.config` in
Expand All @@ -10,7 +8,6 @@ const Page = require( 'wdio-mediawiki/Page' );
* See https://phabricator.wikimedia.org/T347137
*/
class PagePatch extends Page {

/**
* Navigate the browser to a given page.
*
Expand All @@ -24,11 +21,12 @@ class PagePatch extends Page {
async openTitle( title, query = {}, fragment = '' ) {
query.title = title;
await browser.url(
browser.options.baseUrl + '/index.php?' +
browser.options.baseUrl +
'/index.php?' +
querystring.stringify( query ) +
( fragment ? ( '#' + fragment ) : '' )
( fragment ? '#' + fragment : '' )
);
}
}

module.exports = PagePatch;
export default PagePatch;
6 changes: 2 additions & 4 deletions test/helpers/pages/entity/property.page.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
'use strict';

const Page = require( '../page' );
import Page from '../page.js';

class Property extends Page {

Expand All @@ -13,4 +11,4 @@ class Property extends Page {
}
}

module.exports = new Property();
export default new Property();
7 changes: 3 additions & 4 deletions test/helpers/pages/page.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
'use strict';
class Page {
constructor() {
}
constructor() {}

async open( path ) {
await browser.url( 'http://' + process.env.WDQS_FRONTEND_SERVER + path );
}
}
module.exports = Page;

export default Page;
6 changes: 2 additions & 4 deletions test/helpers/pages/queryservice-ui/queryservice-ui.page.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
'use strict';

const Page = require( '../page' );
import Page from '../page.js';

class QueryServiceUI extends Page {

Expand Down Expand Up @@ -36,4 +34,4 @@ class QueryServiceUI extends Page {

}

module.exports = new QueryServiceUI();
export default new QueryServiceUI();
5 changes: 2 additions & 3 deletions test/helpers/pages/special/new-item.page.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';
import Page from '../page.js';

const Page = require( '../page' );
class SpecialNewItem extends Page {

get labelInput() { return $( 'input[name="label"]' ); }
Expand All @@ -20,4 +19,4 @@ class SpecialNewItem extends Page {

}

module.exports = new SpecialNewItem();
export default new SpecialNewItem();
6 changes: 2 additions & 4 deletions test/helpers/pages/special/new-property.page.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
'use strict';

const Page = require( '../page' );
import Page from '../page.js';

class SpecialNewProperty extends Page {

Expand All @@ -25,4 +23,4 @@ class SpecialNewProperty extends Page {

}

module.exports = new SpecialNewProperty();
export default new SpecialNewProperty();
8 changes: 1 addition & 7 deletions test/helpers/readFileEncoding.js
Original file line number Diff line number Diff line change
@@ -1,7 +1 @@
'use strict';

const utf8 = { encoding: 'utf8' };

module.exports = {
utf8: utf8
};
export const utf8 = { encoding: 'utf8' };
Loading

0 comments on commit 845f7e4

Please sign in to comment.