Skip to content

Commit 3accbc6

Browse files
Uroš JarcSBoudrias
Uroš Jarc
authored andcommitted
Adding inDirKeep method in run-context. (#20)
* Adding run-context method inDirKeep and index testDirectoryKeep. * Adding tests for #inDirKeep() in test/run-context.js * Delete comment. * Removing testDirectoryKeep method. * Removing testDirectoryKeep call from inDirKeep... and assert for directory existance. * Remove test for calling testingDirKeep * Remove dir testing. * Removing trailing spaces * Rename inDirKeep -> cd, remove cb and add tests in run-context.
1 parent cb7a9af commit 3accbc6

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
node_modules
22
coverage
3+
.idea

lib/run-context.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,18 @@ RunContext.prototype.inDir = function (dirPath, cb) {
146146
return this;
147147
};
148148

149+
/**
150+
* Change directory into provided directory.
151+
* @param {String} dirPath - Directory path (relative to CWD). Prefer passing an absolute
152+
* file path for predictable results
153+
* @return {this} run context instance
154+
*/
155+
RunContext.prototype.cd = function (dirPath) {
156+
this.inDirSet = true;
157+
this.targetDirectory = dirPath;
158+
return this;
159+
};
160+
149161
/**
150162
* Cleanup a temporary directy and change the CWD into it
151163
*

test/run-context.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,33 @@ describe('RunContext', function () {
274274
});
275275
});
276276

277+
describe('#cd()', function () {
278+
beforeEach(function () {
279+
process.chdir(__dirname);
280+
this.tmp = tmpdir;
281+
});
282+
283+
it('do not call helpers.testDirectory()', function () {
284+
sinon.spy(helpers, 'testDirectory');
285+
this.ctx.cd(this.tmp);
286+
assert(!helpers.testDirectory.calledOnce);
287+
helpers.testDirectory.restore();
288+
});
289+
290+
it('is chainable', function () {
291+
assert.equal(this.ctx.cd(this.tmp), this.ctx);
292+
});
293+
294+
it('should set inDirSet & targetDirectory', function () {
295+
assert(!this.ctx.inDirSet);
296+
assert(!this.ctx.targetDirectory);
297+
this.ctx.cd(this.tmp);
298+
assert.equal(this.ctx.inDirSet, true);
299+
assert.equal(this.ctx.targetDirectory, this.tmp);
300+
});
301+
302+
});
303+
277304
describe('#inTmpDir', function () {
278305
it('call helpers.testDirectory()', function () {
279306
sinon.spy(helpers, 'testDirectory');

0 commit comments

Comments
 (0)