-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
131 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
/* global describe, it */ | ||
import { expect } from 'chai' | ||
import { copyFileSync } from 'fs' | ||
import { update } from '../../lib/commands.js' | ||
|
||
const mockDir = './test/_mock' | ||
const tmpDir = './test/_tmp' | ||
|
||
describe('Functional: update()', function () { | ||
it('should return an error on 7z error', function (done) { | ||
const archive = `/file/not/here` | ||
const seven = update(archive) | ||
seven.on('error', function (err) { | ||
expect(err).to.be.an.instanceof(Error) | ||
done() | ||
}) | ||
}) | ||
|
||
it('should return an error on spawn error', function (done) { | ||
const archive = `` | ||
const source = `` | ||
const bin = '/i/hope/this/is/not/where/your/7zip/bin/is' | ||
const seven = update(archive, source, { | ||
$bin: bin | ||
// or this update will fail | ||
}) | ||
seven.on('error', function (err) { | ||
expect(err).to.be.an.instanceof(Error) | ||
expect(err.errno).to.equal('ENOENT') | ||
expect(err.code).to.equal('ENOENT') | ||
expect(err.syscall).to.equal(`spawn ${bin}`) | ||
expect(err.path).to.equal(bin) | ||
done() | ||
}) | ||
}) | ||
|
||
it('should emit progress values', function (done) { | ||
const archiveBase = `${mockDir}/DirNew/BaseExt.7z` | ||
const archive = `${tmpDir}/update-progress.7z` | ||
const source = `${mockDir}/DirExtUpdate/*` | ||
copyFileSync(archiveBase, archive) | ||
const seven = update(archive, source, { r: true, bs: ['p1'] }) | ||
let once = false | ||
seven.on('progress', function (progress) { | ||
once = true | ||
expect(progress.percent).to.be.an('number') | ||
expect(progress.fileCount).to.be.an('number') | ||
}).on('end', function () { | ||
expect(once).to.be.equal(true) | ||
done() | ||
}) | ||
}) | ||
|
||
it('should emit files on data', function (done) { | ||
const archiveBase = `${mockDir}/DirNew/BaseExt.7z` | ||
const archive = `${tmpDir}/update-data.7z` | ||
const source = `${mockDir}/DirExtUpdate/*` | ||
copyFileSync(archiveBase, archive) | ||
const seven = update(archive, source, { r: true }) | ||
let counter = 0 | ||
seven.on('data', function (data) { | ||
++counter | ||
expect(data.symbol).to.equal('U') | ||
expect(data.file).to.be.a('string') | ||
}).on('end', function () { | ||
expect(counter).to.be.equal(3) | ||
done() | ||
}) | ||
}) | ||
|
||
it('should get info from headers and footers', function (done) { | ||
const archiveBase = `${mockDir}/DirNew/BaseExt.7z` | ||
const archive = `${tmpDir}/update-headers-footers.7z` | ||
const source = `${mockDir}/DirExtUpdate/*` | ||
copyFileSync(archiveBase, archive) | ||
const seven = update(archive, source, { r: true }) | ||
seven.on('end', function () { | ||
// headers | ||
expect(seven.info.get('Open archive')).to.equal(archive) | ||
expect(seven.info.get('Method')).to.equal('LZMA2:12') | ||
// footers | ||
expect(seven.info.get('Files read from disk')).to.equal('3') | ||
expect(seven.info.get('Archive size')).to.equal('2334 bytes (3 KiB)') | ||
done() | ||
}) | ||
}) | ||
|
||
it('should accept multiple targets as a string', function (done) { | ||
const archiveBase = `${mockDir}/DirNew/BaseExt.7z` | ||
const archive = `${tmpDir}/update-one-source.7z` | ||
const source = `${mockDir}/DirExtUpdate/*.txt` | ||
copyFileSync(archiveBase, archive) | ||
const seven = update(archive, source, { r: true }) | ||
let dataAgg = [] | ||
seven.on('data', d => dataAgg.push(d)) | ||
seven.on('end', function () { | ||
expect(dataAgg).to.deep.include({ symbol: 'R', file: '#0' }) | ||
expect(dataAgg).to.deep.include({ symbol: 'R', file: 'root.md' }) | ||
expect(dataAgg).to.deep.include({ symbol: 'R', file: 'root.not' }) | ||
expect(dataAgg).to.deep.include({ symbol: '.', file: 'root.txt' }) | ||
expect(dataAgg).to.deep.include({ symbol: 'U', file: 'root.txt' }) | ||
done() | ||
}) | ||
}) | ||
|
||
it('should accept multiple targets as a array', function (done) { | ||
const archiveBase = `${mockDir}/DirNew/BaseExt.7z` | ||
const archive = `${tmpDir}/update-one-source.7z` | ||
const source = [ | ||
`${mockDir}/DirExtUpdate/*.txt`, | ||
`${mockDir}/DirExtUpdate/*.md` | ||
] | ||
copyFileSync(archiveBase, archive) | ||
const seven = update(archive, source, { r: true }) | ||
let dataAgg = [] | ||
seven.on('data', d => dataAgg.push(d)) | ||
seven.on('end', function () { | ||
expect(dataAgg).to.deep.include({ symbol: 'R', file: '#0' }) | ||
expect(dataAgg).to.deep.include({ symbol: 'R', file: 'root.not' }) | ||
expect(dataAgg).to.deep.include({ symbol: '.', file: 'root.md' }) | ||
expect(dataAgg).to.deep.include({ symbol: 'U', file: 'root.md' }) | ||
expect(dataAgg).to.deep.include({ symbol: '.', file: 'root.txt' }) | ||
expect(dataAgg).to.deep.include({ symbol: 'U', file: 'root.txt' }) | ||
done() | ||
}) | ||
}) | ||
}) |