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

90 lines
2.3 KiB
JavaScript
Raw Normal View History

2015-02-27 20:50:19 +00:00
'use strict';
var fs = require('fs-extra');
2015-06-28 15:44:01 +00:00
var assert = require('assert');
var assets = require('../lib/node-ff-assets');
2015-02-27 20:50:19 +00:00
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,
});
2015-06-28 15:44:01 +00:00
};
2015-02-27 20:50:19 +00:00
}
function createTestBuilder(suite) {
var testConfig = {
assemblerFill: function (assembler, callback) {
var serverResultKey = 'ff_assets_'+assembler.config.assetType;
2015-06-28 15:44:01 +00:00
assert.ok(serverResultKey);
2015-06-28 14:41:57 +00:00
assembler.on ('log',function (logMessage) {
console.log(' ' + ' ' + suite.title + ' assembler ' +logMessage); // == -2 space from asm
2015-02-27 20:50:19 +00:00
});
callback();
},
assets: {
js: {
configCreate: createTestConfig(suite,'js'),
},
css: {
configCreate: createTestConfig(suite,'css'),
}
}
};
2015-06-28 14:41:57 +00:00
return new assets.AssetsBuilder(testConfig);
2015-02-27 20:50:19 +00:00
}
describe('lib/assets-builder.js', function() {
describe('config-null', function() {
this.timeout(10000);
try {
2015-06-28 15:44:01 +00:00
var result = new assets.AssetsBuilder();
assert.ok(result);
2015-02-27 20:50:19 +00:00
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);
}
});
});
});
});