2
0
Fork 0
node-ff-assets/test/test-asset-assembler.js

163 lines
4.9 KiB
JavaScript
Raw Normal View History

2015-02-27 02:31:44 +00:00
'use strict';
var u = require('underscore');
var fs = require('fs-extra');
var assert = require("assert");
var assets = require("../lib/node-ff-assets");
2015-02-27 20:50:19 +00:00
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;
2015-02-27 02:31:44 +00:00
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() {
2015-02-27 14:20:01 +00:00
2015-02-27 20:50:19 +00:00
describe('config-null', function() {
2015-02-27 02:31:44 +00:00
this.timeout(10000);
2015-02-27 20:50:19 +00:00
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);
2015-02-27 02:31:44 +00:00
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);
}
});
});
});
2015-02-27 14:20:01 +00:00
2015-02-27 20:50:19 +00:00
describe('aggregate-two-and-remote', function() {
2015-02-27 02:31:44 +00:00
this.timeout(10000);
2015-02-27 20:50:19 +00:00
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');
2015-02-27 02:31:44 +00:00
it('run builder and check output', function (done) {
assetAssembler.run(function (err) {
try {
assert.ok(true);
assert.equal(true, fs.existsSync(outputFile));
2015-02-27 20:50:19 +00:00
assert.equal(true, fs.existsSync(remoteFile));
2015-02-27 02:31:44 +00:00
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) {
2015-02-27 20:50:19 +00:00
console.log('sdf: '+Object.keys(err));
2015-02-27 02:31:44 +00:00
done(err);
}
});
});
});
2015-02-27 20:50:19 +00:00
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);
}
});
});
});
2015-02-27 02:31:44 +00:00
});