2
0
Fork 0

add some tests

This commit is contained in:
Willem 2015-02-27 03:31:44 +01:00
parent 3f580bbe2d
commit 50f2b83443
7 changed files with 173 additions and 10 deletions

3
.gitignore vendored
View file

@ -6,6 +6,9 @@
node_modules node_modules
npm-debug.log npm-debug.log
# Ignore mocha test data
test/data
# Ignore binary files # Ignore binary files
*.o *.o
*.class *.class

View file

@ -58,6 +58,9 @@ function buildStepConfigCreate(builder, buildConfig, callback) {
} }
function AssetsBuilder(config) { function AssetsBuilder(config) {
if (config === undefined) {
throw new Error('no config');
}
this.config = config; this.config = config;
this.startTime = 0; this.startTime = 0;
this.currentAssetType = ''; this.currentAssetType = '';

View file

@ -122,7 +122,9 @@ var builderAssemblerCreate = {
}, },
}; };
var builderEmptyCallback = function () {}; var builderEmptyCallback = function () {
return function () {};
};
module.exports = { module.exports = {
assembler: { assembler: {

View file

@ -15,7 +15,8 @@
"dependencies": { "dependencies": {
"fetch": "^0.3.6", "fetch": "^0.3.6",
"fs-extra": "^0.16.3", "fs-extra": "^0.16.3",
"minify": "^1.4.8" "minify": "^1.4.8",
"underscore": "^1.8.2"
}, },
"devDependencies": { "devDependencies": {
"mocha": "^2.1.0", "mocha": "^2.1.0",

View file

@ -0,0 +1,88 @@
'use strict';
var u = require('underscore');
var fs = require('fs-extra');
var assert = require("assert");
var assets = require("../lib/node-ff-assets");
var testDataCss = function (testName) {
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.writeFileSync(dataCss0,'');
fs.appendFile(dataCss0,'input__0');
fs.ensureFileSync(dataCss1);
fs.writeFileSync(dataCss1,'');
fs.appendFile(dataCss1,'input__1');
if (fs.existsSync(outputFile)) {
fs.writeFileSync(outputFile,'');
}
return outputFile;
}
var testName = '';
describe('lib/asset-assembler.js', function() {
testName = 'test-aggregate-two';
describe(testName, function() {
this.timeout(10000);
var outputFile = testDataCss(testName);
var assetAssembler = new assets.AssetAssembler({
linkMapping: {'/static-test/': 'test/data/'+testName+'/'},
linkTarget: '/static-test/output.css',
linkSources: [
'/static-test/input0.css',
'/static-test/input1.css',
],
});
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);
}
});
});
});
testName = 'test-aggregate-two-and-remote';
describe(testName, function() {
this.timeout(10000);
var outputFile = testDataCss(testName);
var assetAssembler = new assets.AssetAssembler({
linkMapping: {'/static-test/': 'test/data/'+testName+'/'},
linkTarget: '/static-test/output.css',
linkSources: [
'/static-test/input0.css',
'/static-test/input1.css',
'/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('test/data/'+testName+'/fonts-sans-pro.css'));
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) {
done(err);
}
});
});
});
});

52
test/test-factory.js Normal file
View file

@ -0,0 +1,52 @@
'use strict';
var u = require('underscore');
var assert = require('assert');
var asserts = require('../lib/node-ff-assets');
var checkFunctionResult = function(node,prefixParent) {
var nodeKeys = Object.keys(node);
for (var i = 0; i < nodeKeys.length; i++) {
var nodeKey = nodeKeys[i];
var nodeValue = node[nodeKey];
var prefix = prefixParent + '.'+nodeKey;
if (u.isFunction(nodeValue)) {
var result = null;
try {
result = nodeValue();
} catch (err) {
result = function() {};
}
it(prefix+' should return function', function() {
assert.equal(true, u.isFunction(result));
});
} else if (u.isObject(nodeValue)) {
checkFunctionResult(nodeValue,prefix);
}
}
}
describe('lib/factory.js', function() {
describe('check function paths', function() {
it('asserts.factory.assembler should not be undefined', function() {
assert.equal(false, asserts.factory.assembler === undefined);
});
it('asserts.factory.assembler.constructor should not be undefined', function() {
assert.equal(false, asserts.factory.assembler.constructor === undefined);
});
it('asserts.factory.assembler.event should not be undefined', function() {
assert.equal(false, asserts.factory.assembler.event === undefined);
});
it('asserts.factory.builder should not be undefined', function() {
assert.equal(false, asserts.factory.builder === undefined);
});
it('asserts.factory.lib should not be undefined', function() {
assert.equal(false, asserts.factory.lib === undefined);
});
});
describe('check function results', function() {
checkFunctionResult(asserts.factory,'asserts.factory');
});
});

View file

@ -1,24 +1,38 @@
'use strict'; 'use strict';
var assert = require("assert"); var assert = require("assert");
var asserts = require("../lib/node-ff-assets"); var assets = require("../lib/node-ff-assets");
describe('node-ff-assets', function() { describe('lib/node-ff-assets.js', function() {
describe('export.* check undefined', function() { describe('check exports', function() {
it('asserts.factory should not be undefined', function() { it('asserts.factory should not be undefined', function() {
assert.equal(false, asserts.factory === undefined); assert.equal(false, assets.factory === undefined);
}); });
it('asserts.AssetAssembler should not be undefined', function() { it('asserts.AssetAssembler should not be undefined', function() {
assert.equal(false, asserts.AssetAssembler === undefined); assert.equal(false, assets.AssetAssembler === undefined);
}); });
it('asserts.checkAssemblerConfig should not be undefined', function() { it('asserts.checkAssemblerConfig should not be undefined', function() {
assert.equal(false, asserts.checkAssemblerConfig === undefined); assert.equal(false, assets.checkAssemblerConfig === undefined);
}); });
it('asserts.AssetsBuilder should not be undefined', function() { it('asserts.AssetsBuilder should not be undefined', function() {
assert.equal(false, asserts.AssetsBuilder === undefined); assert.equal(false, assets.AssetsBuilder === undefined);
}); });
it('asserts.checkBuilderConfig should not be undefined', function() { it('asserts.checkBuilderConfig should not be undefined', function() {
assert.equal(false, asserts.checkBuilderConfig === undefined); assert.equal(false, assets.checkBuilderConfig === undefined);
});
it('asserts.build should not be undefined', function() {
assert.equal(false, assets.build === undefined);
});
});
describe('asserts.build', function() {
it('check build missing config error', function() {
var err = null;
try {
assets.build();
} catch (error) {
err = error;
}
assert.equal(false, err === undefined);
}); });
}); });
}); });