diff --git a/.coveralls.yml b/.coveralls.yml new file mode 100644 index 0000000..2cf6b0d --- /dev/null +++ b/.coveralls.yml @@ -0,0 +1,3 @@ +service_name: travis-ci +src_dir: . +coverage_clover: coverage/coverage.raw.json \ No newline at end of file diff --git a/.eslintrc.js b/.eslintrc.js new file mode 100644 index 0000000..dcdc2b0 --- /dev/null +++ b/.eslintrc.js @@ -0,0 +1,36 @@ +module.exports = { + "env": { + "es6": true, + "node": true, + "mocha": true, + }, + "globals": { + "fetch": true, + }, + "extends": "eslint:recommended", + "parserOptions": { + "ecmaVersion": 8, + "sourceType": "module", + }, + "rules": { + "indent": [ + "error", + 4, + { + "SwitchCase": 1, + }, + ], + "linebreak-style": [ + "error", + "unix", + ], + "quotes": [ + "error", + "single", + ], + "semi": [ + "error", + "always", + ], + } +}; \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4572024 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +coverage +.idea +npm-debug.log +node_modules +.DS_Store \ No newline at end of file diff --git a/.istanbul.yml b/.istanbul.yml new file mode 100644 index 0000000..5b9ab07 --- /dev/null +++ b/.istanbul.yml @@ -0,0 +1,3 @@ +instrumentation: + default-excludes: true + include-all-sources: true \ No newline at end of file diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..37e8620 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,5 @@ +language: node_js +node_js: + - 7 +script: + - npm test && npm run report-coverage \ No newline at end of file diff --git a/README.md b/README.md index 934da2d..95e6e60 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,25 @@ -# promise-timeout Promise timeout +=========================== + +It could be useful when you need to make pause in promise pipeline + + +[![Build Status](https://travis-ci.org/evheniy/promise-timeout.svg?branch=master)](https://travis-ci.org/evheniy/promise-timeout) +[![Coverage Status](https://coveralls.io/repos/github/evheniy/promise-timeout/badge.svg?branch=master)](https://coveralls.io/github/evheniy/promise-timeout?branch=master) + + +Installation +------------ + + npm i -S promise-timeout + +Example +------- + + const pause = require('promise-timeout'); + + (async () => { + const data1 = await fetch(url1); + await pause(1000); + const data2 = await fetch(url2); + })(); \ No newline at end of file diff --git a/index.js b/index.js new file mode 100644 index 0000000..10732ba --- /dev/null +++ b/index.js @@ -0,0 +1 @@ +module.exports = ms => new Promise(resolve => setTimeout(resolve, ms)); \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..41e0b2c --- /dev/null +++ b/package.json @@ -0,0 +1,39 @@ +{ + "name": "promise-timeout", + "description": "Promise timeout", + "repository": "evheniy/promise-timeout", + "version": "0.0.1", + "scripts": { + "test": "npm run security && npm run clear && npm run lint && npm run coverage", + "lint": "./node_modules/.bin/eslint index.js tests", + "coverage": "node --harmony ./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha -- tests --recursive", + "report-coverage": "cat ./coverage/lcov.info | ./node_modules/.bin/coveralls", + "clear": "./node_modules/.bin/rimraf coverage", + "security": "./node_modules/.bin/nsp check" + }, + "engines": { + "node": ">=7.0.0" + }, + "keywords": [ + "promise", + "timeout", + "setTimeout", + "async", + "await" + ], + "files": [ + "index.js" + ], + "dependencies": {}, + "devDependencies": { + "chai": "^3.5.0", + "coveralls": "^2.11.15", + "eslint": "^3.14.1", + "istanbul": "^1.1.0-alpha.1", + "mocha": "^3.2.0", + "mocha-lcov-reporter": "^1.2.0", + "nsp": "^2.6.2", + "rimraf": "^2.5.4" + }, + "license": "MIT" +} diff --git a/tests/index.js b/tests/index.js new file mode 100644 index 0000000..ff6b87e --- /dev/null +++ b/tests/index.js @@ -0,0 +1,14 @@ +const expect = require('chai').expect; +const promise = require('../index'); + + +describe('Promise timeout test', () => { + it('it should test promise timeout', async () => { + const start = new Date; + await promise(1000); + const ms = new Date - start; + + expect(ms).to.be.above(1000); + expect(ms).to.be.below(2000); + }); +}); \ No newline at end of file