Fix tests to use 7zdec correctly
Some checks failed
continuous-integration/appveyor/branch AppVeyor build failed
Some checks failed
continuous-integration/appveyor/branch AppVeyor build failed
This commit is contained in:
parent
dbcc431e70
commit
cbc0f7a37a
4 changed files with 29 additions and 25 deletions
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
})
|
||||
|
|
|
@ -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}`)
|
||||
|
|
|
@ -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)
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue