From 72afe92e9eeeac5a9c36a6248d554aedc15f253d Mon Sep 17 00:00:00 2001 From: Luke Childs Date: Thu, 2 Mar 2017 08:57:39 +0700 Subject: [PATCH] Extract window function from browser-env --- .gitignore | 3 +++ .travis.yml | 10 ++++++++++ LICENSE | 21 +++++++++++++++++++++ README.md | 19 +++++++++++++++++++ package.json | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/index.js | 8 ++++++++ test/types.js | 6 ++++++ 7 files changed, 119 insertions(+) create mode 100644 .gitignore create mode 100644 .travis.yml create mode 100644 LICENSE create mode 100644 README.md create mode 100644 package.json create mode 100644 src/index.js create mode 100644 test/types.js diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..abf97e9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +node_modules +.nyc_output +npm-debug.log diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..130dc1a --- /dev/null +++ b/.travis.yml @@ -0,0 +1,10 @@ +language: node_js +node_js: + - '6' + - '5' + - '4' +script: npm run lint && npm test +after_success: npm run coverage +notifications: + email: + on_success: never diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..e2db8f2 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2016 Luke Childs + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..39f50ac --- /dev/null +++ b/README.md @@ -0,0 +1,19 @@ +# window [![Build Status](https://travis-ci.org/lukechilds/window.svg?branch=master)](https://travis-ci.org/lukechilds/window) [![Coverage Status](https://coveralls.io/repos/github/lukechilds/window/badge.svg?branch=master)](https://coveralls.io/github/lukechilds/window?branch=master) [![npm](https://img.shields.io/npm/dm/window.svg)](https://www.npmjs.com/package/window) + +> Exports a [`jsdom`](https://github.com/tmpvar/jsdom) window object. + +## Install + +```shell +npm install --save window +``` + +Or if you're just using for testing you'll probably want: + +```shell +npm install --save-dev window +``` + +## License + +MIT © Luke Childs diff --git a/package.json b/package.json new file mode 100644 index 0000000..43e93c9 --- /dev/null +++ b/package.json @@ -0,0 +1,52 @@ +{ + "name": "window", + "version": "1.0.0", + "description": "Exports a jsdom window object.", + "main": "src/index.js", + "engines": { + "node": ">=4" + }, + "scripts": { + "test": "nyc ava test", + "lint": "eslint src", + "coverage": "nyc report --reporter=text-lcov | coveralls" + }, + "eslintConfig": { + "extends": "lukechilds", + "rules": { + "prefer-rest-params": "off" + } + }, + "repository": { + "type": "git", + "url": "git+https://github.com/lukechilds/window.git" + }, + "keywords": [ + "export", + "jsdom", + "window", + "object", + "simulate", + "node", + "browser", + "environment", + "env" + ], + "author": "Luke Childs (http://lukechilds.co.uk)", + "license": "MIT", + "bugs": { + "url": "https://github.com/lukechilds/window/issues" + }, + "homepage": "https://github.com/lukechilds/window#readme", + "dependencies": { + "clone": "2.1.0", + "jsdom": "9.11.0" + }, + "devDependencies": { + "ava": "^0.18.0", + "coveralls": "^2.11.13", + "eslint": "^3.5.0", + "eslint-config-lukechilds": "^1.9.0", + "nyc": "^10.0.0" + } +} diff --git a/src/index.js b/src/index.js new file mode 100644 index 0000000..0d13151 --- /dev/null +++ b/src/index.js @@ -0,0 +1,8 @@ +const jsdom = require('jsdom'); +const clone = require('clone'); + +// Function to return a window object. +// Accepts a jsdom config object. +// Config object must be cloned before passing through otherwise jsdom will add +// lots of properties to the original reference. +module.exports = window = (jsdomConfig = {}) => jsdom.jsdom('', clone(jsdomConfig)).defaultView; diff --git a/test/types.js b/test/types.js new file mode 100644 index 0000000..de402de --- /dev/null +++ b/test/types.js @@ -0,0 +1,6 @@ +import test from 'ava'; +import window from '../'; + +test('mergeImages is a function', t => { + t.is(typeof window, 'function'); +});