'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 (logMessage) { console.log(' ' + ' ' + suite.title + ' assembler ' +logMessage); // == -2 space from asm }); callback(); }, assets: { js: { configCreate: createTestConfig(suite,'js'), }, css: { configCreate: createTestConfig(suite,'css'), } } }; return new assets.AssetsBuilder(testConfig); } 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); } }); }); }); });