Karma Host Environment
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.
;if hostci// Setup CI/CD test fixturesif hostbrowser// Test browser behaviorif hostbrowserIE// Test Internet Explorer-specific behaviorif hostnode// Test Node.js behaviorif hostnodeversion < 8// Different logic for older versions of Nodeif hostoswindows// Test Windows-specific behavior
Karma configuration builder with sensible defaults to minimize boilerplate
Easily detect what host environment your code is running in
npm install --save-dev @jsdevtools/host-environment @jsdevtools/karma-host-environment
Configure Karma to use the
host-environment framework plug-in:
Import host-environment as you normally would:
You can use all of the
host properties as usual:
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 hostenvQUICK_TEST// Skip long-running tests
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 hostkarma// We're running in Karmaif hostkarmanodeversion > 10// The server is running in Node v10+if hostkarmaoswindows// The server is a Windows OS
To build the project locally on your computer:
Clone this repo
git clone https://github.com/JS-DevTools/karma-host-environment.git
Link the module to itself (so Karma can find the plugin)
npm link karma-host-environment
Run the tests
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 ❤