UNPKG

kazana-example

Version:
61 lines (52 loc) 1.55 kB
var tap = require('tap') var app = require('./app') var startServer = require('./server') var cleanup = require('./cleanup') var startClient = require('./client') var options = { waitforTimeout: 3000, uploadTimeout: 360000 } // Start Kazana server, cleanup databases and start client function setup (useClient, callback) { startServer(app, function (error, server) { if (error) return callback(error) cleanup(server, function (error) { if (error) return callback(error) if (!useClient) return callback(error, server) startClient(server.info.uri, options, function (error, client, child) { callback(error, server, client, child) }) }) }) } // Stop Kazana server and kill client function tearDown (server, child) { // The `process.exit` is needed because otherwise tests with // upload are not ended until taps timeout. server.stop(function () { if (child) { child.on('close', function () { process.exit() }) return child.kill() } process.exit() }) } module.exports = function (name, tapOptions, callback) { if (typeof tapOptions === 'function') { callback = tapOptions tapOptions = {} } var useClient = callback.length > 2 tap.test(name, tapOptions, function (t) { setup(useClient, function (error, server, client, child) { t.error(error) if (client) client.on('error', t.endAll) t.tearDown(tearDown.bind(null, server, child)) callback(t, server, client) }) }) } module.exports.options = options