ntip
v1.0.0
Published
No Tests In Production. To prevent accidental test execution
Downloads
5
Readme
No Tests In Production
This package is designed to prevent accidentally executing tests in production server.
Introduction
Running tests in production servers is a nightmare. Although test execution in a production server is not intentional, accidents can happen due to human errors, configuration errors. This package is designed to provide a validation against such accidents.
In order to provide the validation, tests should be executed via this package.
How to use
Installing
In order to install use following command.
npm install --save-dev ntip
:hand: Please use --save-dev flag, since this is a package related to dev environments.
( if you use tests suites as mocha, jasmine without --save-dev flag, then install this package without --save-dev flag).
Configuration
(please read the about the npm package json in https://docs.npmjs.com/files/package.json)
NODE_ENV value is mandatory for this package.
In development environment, please set NODE_ENV as development, prior to run tests.
./node_modules/.bin/ntip <test command>
eg:
./node_modules/.bin/ntip ./node_modules/.bin/mocha `find test -name '*.js' -not -path '*test/dummy_test*'`
If the development environment is different than "development", then use following command to execute the package.
export DEV_ENV_TAGS=xyz ./node_modules/.bin/ntip ./node_modules/.bin/mocha `find test -name '*.js' -not -path '*test/dummy_test*'`
In Node Js environment, following command is used to run the.
npm test
A sample configuration for the npm install in package.json is as following.
{
"scripts": {
"test": "./node_modules/.bin/mocha `find test -name '*.js' -not -path '*test/fixtures*'`"
}
}
In order to run the test through ntip, change the package.json as follows.
{
"scripts": {
"test": "./node_modules/.bin/ntip ./node_modules/.bin/mocha `find test -name '*.js' -not -path '*test/dummy_test*'`"
}
}
Adding more development environment to the NTIP
Set DEV_ENV_TAGS in following format. (please use the "," as the delimiter).
DEV_ENV_TAGS=env1,env2,env3
eg:
DEV_ENV_TAGS=alpha,beta,gamma
If you set as in above example, NODE_ENV with values either "alpha","beta","gamma" will be considered as development environments and will allow to execute the tests.
Important.
- Never use NODE_ENV in the test command. (refer the example at Features section)
- Always set the NODE_ENV in development environment.
- To execute the tests using single line, please use following command.
export DEV_ENV_TAGS=alpha;NODE_ENV=alpha ./node_modules/.bin/ntip ./node_modules/.bin/mocha test/sample.js
Features
Default development environment name is set as "*** development ***".
Able to identify NODE_ENV names such as "prod", "production", names starts with prod and stop the execution of the tests.
Able to detect NODE_ENV overrides which pass through *** test_command ***, and prevent further execution.
eg: following test command will generate an error when executing.
./node_modules/.bin/ntip env NODE_ENV=do_not_pass ./node_modules/.bin/mocha sample.js
Alternative solutions
In order to prevent test execution in the production environment, avoid installing dev dependencies. Using following command, npm will no install dev dependencies.
npm install --production