@sencha/cmd-linux-64
Version:
Productivity and performance optimization tool for building applications with Sencha Ext JS
152 lines (139 loc) • 5.26 kB
JavaScript
var Fashion = require('../../index.js');
var assert = require('assert');
var fs = require('fs');
var Path = require('path');
var process = require('process'),
cwd = process.cwd();
global.Fashion = Fashion;
describe("extensions", function(){
function compareContent(content, expectedPath) {
var expected = fs.readFileSync(Path.resolve(__dirname, '../expected', expectedPath), {
encoding: 'utf8'
});
var basePath = Path.resolve(__dirname, '../').replace(new RegExp('\\\\', 'g'), '/'),
baseRegex = new RegExp(basePath, 'g'),
actual = content.join('').replace(baseRegex, '..');
console.log("basePath is ", basePath);
expected = expected.replace(baseRegex, '..');
actual = actual.replace(/\r\n/g, "\n");
expected = expected.replace(/\r\n/g, "\n");
assert.equal(actual, expected);
}
it("should import extensions", function(done){
var targetPath = Path.resolve(__dirname, '../files/extensions'),
basePath = Path.relative(cwd, targetPath),
builder = new Fashion.Builder({
compressed: false,
context: {
basePath: basePath,
inliner: {
enable: true,
excludes: [
'image-2\\.png$'
]
},
prune: [
'.selectorToRemove',
'.foo.bar',
'div#someId'
]
}
}),
path = Path.resolve(targetPath, 'test-extension.scss');
builder.build(path, function(content){
setTimeout(function(){
compareContent(content, 'extensionImport.css');
done();
}, 1);
});
});
it("should import extensions using functions", function(done){
var targetPath = Path.resolve(__dirname, '../files/extensions'),
basePath = Path.relative(cwd, targetPath),
builder = new Fashion.Builder({
compressed: false,
context: {
basePath: basePath,
inliner: {
enable: true
}
}
}),
path = Path.resolve(targetPath, 'test-extension-functions.scss');
builder.build(path, function(content, err){
setTimeout(function(){
compareContent(content, 'extensionImportFunction.css');
done();
}, 1);
});
});
it("should import extensions compressed", function(done){
var targetPath = Path.resolve(__dirname, '../files/extensions'),
basePath = Path.relative(cwd, targetPath),
builder = new Fashion.Builder({
compressed: true,
context: {
basePath: basePath,
inliner: {
enable: true,
excludes: [
'image-2\\.png$'
]
},
prune: [
'.selectorToRemove',
'.foo.bar',
'div#someId'
]
}
}),
path = Path.resolve(targetPath, 'test-extension.scss');
builder.build(path, function(content){
setTimeout(function(){
compareContent(content, 'extensionImportCompressed.css');
done();
}, 1);
});
});
it("should import extensions using functions compressed", function(done){
var targetPath = Path.resolve(__dirname, '../files/extensions'),
basePath = Path.relative(cwd, targetPath),
builder = new Fashion.Builder({
compressed: true,
context: {
basePath: basePath,
inliner: {
enable: true
}
}
}),
path = Path.resolve(targetPath, 'test-extension-functions.scss');
builder.build(path, function(content, err){
setTimeout(function(){
compareContent(content, 'extensionImportFunctionCompressed.css');
done();
}, 1);
});
});
it("should detect cycles in import statements", function(done){
var targetPath = Path.resolve(__dirname, '../files/import_cycle'),
basePath = Path.relative(cwd, targetPath),
builder = new Fashion.Builder({
compressed: true,
context: {
basePath: basePath,
inliner: {
enable: true
}
}
}),
path = Path.resolve(targetPath, 'A.scss');
builder.build(path, function(content, err){
setTimeout(function(){
err = err.message;
assert.equal(err.indexOf('Import cycle'), 0);
done();
}, 1);
});
});
});