Skip to content

Commit

Permalink
feat: initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreasPizsa committed Nov 17, 2018
0 parents commit bbcff5c
Show file tree
Hide file tree
Showing 8 changed files with 9,889 additions and 0 deletions.
76 changes: 76 additions & 0 deletions .gitignore
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/
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
language: node_js
node_js:
- "node"
- "lts/*"
91 changes: 91 additions & 0 deletions README.md
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
27 changes: 27 additions & 0 deletions index.js
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
})
Loading

0 comments on commit bbcff5c

Please sign in to comment.