mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Popups
synced 2024-12-01 02:36:35 +00:00
742f341e5c
Since Ieea378c9 all QUnit tests are run in Node.js and not in the browser. Tidy up references to QUnit inside of the codebase and tooling. Changes: * Don't exclude src/processLinks.js in Istanbul code coverage reports. * Don't test for window.QUnit in createSchema. We no longer run the risk of sending beacons while running the QUnit test suite as it's no longer run in the browser. Bug: T160406 Change-Id: Ifb6adb84b8019dd69231b50af00bf978b708fc60
58 lines
1.3 KiB
JavaScript
58 lines
1.3 KiB
JavaScript
var mw = mediaWiki,
|
|
createSchema = require( '../../src/schema' ),
|
|
createStubMap = require( './stubs' ).createStubMap;
|
|
|
|
QUnit.module( 'ext.popups/schema', {
|
|
beforeEach: function () {
|
|
this.config = createStubMap();
|
|
|
|
this.config.set( 'wgPopupsSchemaSamplingRate', 1 );
|
|
|
|
this.window = {
|
|
navigator: {
|
|
sendBeacon: function () {}
|
|
}
|
|
};
|
|
|
|
// Stub out the mw.eventLog.Schema constructor function.
|
|
mw.eventLog = { Schema: this.sandbox.stub() };
|
|
}
|
|
} );
|
|
|
|
QUnit.test( 'it should use $wgPopupsSchemaSamplingRate as the sampling rate', function ( assert ) {
|
|
assert.expect( 2 );
|
|
|
|
createSchema( this.config, this.window );
|
|
|
|
assert.ok( mw.eventLog.Schema.calledWith( 'Popups', 1 ) );
|
|
|
|
// ---
|
|
|
|
createSchema( createStubMap(), this.window );
|
|
|
|
assert.ok(
|
|
mw.eventLog.Schema.calledWith( 'Popups', 0 ),
|
|
'If $wgPopupsSchemaSamplingRate isn\'t set, then the sampling rate should be 0.'
|
|
);
|
|
} );
|
|
|
|
QUnit.test( 'it should use a 0 sampling rate when sendBeacon isn\'t supported', function ( assert ) {
|
|
var expectedArgs = [ 'Popups', 0 ];
|
|
|
|
assert.expect( 2 );
|
|
|
|
createSchema( this.config, { } );
|
|
|
|
assert.deepEqual( mw.eventLog.Schema.getCall( 0 ).args, expectedArgs );
|
|
|
|
// ---
|
|
|
|
createSchema( this.config, {
|
|
navigator: {
|
|
sendBeacon: 'NOT A FUNCTION'
|
|
}
|
|
} );
|
|
|
|
assert.deepEqual( mw.eventLog.Schema.getCall( 1 ).args, expectedArgs );
|
|
} );
|