diff --git a/bin/cli.js b/bin/cli.js index 88b615a..6d815cf 100644 --- a/bin/cli.js +++ b/bin/cli.js @@ -2,7 +2,7 @@ var debug = require('debug')('ylt:cli'); -var YellowLabTools = require('../lib/yellowlabtools'); +var ylt = require('../lib/index'); // Check parameters if (process.argv.length !== 3) { @@ -16,10 +16,8 @@ var url = process.argv[2]; (function execute(url) { 'use strict'; - var ylt = new YellowLabTools(url); - debug('Test launched...'); + ylt(url). - ylt. then(function(data) { debug('Success'); @@ -32,4 +30,6 @@ var url = process.argv[2]; }); + debug('Test launched...'); + })(url); \ No newline at end of file diff --git a/lib/yellowlabtools.js b/lib/index.js similarity index 89% rename from lib/yellowlabtools.js rename to lib/index.js index bca7a61..00513bb 100644 --- a/lib/yellowlabtools.js +++ b/lib/index.js @@ -3,7 +3,7 @@ var Q = require('q'); var Runner = require('./runner'); -var YellowLabTools = function(url, options) { +var yellowLabTools = function(url, options) { 'use strict'; var deferred = Q.defer(); @@ -35,4 +35,4 @@ var YellowLabTools = function(url, options) { return deferred.promise; }; -module.exports = YellowLabTools; \ No newline at end of file +module.exports = yellowLabTools; \ No newline at end of file diff --git a/lib/server/controllers/apiController.js b/lib/server/controllers/apiController.js index ac452bc..fd4da75 100644 --- a/lib/server/controllers/apiController.js +++ b/lib/server/controllers/apiController.js @@ -1,6 +1,6 @@ var debug = require('debug')('ylt:server'); -var YellowLabTools = require('../../yellowlabtools'); +var ylt = require('../../index'); var RunsQueue = require('../datastores/runsQueue'); var RunsDatastore = require('../datastores/runsDatastore'); var ResultsDatastore = require('../datastores/resultsDatastore'); @@ -49,7 +49,8 @@ var ApiController = function(app) { debug('Launching test %s on %s', run.runId, run.params.url); - new YellowLabTools(run.params.url) + ylt(run.params.url) + .then(function(data) { debug('Success'); @@ -92,7 +93,9 @@ var ApiController = function(app) { res.status(500).send('Saving results failed'); }); - }).fail(function(err) { + }) + + .fail(function(err) { console.error('Test failed for URL: %s', run.params.url); console.error(err.toString()); @@ -101,7 +104,9 @@ var ApiController = function(app) { res.status(400).send('Bad request'); - }).finally(function() { + }) + + .finally(function() { queue.remove(run.runId); }); diff --git a/package.json b/package.json index 6fef44a..39a277d 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "bin": { "yellowlabtools": "./bin/cli.js" }, - "main": "./lib/yellowlabtools.js", + "main": "./lib/index.js", "dependencies": { "async": "~0.9.0", "body-parser": "~1.10.0", diff --git a/test/core/yellowlabtoolsTest.js b/test/core/indexTest.js similarity index 89% rename from test/core/yellowlabtoolsTest.js rename to test/core/indexTest.js index 2b5632c..6207241 100644 --- a/test/core/yellowlabtoolsTest.js +++ b/test/core/indexTest.js @@ -2,29 +2,29 @@ var chai = require('chai'); var sinon = require('sinon'); var sinonChai = require('sinon-chai'); var should = chai.should(); -var YellowLabTools = require('../../lib/yellowlabtools.js'); +var ylt = require('../../lib/index'); chai.use(sinonChai); -describe('yellowlabtools', function() { +describe('index.js', function() { it('should return a promise', function() { - var ylt = new YellowLabTools(); + var promise = ylt(); - ylt.should.have.property('then').that.is.a('function'); - ylt.should.have.property('fail').that.is.a('function'); + promise.should.have.property('then').that.is.a('function'); + promise.should.have.property('fail').that.is.a('function'); }); it('should fail an undefined url', function(done) { - var ylt = new YellowLabTools().fail(function(err) { + ylt().fail(function(err) { err.should.be.a('string').that.equals('URL missing'); done(); }); }); it('should fail with an empty url string', function(done) { - var ylt = new YellowLabTools('').fail(function(err) { + ylt('').fail(function(err) { err.should.be.a('string').that.equals('URL missing'); done(); }); @@ -38,7 +38,7 @@ describe('yellowlabtools', function() { var url = 'http://localhost:8388/simple-page.html'; - var ylt = new YellowLabTools(url) + ylt(url) .then(function(data) { data.should.be.an('object');