Skip to content

Commit

Permalink
Test in a real browser (err, I mean, Electron)
Browse files Browse the repository at this point in the history
Inspired by #11
  • Loading branch information
TehShrike committed Jun 28, 2019
1 parent 34aca4e commit 9573937
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 42 deletions.
9 changes: 9 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,12 @@ sudo: false
language: node_js
script: "npm run test"
after_success: "npm i -g codecov && npm run coverage && codecov"
before_install:
- npm i
addons:
apt:
packages:
- xvfb
install:
- export DISPLAY=':99.0'
- Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &
16 changes: 8 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
var isObject = require('is-object')
var isWindow = require('is-window')
const isObject = require(`is-object`)
const isWindow = require(`is-window`)

function isNode (val) {
if (!isObject(val) || !isWindow(window) || typeof window.Node !== 'function') {
return false
}
function isNode(val) {
if (!isObject(val) || !isWindow(window) || typeof window.Node !== `function`) {
return false
}

return typeof val.nodeType === 'number' &&
typeof val.nodeName === 'string'
return typeof val.nodeType === `number`
&& typeof val.nodeName === `string`
}

module.exports = isNode
10 changes: 4 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
"description": "Check if the given object is a dom node",
"main": "index.js",
"scripts": {
"test": "standard && nyc node test.js",
"coverage": "nyc report --reporter=text-lcov > coverage.lcov"
"test": "browserify test.js | tape-run"
},
"repository": "npm-dom/is-dom",
"keywords": [
Expand All @@ -21,9 +20,8 @@
"is-window": "^1.0.2"
},
"devDependencies": {
"jsdom": "^15.1.1",
"nyc": "^14.1.1",
"standard": "^12.0.1",
"tape": "^4.10.2"
"browserify": "^16.2.3",
"tape": "^4.10.2",
"tape-run": "^6.0.0"
}
}
47 changes: 19 additions & 28 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,26 @@
'use strict'
var JSDOM = require('jsdom').JSDOM
var tape = require('tape')
const test = require(`tape`)

var isDom = require('./index')
const isDom = require(`./index.js`)

tape('is-dom', function (t) {
var currentRealm = new JSDOM('<html><body></body></html>')
var otherRealm = new JSDOM('<html><body></body></html>')
global.window = currentRealm.window
global.document = currentRealm.window.document
test(`is-dom`, t => {
t.plan(14)
console.log(`wat`)
t.equal(isDom(null), false)
t.equal(isDom(null), false)
t.equal(isDom(false), false)
t.equal(isDom(new Date()), false)

t.test('should check if supplied argument is a dom node', function (t) {
t.plan(17)
t.equal(isDom(null), false)
t.equal(isDom(null), false)
t.equal(isDom(false), false)
t.equal(isDom(new Date()), false)
t.equal(isDom(), false)
t.equal(isDom([]), false)
t.equal(isDom(2), false)
t.equal(isDom('foo'), false)
t.equal(isDom(/asda/), false)
t.equal(isDom({}), false)
t.equal(isDom(), false)
t.equal(isDom([]), false)
t.equal(isDom(2), false)
t.equal(isDom(`foo`), false)
t.equal(isDom(/asda/), false)
t.equal(isDom({}), false)

t.equal(isDom({ nodeType: 1, nodeName: 'BODY' }), true)
t.equal(isDom(document.createElement('body')), true)
t.equal(isDom(window), false)
t.equal(isDom(document), true)

t.equal(isDom(otherRealm.window), false)
t.equal(isDom(otherRealm.window.document), true)
t.equal(isDom(otherRealm.window.document.createElement('body')), true)
})
t.equal(isDom({ nodeType: 1, nodeName: `BODY` }), true)
t.equal(isDom(document.createElement(`body`)), true)
t.equal(isDom(window), false)
t.equal(isDom(document), true)
})

0 comments on commit 9573937

Please sign in to comment.