Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
karma-host-environment
Advanced tools
Access host info (OS, browser version, environment variables) in browser tests
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.
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
}
}
karma-config
Karma configuration builder with sensible defaults to minimize boilerplate
host-environment
Easily detect what host environment your code is running in
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
Configure Karma to use the host-environment
framework plug-in:
karma.conf.js
module.exports = function(config) {
config.set({
frameworks: ["host-environment"],
...
});
};
Import host-environment as you normally would:
import host from "@jsdevtools/host-environment";
host
objectYou can use all of the host
properties as usual:
host.env
propertyNormally 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
}
host.karma
propertyIn 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
}
}
Contributions, enhancements, and bug-fixes are welcome! Open an issue on GitHub and submit a pull request.
To build the project locally on your computer:
Clone this repo
git clone https://github.com/JS-DevTools/karma-host-environment.git
Install dependencies
npm install
Link the module to itself (so Karma can find the plugin)
npm link
npm link karma-host-environment
Run the tests
npm test
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.
Thanks to these awesome companies for their support of Open Source developers ❤
FAQs
Access host info (OS, browser version, environment variables) in browser tests
We found that karma-host-environment demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.