Skip to content

Commit

Permalink
added some tests to check that removing parts of directories works as…
Browse files Browse the repository at this point in the history
… expected, and fixed some bugs related to it
  • Loading branch information
Ivar Prudnikovas committed Jul 11, 2014
1 parent 7c6ffda commit ead2ed4
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/configwriter.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ ConfigWriter.prototype.process = function (file, config) {
} else if (context.inDir.indexOf('/' + self.srcStrip) > -1){
regexp = new RegExp('/' + self.srcStrip + '$');
strippedInDir = context.inDir.replace(regexp,'');
} else if (context.inDir === self.srcStrip){
strippedInDir = '';
}
}

Expand Down
111 changes: 111 additions & 0 deletions test/test-config-writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,117 @@ describe('ConfigWriter', function () {
assert.deepEqual(config, expected);
});

it('should allow removing one level of directory', function () {
var flow = new Flow({
steps: {
js: ['concat', 'uglifyjs']
}
});

var file = helpers.createFile('foo', 'app', blocks);
var c = new ConfigWriter(flow, {
srcStrip: 'app',
input: 'app',
dest: 'dist',
staging: 'staging'
});
var config = c.process(file);
var expected = helpers.normalize({
concat: {
generated: {
files: [{
dest: 'staging/scripts/site.js',
src: ['app/foo.js', 'app/bar.js', 'app/baz.js']
}]
}
},
uglify: {
generated: {
files: [{
dest: 'dist/scripts/site.js',
src: ['staging/scripts/site.js']
}]
}
}
});

assert.deepEqual(config, expected);
});

it('should allow removing parts of directory', function () {
var flow = new Flow({
steps: {
js: ['concat', 'uglifyjs']
}
});

var file = helpers.createFile('foo', 'app/in/some/dir', blocks);
var c = new ConfigWriter(flow, {
srcStrip: 'app/in',
input: 'app',
dest: 'dist',
staging: 'staging'
});
var config = c.process(file);
var expected = helpers.normalize({
concat: {
generated: {
files: [{
dest: 'staging/some/dir/scripts/site.js',
src: ['app/in/some/dir/foo.js', 'app/in/some/dir/bar.js', 'app/in/some/dir/baz.js']
}]
}
},
uglify: {
generated: {
files: [{
dest: 'dist/some/dir/scripts/site.js',
src: ['staging/some/dir/scripts/site.js']
}]
}
}
});

assert.deepEqual(config, expected);
});

it('should allow removing middle parts of directory', function () {
var flow = new Flow({
steps: {
js: ['concat', 'uglifyjs']
}
});

var file = helpers.createFile('foo', 'app/in/some/dir', blocks);
var c = new ConfigWriter(flow, {
srcStrip: 'in/some',
input: 'app',
dest: 'dist',
staging: 'staging'
});
var config = c.process(file);
var expected = helpers.normalize({
concat: {
generated: {
files: [{
dest: 'staging/app/dir/scripts/site.js',
src: ['app/in/some/dir/foo.js', 'app/in/some/dir/bar.js', 'app/in/some/dir/baz.js']
}]
}
},
uglify: {
generated: {
files: [{
dest: 'dist/app/dir/scripts/site.js',
src: ['staging/app/dir/scripts/site.js']
}]
}
}
});

assert.deepEqual(config, expected);
});

it('should allow for single step flow', function () {
var flow = new Flow({
steps: {
Expand Down

0 comments on commit ead2ed4

Please sign in to comment.