Fix tests (#96)
Closes #63 - Switch from testling to jsdom for browser APIs - Switch from coverify to nyc for coverage reports - Clean up related dead code and tooling - Update Travis to use Node v6 and v8, since we need ES6 features for jsdom.
This commit was merged in pull request #96.
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -2,3 +2,4 @@
|
|||||||
node_modules/
|
node_modules/
|
||||||
tests/scripts/index.html
|
tests/scripts/index.html
|
||||||
pjax.js
|
pjax.js
|
||||||
|
.nyc_output/
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
language: "node_js"
|
language: "node_js"
|
||||||
before_script:
|
node_js:
|
||||||
# testling use headless browser
|
- "6"
|
||||||
# on travis-ci, firefox is the default one
|
- "8"
|
||||||
# & it needs a display to works
|
|
||||||
- export DISPLAY=:99.0
|
|
||||||
- sh -e /etc/init.d/xvfb start
|
|
||||||
|
|||||||
35
package.json
35
package.json
@@ -22,44 +22,29 @@
|
|||||||
],
|
],
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"browserify": "^3.46.0",
|
"browserify": "^3.46.0",
|
||||||
"coverify": "^1.0.6",
|
|
||||||
"jscs": "^1.6.2",
|
"jscs": "^1.6.2",
|
||||||
|
"jsdom": "^11.5.1",
|
||||||
|
"jsdom-global": "^3.0.2",
|
||||||
"jshint": "^2.5.6",
|
"jshint": "^2.5.6",
|
||||||
"npmpub": "^3.1.0",
|
"npmpub": "^3.1.0",
|
||||||
|
"nyc": "^11.4.1",
|
||||||
"opn-cli": "^3.1.0",
|
"opn-cli": "^3.1.0",
|
||||||
"serve": "1.4.0",
|
"serve": "1.4.0",
|
||||||
"tape": "^3.0.0",
|
"tap-nyc": "^1.0.3",
|
||||||
"testling": "^1.6.1"
|
"tap-spec": "^4.1.1",
|
||||||
|
"tape": "^3.0.0"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"lint": "jscs **/*.js && jshint . --exclude-path .gitignore",
|
"lint": "jscs **/*.js && jshint . --exclude-path .gitignore",
|
||||||
"standalone": "browserify index.js --standalone Pjax > pjax.js",
|
"standalone": "browserify index.js --standalone Pjax > pjax.js",
|
||||||
"build-debug": "browserify index.js --debug --standalone Pjax > pjax.js",
|
"build-debug": "browserify index.js --debug --standalone Pjax > pjax.js",
|
||||||
"tests": "testling",
|
"tests": "tape -r ./tests/index.js ./tests/**/*.js",
|
||||||
"test": "npm run lint && npm run standalone && npm run tests",
|
"test": "npm run lint && npm run tests | tap-spec",
|
||||||
"test--html": "testling --html > tests/scripts/index.html",
|
"coverage-tests": "npm run tests | tap-nyc",
|
||||||
"coverage": "browserify -t coverify tests/**/*.js | testling | coverify",
|
"coverage": "nyc -x \"tests/**\" npm run coverage-tests",
|
||||||
"example": "opn http://localhost:3000/example/; serve .",
|
"example": "opn http://localhost:3000/example/; serve .",
|
||||||
"prepublish": "npm run standalone",
|
"prepublish": "npm run standalone",
|
||||||
"#release": "testling does not work in a process launch by npm... :facepalm:",
|
"#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\""
|
"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"
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
12496
tests/index.html
12496
tests/index.html
File diff suppressed because one or more lines are too long
6
tests/index.js
Normal file
6
tests/index.js
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
var jsdomOptions = {
|
||||||
|
url: "https://example.org/",
|
||||||
|
runScripts: "dangerously"
|
||||||
|
}
|
||||||
|
|
||||||
|
require("jsdom-global")("", jsdomOptions)
|
||||||
@@ -102,7 +102,8 @@ tape("test events on top level elements", function(t) {
|
|||||||
el = window;
|
el = window;
|
||||||
|
|
||||||
el.className = ""
|
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")
|
trigger(el, "click")
|
||||||
t.equal(el.className, "on", "attached callback has been fired properly on window")
|
t.equal(el.className, "on", "attached callback has been fired properly on window")
|
||||||
|
|
||||||
|
|||||||
@@ -15,14 +15,16 @@ if (!('responseURL' in XMLHttpRequest.prototype)) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
tape("test xhr request", function(t) {
|
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) {
|
t.test("- request is made, gets a result, and is cache-busted", function(t) {
|
||||||
var requestCacheBust = request.bind({
|
var requestCacheBust = request.bind({
|
||||||
options: {
|
options: {
|
||||||
cacheBust: true,
|
cacheBust: true,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
var r = requestCacheBust("https://api.github.com/", {}, function(result) {
|
var r = requestCacheBust(url, {}, function(result) {
|
||||||
t.equal(r.responseURL.indexOf("?"), 23, "XHR URL is cache-busted when configured to be")
|
t.equal(r.responseURL.indexOf("?"), url.length, "XHR URL is cache-busted when configured to be")
|
||||||
try {
|
try {
|
||||||
result = JSON.parse(result)
|
result = JSON.parse(result)
|
||||||
}
|
}
|
||||||
@@ -39,8 +41,8 @@ tape("test xhr request", function(t) {
|
|||||||
cacheBust: false,
|
cacheBust: false,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
var r = requestNoCacheBust("https://api.github.com/", {}, function() {
|
var r = requestNoCacheBust(url, {}, function() {
|
||||||
t.equal(r.responseURL, "https://api.github.com/", "XHR URL is left untouched")
|
t.equal(r.responseURL, url, "XHR URL is left untouched")
|
||||||
t.end()
|
t.end()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user