diff --git a/Gruntfile.js b/Gruntfile.js index 6f632861d..c66342ddd 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -99,6 +99,7 @@ grunt.initConfig( { "test/only.html", "test/seed.html", "test/overload.html", + "test/preconfigured.html", "test/regex-filter.html", "test/regex-exclude-filter.html", "test/string-filter.html" diff --git a/src/core/config.js b/src/core/config.js index 5ecd0a097..f20c5ea2b 100644 --- a/src/core/config.js +++ b/src/core/config.js @@ -1,4 +1,5 @@ -import { sessionStorage } from "../globals"; +import { window, sessionStorage } from "../globals"; +import { extend } from "./utilities"; /** * Config object: Maintain internal state @@ -56,6 +57,13 @@ const config = { storage: sessionStorage }; +// take a predefined QUnit.config and extend the defaults +var globalConfig = window && window.QUnit && window.QUnit.config; +// only extend the global config if there is no QUnit overload +if ( window && window.QUnit && !window.QUnit.version ) { + extend( config, globalConfig ); +} + // Push a loose unnamed module to the modules collection config.modules.push( config.currentModule ); diff --git a/src/export.js b/src/export.js index c885f69ab..4089cfbdf 100644 --- a/src/export.js +++ b/src/export.js @@ -47,7 +47,9 @@ Object.defineProperty( QUnit, "reset", { } ); if ( defined.document ) { - if ( window.QUnit ) { + + // QUnit may be defined when it is preconfigured but then only QUnit and QUnit.config may be defined. + if ( window.QUnit && window.QUnit.version ) { throw new Error( "QUnit has already been defined." ); } diff --git a/test/preconfigured.html b/test/preconfigured.html new file mode 100644 index 000000000..0205b3f02 --- /dev/null +++ b/test/preconfigured.html @@ -0,0 +1,21 @@ + + + + + QUnit Preconfigured Test Suite + + + + + + +
+ + diff --git a/test/preconfigured.js b/test/preconfigured.js new file mode 100644 index 000000000..243a1a47a --- /dev/null +++ b/test/preconfigured.js @@ -0,0 +1,21 @@ +window.addEventListener( "load", function() { + + // make sure QUnit has started if autostart would be true + setTimeout( function() { + QUnit.module( "QUnit.preconfigured.asyncTests" ); + QUnit.test( "QUnit.config should have an expected default", function( assert ) { + assert.ok( QUnit.config.scrolltop, "The scrolltop default is true" ); + } ); + + QUnit.test( "Qunit.config.reorder default was overwritten", function( assert ) { + assert.notOk( QUnit.config.reorder, "reorder was overwritten" ); + } ); + + QUnit.start(); + }, 100 ); +} ); + +QUnit.module( "QUnit.preconfigured" ); +QUnit.test( "Autostart is false", function( assert ) { + assert.notOk( QUnit.config.autostart, "The global autostart setting is applied" ); +} );