Skip to content

Commit

Permalink
feat: extract()#data fires
Browse files Browse the repository at this point in the history
  • Loading branch information
Quentin Rossetti committed Oct 17, 2018
1 parent 6888108 commit 1cba732
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 63 deletions.
2 changes: 1 addition & 1 deletion lib/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export function matchProgress (line) {
if (isLineEmpty) {
return
}
const regexp = /^ *((?<percent>\d+)%( (?<fileCount>\d+))?\x08* *\x08* *)*((?<symbol>[TU+R.]) (?<file>.*))?$/
const regexp = /^ *((?<percent>\d+)%( (?<fileCount>\d+))?\x08* *\x08* *)*((?<symbol>[TU+R.-]) (?<file>.*))?$/
const match = line.match(regexp)
if (match) {
const parsed = {
Expand Down
94 changes: 32 additions & 62 deletions test/func/extract.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,67 +102,37 @@ describe('Functional: extract()', function () {
})
})

// it('should reduce archive size by deleting content') function (done) {
// const archiveBase = `${mockDir}/DirNew/ExtArchive.7z`
// const archive = `${tmpDir}/del-md.7z`
// const target = `DirExt/*.md`
// copyFileSync(archiveBase, archive)
// const sizeBase = statSync(archiveBase).size
// const seven = del(archive, target, { r: true })
// seven.on('end', function () {
// const size = statSync(archive).size
// expect(size).to.lessThan(sizeBase)
// expect(seven.info['Updating archive']).to.equal(archive)
// done()
// })
// })

// it('should accept multiple sources as a array', function (done) {
// const archiveBase = `${mockDir}/DirNew/ExtArchive.7z`
// const archive = `${tmpDir}/del-multiple.7z`
// const target = [`DirExt/*.md`, `DirExt/*.txt`]
// copyFileSync(archiveBase, archive)
// const sizeBase = statSync(archiveBase).size
// const seven = del(archive, target, { r: true })
// seven.on('end', function () {
// const size = statSync(archive).size
// expect(size).to.lessThan(sizeBase)
// expect(seven.info['Updating archive']).to.equal(archive)
// done()
// })
// })

// it('should emit progress values', function (done) {
// const archiveBase = `${mockDir}/DirNew/ExtArchive.7z`
// const archive = `${tmpDir}/progress-del.7z`
// const target = `DirExt/*.md`
// copyFileSync(archiveBase, archive)
// const seven = del(archive, target, { 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 progress values', function (done) {
const archiveBase = `${mockDir}/DirNew/ExtArchive.7z`
const archive = `${tmpDir}/extract-flat-progress.7z`
const output = `${tmpDir}/extract-flat-progress`
copyFileSync(archiveBase, archive)
let once = false
const seven = extract(archive, output, false, { r: true, bs: ['p1'] })
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 progress', function (done) {
// const archiveBase = `${mockDir}/DirNew/ExtArchive.7z`
// const archive = `${tmpDir}/progress-file-del.7z`
// const target = `DirExt/*.md`
// copyFileSync(archiveBase, archive)
// const seven = del(archive, target, { bs: ['p1'], r: true })
// let once = false
// seven.on('data', function (progress) {
// once = true
// expect(progress.symbol).to.be.an('string')
// expect(progress.file).to.be.an('string')
// }).on('end', function () {
// expect(once).to.be.equal(true)
// done()
// })
// })
it('should emit files on progress', function (done) {
const archiveBase = `${mockDir}/DirNew/ExtArchive.7z`
const archive = `${tmpDir}/extract-flat-data.7z`
const output = `${tmpDir}/extract-flat-data`
copyFileSync(archiveBase, archive)
let once = false
const seven = extract(archive, output, false, { r: true })
seven.on('data', function (data) {
once = true
expect(data.symbol).to.be.equal('-')
expect(data.file).to.be.an('string')
}).on('end', function () {
expect(once).to.be.equal(true)
done()
})
})
})
7 changes: 7 additions & 0 deletions test/unit/parser.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ describe('Specification: parser.js', function () {
expect(r['file']).to.equal('test/file')
})

it('matchProgress() should return file on extracted', function () {
const r = matchProgress('- test/file')
expect(r).to.be.an('object')
expect(r['symbol']).to.equal('-')
expect(r['file']).to.equal('test/file')
})

it('matchProgress() should return file on Windows drive', function () {
const r = matchProgress('+ C:\\test\\file')
expect(r).to.be.an('object')
Expand Down

0 comments on commit 1cba732

Please sign in to comment.