Skip to content

Commit

Permalink
chore: Cleanup testing fs
Browse files Browse the repository at this point in the history
  • Loading branch information
q2s2t committed Oct 15, 2018
1 parent 3491c8b commit 9ccf80d
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 18 deletions.
3 changes: 3 additions & 0 deletions TODO
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Features:
☐ Full-named switches for cleaner API
☐ Stream methods returns stream
☐ Esier to use progress
☐ Status (TU+R. and others?) as plain text
Documentation:
☐ Usage for wildcard/raw/bin input ($ instead of _ preffix)
☐ Usage for repeating switches
Expand All @@ -49,3 +50,5 @@ Documentation:
✔ -bb switch @done(18-09-11 22:54)
☐ $defer
☐ add(archive, [source1, source2]) usage
☐ No benchmark command: It will output based on the system that it is on, "system-static"
☐ Hack to use delete() command (delete is a JS reserved word)
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "A Node.js wrapper for 7-Zip with platform binaries",
"main": "lib/index.js",
"scripts": {
"test": "npx mocha -r esm --reporter=spec 'test/**/*.spec.js' --timeout=0 && rm -rf test/_tmp/*.*",
"test": "npx mocha -r esm --reporter=spec 'test/**/*.spec.js' --timeout=0 ; rm -rf test/_tmp/*.*",
"test-docker": "circleci local execute --job build",
"coverage": "npx nyc --reporter=lcov npm test",
"coveralls": "cat ./coverage/lcov.info | npx coveralls"
Expand Down Expand Up @@ -56,6 +56,7 @@
"chalk": "^2.4.1",
"coveralls": "^3.0.2",
"mocha": "^5.2.0",
"mock-fs": "^4.7.0",
"nyc": "^12.0.2",
"rimraf": "^2.6.2",
"standard": "^11.0.1",
Expand Down
36 changes: 19 additions & 17 deletions test/func/add.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* global describe, it */
import { expect } from 'chai'
import { existsSync, statSync } from 'fs'
import kill from 'tree-kill'
import { copyFileSync, existsSync, statSync } from 'fs'
import { add } from '../../lib/commands.js'

const mockDir = './test/_mock'
Expand All @@ -24,7 +23,7 @@ describe('Functional: add()', function () {
it('should return an error on spawn error', function (done) {
const archive = ``
const source = ``
const bin = '/i/hope/this/is/not/where/yout/7zip/bin/is'
const bin = '/i/hope/this/is/not/where/your/7zip/bin/is'
const seven = add(archive, source, {
$bin: bin
// or this test will fail
Expand Down Expand Up @@ -82,14 +81,18 @@ describe('Functional: add()', function () {
})

it('should emit files on progress', function (done) {
const archive = `${tmpDir}/files.7z`
const archive = `${tmpDir}/files-add.7z`
const source = `${mockDir}/DirHex/`
const seven = add(archive, source, { bs: ['p1'] })
let once = false
seven.on('data', function (data) {
once = true
expect(data.symbol).to.equal('+')
expect(data.file).to.be.a('string')
try { kill(seven._childProcess.pid) } catch (e) {}
}).on('end', () => done())
}).on('end', function () {
expect(once).to.be.equal(true)
done()
})
})

it('should accept multiple sources as a array', function (done) {
Expand All @@ -109,12 +112,13 @@ describe('Functional: add()', function () {
})

it('should add files to an exsiting archive', function (done) {
// This test relies on a predecessor test
const archive = `${tmpDir}/files.7z`
const archiveBase = `${mockDir}/DirNew/DirEmpty.7z`
const archive = `${tmpDir}/files-add-existing.7z`
const source = [
`${mockDir}/DirExt/*.txt`,
`${mockDir}/DirExt/*.md`
]
copyFileSync(archiveBase, archive)
const seven = add(archive, source, {
r: true
})
Expand All @@ -132,21 +136,19 @@ describe('Functional: add()', function () {
})

it('should update files of an exsiting archive', function (done) {
// This test relies on a predecessor test
const archive = `${tmpDir}/files.7z`
const source = [
`${mockDir}/DirExtUpdate/*.txt`,
`${mockDir}/DirExtUpdate/*.md`
]
const seven = add(archive, source)
const archiveBase = `${mockDir}/DirNew/BaseExt.7z`
const archive = `${tmpDir}/files-add-update-existing.7z`
const source = `./${mockDir}/DirExtUpdate/*`
const seven = add(archive, source, { bs: ['p1'] })
copyFileSync(archiveBase, archive)
seven.on('data', function (data) {
expect(data.symbol).to.equal('U')
expect(data.file).to.be.a('string')
}).on('end', function () {
expect(seven.info['Open archive']).to.equal(archive)
expect(seven.info['Updating archive']).to.equal(archive)
expect(seven.info['Items to compress']).to.equal('2')
expect(seven.info['Files read from disk']).to.equal('2')
expect(seven.info['Items to compress']).to.equal('3')
expect(seven.info['Files read from disk']).to.equal('3')
expect(seven.info['Archive size']).to.be.a('string')
done()
})
Expand Down

0 comments on commit 9ccf80d

Please sign in to comment.