Bladeren bron

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

Gaël Métais 10 jaren geleden
bovenliggende
commit
377dee7d83
5 gewijzigde bestanden met toevoegingen van 24 en 19 verwijderingen
  1. 4 4
      bin/cli.js
  2. 2 2
      lib/index.js
  3. 9 4
      lib/server/controllers/apiController.js
  4. 1 1
      package.json
  5. 8 8
      test/core/indexTest.js

+ 4 - 4
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);

+ 2 - 2
lib/yellowlabtools.js → 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;
+module.exports = yellowLabTools;

+ 9 - 4
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);
                 });
 

+ 1 - 1
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",

+ 8 - 8
test/core/yellowlabtoolsTest.js → 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');