acs
Version: 
Appcelerator Server Side Node
51 lines (49 loc) • 2.44 kB
JavaScript
var chai = require('chai'),
    should = chai.should(),
    sinon = require('sinon'),
    u = require('../lib/util');
describe('util - ', function(){
    // Will test if the validateConfig would catch the missing keys in package.json
    // It will verify name, version, main, scripts.start, dependencies
    describe('functional tests: validateConfig, will verify the missing keys in package.json', function() {
        var config_test = {};
        it('should return error if config is null', function() {
            u.validateConfig(null).should.eql('No configuration to validate.');
        });
        it('should return error if Invalid name', function() {
            u.validateConfig(config_test).should.eql('Invalid \'name\'.');
        });
        it('should return error if Invalid version', function() {
            config_test["name"] = "NODEJS_TEST";
            u.validateConfig(config_test).should.eql('Invalid \'version\'.');
        });
        describe('validate the main script config', function() {
            var config_test = {};
            config_test["name"] = "NODEJS_TEST";
            config_test["version"] = "0.1.0";
            it('should return error if Invalid main or scripts', function() {
                u.validateConfig(config_test).should.eql('You must specify either \'main\' or \'scripts.start\' for launching app.');
            });
            it('should return warn if both main and scripts', function() {
                var logOutput = "";
                config_test["main"] = "app.js";
                config_test["scripts"] = {"start":"node app.js"};
                var stub = sinon.stub(process.stdout, 'write', function(log) {
                    logOutput = log;
                });
                u.validateConfig(config_test);
                logOutput.should.contain('Both \'main\' and \'scripts.start\' are specified. \'scripts.start\' will take precedence.');
                stub.restore();
            });
            it('should return valid with main', function() {
                config_test["scripts"] = null;
                should.not.exist(u.validateConfig(config_test));
            });
            it('should return valid with scripts.start', function() {
                config_test["main"] = null;
                config_test["scripts"] = {"start":"node app.js"};
                should.not.exist(u.validateConfig(config_test));
            });
        });
    });
});