Skip to content

Instantly share code, notes, and snippets.

@max-mapper
Last active August 29, 2015 14:24
Show Gist options
  • Save max-mapper/2e1c146333c3d08fb862 to your computer and use it in GitHub Desktop.
Save max-mapper/2e1c146333c3d08fb862 to your computer and use it in GitHub Desktop.
tape + http local server test scaffolding
// the two testing modules I like
var test = require('tape')
var spawn = require('tape-spawn')
var execspawn = require('npm-execspawn') // can spawn from require() scope, check it out!
// put this in outer scope so we can kill the local server at the end
var server
test('start test server', function (t) {
// start a local http-server in the current dir (you can change path if you need to)
server = execspawn('http-server ./ -p 54321', {cwd: __dirname})
// listen for first output from server
server.stdout.once('data', function (ch) {
if (ch.toString().indexOf('Starting up') > -1) t.ok(true, 'server started')
else t.ok(false, ch) // if it failed print out output
t.end()
})
})
// put your tests here
test('stop server', function (t) {
server.kill()
t.ok(true, 'sent kill signal')
t.end()
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment