Skip to content
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

Throw if the given source file does not exist #68

Merged
merged 13 commits into from
Sep 22, 2019
7 changes: 1 addition & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,7 @@ module.exports = (source, destination, options = {}) => {
}

if (files.length === 0) {
progressEmitter.emit('progress', {
totalFiles: 0,
percent: 1,
completedFiles: 0,
completedSize: 0
});
throw new CpyError(`Cannot copy \`${source}\`: no files found`);
whitecrownclown marked this conversation as resolved.
Show resolved Hide resolved
}

const fileProgressHandler = event => {
Expand Down
16 changes: 3 additions & 13 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,21 +135,11 @@ test('glob errors are CpyErrors', async t => {
t.true(error instanceof CpyError);
});

test('reports copy progress of no files', async t => {
test('throws on non-existing file', async t => {
fs.mkdirSync(t.context.tmp);
fs.mkdirSync(path.join(t.context.tmp, 'cwd'));

let report;
await cpy('*', t.context.tmp, {cwd: path.join(t.context.tmp, 'cwd')})
.on('progress', event => {
report = event;
});

t.not(report, undefined);
t.is(report.totalFiles, 0);
t.is(report.completedFiles, 0);
t.is(report.completedSize, 0);
t.is(report.percent, 1);
const error = await t.throwsAsync(cpy(['no-file'], t.context.tmp));
whitecrownclown marked this conversation as resolved.
Show resolved Hide resolved
t.true(error instanceof CpyError);
});

test('reports copy progress of single file', async t => {
Expand Down