From cbc0f7a37a40dbc43cac3f14869a9b12d3296ea4 Mon Sep 17 00:00:00 2001 From: Jonatan Nilsson Date: Wed, 16 Feb 2022 11:49:48 +0000 Subject: [PATCH] Fix tests to use 7zdec correctly --- appveyor.yml | 1 + core/util.mjs | 33 ++++++++++++++++----------------- test/core.test.integration.mjs | 12 ++++++++---- test/util.test.mjs | 8 ++++---- 4 files changed, 29 insertions(+), 25 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index b2490d0..ab57213 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -23,6 +23,7 @@ environment: test_script: - sh: | + ln -s /lib/libc.musl-x86_64.so.1 /lib64/ld-linux-x86-64.so.2 chmod -R 777 /appveyor/projects npm install npm test diff --git a/core/util.mjs b/core/util.mjs index 4e92625..02b6f41 100644 --- a/core/util.mjs +++ b/core/util.mjs @@ -88,9 +88,9 @@ export default class Util { get7zipExecutable() { const util = new Util(import.meta.url) if (process.platform === 'win32') { - return util.getPathFromRoot('../bin/7za.exe') + return util.getPathFromRoot('../bin/7zdec.exe') } - return util.getPathFromRoot('../bin/7zas') + return util.getPathFromRoot('../bin/7zdec') } verifyConfig(config) { @@ -100,22 +100,19 @@ export default class Util { } extractFile(file, stream = function() {}) { - return this.runCommand(this.get7zipExecutable(), ['x', file], path.dirname(file), stream) - .then(() => { - if (!file.indexOf('.tar.')) return - - let tarFile = file.slice(0, file.lastIndexOf('.')) - return fs.stat(tarFile) - .catch(function() { return null }) - .then((stat) => { - if (!stat) return - return this.extractFile(tarFile) - .then(function() { return fs.rm(tarFile, { force: true }) }) - }) - }) + let program = this.get7zipExecutable() + let args = ['x', file] + if (file.indexOf('.tar.') > 0) { + program = 'tar' + args = ['xvf', file] + } + return this.runCommand(program, args, path.dirname(file), stream) } runCommand(command, options = [], folder = null, stream = function() {}) { + + let baseError = new Error('') + return new Promise(function(res, rej) { let fullcommand = path.join(folder ? folder : '', command) if (command.indexOf('/') >= 0 || command.indexOf('\\') >= 0) { @@ -142,12 +139,14 @@ export default class Util { }) processor.on('error', function(err) { clearInterval(timeOuter) - rej(err) + baseError.message = err.message + rej(baseError) }) processor.on('exit', function (code) { clearInterval(timeOuter) if (code !== 0) { - return rej(new Error('Program returned error code: ' + code)) + baseError.message = 'Program returned error code: ' + code + return rej(baseError) } res(code) }) diff --git a/test/core.test.integration.mjs b/test/core.test.integration.mjs index 8612960..45969ab 100644 --- a/test/core.test.integration.mjs +++ b/test/core.test.integration.mjs @@ -19,6 +19,10 @@ t.timeout(10000).describe('', function() { let versions = [] let processor let integrationLog = getLog('test.integration', []) + let compressorPath = util.getPathFromRoot('./7za.exe') + if (process.platform !== 'win32') { + compressorPath = util.getPathFromRoot('./7zas') + } t.before(function(cb) { server = http.createServer(function(req, res) { @@ -222,7 +226,7 @@ t.timeout(10000).describe('', function() { let index = file('./index.mjs') await fs.writeFile(index, version_1_stable) - await util.runCommand(util.get7zipExecutable(), ['a', file('./v1-sc.7z'), index], util.getPathFromRoot('./testapp')) + await util.runCommand(compressorPath, ['a', file('./v1-sc.7z'), index], util.getPathFromRoot('./testapp')) processor = startRunner() @@ -273,7 +277,7 @@ t.timeout(10000).describe('', function() { // Create our second version await fs.writeFile(index, version_2_nolisten) - await util.runCommand(util.get7zipExecutable(), ['a', file('./v2-sc.7z'), index], util.getPathFromRoot('./testapp')) + await util.runCommand(compressorPath, ['a', file('./v2-sc.7z'), index], util.getPathFromRoot('./testapp')) const assertNameVersion2 = 'v2_nolisten' file(`./testapp/${assertNameVersion2}`) @@ -366,7 +370,7 @@ t.timeout(10000).describe('', function() { // Create our third version await fs.writeFile(index, version_3_crashing) - await util.runCommand(util.get7zipExecutable(), ['a', file('./v3-sc.7z'), index], util.getPathFromRoot('./testapp')) + await util.runCommand(compressorPath, ['a', file('./v3-sc.7z'), index], util.getPathFromRoot('./testapp')) const assertNameVersion3 = 'v3_crash' file(`./testapp/${assertNameVersion3}`) @@ -412,7 +416,7 @@ t.timeout(10000).describe('', function() { // Create our fourth version await fs.writeFile(index, version_4_stable) - await util.runCommand(util.get7zipExecutable(), ['a', file('./v4-sc.7z'), index], util.getPathFromRoot('./testapp')) + await util.runCommand(compressorPath, ['a', file('./v4-sc.7z'), index], util.getPathFromRoot('./testapp')) const assertNameVersion4 = 'v4_stable' file(`./testapp/${assertNameVersion4}`) diff --git a/test/util.test.mjs b/test/util.test.mjs index ac0238d..09db98b 100644 --- a/test/util.test.mjs +++ b/test/util.test.mjs @@ -43,13 +43,13 @@ t.describe('#get7zipExecutable()', function() { console.log('Adding 7zip windows exe path test') t.test('should return windows executable path', function() { - assert.ok(util.get7zipExecutable().endsWith('\\service-core\\bin\\7za.exe'), `${util.get7zipExecutable()} should end with 7za.exe`) + assert.ok(util.get7zipExecutable().endsWith('\\service-core\\bin\\7zdec.exe'), `${util.get7zipExecutable()} should end with 7zdec.exe`) }) } else { console.log('Adding 7zip linux exe path test') t.test('should return linux executable path', function() { - assert.ok(util.get7zipExecutable().endsWith('/service-core/bin/7zas'), `${util.get7zipExecutable()} should end with 7zas`) + assert.ok(util.get7zipExecutable().endsWith('/service-core/bin/7zdec'), `${util.get7zipExecutable()} should end with 7zdec`) }) } }) @@ -426,8 +426,8 @@ t.describe('#extractFile()', function() { throw err } - assert.match(output, /Extracting archive\:.+example.tar.gz/) - assert.match(output, /1 file, 123 bytes/) + assert.match(output, /file1.txt/) + assert.match(output, /file2.txt/) assert.strictEqual(output.indexOf('\r\n'), -1) }) })