From b3fb3762fc7da71ecffed9121eda311655900b88 Mon Sep 17 00:00:00 2001 From: Quentin Rossetti Date: Sat, 13 Oct 2018 00:02:28 +0200 Subject: [PATCH] test: Please TravisCI --- .gitignore | 1 + lib/stream.js | 11 ++++++----- test/func/add.spec.js | 18 ++++++++++++++++-- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 7ea4bd2..56eecd6 100644 --- a/.gitignore +++ b/.gitignore @@ -21,6 +21,7 @@ package-lock.json # Dummy files for local testing dummy.* +_tmp/ # Editors, IDE & stuff inbetween .c9 diff --git a/lib/stream.js b/lib/stream.js index c227f79..820c19e 100644 --- a/lib/stream.js +++ b/lib/stream.js @@ -169,13 +169,14 @@ export class SevenZipStream extends Readable { onSubprocessError (chunk) { const stderr = chunk.toString() const inLineErrorRegExp = /ERROR: (?.*)\n/ - const offLineErrorRegExp = /ERROR:\n(?.*)\n/ + const offLineErrorRegExp = /(?WARNING|ERROR): (?.+)(\n(?.+)\n)?/ const inLineError = stderr.match(inLineErrorRegExp) const offLineError = stderr.match(offLineErrorRegExp) - let message = 'unknown error' - message = (inLineError) ? inLineError.groups.message : message - message = (offLineError) ? offLineError.groups.message : message - const err = new Error(message) + const err = new Error('unknown error') + let errProps = {} + errProps = (inLineError) ? inLineError.groups : errProps + errProps = (offLineError) ? offLineError.groups : errProps + Object.assign(err, errProps) err.stderr = stderr // @TODO doc: usage of raw stderr to get more info this.emit('error', err) diff --git a/test/func/add.spec.js b/test/func/add.spec.js index 1482a1c..1a029bf 100644 --- a/test/func/add.spec.js +++ b/test/func/add.spec.js @@ -31,15 +31,29 @@ describe('Functional: add()', function () { before(function (done) { rimraf('*/**/.DS_Store') - rimraf(`${tmpDir}/*`) + // rimraf(`${tmpDir}/*`) done() }) after(function (done) { - rimraf(`${tmpDir}/*`) + // rimraf(`${tmpDir}/*`) done() }) + it('should return an error on 7z error', function (done) { + const archive = `${tmpDir}/addnot.7z` + const source = `${mockDir}/dev/null` + const seven = add(archive, source) + seven.on('error', function (err) { + expect(err).to.be.an.instanceof(Error) + expect(err.level).to.equal('WARNING') + expect(err.message).to.equal('No such file or directory') + expect(err.path).to.equal(source) + done() + try { kill(seven._childProcess.pid) } catch (e) {} + }) + }) + it('should emit progress values', function (done) { const archive = `${tmpDir}/progress.7z` const source = `${mockDir}/DirImages/`