Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Like UNIX Expect, but for Node.js.

branch: master
Octocat-spinner-32 lib return childprocess object November 07, 2013
Octocat-spinner-32 test use platform debug files May 01, 2013
Octocat-spinner-32 .gitignore Inital commit. August 03, 2012
Octocat-spinner-32 .travis.yml dropped Node v0.6 support May 01, 2013
Octocat-spinner-32 CHANGELOG.md v0.3.0 November 07, 2013
Octocat-spinner-32 LICENSE Inital commit. August 03, 2012
Octocat-spinner-32 README.md readme update November 07, 2013
Octocat-spinner-32 package.json v0.3.0 November 07, 2013
README.md

Node.js - suppose

Have you ever heard of the command line program expect? Basically, expect allows you to automate command line programs. suppose is a programmable Node.js module that allows the same behavior.

Why?

From the expect wikipedia page, you can see many examples of expect scripts automating tasks such as telnet or ftp sessions. Now you can easily write Node.js scripts to do the same. This may be most beneficial during testing.

Installation

npm install suppose

Example

Automate the command npm init, which initializes a new npm module.

var suppose = require('suppose')
  , fs = require('fs')
  , assert = require('assert')

process.chdir('/tmp/awesome');
fs.writeFileSync('/tmp/awesome/README.md', 'READ IT')
suppose('npm', ['init'])
  .debug(fs.createWriteStream('/tmp/debug.txt')) //optional writeable output stream
  .on(/name\: \([\w|\-]+\)[\s]*/).respond('awesome_package\n')
  .on('version: (0.0.0) ').respond('0.0.1\n')
  .on('description: ').respond("It's an awesome package man!\n")
  .on('entry point: (index.js) ').respond("\n")
  .on('test command: ').respond('npm test\n')
  .on('git repository: ').respond("\n")
  .on('keywords: ').respond('awesome, cool\n')
  .on('author: ').respond('JP Richardson\n')
  .on('license: (BSD) ').respond('MIT\n')
  .on('ok? (yes) ' ).respond('yes\n')
.error(function(err){
  console.log(err.message);
})
.end(function(code){
  var packageFile = '/tmp/awesome/package.json';
  fs.readFile(packageFile, function(err, data){
    var packageObj = JSON.parse(data.toString());
    console.log(packageObj.name); //'awesome_package'
  })
})

Always follow an .on() with a .respond() and then finish with a .end().

Contributors

License

(MIT License)

Copyright 2012-2013, JP Richardson

Something went wrong with that request. Please try again.