npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

karma-host-environment

v3.0.3

Published

Access host info (OS, browser version, environment variables) in browser tests

Downloads

1,410

Readme

Karma Host Environment

npm License Buy us a tree

Build Status Coverage Status Dependencies

OS and Browser Compatibility

Host Environment is a library that makes it easy to detect whether your code is running in Node.js or a web browser, Windows or Mac, Internet Explorer or Chrome, etc.

Karma Host Environment is a companion to Host Environment, specifically for the Karma test runner. It allows you to detect not only the browser that your tests are running in, but also information about the host server, such as the operating system, Node.js version, and even environment variables.

Example

import host from "@jsdevtools/host-environment";

if (host.ci) {
  // Setup CI/CD test fixtures
}

if (host.browser) {
  // Test browser behavior

  if (host.browser.IE) {
    // Test Internet Explorer-specific behavior
  }
}

if (host.node) {
  // Test Node.js behavior

  if (host.node.version < 8) {
    // Different logic for older versions of Node
  }

  if (host.os.windows) {
    // Test Windows-specific behavior
  }
}

Related Projects

  • karma-config Karma configuration builder with sensible defaults to minimize boilerplate

  • host-environment Easily detect what host environment your code is running in

Installation

Use npm or yarn to install @jsdevtools/host-environment and @jsdevtools/karma-host-environment as development dependencies:

npm install --save-dev @jsdevtools/host-environment @jsdevtools/karma-host-environment

Usage

Configure Karma to use the host-environment framework plug-in:

karma.conf.js

module.exports = function(config) {
  config.set({
    frameworks: ["host-environment"],
    ...
  });
};

API

Import host-environment as you normally would:

import host from "@jsdevtools/host-environment";

The host object

You can use all of the host properties as usual:

The host.env property

Normally the host.env property would be an empty object when running in a web browser, since web browsers don't have access to environment variables. But Karma Host Environment exposes the host server's environment variables, so you can use host.env just as you would if you were running in Node.js:

if (host.env.QUICK_TEST) {
  // Skip long-running tests
}

The host.karma property

In addition to all the usual host properties, Karma Host Environment adds an additional host.karma property. This object exposes all the host properties of the Karma server itself, such as the operating system, Node.js version, environmenv variables, etc.

if (host.karma) {
  // We're running in Karma

  if (host.karma.node.version > 10) {
    // The server is running in Node v10+
  }

  if (host.karma.os.windows) {
    // The server is a Windows OS
  }
}

Contributing

Contributions, enhancements, and bug-fixes are welcome! Open an issue on GitHub and submit a pull request.

Building

To build the project locally on your computer:

  1. Clone this repo git clone https://github.com/JS-DevTools/karma-host-environment.git

  2. Install dependencies npm install

  3. Link the module to itself (so Karma can find the plugin) npm link npm link karma-host-environment

  4. Run the tests npm test

License

Karma Host Environment is 100% free and open-source, under the MIT license. Use it however you want.

This package is Treeware. If you use it in production, then we ask that you buy the world a tree to thank us for our work. By contributing to the Treeware forest you’ll be creating employment for local families and restoring wildlife habitats.

Big Thanks To

Thanks to these awesome companies for their support of Open Source developers ❤

Travis CI SauceLabs Coveralls