Skip to content

tests and documentation for copy option #1

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

Merged
merged 3 commits into from
May 12, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
18 changes: 18 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,24 @@ module.exports = function (grunt) {
},
src: ['test/fixtures/file.png', 'test/fixtures/another.png'],
dest: 'test/tmp'
},
withCopyTrue: {
options: {
algorithm: 'sha1',
length: 4,
copy: 1
},
src: ['test/tmp/another.png'],
dest: 'test/tmp'
},
withCopyFalse: {
options: {
algorithm: 'sha1',
length: 4,
copy: 0
},
src: ['test/tmp/movedfile.png'],
dest: 'test/tmp/copyfalse'
}
},
simplemocha: {
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ Default: `8`

The number of characters of the file hash to prefix the file name with.

#### options.copy

Type: `Boolean`
Default: `null`

Flag controlling whether the original file is copied or moved. If not set,
other parameters, such as setting a [destination](#destination) control the behaviour.

### Destination

It will overwrite the `src` files if you don't specify a `dest`:
Expand Down
16 changes: 16 additions & 0 deletions test/filerev_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,20 @@ describe('filerev', function () {
var revisioned= fs.statSync('test/tmp/expand/file.a0539763.png').size;
assert(revisioned === original);
});

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

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