jsdom-global
Advanced tools
Comparing version 1.3.0 to 1.4.0
@@ -0,1 +1,8 @@ | ||
## [v1.4.0] | ||
> Jan 12, 2016 | ||
- `tape`: Shows navigator userAgent in tape output. | ||
[v1.4.0]: https://github.com/rstacruz/jsdom-global/compare/v1.3.0...v1.4.0 | ||
## [v1.3.0] | ||
@@ -2,0 +9,0 @@ > Jan 11, 2016 |
{ | ||
"name": "jsdom-global", | ||
"version": "1.3.0", | ||
"version": "1.4.0", | ||
"description": "Enable DOM in Node.js", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -5,3 +5,3 @@ # jsdom-global | ||
jsdom-global will inject `document`, `window` and other DOM API into your Node.js environment. Useful for tests. | ||
jsdom-global will inject `document`, `window` and other DOM API into your Node.js environment. Useful for running, in Node.js, tests that are made for browsers. | ||
@@ -25,4 +25,3 @@ [![Status](https://travis-ci.org/rstacruz/jsdom-global.svg?branch=master)](https://travis-ci.org/rstacruz/jsdom-global "See test builds") | ||
```js | ||
var jsdom = require('jsdom-global') | ||
jsdom() | ||
require('jsdom-global')() | ||
@@ -36,4 +35,3 @@ // you can now use the DOM | ||
```js | ||
var jsdom = require('jsdom-global') | ||
var cleanup = jsdom() | ||
var cleanup = require('jsdom-global')() | ||
@@ -48,2 +46,4 @@ // do things | ||
```js | ||
var jsdom = require('jsdom-global') | ||
jsdom(function () { | ||
@@ -60,16 +60,10 @@ var $ = require('jquery') | ||
```js | ||
var test = require('tape') | ||
require('jsdom-global')() | ||
// example: run your tests with `env JSDOM=1` to enable jsdom in an otherwise | ||
// browser-only test | ||
if (process.env.JSDOM) { | ||
test('jsdom', (t) => { | ||
require('jsdom-global')() | ||
t.pass('jsdom enabled') | ||
t.end() | ||
}) | ||
} | ||
test('your tests', (t) => { | ||
/* and so on... */ | ||
}) | ||
``` | ||
Or even use the tape helper, which will accomplish the same thing: | ||
_Optional:_ you can also use the tape helper, which will add jsdom initialization to the tap output, letting you see how long it takes to bootstrap the jsdom environment. | ||
@@ -79,2 +73,7 @@ ```js | ||
test('jsdom', require('jsdom-global/tape')()) | ||
// TAP version 13 | ||
// # jsdom | ||
// ok 1 jsdom enabled | ||
// ... | ||
``` | ||
@@ -99,2 +98,39 @@ | ||
## Browserify | ||
If you use [Browserify] on your tests (eg: [smokestack], [tape-run], [budo], [hihat], [zuul], and so on), doing `require('jsdom-global')()` is a noop. In practice, this means you can use jsdom-global even if your tests are powered by browserify, and your test will now work in both the browser and Node. | ||
[zuul]: https://www.npmjs.com/package/zuul | ||
[tape-run]: https://www.npmjs.com/package/tape-run | ||
[budo]: https://github.com/mattdesl/budo | ||
[hihat]: https://www.npmjs.com/package/hihat | ||
[smokestack]: https://www.npmjs.com/package/smokestack | ||
* Writing your tests (`test.js`): | ||
```js | ||
require('jsdom-global')() | ||
// ...do your tests here | ||
``` | ||
* Running it with [smokestack]: | ||
```sh | ||
browserify test.js | smokestack # run in a browser | ||
node test.js # or the console | ||
browserify test.js --no-bundle-external # also works (but why bother?) | ||
``` | ||
* Running it with Babel ([babelify] or [babel-cli]): | ||
```sh | ||
browserify test.js -t babelify | smokestack # run in a browser (with babel) | ||
babel-node test.js # or the console | ||
``` | ||
[Browserify]: http://browserify.org/ | ||
[babel-cli]: https://babeljs.io/docs/usage/cli/ | ||
[babelify]: https://github.com/babel/babelify | ||
## Thanks | ||
@@ -101,0 +137,0 @@ |
@@ -7,6 +7,6 @@ /* | ||
return function (t) { | ||
require('./index')() | ||
t.pass('jsdom on') | ||
require('./index')(options) | ||
t.pass(navigator.userAgent) | ||
t.end() | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6904
140