-
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.
Test command implemented with Promises
- Loading branch information
Showing
2 changed files
with
49 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
'use strict'; | ||
|
||
var Promise = require('promise'); | ||
var process = require('child_process'); | ||
var os = require('os'); | ||
var path = require('path'); | ||
|
||
module.exports.test = function test(archivePath) { | ||
|
||
return new Promise(function (fulfill, reject){ | ||
var command = '7z t ' + archivePath; | ||
process.exec(command, function (err, stdout, stderr) { | ||
//TODO: Custom error | ||
if (err) return reject(err); | ||
if (stderr) return reject(stderr); | ||
var r = []; | ||
stdout.split(os.EOL).forEach(function (_line) { | ||
if (_line.substr(0, 12) === 'Testing ') { | ||
return r.push(_line.substr(12, _line.length).replace(path.sep, '/')); | ||
} | ||
}); | ||
return fulfill(r); | ||
}); | ||
}); | ||
|
||
}; |
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,23 @@ | ||
'use strict'; | ||
var sevenzip = require('../index'); | ||
var expect = require('chai').expect; | ||
|
||
describe('Specifications for the `test` function', function(){ | ||
|
||
it('should get an error when 7z gets an error', function (done) { | ||
sevenzip.test('test/resource/nothere.7z') | ||
.then(null, function (err) { | ||
expect(err.message.substr(0, 14)).to.eql('Command failed'); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should get a list of files and directories', function (done) { | ||
sevenzip.test('test/resource/resource.7z') | ||
.then(function (files) { | ||
expect(files.length).to.be.at.least(6); | ||
done(); | ||
}); | ||
}); | ||
|
||
}); |