Rename yellowlabtools.js to index.js and change the way to call it

This commit is contained in:
Gaël Métais
2015-01-06 22:50:32 +01:00
parent 079ec94197
commit 377dee7d83
5 changed files with 24 additions and 19 deletions
+4 -4
View File
@@ -2,7 +2,7 @@
var debug = require('debug')('ylt:cli'); var debug = require('debug')('ylt:cli');
var YellowLabTools = require('../lib/yellowlabtools'); var ylt = require('../lib/index');
// Check parameters // Check parameters
if (process.argv.length !== 3) { if (process.argv.length !== 3) {
@@ -16,10 +16,8 @@ var url = process.argv[2];
(function execute(url) { (function execute(url) {
'use strict'; 'use strict';
var ylt = new YellowLabTools(url); ylt(url).
debug('Test launched...');
ylt.
then(function(data) { then(function(data) {
debug('Success'); debug('Success');
@@ -32,4 +30,6 @@ var url = process.argv[2];
}); });
debug('Test launched...');
})(url); })(url);
+2 -2
View File
@@ -3,7 +3,7 @@ var Q = require('q');
var Runner = require('./runner'); var Runner = require('./runner');
var YellowLabTools = function(url, options) { var yellowLabTools = function(url, options) {
'use strict'; 'use strict';
var deferred = Q.defer(); var deferred = Q.defer();
@@ -35,4 +35,4 @@ var YellowLabTools = function(url, options) {
return deferred.promise; return deferred.promise;
}; };
module.exports = YellowLabTools; module.exports = yellowLabTools;
+9 -4
View File
@@ -1,6 +1,6 @@
var debug = require('debug')('ylt:server'); var debug = require('debug')('ylt:server');
var YellowLabTools = require('../../yellowlabtools'); var ylt = require('../../index');
var RunsQueue = require('../datastores/runsQueue'); var RunsQueue = require('../datastores/runsQueue');
var RunsDatastore = require('../datastores/runsDatastore'); var RunsDatastore = require('../datastores/runsDatastore');
var ResultsDatastore = require('../datastores/resultsDatastore'); var ResultsDatastore = require('../datastores/resultsDatastore');
@@ -49,7 +49,8 @@ var ApiController = function(app) {
debug('Launching test %s on %s', run.runId, run.params.url); debug('Launching test %s on %s', run.runId, run.params.url);
new YellowLabTools(run.params.url) ylt(run.params.url)
.then(function(data) { .then(function(data) {
debug('Success'); debug('Success');
@@ -92,7 +93,9 @@ var ApiController = function(app) {
res.status(500).send('Saving results failed'); 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('Test failed for URL: %s', run.params.url);
console.error(err.toString()); console.error(err.toString());
@@ -101,7 +104,9 @@ var ApiController = function(app) {
res.status(400).send('Bad request'); res.status(400).send('Bad request');
}).finally(function() { })
.finally(function() {
queue.remove(run.runId); queue.remove(run.runId);
}); });
+1 -1
View File
@@ -8,7 +8,7 @@
"bin": { "bin": {
"yellowlabtools": "./bin/cli.js" "yellowlabtools": "./bin/cli.js"
}, },
"main": "./lib/yellowlabtools.js", "main": "./lib/index.js",
"dependencies": { "dependencies": {
"async": "~0.9.0", "async": "~0.9.0",
"body-parser": "~1.10.0", "body-parser": "~1.10.0",
@@ -2,29 +2,29 @@ var chai = require('chai');
var sinon = require('sinon'); var sinon = require('sinon');
var sinonChai = require('sinon-chai'); var sinonChai = require('sinon-chai');
var should = chai.should(); var should = chai.should();
var YellowLabTools = require('../../lib/yellowlabtools.js'); var ylt = require('../../lib/index');
chai.use(sinonChai); chai.use(sinonChai);
describe('yellowlabtools', function() { describe('index.js', function() {
it('should return a promise', function() { it('should return a promise', function() {
var ylt = new YellowLabTools(); var promise = ylt();
ylt.should.have.property('then').that.is.a('function'); promise.should.have.property('then').that.is.a('function');
ylt.should.have.property('fail').that.is.a('function'); promise.should.have.property('fail').that.is.a('function');
}); });
it('should fail an undefined url', function(done) { 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'); err.should.be.a('string').that.equals('URL missing');
done(); done();
}); });
}); });
it('should fail with an empty url string', function(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'); err.should.be.a('string').that.equals('URL missing');
done(); done();
}); });
@@ -38,7 +38,7 @@ describe('yellowlabtools', function() {
var url = 'http://localhost:8388/simple-page.html'; var url = 'http://localhost:8388/simple-page.html';
var ylt = new YellowLabTools(url) ylt(url)
.then(function(data) { .then(function(data) {
data.should.be.an('object'); data.should.be.an('object');