Registry / devops / cross-env-test

cross-env-test

JSON →
library0.1.1jsnpmunverified

cross-env-test is a command-line utility designed to provide a cross-platform method for checking environment variable values within npm scripts or CI/CD pipelines. It allows users to test if a specified environment variable is set to a particular value, exiting with a `0` (success) status code if the condition is met, and a non-zero (failure) code otherwise. This enables conditional execution of scripts, for example, running a build step only when not in a test environment. The current stable version is 0.1.1. Due to its minimal scope and stable functionality, it typically experiences an infrequent release cadence. Its key differentiator is simplifying cross-platform environment variable checks without requiring complex shell-specific logic or full JavaScript execution for simple comparisons, making npm scripts more robust across Windows, macOS, and Linux.

npm install cross-env-test
INSTALL
IMPORT
SIG · CROSS-ENV-TEST
C
cross-env-test
devopsjavascriptv0.1.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Demonstrates using `cross-env-test` in npm scripts for conditional command execution. The `postinstall` script runs `npm run build` only if `NODE_ENV` is NOT 'testing'. The `test:e2e` script shows how to check if `CI` is not 'true'.

{ "name": "my-project", "version": "1.0.0", "scripts": { "postinstall": "cross-env-test NODE_ENV=testing || npm run build", "build": "echo 'Building project in development mode...'", "test:e2e": "cross-env-test CI!=true && echo 'Running E2E tests locally' || echo 'Skipping E2E tests in CI'" }, "devDependencies": { "cross-env-test": "^0.1.1" } }
cross-env-test --version
Debug
Known issues
gotchacross-env-test currently only supports the '==' (represented by '=') and '!=' operators for comparisons. More complex logical operations (like greater than, less than) are not supported.
fix
For more complex comparisons, consider using a dedicated JavaScript file executed via `node -e '...'` or a full scripting language.
affects: >=0.1.0
gotchaThe environment variable must always be on the left-hand side of the operator. For example, `NODE_ENV=production` is valid, but `production=NODE_ENV` is not and will cause an error.
fix
Always format arguments as `ENV_VAR=VALUE` or `ENV_VAR!=VALUE`.
affects: >=0.1.0
gotchaChained arguments are implicitly treated as logical AND (`&&`). There is no explicit `--or` modifier or support for complex OR logic between conditions.
fix
If OR logic is required, you might need to use multiple `cross-env-test` calls with shell `||` operators or revert to platform-specific scripting.
affects: >=0.1.0
gotchaProviding arguments that are not in the `lh=rh` or `lh!=rh` format will result in the program exiting with an error code.
fix
Ensure all arguments passed to `cross-env-test` adhere strictly to the expected `KEY=VALUE` or `KEY!=VALUE` format.
affects: >=0.1.0
Errors
Common errors & fixes
Command not found: cross-env-test
The `cross-env-test` package is not installed or not in the system's PATH.
fix
Install it as a dev dependency (`npm install --save-dev cross-env-test`) and ensure it's used within npm scripts or via `npx cross-env-test`.
Error: Invalid argument format: 'NODE_ENV testing'
The argument provided did not include an '=' or '!=' operator between the environment variable name and its value.
fix
Ensure arguments are in the format `NODE_ENV=testing` or `NODE_ENV!=development`.
The script exited with a non-zero status code (e.g., 1).
This is often expected behavior, indicating that the tested environment variable condition was NOT met, causing `cross-env-test` to signal failure.
fix
Check the condition you are testing. If you intended for the script to fail when the condition isn't met, this is correct. If you expected success, verify the environment variable's actual value or the comparison string.
Upgrade
Version history
0.1.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
9 hits · last 30 days
node
8
OpenAI (training)
1
Resources
cross-env-test — npm install cross-env-test · libregistry