Skip to content

Commit

Permalink
Merge pull request #130 from enb-bem/issue-129
Browse files Browse the repository at this point in the history
Fixed bug with entities order in files tech
  • Loading branch information
blond committed Apr 20, 2015
2 parents c9e9a90 + cd4931d commit 0b23bcc
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 20 deletions.
32 changes: 12 additions & 20 deletions techs/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,39 +106,31 @@ module.exports = inherit(require('enb/lib/tech/base-tech.js'), {
.spread(function (data, levels) {
return requireSourceDeps(data, depsFilename)
.then(function (sourceDeps) {
var fileList = new FileList(),
dirList = new FileList(),
files = {},
dirs = {};
var hash = {},
fileList = new FileList(),
dirList = new FileList();

for (var i = 0, l = sourceDeps.length; i < l; i++) {
var dep = sourceDeps[i],
entities;

if (dep.elem) {
entities = levels.getElemEntities(dep.block, dep.elem, dep.mod, dep.val);
} else {
entities = levels.getBlockEntities(dep.block, dep.mod, dep.val);
}

addEntityFiles(entities);
fileList.addFiles(entities.files.filter(filter));
dirList.addFiles(entities.dirs.filter(filter));
}

fileList.addFiles(Object.keys(files).map(function (filename) {
return files[filename];
}));

dirList.addFiles(Object.keys(dirs).map(function (dirname) {
return dirs[dirname];
}));

function addEntityFiles(entities) {
entities.files.forEach(function (file) {
files[file.fullname] = file;
});
function filter(file) {
if (hash[file.fullname]) {
return false;
}

entities.dirs.forEach(function (dir) {
dirs[dir.fullname] = dir;
});
hash[file.fullname] = true;
return true;
}

_this.node.resolveTarget(filesTarget, fileList);
Expand Down
45 changes: 45 additions & 0 deletions test/techs/files.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,51 @@ describe('techs', function () {
.then(done, done);
});

it('must keep order of entities', function (done) {
mockFs({
blocks: {
'block-1': {
'block-1.ext-1': '',
'block-1.ext-2': ''
},
'block-2': {
'block-2.ext-1': '',
'block-2.ext-2': ''
}
},
bundle: {}
});

var bundle = new TestNode('bundle'),
deps = [
{ block: 'block-1' },
{ block: 'block-2' }
],
files = [
'block-1.ext-1',
'block-1.ext-2',
'block-2.ext-1',
'block-2.ext-2'
];

bundle.runTech(levelsTech, { levels: ['blocks'] })
.then(function (levels) {
bundle.provideTechData('?.levels', levels);
bundle.provideTechData('?.deps.js', deps);

return bundle.runTechAndGetResults(filesTech);
})
.then(function (result) {
var FileList = result['bundle.files'],
filenames = FileList.getBySuffix(['ext-1', 'ext-2']).map(function (fileInfo) {
return fileInfo.name;
});

filenames.must.eql(files);
})
.then(done, done);
});

it('must get block file by deps', function (done) {
var scheme = {
blocks: {
Expand Down

0 comments on commit 0b23bcc

Please sign in to comment.