Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[api test] Expose `options.cwd` and update tests accordingly

  • Loading branch information...
commit 446348e21627f1a91218fce0bcefe8c492162cf6 1 parent bb2eac9
@indexzero indexzero authored
View
7 README.md
@@ -27,9 +27,12 @@ The core method, `nexpect.spawn(command, [params], [options])`, takes three para
* command: The command that you wish to spawn
* params: The argv that you want to pass to the child process
* options: An object literal which may contain
- - verbose: Writes the stdout for the child process to `process.stdout` of the current process.
- - stripColors: Strips any ANSI colors from the output for `.expect()` and `.wait()` statements.
+ - cwd: Current working directory of the child process.
- ignoreCase: Ignores the case of any output from the child process.
+ - stripColors: Strips any ANSI colors from the output for `.expect()` and `.wait()` statements.
+ - verbose: Writes the stdout for the child process to `process.stdout` of the current process.
+
+
Lets take a look at some sample usage:
View
16 lib/nexpect.js
@@ -66,8 +66,9 @@ function chain (context) {
//
run: function (callback) {
var errState = null,
- responded = false,
- stdout = [];
+ responded = false,
+ stdout = [],
+ options;
//
// **onError**
@@ -245,11 +246,15 @@ function chain (context) {
process.stdout.write(data);
}
+ if (context.cwd) {
+ options = { cwd: context.cwd };
+ }
+
//
// Spawn the child process and begin processing the target
// stream for this chain.
//
- context.process = spawn(context.command, context.params);
+ context.process = spawn(context.command, context.params, options);
if (context.verbose) {
context.process.stdout.on('data', onData);
@@ -314,12 +319,13 @@ function nspawn (command, params, options) {
options = options || {};
context = {
command: command,
+ cwd: options.cwd || undefined,
+ ignoreCase: options.ignoreCase,
params: params,
queue: [],
stream: options.stream || 'stdout',
- verbose: options.verbose,
stripColors: options.stripColors,
- ignoreCase: options.ignoreCase
+ verbose: options.verbose
};
return chain(context);
View
6 test/fixtures/show-cwd
@@ -0,0 +1,6 @@
+#!/usr/bin/env node
+
+console.log('dont output process.cwd() yet');
+console.log('dont output process.cwd() yet');
+console.log('dont output process.cwd() yet');
+console.log(process.cwd());
View
4 test/nexpect-test.js
@@ -90,6 +90,10 @@ vows.describe('nexpect').addBatch({
nexpect.spawn(path.join(__dirname, 'fixtures', 'multiple-cases'), { ignoreCase: true })
.wait('this has many cases')
.expect('this also has many cases')
+ ),
+ "when options.cwd is set": assertSpawn(
+ nexpect.spawn(path.join(__dirname, 'fixtures', 'show-cwd'), { cwd: path.join(__dirname, 'fixtures') })
+ .wait(path.join(__dirname, 'fixtures'))
)
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.