add some tests
This commit is contained in:
parent
3f580bbe2d
commit
50f2b83443
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -6,6 +6,9 @@
|
|||
node_modules
|
||||
npm-debug.log
|
||||
|
||||
# Ignore mocha test data
|
||||
test/data
|
||||
|
||||
# Ignore binary files
|
||||
*.o
|
||||
*.class
|
||||
|
|
|
@ -58,6 +58,9 @@ function buildStepConfigCreate(builder, buildConfig, callback) {
|
|||
}
|
||||
|
||||
function AssetsBuilder(config) {
|
||||
if (config === undefined) {
|
||||
throw new Error('no config');
|
||||
}
|
||||
this.config = config;
|
||||
this.startTime = 0;
|
||||
this.currentAssetType = '';
|
||||
|
|
|
@ -122,7 +122,9 @@ var builderAssemblerCreate = {
|
|||
},
|
||||
};
|
||||
|
||||
var builderEmptyCallback = function () {};
|
||||
var builderEmptyCallback = function () {
|
||||
return function () {};
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
assembler: {
|
||||
|
|
|
@ -15,7 +15,8 @@
|
|||
"dependencies": {
|
||||
"fetch": "^0.3.6",
|
||||
"fs-extra": "^0.16.3",
|
||||
"minify": "^1.4.8"
|
||||
"minify": "^1.4.8",
|
||||
"underscore": "^1.8.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"mocha": "^2.1.0",
|
||||
|
|
88
test/test-asset-assembler.js
Normal file
88
test/test-asset-assembler.js
Normal 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
52
test/test-factory.js
Normal 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');
|
||||
});
|
||||
});
|
||||
|
|
@ -1,24 +1,38 @@
|
|||
'use strict';
|
||||
|
||||
var assert = require("assert");
|
||||
var asserts = require("../lib/node-ff-assets");
|
||||
var assets = require("../lib/node-ff-assets");
|
||||
|
||||
describe('node-ff-assets', function() {
|
||||
describe('export.* check undefined', function() {
|
||||
describe('lib/node-ff-assets.js', function() {
|
||||
describe('check exports', 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() {
|
||||
assert.equal(false, asserts.AssetAssembler === undefined);
|
||||
assert.equal(false, assets.AssetAssembler === undefined);
|
||||
});
|
||||
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() {
|
||||
assert.equal(false, asserts.AssetsBuilder === undefined);
|
||||
assert.equal(false, assets.AssetsBuilder === undefined);
|
||||
});
|
||||
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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue