aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMichał Gołębiowski-Owczarek <m.goleb@gmail.com>2019-03-11 20:03:54 +0100
committerGitHub <noreply@github.com>2019-03-11 20:03:54 +0100
commit0ec25abba212efde462a8abcf3376f50116fd6c4 (patch)
treeca3667e28336695a713bd55b88269ee33ba9f1c9 /test
parent84b6a0beb1de193520bb5541c841cbecc7195a5b (diff)
downloadjquery-0ec25abba212efde462a8abcf3376f50116fd6c4.tar.gz
jquery-0ec25abba212efde462a8abcf3376f50116fd6c4.zip
Build: Run the basic test suite in jsdom
The basic test suite is now run in jsdom on all supported Node.js versions (8, 10 & 11 as of now). Closes gh-4310
Diffstat (limited to 'test')
-rw-r--r--test/.eslintrc.json5
-rw-r--r--test/data/testinit-jsdom.js40
-rw-r--r--test/unit/basic.js4
3 files changed, 47 insertions, 2 deletions
diff --git a/test/.eslintrc.json b/test/.eslintrc.json
index 2c724626f..a23ea5f98 100644
--- a/test/.eslintrc.json
+++ b/test/.eslintrc.json
@@ -55,7 +55,10 @@
"overrides": [
{
- "files": ["data/core/jquery-iterability-transpiled-es6.js"],
+ "files": [
+ "data/core/jquery-iterability-transpiled-es6.js",
+ "data/testinit-jsdom.js"
+ ],
"parserOptions": {
"ecmaVersion": 2015
}
diff --git a/test/data/testinit-jsdom.js b/test/data/testinit-jsdom.js
new file mode 100644
index 000000000..e0830cc92
--- /dev/null
+++ b/test/data/testinit-jsdom.js
@@ -0,0 +1,40 @@
+"use strict";
+
+// Support: jsdom 13.2+
+// jsdom implements a throwing `window.scrollTo`.
+QUnit.config.scrolltop = false;
+
+const FILEPATH = "/test/data/testinit-jsdom.js";
+const activeScript = document.currentScript;
+const parentUrl = activeScript && activeScript.src ?
+ activeScript.src.replace( /[?#].*/, "" ) + FILEPATH.replace( /[^/]+/g, ".." ) + "/" :
+ "../";
+const supportjQuery = this.jQuery;
+
+// baseURL is intentionally set to "data/" instead of "".
+// This is not just for convenience (since most files are in data/)
+// but also to ensure that urls without prefix fail.
+// Otherwise it's easy to write tests that pass on test/index.html
+// but fail in Karma runner (where the baseURL is different).
+const baseURL = parentUrl + "test/data/";
+
+// Setup global variables before loading jQuery for testing .noConflict()
+supportjQuery.noConflict( true );
+window.originaljQuery = this.jQuery = undefined;
+window.original$ = this.$ = "replaced";
+
+/**
+ * Add random number to url to stop caching
+ *
+ * Also prefixes with baseURL automatically.
+ *
+ * @example url("index.html")
+ * @result "data/index.html?10538358428943"
+ *
+ * @example url("mock.php?foo=bar")
+ * @result "data/mock.php?foo=bar&10538358345554"
+ */
+function url( value ) {
+ return baseURL + value + ( /\?/.test( value ) ? "&" : "?" ) +
+ new Date().getTime() + "" + parseInt( Math.random() * 100000, 10 );
+}
diff --git a/test/unit/basic.js b/test/unit/basic.js
index b57c0c0ba..bed27dcba 100644
--- a/test/unit/basic.js
+++ b/test/unit/basic.js
@@ -193,7 +193,9 @@ QUnit.test( "manipulation", function( assert ) {
);
} );
-QUnit.test( "offset", function( assert ) {
+// Support: jsdom 13.2+
+// jsdom returns 0 for offset-related properties
+QUnit[ /jsdom\//.test( navigator.userAgent ) ? "skip" : "test" ]( "offset", function( assert ) {
assert.expect( 3 );
var parent = jQuery( "<div style='position:fixed;top:20px;'/>" ).appendTo( "#qunit-fixture" ),