Skip to content

Commit

Permalink
feat: replace Q with Bluebird, close #4
Browse files Browse the repository at this point in the history
  • Loading branch information
bahmutov committed Oct 28, 2017
1 parent 6b5a6c1 commit 6ce2e49
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 33 deletions.
4 changes: 1 addition & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ function comeBack () {
}

const chdirTo = folderName => {
return Promise.try(() => {
return _to(folderName)
})
return Promise.try(() => _to(folderName))
}

module.exports = {
Expand Down
13 changes: 10 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
"description": "Change working dir and return a promise, a stack of folders is maintained to jump back",
"main": "index.js",
"scripts": {
"test": "node test/chdir-promise-spec.js",
"test": "echo running unit tests",
"posttest": "mocha test/*-spec.js",
"demo": "DEBUG=chdir-promise node test/demo.js",
"deps": "deps-ok && dependency-check --no-dev .",
"semantic-release": "semantic-release",
"commit": "commit-wizard",
"size": "t=\"$(npm pack .)\"; wc -c \"${t}\"; tar tvf \"${t}\"; rm \"${t}\";",
"pretty": "prettier-standard *.js src/*.js",
"pretty": "prettier-standard *.js src/*.js test/*.js",
"prelint": "npm run pretty",
"lint": "standard --verbose --fix *.js src/*.js",
"lint": "standard --verbose --fix *.js src/*.js test/*.js",
"pretest": "npm run lint",
"issues": "git-issues"
},
Expand Down Expand Up @@ -46,8 +49,11 @@
"spots": "0.5.0"
},
"devDependencies": {
"dependency-check": "2.9.1",
"deps-ok": "1.2.1",
"git-issues": "^1.3.1",
"github-post-release": "1.13.1",
"mocha": "^4.0.1",
"pre-git": "3.15.3",
"prettier-standard": "7.0.3",
"semantic-release": "9.0.0",
Expand All @@ -60,6 +66,7 @@
"npm test"
],
"pre-push": [
"npm run deps",
"npm run size"
],
"post-commit": [],
Expand Down
95 changes: 68 additions & 27 deletions test/chdir-promise-spec.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,70 @@
var la = require('lazy-ass');
var check = require('check-more-types');
var folders = require('..');
var join = require('path').join;
var parentFolder = join(process.cwd(), '..')

la(check.object(folders), 'expected folders to be an object', folders);
la(check.fn(folders.to), 'expected folders.to to be a function', folders);

folders.to(__dirname)
.then(folders.back)
.then(folders.to(__dirname))
.then(folders.from)
.then(folders.to(__dirname))
.then(function () {
return 'foo';
const la = require('lazy-ass')
const is = require('check-more-types')

/* eslint-env mocha */
describe('chdir-promise', () => {
const chdir = require('..')
const originalFolder = process.cwd()

const here = () =>
la(
process.cwd() === __dirname,
'expected to be in',
__dirname,
'but was in',
process.cwd()
)

const inOriginal = () =>
la(
process.cwd() === originalFolder,
'expected to be in',
originalFolder,
'but was in',
process.cwd()
)

it('has to method', () => {
la(is.fn(chdir.to))
})

it('starts in original folder', () => {
inOriginal()
})
.tap(folders.back)
.then(function (result) {
la(result === 'foo', 'incorrect result', result);

it('changes folders once', () => {
return chdir
.to(__dirname)
.then(here)
.then(chdir.back)
.then(inOriginal)
})

it('changes folders twice', () => {
return chdir
.to(__dirname)
.then(here)
.then(chdir.back)
.then(inOriginal)
.then(_ => chdir.to(__dirname))
.then(here)
.then(chdir.back)
.then(inOriginal)
})

context('back', () => {
it('is a function', () => {
la(is.fn(chdir.back))
})

it('returns a promise', () => {
return chdir
.to(__dirname)
.then(here)
.then(_ => chdir.back().then(_ => 'foo'))
.then(value => {
la(value === 'foo', 'got', value)
})
})
})
.done();

// .back() returns a promise
folders.to(parentFolder)
.then(function () {
return folders.back()
.then(function () {})
}).done();
})
32 changes: 32 additions & 0 deletions test/demo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const la = require('lazy-ass')
const check = require('check-more-types')
const folders = require('..')
// const join = require('path').join
// const parentFolder = join(process.cwd(), '..')

la(check.object(folders), 'expected folders to be an object', folders)
la(check.fn(folders.to), 'expected folders.to to be a function', folders)

folders
.to(__dirname)
.then(folders.back)
.then(() => folders.to(__dirname))
.then(folders.from)
.then(() => folders.to(__dirname))
.then(function () {
return 'foo'
})
.tap(folders.back)
.then(function (result) {
la(result === 'foo', 'incorrect result', result)
console.log('result', result)
})
.done()

// .back() returns a promise
// folders
// .to(parentFolder)
// .then(function () {
// return folders.back().then(function () {})
// })
// .done()

0 comments on commit 6ce2e49

Please sign in to comment.