mediawiki-extensions-Popups/tests/node-qunit/run.js
jdlrobson 7d6a903d69 Upgrade Popups mw-node-qunit version
Bug: T203137
Change-Id: I0cf856d04eacf5bf7764c58db55eeae04811e973
2019-10-15 15:36:54 -07:00

63 lines
1.5 KiB
JavaScript
Executable file

#!/usr/bin/env node
const fs = require( 'fs' ),
mwNodeQunit = require( '@wikimedia/mw-node-qunit' ),
sinon = mwNodeQunit.sinon,
sandbox = sinon.sandbox.create(),
QUnitModule = QUnit.module,
svgInlineLoader = require( 'svg-inline-loader' );
require( '@babel/register' )( {
presets: [
[ '@babel/preset-env', {
targets: {
node: 6
}
} ]
]
} );
require.extensions[ '.svg' ] = ( module, filename ) => {
const svg = fs.readFileSync( filename, { encoding: 'utf8' } );
// eslint-disable-next-line no-underscore-dangle
module._compile( svgInlineLoader( svg ), filename );
};
sinon.config = {
injectIntoThis: true,
injectInto: null,
useFakeTimers: false,
useFakeServer: false,
properties: [ 'spy', 'stub', 'mock', 'sandbox' ]
};
mwNodeQunit.dom.setUp( sandbox, global );
mwNodeQunit.jQuery.setUp( sandbox, global );
mwNodeQunit.mw.setUp( sandbox, global );
global.mediaWiki = global.mw;
global.jQuery = global.$;
// Override Qunit.module to set up a sinon sandbox automatically
QUnit.module = function ( name, localEnv ) {
localEnv = localEnv || {};
QUnitModule( name, {
beforeEach: function () {
const config = Object.assign( {}, sinon.config, {
injectInto: this
} );
sinon.sandbox.create( config );
if ( localEnv.beforeEach ) {
localEnv.beforeEach.call( this );
}
},
afterEach: function () {
// Interop with old teardown config on mediawiki codebases
this.sandbox.restore();
if ( localEnv.afterEach ) {
localEnv.afterEach.call( this );
}
}
} );
};