Skip to content

Commit

Permalink
General tidying and testing.
Browse files Browse the repository at this point in the history
  • Loading branch information
mattyod committed Jul 31, 2014
1 parent 0ce4545 commit e5498d9
Show file tree
Hide file tree
Showing 27 changed files with 183 additions and 903 deletions.
30 changes: 15 additions & 15 deletions bin/args.js
Expand Up @@ -21,21 +21,21 @@ module.exports = (function () {

// Take the first and attempt to act upon it.
switch (args[0]) {
case '--help':
case '-help':
case '-h':
case 'help':
require('./args/help');
break;
case '--version':
case '-version':
case '-v':
case 'version':
require('./args/version');
break;
default:
log.warn('Unknown argument, try matic help');
process.exit(0);
case '--help':
case '-help':
case '-h':
case 'help':
require('./args/help');
break;
case '--version':
case '-version':
case '-v':
case 'version':
require('./args/version');
break;
default:
log.warn('Unknown argument, try matic help');
process.exit(0);
}

}
Expand Down
16 changes: 0 additions & 16 deletions bin/done.js

This file was deleted.

5 changes: 4 additions & 1 deletion bin/extend.js
Expand Up @@ -17,7 +17,8 @@

var _ = require('underscore'),
rightClick = require('rightClick'),
getConfig = require('./get-config');
getConfig = require('./get-config'),
log = require('col');

module.exports = function (config) {
var userConfig = {},
Expand All @@ -36,9 +37,11 @@ module.exports = function (config) {
userConfig.target = {
path: userConfig.target
};
log.warn('Config target attribute is deprecated. Please use target.path');

if (userConfig.suffix) {
userConfig.target.suffix = userConfig.suffix;
log.warn('Config suffix attribute is deprecated. Please use target.suffix');
}
}

Expand Down
2 changes: 1 addition & 1 deletion bin/get-config.js
Expand Up @@ -10,7 +10,7 @@ module.exports = function () {

if (files.indexOf('.maticrc') !== -1) {
config = '.maticrc';
} else {
} else if (files.indexOf('config.json') !== -1) {
config = 'config.json';
log.warn('Use of config.json is deprecated. Please rename it to ".maticrc"');
}
Expand Down
3 changes: 1 addition & 2 deletions bin/matic
Expand Up @@ -10,7 +10,6 @@ var matic = require('../lib/matic.js'),
config = require('./config'),
check = require('./check'),
extend = require('./extend'),
done = require('./done'),
log = require('col');

// Extend local config with a project based one if it exists.
Expand All @@ -21,7 +20,7 @@ if (check(config)) {

emitter.on('done', function () {
// Let the user know that build is complete.
log.success(done(config));
log.success('Documentation built to ' + config.target.path + '\n');
});

}
18 changes: 0 additions & 18 deletions bin/unrequire.js

This file was deleted.

1 change: 0 additions & 1 deletion package.json
Expand Up @@ -36,7 +36,6 @@
"jscs": "1.5.7"
},
"scripts": {
"unitold": "nodeunit tests",
"lint": "./node_modules/jshint/bin/jshint ./",
"jscs": "./node_modules/jscs/bin/jscs ./",
"unit": "mocha test/unit",
Expand Down
15 changes: 15 additions & 0 deletions test/testfiles/new-style-rc/.maticrc
@@ -0,0 +1,15 @@
{
"source": "foo",
"target": "bar",
"suffix": "html",
"template": {
"folder": true,
"path": "foobar",
"file": "default",
"lib": "barfoo"
},
"index": {
"schemas": true
},
"assets": ["foo", "bar"]
}
15 changes: 15 additions & 0 deletions test/testfiles/old-style-config/config.json
@@ -0,0 +1,15 @@
{
"source": "foo",
"target": "bar",
"suffix": "html",
"template": {
"folder": true,
"path": "foobar",
"file": "default",
"lib": "barfoo"
},
"index": {
"schemas": true
},
"assets": ["foo", "bar"]
}
82 changes: 82 additions & 0 deletions test/unit/bin/extend.test.js
@@ -0,0 +1,82 @@
'use strict';

var extend = require('../../../bin/extend'),
path = require('path'),
log = require('col');

describe('bin/extend', sandbox(function () {
var config, expected;

beforeEach(function () {
config = {
target: {
path: 'web',
suffix: 'html'
},
schemas: {
path: 'schemas',
suffix: 'json',
indent: 2
},
templates: {
folder: true,
path: 'templates',
file: 'default',
lib: 'jade',
suffix: 'jade'
}
};

expected = {
target: {
path: 'bar',
suffix: 'html'
},
schemas: {
path: 'schemas',
suffix: 'json',
indent: 2
},
templates: {
folder: true,
path: 'templates',
file: 'default',
lib: 'jade',
suffix: 'jade'
},
index: {
schemas: true
},
assets: [ 'foo', 'bar' ]
};

sandbox.stub(log, 'warn');
});

describe('for old style config files', function () {

beforeEach(function () {
sandbox.stub(process, 'cwd')
.returns(path.join(__dirname, '../../testfiles/old-style-config/'));
});

it('extends the user config and updates it to the new format', function () {
extend(config).should.deep.equal(expected);
});

});

describe('for new stlye .rc files', function () {

beforeEach(function () {
sandbox.stub(process, 'cwd')
.returns(path.join(__dirname, '../../testfiles/new-style-rc/'));
});

it('extends the user config', function () {
extend(config).should.deep.equal(expected);
});

});

}));
50 changes: 50 additions & 0 deletions test/unit/bin/get-config.test.js
@@ -0,0 +1,50 @@
'use strict';

var getConfig = require('../../../bin/get-config'),
fs = require('fs'),
log = require('col');

describe('bin/get-config', sandbox(function () {
var config, files;

describe('dot file', function () {

beforeEach(function () {
files = ['foo.bar', '.maticrc', 'config.json', 'bar.foo'];

sandbox.stub(fs, 'readdirSync')
.returns(files);

config = getConfig();
});

it('returns the name of the dot file', function () {
config.should.equal('.maticrc');
});

});

describe('config file', function () {

beforeEach(function () {
files = ['foo.bar', 'config.json', 'bar.foo'];

sandbox.stub(fs, 'readdirSync')
.returns(files);

sandbox.stub(log, 'warn');

config = getConfig();
});

it('returns the name of the json file', function () {
config.should.equal('config.json');
});

it('logs a deprecation warning', function () {
(typeof log.warn.args[0][0]).should.equal('string');
});

});

}));
56 changes: 0 additions & 56 deletions tests/args.help.test.js

This file was deleted.

0 comments on commit e5498d9

Please sign in to comment.