{"id":13014,"library":"cross-env-test","title":"Cross-Platform Environment Variable Test","description":"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.","status":"maintenance","version":"0.1.1","language":"javascript","source_language":"en","source_url":"https://github.com/rangle/cross-env-test","tags":["javascript","cross","platform","environment","variable","test","condition","npm","scripts"],"install":[{"cmd":"npm install cross-env-test","lang":"bash","label":"npm"},{"cmd":"yarn add cross-env-test","lang":"bash","label":"yarn"},{"cmd":"pnpm add cross-env-test","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[],"quickstart":{"code":"{\n  \"name\": \"my-project\",\n  \"version\": \"1.0.0\",\n  \"scripts\": {\n    \"postinstall\": \"cross-env-test NODE_ENV=testing || npm run build\",\n    \"build\": \"echo 'Building project in development mode...'\",\n    \"test:e2e\": \"cross-env-test CI!=true && echo 'Running E2E tests locally' || echo 'Skipping E2E tests in CI'\"\n  },\n  \"devDependencies\": {\n    \"cross-env-test\": \"^0.1.1\"\n  }\n}","lang":"javascript","description":"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'."},"warnings":[{"fix":"For more complex comparisons, consider using a dedicated JavaScript file executed via `node -e '...'` or a full scripting language.","message":"cross-env-test currently only supports the '==' (represented by '=') and '!=' operators for comparisons. More complex logical operations (like greater than, less than) are not supported.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Always format arguments as `ENV_VAR=VALUE` or `ENV_VAR!=VALUE`.","message":"The 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.","severity":"gotcha","affected_versions":">=0.1.0"},{"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.","message":"Chained arguments are implicitly treated as logical AND (`&&`). There is no explicit `--or` modifier or support for complex OR logic between conditions.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Ensure all arguments passed to `cross-env-test` adhere strictly to the expected `KEY=VALUE` or `KEY!=VALUE` format.","message":"Providing arguments that are not in the `lh=rh` or `lh!=rh` format will result in the program exiting with an error code.","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"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`.","cause":"The `cross-env-test` package is not installed or not in the system's PATH.","error":"Command not found: cross-env-test"},{"fix":"Ensure arguments are in the format `NODE_ENV=testing` or `NODE_ENV!=development`.","cause":"The argument provided did not include an '=' or '!=' operator between the environment variable name and its value.","error":"Error: Invalid argument format: 'NODE_ENV testing'"},{"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.","cause":"This is often expected behavior, indicating that the tested environment variable condition was NOT met, causing `cross-env-test` to signal failure.","error":"The script exited with a non-zero status code (e.g., 1)."}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"cross-env-test"}