From bc4217d37270f6f823f82bf249e206bfc643d509 Mon Sep 17 00:00:00 2001 From: Daniel Andrei Date: Wed, 19 Jun 2019 19:32:26 +0300 Subject: [PATCH] Throw on no file found --- index.js | 7 +------ test.js | 16 +++------------- 2 files changed, 4 insertions(+), 19 deletions(-) diff --git a/index.js b/index.js index 39fabae..8c7f77a 100644 --- a/index.js +++ b/index.js @@ -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`); } const fileProgressHandler = event => { diff --git a/test.js b/test.js index b26d710..4fbb3a0 100644 --- a/test.js +++ b/test.js @@ -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)); + t.true(error instanceof CpyError); }); test('reports copy progress of single file', async t => {