'use strict'; var u = require('underscore'); var fs = require('fs-extra'); var assert = require("assert"); var assets = require("../lib/node-ff-assets"); function createTestAssembler(suite) { var assetAssembler = new assets.AssetAssembler({ linkMapping: {'/static-test/': 'test/data/'+suite.title+'/'}, linkTarget: '/static-test/output.css', linkSources: [ '/static-test/input0.css', '/static-test/input1.css', ], }); assetAssembler.on ('log',function (logLevel, logMessage) { var level = (logLevel+' ').substring(0,6); console.log(' '+ level + ' ' + suite.title + ' ' +logMessage); }); return assetAssembler; } function createTestData(suite) { var testName = suite.title; var outputFile = 'test/data/'+testName+'/output.css'; var dataCss0 = 'test/data/'+testName+'/input0.css'; var dataCss1 = 'test/data/'+testName+'/input1.css'; fs.ensureFileSync(dataCss0); fs.appendFile(dataCss0,'input__0'); fs.ensureFileSync(dataCss1); fs.appendFile(dataCss1,'input__1'); return outputFile; } describe('lib/asset-assembler.js', function() { describe('config-null', function() { this.timeout(10000); try { new assets.AssetAssembler(); assert.ok(false); } catch (err) { assert.ok(err !== undefined); } }); describe('aggregate-two', function() { this.timeout(10000); var outputFile = createTestData(this); var assetAssembler = createTestAssembler(this); it('run builder and check output', function (done) { assetAssembler.run(function (err) { try { assert.ok(true); assert.equal(true, fs.existsSync(outputFile)); var outputData = ''+fs.readFileSync(outputFile); assert.equal(true, outputData.indexOf('input__0') > 0); assert.equal(true, outputData.indexOf('input__1') > 0); done(); } catch (err) { done(err); } }); }); }); describe('aggregate-two-and-remote', function() { this.timeout(10000); var remoteFile = 'test/data/'+this.title+'/fonts-sans-pro.css' var outputFile = createTestData(this); var assetAssembler = createTestAssembler(this); assetAssembler.config.linkSources.push('/static-test/fonts-sans-pro.css@http://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,700'); it('run builder and check output', function (done) { assetAssembler.run(function (err) { try { assert.ok(true); assert.equal(true, fs.existsSync(outputFile)); assert.equal(true, fs.existsSync(remoteFile)); var outputData = ''+fs.readFileSync(outputFile); assert.equal(true, outputData.indexOf('input__0') > 0); assert.equal(true, outputData.indexOf('input__1') > 0); assert.equal(true, outputData.indexOf('Source Sans Pro') > 0); done(); } catch (err) { console.log('sdf: '+Object.keys(err)); done(err); } }); }); }); describe('remote-404', function() { this.timeout(10000); var remoteFile = 'test/data/'+this.title+'/font-404.css'; var outputFile = createTestData(this); var assetAssembler = createTestAssembler(this); assetAssembler.config.linkSources.push('/static-test/font-404.css@http://fonts.googleapis.com/404'); it('run builder and check output', function (done) { assetAssembler.run(function (err) { try { assert.ok(err !== undefined); assert.equal(true, err.message.indexOf('404') >= 0); assert.equal(true, fs.existsSync(outputFile)); assert.equal(true, fs.existsSync(remoteFile)); var outputData = ''+fs.readFileSync(outputFile); assert.equal(true, outputData.length !== 0); assert.equal(true, outputData.indexOf('input__0') === -1); assert.equal(true, outputData.indexOf('input__1') === -1); assert.equal(true, outputData.indexOf('Source Sans Pro') === -1); var remoteData = ''+fs.readFileSync(remoteFile); assert.equal(true, remoteData.indexOf('404') > 0); done(); } catch (err) { done(err); } }); }); }); describe('remote-closed', function() { this.timeout(10000); var remoteFile = 'test/data/'+this.title+'/font-closed.css' var outputFile = createTestData(this); var assetAssembler = createTestAssembler(this); assetAssembler.config.linkSources.push('/static-test/font-closed.css@http://localhost:12345/closed'); it('run builder and check output', function (done) { assetAssembler.run(function (err) { try { assert.ok(err !== undefined); assert.equal(true, err.message.indexOf('REFUSED') >= 0); assert.equal(true, fs.existsSync(outputFile)); assert.equal(true, fs.existsSync(remoteFile)); var outputData = ''+fs.readFileSync(outputFile); assert.equal(true, outputData.indexOf('input__0') === -1); assert.equal(true, outputData.indexOf('input__1') === -1); var remoteData = ''+fs.readFileSync(remoteFile); assert.equal(true, remoteData.length === 0); done(); } catch (err) { done(err); } }); }); }); });