Skip to content

Commit

Permalink
Fix test case with no paths specified.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcfarljw committed Feb 12, 2016
1 parent b3c577c commit 427a412
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 66 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ ReplaceCompiler.prototype.getPaths = function(files, config) {
return file.destinationPath || file.path;
})
.filter(function(path) {
return config.paths.indexOf(path) > -1;
return !config.paths.length || config.paths.indexOf(path) > -1;
})
.value();
};
Expand Down
163 changes: 98 additions & 65 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ describe('Plugin', function() {
var Plugin = require('./');

afterEach(function(done) {
async.parallel([
async.apply(filesystem.writeFile, 'test_files/date.txt', '{!date!}', 'utf8'),
async.apply(filesystem.writeFile, 'test_files/manifest.json', '{"version": "{?version?}"}', 'utf8'),
async.apply(filesystem.writeFile, 'test_files/timestamp.txt', '{!timestamp!}', 'utf8'),
async.apply(filesystem.writeFile, 'test_files/version.txt', '{?version?}', 'utf8')
], done);
async.parallel(
[
async.apply(filesystem.writeFile, 'test_files/date.txt', '{!date!}', 'utf8'),
async.apply(filesystem.writeFile, 'test_files/manifest.json', '{"version": "{?version?}"}', 'utf8'),
async.apply(filesystem.writeFile, 'test_files/timestamp.txt', '{!timestamp!}', 'utf8'),
async.apply(filesystem.writeFile, 'test_files/version.txt', '{?version?}', 'utf8')
],
done
);
});

it('should compile user specified paths', function() {
Expand All @@ -22,57 +25,76 @@ describe('Plugin', function() {
}
}
});
var paths = plugin.getPaths([
{path: 'test_files/date.txt'},
{path: 'test_files/timestamp.txt'},
{path: 'test_files/version.txt'}
], plugin.getConfig());
var paths = plugin.getPaths(
[
{path: 'test_files/date.txt'},
{path: 'test_files/manifest.json'},
{path: 'test_files/timestamp.txt'},
{path: 'test_files/version.txt'}
],
plugin.getConfig()
);
expect(paths[0]).to.equal('test_files/version.txt');
});

it('should set default configs and paths', function() {
var plugin = new Plugin();
var config = plugin.getConfig();
var paths = plugin.getPaths([
{path: 'test_files/date.txt'},
{path: 'test_files/timestamp.txt'},
{path: 'test_files/version.txt'}
], config);
var paths = plugin.getPaths(
[
{path: 'test_files/date.txt'},
{path: 'test_files/manifest.json'},
{path: 'test_files/timestamp.txt'},
{path: 'test_files/version.txt'}
],
config
);
expect(config.encoding).to.equal('utf8');
expect(config.mappings.date).to.be.a('string');
expect(config.mappings.timestamp).to.be.a('number');
expect(config.replacePrefix).to.equal('{!');
expect(config.replaceSuffix).to.equal('!}');
expect(paths).to.have.length(3);
expect(paths).to.have.length(4);
});

it('should replace default string mappings', function(done) {
var plugin = new Plugin();
var config = plugin.getConfig();
async.parallel([
function(callback) {
plugin.replaceFile('test_files/date.txt', config, function(error, path, data) {
if (error) {
callback(error);
} else {
var date = data.toString();
expect(date).to.have.equal(config.mappings.date);
callback();
}
});
},
function(callback) {
plugin.replaceFile('test_files/timestamp.txt', config, function(error, path, data) {
if (error) {
callback(error);
} else {
var date = parseInt(data, 10);
expect(date).to.equal(config.mappings.timestamp);
callback();
}
});
}
], done);
async.parallel(
[
function(callback) {
plugin.replaceFile(
'test_files/date.txt',
config,
function(error, path, data) {
if (error) {
callback(error);
} else {
var date = data.toString();
expect(date).to.have.equal(config.mappings.date);
callback();
}
}
);
},
function(callback) {
plugin.replaceFile(
'test_files/timestamp.txt',
config,
function(error, path, data) {
if (error) {
callback(error);
} else {
var date = parseInt(data, 10);
expect(date).to.equal(config.mappings.timestamp);
callback();
}
}
);
}
],
done
);
});

it('should replace user string mappings', function(done) {
Expand All @@ -86,30 +108,41 @@ describe('Plugin', function() {
}
});
var config = plugin.getConfig();
async.parallel([
function(callback) {
plugin.replaceFile('test_files/manifest.json', config, function(error, path, data) {
if (error) {
callback(error);
} else {
var version = data.toString();
expect(version).to.equal('{"version": "0.0.1"}');
callback();
}
});
},
function(callback) {
plugin.replaceFile('test_files/version.txt', config, function(error, path, data) {
if (error) {
callback(error);
} else {
var version = data.toString();
expect(version).to.equal('0.0.1');
callback();
}
});
}
], done);
async.parallel(
[
function(callback) {
plugin.replaceFile(
'test_files/manifest.json',
config,
function(error, path, data) {
if (error) {
callback(error);
} else {
var version = data.toString();
expect(version).to.equal('{"version": "0.0.1"}');
callback();
}
}
);
},
function(callback) {
plugin.replaceFile(
'test_files/version.txt',
config,
function(error, path, data) {
if (error) {
callback(error);
} else {
var version = data.toString();
expect(version).to.equal('0.0.1');
callback();
}
}
);
}
],
done
);

});

Expand Down

0 comments on commit 427a412

Please sign in to comment.