From 96b2add16fe37cbd6df6456af3d6c6e9f341ea57 Mon Sep 17 00:00:00 2001 From: Behind The Math Date: Mon, 8 Jan 2018 16:54:36 -0500 Subject: [PATCH] Fix tests See #63 - Switch from testling to jsdom for browser APIs - Switch from coverify to nyc for coverage reports - Clean up related dead code and tooling --- .gitignore | 1 + .travis.yml | 6 - package.json | 35 +- tests/index.html | 12496 ----------------------------------------- tests/index.js | 6 + tests/lib/events.js | 3 +- tests/lib/request.js | 10 +- 7 files changed, 25 insertions(+), 12532 deletions(-) delete mode 100644 tests/index.html create mode 100644 tests/index.js diff --git a/.gitignore b/.gitignore index ecd1403..2128eae 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ node_modules/ tests/scripts/index.html pjax.js +.nyc_output/ diff --git a/.travis.yml b/.travis.yml index 06ddbfa..0d23ca2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1 @@ language: "node_js" -before_script: - # testling use headless browser - # on travis-ci, firefox is the default one - # & it needs a display to works - - export DISPLAY=:99.0 - - sh -e /etc/init.d/xvfb start diff --git a/package.json b/package.json index bef1b41..48adb94 100644 --- a/package.json +++ b/package.json @@ -22,44 +22,29 @@ ], "devDependencies": { "browserify": "^3.46.0", - "coverify": "^1.0.6", "jscs": "^1.6.2", + "jsdom": "^11.5.1", + "jsdom-global": "^3.0.2", "jshint": "^2.5.6", "npmpub": "^3.1.0", + "nyc": "^11.4.1", "opn-cli": "^3.1.0", "serve": "1.4.0", - "tape": "^3.0.0", - "testling": "^1.6.1" + "tap-nyc": "^1.0.3", + "tap-spec": "^4.1.1", + "tape": "^3.0.0" }, "scripts": { "lint": "jscs **/*.js && jshint . --exclude-path .gitignore", "standalone": "browserify index.js --standalone Pjax > pjax.js", "build-debug": "browserify index.js --debug --standalone Pjax > pjax.js", - "tests": "testling", - "test": "npm run lint && npm run standalone && npm run tests", - "test--html": "testling --html > tests/scripts/index.html", - "coverage": "browserify -t coverify tests/**/*.js | testling | coverify", + "tests": "tape -r ./tests/index.js ./tests/**/*.js", + "test": "npm run lint && npm run tests | tap-spec", + "coverage-tests": "npm run tests | tap-nyc", + "coverage": "nyc -x \"tests/**\" npm run coverage-tests", "example": "opn http://localhost:3000/example/; serve .", "prepublish": "npm run standalone", "#release": "testling does not work in a process launch by npm... :facepalm:", "release": "echo \"npmpub --skip-test --dry && npm test && npmpub --skip-test --skip-cleanup\"" - }, - "testling": { - "files": "tests/**/*.js", - "browsers": [ - "ie/10..latest", - "firefox/4.0", - "firefox/latest", - "firefox/nightly", - "chrome/10", - "chrome/latest", - "chrome/canary", - "opera/12..latest", - "opera/next", - "safari/5.1..latest", - "ipad/6.0..latest", - "iphone/6.0..latest", - "android-browser/4.2..latest" - ] } } diff --git a/tests/index.html b/tests/index.html deleted file mode 100644 index a9ef972..0000000 --- a/tests/index.html +++ /dev/null @@ -1,12496 +0,0 @@ -

diff --git a/tests/index.js b/tests/index.js
new file mode 100644
index 0000000..e025786
--- /dev/null
+++ b/tests/index.js
@@ -0,0 +1,6 @@
+var jsdomOptions = {
+  url: "https://example.org/",
+  runScripts: 'dangerously'
+}
+
+require("jsdom-global")("", jsdomOptions)
diff --git a/tests/lib/events.js b/tests/lib/events.js
index 4eb7824..94fda00 100644
--- a/tests/lib/events.js
+++ b/tests/lib/events.js
@@ -102,7 +102,8 @@ tape("test events on top level elements", function(t) {
   el = window;
 
   el.className = ""
-  on(el, "click", classCb)
+  // With jsdom, the default this is global, not window, so we need to explicitly bind to window.
+  on(el, "click", classCb.bind(window))
   trigger(el, "click")
   t.equal(el.className, "on", "attached callback has been fired properly on window")
 
diff --git a/tests/lib/request.js b/tests/lib/request.js
index b53f754..f99763e 100644
--- a/tests/lib/request.js
+++ b/tests/lib/request.js
@@ -15,14 +15,16 @@ if (!('responseURL' in XMLHttpRequest.prototype)) {
 }
 
 tape("test xhr request", function(t) {
+  var url = "https://httpbin.org/get"
+
   t.test("- request is made, gets a result, and is cache-busted", function(t) {
     var requestCacheBust = request.bind({
       options: {
         cacheBust: true,
       },
     });
-    var r = requestCacheBust("https://api.github.com/", {}, function(result) {
-      t.equal(r.responseURL.indexOf("?"), 23, "XHR URL is cache-busted when configured to be")
+    var r = requestCacheBust(url, {}, function(result) {
+      t.equal(r.responseURL.indexOf("?"), url.length, "XHR URL is cache-busted when configured to be")
       try {
         result = JSON.parse(result)
       }
@@ -39,8 +41,8 @@ tape("test xhr request", function(t) {
         cacheBust: false,
       },
     });
-    var r = requestNoCacheBust("https://api.github.com/", {}, function() {
-      t.equal(r.responseURL, "https://api.github.com/", "XHR URL is left untouched")
+    var r = requestNoCacheBust(url, {}, function() {
+      t.equal(r.responseURL, url, "XHR URL is left untouched")
       t.end()
     })
   })