2
0
Fork 0
node-ff-assets/test/test-assets-builder.js

95 lines
2.6 KiB
JavaScript
Raw Permalink Normal View History

2015-02-27 20:50:19 +00:00
'use strict';
var u = require('underscore');
var fs = require('fs-extra');
var assert = require("assert");
var assets = require("../lib/node-ff-assets");
function createTestConfig(suite,type) {
var inputFile0 = 'test/data/'+suite.title+'/'+type+'/input0.'+type;
fs.ensureFileSync(inputFile0);
fs.appendFile(inputFile0,'\n// input0__'+suite.title+'__'+type);
var inputFile1 = 'test/data/'+suite.title+'/'+type+'/input1.'+type;
fs.ensureFileSync(inputFile1);
fs.appendFile(inputFile1,'\n// input0__'+suite.title+'__'+type);
return function (callback) {
var linkMapping = {};
linkMapping['/static-test/'+type+'/'] = 'test/data/'+suite.title+'/'+type+'/';
callback(null, {
linkMapping: linkMapping,
linkTarget: '/static-test/'+type+'/output.'+type,
linkSources: [
'/static-test/'+type+'/input0.'+type,
'/static-test/'+type+'/input1.'+type,
],
assetType: type,
});
}
}
function createTestBuilder(suite) {
var testConfig = {
assemblerFill: function (assembler, callback) {
var serverResultKey = 'ff_assets_'+assembler.config.assetType;
assembler.on ('log',function (logLevel, logMessage) {
var level = (logLevel+' ').substring(0,6);
console.log(' '+ level + ' ' + suite.title + ' assembler ' +logMessage); // == -2 space from asm
});
callback();
},
assets: {
js: {
configCreate: createTestConfig(suite,'js'),
},
css: {
configCreate: createTestConfig(suite,'css'),
}
}
};
var assetsBuilder = new assets.AssetsBuilder(testConfig);
assetsBuilder.on ('log',function (logLevel, logMessage) {
var level = (logLevel+' ').substring(0,6);
console.log(' '+ level + ' ' + suite.title + ' builder ' +logMessage); // == -1 space from asm
});
return assetsBuilder;
}
describe('lib/assets-builder.js', function() {
describe('config-null', function() {
this.timeout(10000);
try {
new assets.AssetsBuilder();
assert.ok(false);
} catch (err) {
assert.ok(err !== undefined);
}
});
describe('run-all', function() {
this.timeout(10000);
var assetsBuilder = createTestBuilder(this);
it('run builder and check output', function (done) {
assetsBuilder.runAll(function (err) {
if (err) {
done(err);
return;
}
var outputFileJs = 'test/data/run-all/js/output.js';
var outputFileCss = 'test/data/run-all/css/output.css';
try {
assert.ok(true);
assert.equal(true, fs.existsSync(outputFileJs));
assert.equal(true, fs.existsSync(outputFileCss));
done();
} catch (err) {
done(err);
}
});
});
});
});