├── .travis.yml ├── .editorconfig ├── CHANGELOG.md ├── .gitignore ├── index.js ├── package.json ├── LICENSE ├── README.md └── test └── simple-jsdom.js /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - '4' 4 | - 'stable' 5 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig is awesome: http://EditorConfig.org 2 | 3 | root = true; 4 | 5 | [*] 6 | # Ensure there's no lingering whitespace 7 | trim_trailing_whitespace = true 8 | # Ensure a newline at the end of each file 9 | insert_final_newline = true 10 | 11 | [*.js] 12 | # Unix-style newlines 13 | end_of_line = lf 14 | charset = utf-8 15 | indent_style = space 16 | indent_size = 2 17 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ### [3.0.0](https://github.com/jmeas/simple-jsdom/releases/3.0.0) 2 | 3 | - JSDom is now a peerDependency 4 | 5 | ### [2.0.0](https://github.com/jmeas/simple-jsdom/releases/2.0.0) 6 | 7 | - Supports JSDom 8.x 8 | 9 | ### [1.0.0](https://github.com/jmeas/simple-jsdom/releases/1.0.0) 10 | 11 | - Supports Node v4 and the latest JSDom 12 | 13 | ### [0.0.2](https://github.com/jmeas/simple-jsdom/releases/v0.0.2) 14 | 15 | - The global namespace is not modified until you run `install()` 16 | 17 | ### [0.0.1](https://github.com/jmeas/simple-jsdom/releases/v0.0.1) 18 | 19 | - The first release 20 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | 5 | # Runtime data 6 | pids 7 | *.pid 8 | *.seed 9 | 10 | # Directory for instrumented libs generated by jscoverage/JSCover 11 | lib-cov 12 | 13 | # Coverage directory used by tools like istanbul 14 | coverage 15 | 16 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 17 | .grunt 18 | 19 | # node-waf configuration 20 | .lock-wscript 21 | 22 | # Compiled binary addons (http://nodejs.org/api/addons.html) 23 | build/Release 24 | 25 | # Dependency directory 26 | # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git 27 | node_modules 28 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var jsdom = require('jsdom').jsdom; 4 | var document = jsdom(''); 5 | var window = document.defaultView; 6 | var navigator = window.navigator = { 7 | userAgent: 'NodeJS JSDom', 8 | appVersion: '' 9 | }; 10 | 11 | // References to the objects are available under `globals` 12 | exports.globals = { 13 | jsdom: jsdom, 14 | document: document, 15 | window: window, 16 | navigator: navigator 17 | }; 18 | 19 | // Run this method to modify the global namespace 20 | exports.install = function() { 21 | global.jsdom = jsdom; 22 | global.document = document; 23 | global.window = window; 24 | global.navigator = navigator; 25 | }; 26 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "simple-jsdom", 3 | "version": "3.0.0", 4 | "description": "A simple JSDom configuration for testing libraries.", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "mocha" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/jmeas/simple-jsdom.git" 12 | }, 13 | "keywords": [ 14 | "jsdom", 15 | "test", 16 | "boilerplate" 17 | ], 18 | "author": "Jmeas", 19 | "license": "MIT", 20 | "bugs": { 21 | "url": "https://github.com/jmeas/simple-jsdom/issues" 22 | }, 23 | "homepage": "https://github.com/jmeas/simple-jsdom#readme", 24 | "peerDependencies": { 25 | "jsdom": ">=8.0.0" 26 | }, 27 | "devDependencies": { 28 | "jsdom": "^9.4.2", 29 | "mocha": "^2.3.3" 30 | }, 31 | "engine": "node >= 4.0.0" 32 | } 33 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 James Smith 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # simple-jsdom 2 | [![Travis build status](http://img.shields.io/travis/jmeas/simple-jsdom.svg?style=flat)](https://travis-ci.org/jmeas/simple-jsdom) 3 | 4 | A simple JSDom configuration for testing libraries. 5 | 6 | ### Installation 7 | 8 | The easiest way to get simple-jsdom is through npm. 9 | 10 | `npm i simple-jsdom --save-dev` 11 | 12 | You'll also need to install the version of JSDom that you'd like to use. 13 | 14 | `npm i jsdom --save-dev` 15 | 16 | ### Getting Started 17 | 18 | To modify the global namespace, run: 19 | 20 | `require('simple-jsdom').install();` 21 | 22 | ### Motivation 23 | 24 | Most of the time that I use JSDom, I only want to make it so that my client side tests 25 | work in a Node environment without blowing up. I'm less interested in thinking 26 | about how JSDom works. 27 | 28 | I found myself copying and pasting the same code between projects, so I abstracted into 29 | this bare bones JSDom configuration. Require this in and your tests should Just Work©. 30 | 31 | For instance, you should be able to use most (all?) of the jQuery API after you've included this. 32 | 33 | ### Versioning 34 | 35 | This library requires Node v4+ and JSDom v8+. 36 | 37 | ### API 38 | 39 | This module returns two things: a `globals` object, which returns the globals created by JSDom, 40 | and an `install` method, which attaches those things to the global namespace. 41 | 42 | The four objects are: 43 | 44 | - `document` 45 | - `window` 46 | - `navigator` 47 | - [`jsdom`](https://github.com/tmpvar/jsdom#for-the-hardcore-jsdomjsdom) 48 | -------------------------------------------------------------------------------- /test/simple-jsdom.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var assert = require('assert'); 4 | var simpleJsdom = require('../index'); 5 | var globals = simpleJsdom.globals; 6 | var install = simpleJsdom.install; 7 | 8 | describe('Simple JSDom', function() { 9 | describe('globals', function() { 10 | it('should contain `document`', function() { 11 | assert.ok(globals.document); 12 | }); 13 | 14 | it('should contain `window`', function() { 15 | assert.ok(globals.window); 16 | }); 17 | 18 | it('should contain `navigator`', function() { 19 | assert.ok(globals.navigator); 20 | }); 21 | 22 | it('should contain `jsdom`', function() { 23 | assert.ok(globals.jsdom); 24 | }); 25 | 26 | it('should not set anything on the global scope', function() { 27 | assert.equal(global.document, undefined); 28 | assert.equal(global.window, undefined); 29 | assert.equal(global.navigator, undefined); 30 | assert.equal(global.jsdom, undefined); 31 | }); 32 | }); 33 | 34 | describe('installs', function() { 35 | beforeEach(function() { 36 | install(); 37 | }); 38 | 39 | it('should set a `document`', function() { 40 | assert.ok(global.document); 41 | }); 42 | 43 | it('should set a `window`', function() { 44 | assert.ok(global.window); 45 | }); 46 | 47 | it('should set a `navigator`', function() { 48 | assert.ok(global.navigator); 49 | }); 50 | 51 | it('should set a `jsdom`', function() { 52 | assert.ok(global.jsdom); 53 | }); 54 | }); 55 | }); 56 | --------------------------------------------------------------------------------