@avikalpa/environment
v1.1.1
Published
Provides only two flags |isNode| and |isBrowser| for detection of js runtime environment. Useful for unit testing where specific tests are only suited in one of the environments. For example, a test using |requestAnimationFrame| must be run in browser (us
Downloads
16
Readme
@avikalpa/environment
Provides only two flags isNode
and isBrowser
for detection
of js runtime environment. Useful for unit testing where specific tests are only
suited in one of the environments. For example, a test using requestAnimationFrame
must be run in browser (using mocha and karma). Again, a test using Buffer
must be run in Node.js.
Purpose
To be used in projects that require testing of both client-side and server-side. With this lib, the entire testsuite can be passed to both mocha or jasmine and karma without the need to seperate the client-side tests from the server-side tests.
Usage
npm i -D @avikalpa/environment
Example
import * as Environment from '@avikalpa/environment';
describe( 'A browser test', function(){
it('should run only in the browser', function(){
if(Environment.isBrowser)
requestAnimationFrame(someWebGLObject);
else
this.skip();
});
});
describe( 'A node.js test', function(){
it('should run only in node.js', function(){
if(Environment.isNode)
doSomethingWithBuffer();
else
this.skip();
});
});
Changelog
v1.1.1
- Now it returns two flags instead of function objects.
- Added typings.
- Made minor corrections to README.md
License
MIT License
Copyright (c) 2017 Avikalpa Kundu.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.