lmd
Version:
LMD: Lazy Module Declaration
91 lines (73 loc) • 3.24 kB
JavaScript
/*global describe, it, beforeEach, afterEach*/
/*jshint expr:true*/
var path = require('path'),
Stream = require('stream'),
vow = require('vow'),
expect = require('chai').expect,
readStream = require('./lib/read_stream');
// disable colors
require('colors').mode = 'none';
var Builder = require('../..');
var fixtures = path.join(__dirname, 'fixtures', 'banner');
function cfgPath(name) {
return path.join(fixtures, '.lmd', name + '.lmd.json');
}
describe('lmd', function() {
describe('banner', function() {
it('prints default banner that consists of config file and mixins', function (done) {
var build = new Builder(cfgPath('default'));
var banner = '// This file was automatically generated from "default.lmd.json" using mixins "mixin.lmd.json"';
readStream(build)
.then(function (code) {
expect(code.split('\n')[0]).to.be.eql(banner);
})
.then(done, done);
});
it('prints warning and uses default banner if `banner` property is not a string', function (done) {
var build = new Builder(cfgPath('non-string'));
var banner = '// This file was automatically generated from "non-string.lmd.json"';
var warning = '`banner` should be a string';
vow.all({
code: readStream(build),
log: readStream(build.log)
})
.then(function (data) {
expect(data.code.split('\n')[0]).to.be.eql(banner);
expect(data.log).to.have.string(warning);
})
.then(done, done);
});
it('can use `__dirname` and `__filename` variables', function (done) {
var build = new Builder(cfgPath('dirname-filename'));
var banner = '// /dirname-filename.lmd.json';
readStream(build)
.then(function (code) {
expect(code.split('\n')[0]).to.be.eql(banner);
})
.then(done, done);
});
it('should warn if `banner` contains any JavaScript but print `banner` as is', function (done) {
var build = new Builder(cfgPath('javascript'));
var banner = 'console.log(\'banner\');';
var warning = '`banner` should be a JavaScript comment. Please remove any executable JavaScript from `banner`.';
vow.all({
code: readStream(build),
log: readStream(build.log)
})
.then(function (data) {
expect(data.code.split('\n')[0]).to.be.eql(banner);
expect(data.log).to.have.string(warning);
})
.then(done, done);
});
it('is inherited by bundles', function (done) {
var build = new Builder(cfgPath('bundle-inherits-banner'));
var banner = '//inherits';
readStream(build.bundles.test)
.then(function (code) {
expect(code.split('\n')[0]).to.be.eql(banner);
})
.then(done, done);
});
});
});