Skip to content

added more tests to cover additional scenarios, simplified code change #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,21 @@ module.exports = function (grunt) {
},
src: ['test/tmp/movedfile.png'],
dest: 'test/tmp/copyfalse'
},
withCopyNullDest: {
options: {
algorithm: 'sha1',
length: 4
},
src: ['test/tmp/another.png'],
dest: 'test/tmp/nocopy'
},
withCopyNullNoDest: {
options: {
algorithm: 'sha1',
length: 4
},
src: ['test/tmp/movednocopyfile.png']
}
},
simplemocha: {
Expand Down
9 changes: 1 addition & 8 deletions tasks/filerev.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,7 @@ module.exports = function (grunt) {
dirname = el.dest ? el.dest : path.dirname(file);
resultPath = path.resolve(dirname, newName);

if (options.copy === null) {
// If options.copy is null, defer to wether or not destination is defined (old behavior)
if (el.dest) {
grunt.file.copy(file, resultPath);
} else {
fs.renameSync(file, resultPath);
}
} else if (options.copy) {
if (options.copy || (options.copy === null && el.dest)) {
grunt.file.copy(file, resultPath);
} else {
fs.renameSync(file, resultPath);
Expand Down
16 changes: 16 additions & 0 deletions test/filerev_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,20 @@ describe('filerev', function () {
var fileExists = fs.existsSync('test/tmp/movedfile.png');
assert(fileExists === false);
});

it('should copy the file without copy option when dest is specified', function () {
var original = fs.statSync('test/fixtures/another.png').size;
var revisioned= fs.statSync('test/tmp/nocopy/another.37ba.png').size;
assert(revisioned === original);
var fileExists = fs.existsSync('test/tmp/another.png');
assert(fileExists === true);
});

it('should move the file without copy option when dest is not specified', function () {
var original = fs.statSync('test/fixtures/movednocopyfile.png').size;
var revisioned= fs.statSync('test/tmp/movednocopyfile.37ba.png').size;
assert(revisioned === original);
var fileExists = fs.existsSync('test/tmp/movednocopyfile.png');
assert(fileExists === false);
});
});
Binary file added test/fixtures/movednocopyfile.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.