-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit bbcff5c
Showing
8 changed files
with
9,889 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
*.pid.lock | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
|
||
# nyc test coverage | ||
.nyc_output | ||
|
||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# Bower dependency directory (https://bower.io/) | ||
bower_components | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (https://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directories | ||
node_modules/ | ||
jspm_packages/ | ||
|
||
# TypeScript v1 declaration files | ||
typings/ | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional eslint cache | ||
.eslintcache | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
# Output of 'npm pack' | ||
*.tgz | ||
|
||
# Yarn Integrity file | ||
.yarn-integrity | ||
|
||
# dotenv environment variables file | ||
.env | ||
|
||
# parcel-bundler cache (https://parceljs.org/) | ||
.cache | ||
|
||
# next.js build output | ||
.next | ||
|
||
# nuxt.js build output | ||
.nuxt | ||
|
||
# vuepress build output | ||
.vuepress/dist | ||
|
||
# Serverless directories | ||
.serverless | ||
|
||
# FuseBox cache | ||
.fusebox/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
language: node_js | ||
node_js: | ||
- "node" | ||
- "lts/*" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
# `browser-env-register` | ||
|
||
> Simplified browser testing in your node test suite. | ||
# Motivation | ||
|
||
`browser-env-register` lets you register a simulated browser environment using [browser-env], saving the hassle of creating and loading a test-helper file. | ||
|
||
# Features | ||
|
||
+ ✅ **Compatible.** Works with [ava], [mocha] and everything else. | ||
+ ✅ **Configurable.** via `package.json` or `browser-env.{js, json, yaml}` | ||
+ ✅ **Reliable.** 100% Code Coverage. | ||
+ ✅ **Free.** MIT License. | ||
|
||
# Usage | ||
|
||
## Install | ||
|
||
```sh | ||
npm add -D browser-env-register | ||
``` | ||
|
||
### ava | ||
|
||
```js | ||
// package.json | ||
|
||
{ | ||
"ava": { | ||
require: [ | ||
"browser-env-register" | ||
] | ||
} | ||
} | ||
``` | ||
|
||
### mocha | ||
|
||
```js | ||
# mocha.opts | ||
--require browser-env-register | ||
``` | ||
|
||
## Configuration (optional) | ||
|
||
`browser-env-register` runs out of the box without further configuration, but you can set options if needed in your `package.json` or a `browser-env.{js,json,yaml}` config file. | ||
|
||
#### package.json | ||
|
||
``` | ||
{ | ||
"browser-env": { | ||
"globals": ['window', 'document'], | ||
"jsdom": { | ||
userAgent: 'My User Agent' | ||
} | ||
} | ||
} | ||
``` | ||
|
||
|
||
#### Shortcuts | ||
|
||
Pass only the of name global properties without setting jsdom options: | ||
|
||
``` | ||
{ | ||
"browser-env": "window document" | ||
} | ||
``` | ||
|
||
``` | ||
{ | ||
"browser-env": ["window", "document"] | ||
} | ||
``` | ||
|
||
Pass only jsdom options without setting the of name global properties: | ||
|
||
``` | ||
{ | ||
"browser-env": { | ||
"userAgent": "My User Agent" | ||
} | ||
} | ||
``` | ||
|
||
[ava]: https://github.com/avajs/ava | ||
[mocha]: https://mochajs.org | ||
[browser-env]: https://www.npmjs.com/package/browser-env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
function browserEnvConfig(config) { | ||
if (typeof config === 'string') { | ||
config = config.split(/(?:\s*,\s*)|\s+/) | ||
} | ||
|
||
const args = [ | ||
config && Array.isArray(config) ? config : config && config.globals, | ||
config && !Array.isArray(config) && ((config && config.jsdom) || config) | ||
].filter(x => x) | ||
return args.length > 0 ? args : undefined | ||
} | ||
|
||
function loadConfiguration(from) { | ||
const {searchSync} = require('cosmiconfig')('browser-env') | ||
const result = searchSync(from) | ||
return result && result.config | ||
} | ||
|
||
module.exports = require('browser-env').apply( | ||
this, | ||
browserEnvConfig(loadConfiguration()) | ||
) | ||
|
||
Object.assign(module.exports, { | ||
browserEnvConfig, | ||
loadConfiguration | ||
}) |
Oops, something went wrong.