aboutsummaryrefslogtreecommitdiffstats
path: root/test/data
diff options
context:
space:
mode:
authorMichał Gołębiowski-Owczarek <m.goleb@gmail.com>2020-01-21 13:26:47 +0100
committerGitHub <noreply@github.com>2020-01-21 13:26:47 +0100
commit46c284b12b4ac89727b1b7a0d5497bc9149cc2af (patch)
treef29d7e557e67d13f086702acabd9fa3e1b8cba1a /test/data
parentd72faced11dc9f785dba5c24c97b045539cbce9c (diff)
downloadjquery-46c284b12b4ac89727b1b7a0d5497bc9149cc2af.tar.gz
jquery-46c284b12b4ac89727b1b7a0d5497bc9149cc2af.zip
Build: Make Karma work in AMD mode
Also, run such a suite in CI to make sure modules are working as expected when used directly. (partially cherry picked from 341c6d1b5abe4829f59fbc32e93f6a6a1afb900f) (partially cherry picked from 437f389a24a6bef213d4df507909e7e69062300b) Closes gh-4595 Ref gh-4550 Ref gh-4574
Diffstat (limited to 'test/data')
-rw-r--r--test/data/testinit-jsdom.js14
-rw-r--r--test/data/testinit.js18
2 files changed, 26 insertions, 6 deletions
diff --git a/test/data/testinit-jsdom.js b/test/data/testinit-jsdom.js
index e0830cc92..bedf093a9 100644
--- a/test/data/testinit-jsdom.js
+++ b/test/data/testinit-jsdom.js
@@ -38,3 +38,17 @@ function url( value ) {
return baseURL + value + ( /\?/.test( value ) ? "&" : "?" ) +
new Date().getTime() + "" + parseInt( Math.random() * 100000, 10 );
}
+
+// The file-loading part of testinit.js#loadTests is handled by
+// jsdom Karma config; here we just need to trigger relevant APIs.
+this.loadTests = function() {
+
+ // Delay the initialization until after all the files are loaded
+ // as in the JSDOM case we load them via Karma (see Gruntfile.js)
+ // instead of directly in testinit.js.
+ window.addEventListener( "load", function() {
+ window.__karma__.start();
+ jQuery.noConflict();
+ QUnit.start();
+ } );
+};
diff --git a/test/data/testinit.js b/test/data/testinit.js
index e1d81c5c7..6938fed24 100644
--- a/test/data/testinit.js
+++ b/test/data/testinit.js
@@ -299,14 +299,16 @@ moduleTypeSupported();
this.loadTests = function() {
- // Directly load tests that need synchronous evaluation
- if ( !QUnit.urlParams.amd || document.readyState === "loading" ) {
+ // QUnit.config is populated from QUnit.urlParams but only at the beginning
+ // of the test run. We need to read both.
+ var amd = QUnit.config.amd || QUnit.urlParams.amd;
+
+ // Directly load tests that need evaluation before DOMContentLoaded.
+ if ( !amd || document.readyState === "loading" ) {
document.write( "<script src='" + parentUrl + "test/unit/ready.js'><\x2Fscript>" );
} else {
QUnit.module( "ready", function() {
- QUnit.test( "jQuery ready", function( assert ) {
- assert.ok( false, "Test should be initialized before DOM ready" );
- } );
+ QUnit.skip( "jQuery ready tests skipped in async mode", function() {} );
} );
}
@@ -360,7 +362,11 @@ this.loadTests = function() {
}
} else {
- QUnit.load();
+ if ( window.__karma__ && window.__karma__.start ) {
+ window.__karma__.start();
+ } else {
+ QUnit.load();
+ }
/**
* Run in noConflict mode