Skip to content

AndreasPizsa/setup-browser-env

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

setup-browser-env

postinstaller build coverage license version downloads

Simplifies simulating a global browser environment using browser-env.

Motivation

setup-browser-env simplifies simulating a global browser environment using browser-env with zero configuration, keeping your project structure lean, clean & organized.

Features

  • Compatible. Works with ava, mocha and everything else.
  • Zero Configuration for ava. npm add, done.
  • Configurable. via package.json or browser-env.{js, json, yaml}
  • Reliable. 100% Code Coverage.
  • Free. MIT License.

Usage

Install

npm add -D setup-browser-env

ava

Automatic configuration

If you’re using ava as a devDependency, installing setup-browser-env will configure ava automatically (using postinstaller).

Manual configuration
// package.json
{
  "ava": {
    "require": [
      "setup-browser-env"
    ]
  }
}

mocha

Manual configuration
# mocha.opts
--require setup-browser-env

Advanced Configuration

setup-browser-env runs out of the box without further configuration. You can still set options if needed in your package.json or a browser-env.{js,json,yaml} config file.

To learn about all configuration options, please see browser-env and jsdom.

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"
  }
}

Copyright © 2018 Andreas Pizsa. Licensed under the MIT license.