Skip to content

Commit

Permalink
Fix: copying of a file in cwd (refs #11)
Browse files Browse the repository at this point in the history
  • Loading branch information
mysticatea committed Jul 18, 2015
1 parent 74cee07 commit b150cdd
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/cpx.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {EventEmitter} from "events";
import {dirname} from "path";
import {dirname, join as joinPath} from "path";
import {unlink, unlinkSync, rmdir, rmdirSync} from "fs";
import mkdir, {sync as mkdirSync} from "mkdirp";
import {Minimatch} from "minimatch";
Expand Down Expand Up @@ -133,6 +133,9 @@ export default class Cpx extends EventEmitter {
*/
src2dst(path) {
assertType(path, "path", "string");
if (this.base === ".") {
return joinPath(this.outDir, path);
}
return path.replace(this.base, this.outDir);
}

Expand Down
35 changes: 35 additions & 0 deletions test/copy.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,4 +186,39 @@ describe("The copy method", () => {

});

describe("should copy as expected even if the path does not included with `/`.", () => {
beforeEach(() => {
setupTestDir({
"hello.txt": "Hello"
});
});
afterEach(() => {
teardownTestDir("hello.txt");
teardownTestDir("test-ws");
});

function verifyFiles() {
expect(content("test-ws/hello.txt")).to.equal("Hello");
}

it("lib async version.", done => {
cpx.copy("hello.txt", "test-ws", err => {
expect(err).to.be.null;
verifyFiles();
done();
});
});

it("lib sync version.", () => {
cpx.copySync("hello.txt", "test-ws");
verifyFiles();
});

it("command version.", () => {
execSync("node lib/command.js hello.txt test-ws");
verifyFiles();
});

});

});

0 comments on commit b150cdd

Please sign in to comment.