Yoji SHIDARA
null+****@clear*****
Wed Oct 24 15:56:18 JST 2012
Yoji SHIDARA 2012-10-24 15:56:18 +0900 (Wed, 24 Oct 2012) New Revision: 9565a6127e2cb43f8b1bbe9ee7e09368747d67a4 https://github.com/groonga/gcs-console/commit/9565a6127e2cb43f8b1bbe9ee7e09368747d67a4 Merged 610da59: Merge branch 'test' Log: test: Extract test utilities Added files: test/test-utils.js Modified files: test/index.test.js Modified: test/index.test.js (+4 -51) =================================================================== --- test/index.test.js 2012-10-24 11:58:09 +0900 (30f03b9) +++ test/index.test.js 2012-10-24 15:56:18 +0900 (18f6454) @@ -1,61 +1,14 @@ var assert = require('chai').assert; var Browser = require('zombie'); -var spawn = require('child_process').spawn; -var mkdirp = require('mkdirp'); -var rimraf = require('rimraf'); -var fs = require('fs'); -var path = require('path'); -var existsSync = fs.existsSync || path.existsSync; // to support older nodes than 0.8 - -// TODO extract these test helpers to another file - -function runServer(path, options, callback) { - var command = spawn(path, options); - command.stdout.on('data', function(data) { - if (data.toString().match(/listening/)) { - callback(); - } - process.stdout.write(data); - }); - command.stderr.on('data', function(data) { - process.stderr.write(data); - }); - return command; -} +var Target = require('./test-utils').Target; suite('dashboard', function() { - var gcs, gcsConsole; - var databaseDir = __dirname + '/../test/tmp/gcs'; - var databasePath = databaseDir + '/gcs'; + var target = new Target(); setup(function(done) { - var gcsPath = __dirname + '/../node_modules/.bin/gcs'; - var gcsOptions = [ - '--database-path', databasePath - ]; // TODO set port for gcs - var gcsConsolePath = __dirname + '/../bin/gcs-console'; - var gcsConsoleOptions = []; // TODO set port of gcs and gcs-console - - if (!existsSync(gcsPath)) { - var error = new Error('gcs executable is not found at ' + gcsPath + '. You need to setup gcs to test with gcs-console. Run "npm install gcs" (for the latest release) or "npm install git://github.com/groonga/gcs.git" (for the development)'); - return done(error); - } - - mkdirp.sync(databaseDir); - gcs = runServer(gcsPath, gcsOptions, function() { - gcsConsole = runServer(gcsConsolePath, gcsConsoleOptions, function() { - done(); - }) - }); + target.setup(done) }); - teardown(function() { - if (gcs) { - gcs.kill(); - rimraf.sync(databaseDir); - } - if (gcsConsole) { - gcsConsole.kill(); - } + target.teardown() }); test('GET /', function(done) { Added: test/test-utils.js (+66 -0) 100644 =================================================================== --- /dev/null +++ test/test-utils.js 2012-10-24 15:56:18 +0900 (7b97451) @@ -0,0 +1,66 @@ +var spawn = require('child_process').spawn; +var mkdirp = require('mkdirp'); +var rimraf = require('rimraf'); +var fs = require('fs'); +var path = require('path'); +var existsSync = fs.existsSync || path.existsSync; // to support older nodes than 0.8 + +function runServer(path, options, callback) { + var command = spawn(path, options); + command.stdout.on('data', function(data) { + if (data.toString().match(/listening/)) { + callback(); + } + process.stdout.write(data); + }); + command.stderr.on('data', function(data) { + process.stderr.write(data); + }); + return command; +} + +var Target = function() { + this.databaseDir = __dirname + '/../test/tmp/gcs'; + this.databasePath = this.databaseDir + '/gcs'; + this.gcsPath = __dirname + '/../node_modules/.bin/gcs'; + this.gcsConsolePath = __dirname + '/../bin/gcs-console'; +}; + +Target.prototype = { + gcs: null, + gcsConsole: null, + setup: function(done) { + var self = this; + var gcsOptions = [ + '--database-path', self.databasePath + ]; // TODO set port for gcs + var gcsConsoleOptions = []; // TODO set port of gcs and gcs-console + + if (!existsSync(self.gcsPath)) { + var error = new Error('gcs executable is not found at ' + self.gcsPath + '. You need to setup gcs to test with gcs-console. Run "npm install gcs" (for the latest release) or "npm install git://github.com/groonga/gcs.git" (for the development)'); + return done(error); + } + + mkdirp.sync(self.databaseDir); + self.gcs = runServer(self.gcsPath, gcsOptions, function() { + self.gcsConsole = runServer( + self.gcsConsolePath, + gcsConsoleOptions, + function() { + done(); + } + ) + }); + }, + teardown: function() { + if (this.gcs) { + this.gcs.kill(); + rimraf.sync(this.databaseDir); + } + if (this.gcsConsole) { + this.gcsConsole.kill(); + } + } +}; + +module.exports.Target = Target; -------------- next part -------------- HTML����������������������������... Download