Permalink
Browse files

fixed all unit tests on windows, run using '> build.bat'

  • Loading branch information...
1 parent 8b8932f commit ed97c572a068c1fc561490f6c9027a92e9f92870 @schaermu schaermu committed Oct 30, 2012
Showing with 66 additions and 40 deletions.
  1. +9 −1 lib/extensions.js
  2. +15 −4 lib/metadata.js
  3. +8 −3 lib/processor.js
  4. +2 −2 test/args.test.js
  5. +2 −2 test/debug.test.js
  6. +30 −28 test/processor.test.js
View
@@ -57,7 +57,10 @@ exports = module.exports = function Extensions() {
};
this.parseVersionString = function(versionstr) {
- var x = versionstr.split('.');
+ if (typeof versionstr != 'string' || versionstr.indexOf('.') == -1) {
+ return false;
+ }
+ var x = versionstr.split('.');
// parse from string or default to 0 if can't parse
var maj = parseInt(x[0], 10) || 0;
var min = parseInt(x[1], 10) || 0;
@@ -73,6 +76,11 @@ exports = module.exports = function Extensions() {
var minimum = this.parseVersionString(minVersion);
var running = this.parseVersionString(actualVersion);
+ // if we can't even parse the version string (affects git builds for windows),
+ // we simply return true and assume a current build
+ if (!running)
+ return true;
+
if (running.major !== minimum.major) {
return (running.major > minimum.major);
} else {
View
@@ -1,12 +1,23 @@
-var exec = require('child_process').exec;
+var exec = require('child_process').exec
+ , os = require('os').platform();
exports = module.exports = function Metadata(inputfile) {
-
- this.escapedPath = function(path) {
+ this.escapedPath = function(path, enclose) {
if(/http/.exec(path)) {
path = path.replace(' ', '%20');
} else {
- path = '"' + path + '"';
+ if (os.match(/win(32|64)/)) {
+ // on windows, we have to fix up the filename
+ var parts = path.split(/\\/gi);
+ var fName = parts[parts.length - 1];
+ parts[parts.length - 1] = fName.replace(/[\s\\:"'*?<>|\/]+/mig, '-');
+ path = parts.join('\\');
+ if (enclose)
+ path = '"' + path + '"'
+ } else {
+ if (enclose)
+ path = '"' + path + '"';
+ }
}
return path;
};
View
@@ -281,8 +281,8 @@ exports = module.exports = function Processor(command) {
offset = secondOffset * j;
}
var fname = _renderOutputName(j, offset) + '.jpg';
- var target = self.escapedPath(folder + '/' + fname);
- var input = self.escapedPath(self.options.inputfile);
+ var target = self.escapedPath(path.join(folder, fname), true);
+ var input = self.escapedPath(self.options.inputfile, true);
// build screenshot command
var command = [
@@ -587,7 +587,12 @@ exports = module.exports = function Processor(command) {
}
if (this.options.outputfile) {
- args.push('-y', this.options.outputfile.replace(' ', '\\ '));
+ var target = this.escapedPath(this.options.outputfile, false);
+ if (!os.match(/win(32|64)/)) {
+ args.push('-y', target.replace(' ', '\\ '));
+ } else {
+ args.push('-y', target);
+ }
} else {
if (!overrideOutputCheck) {
this.options.logger.error('no outputfile specified');
View
@@ -6,8 +6,8 @@ var Ffmpeg = require('../index'),
describe('Command', function() {
before(function(done) {
// check for ffmpeg installation
- this.testfile = __dirname + '/assets/testvideo-43.avi';
- this.testfilewide = __dirname + '/assets/testvideo-169.avi';
+ this.testfile = path.join(__dirname, 'assets', 'testvideo-43.avi');
+ this.testfilewide = path.join(__dirname, 'assets', 'testvideo-169.avi');
var self = this;
exec(testhelper.getFfmpegCheck(), function(err, stdout, stderr) {
View
@@ -6,8 +6,8 @@ var Ffmpeg = require('../index'),
describe('Debug', function() {
before(function(done) {
// check for ffmpeg installation
- this.testfile = __dirname + '/assets/testvideo-43.avi';
- this.testfilewide = __dirname + '/assets/testvideo-169.avi';
+ this.testfile = path.join(__dirname, 'assets', 'testvideo-43.avi');
+ this.testfilewide = path.join(__dirname, 'assets', 'testvideo-169.avi');
var self = this;
exec(testhelper.getFfmpegCheck(), function(err, stdout, stderr) {
View
@@ -9,9 +9,8 @@ var Ffmpeg = require('../index'),
describe('Processor', function() {
before(function(done) {
// check for ffmpeg installation
- this.testfile = __dirname + '/assets/testvideo-43.avi';
- this.testfilewide = __dirname + '/assets/testvideo-169.avi';
- this.testfileEscaped = __dirname + '/assets/te[s]t audio \' " .ogg';
+ this.testfile = path.join(__dirname, 'assets', 'testvideo-43.avi');
+ this.testfilewide = path.join(__dirname, 'assets', 'testvideo-169.avi');
var self = this;
exec(testhelper.getFfmpegCheck(), function(err, stdout, stderr) {
@@ -37,44 +36,46 @@ describe('Processor', function() {
});
}
- describe('Proper path escaping', function() {
+ describe('\'s proper path escaping', function() {
it('should save the output file properly to disk using a stream', function(done) {
- var testFile = __dirname + '/assets/testConvertToStream.mp3';
- var outstream = fs.createWriteStream(testFile);
- new Ffmpeg({ source: this.testfileEscaped, nolog: true })
- .withAudioBitrate('128k')
- .withAudioCodec('libmp3lame')
- .withAudioChannels('2')
- .toFormat('mp3')
- .writeToStream(outstream, function(code, stderr) {
- code.should.equal(0);
- done();
+ var testFile = path.join(__dirname, 'assets', 'te[s]t video \' " .flv');
+
+ new Ffmpeg({ source: this.testfile, nolog: false })
+ .usingPreset('flashvideo')
+ .renice(19)
+ .saveToFile(testFile, function(code, stderr) {
path.exists(testFile, function(exist) {
- exist.should.true;
- fs.unlinkSync(testFile);
+ if (exist) {
+ fs.unlinkSync(testFile);
+ }
+ done();
});
});
});
});
it('should kill the process on timeout', function(done) {
- var testFile = __dirname + '/assets/testProcessKill.flv';
- new Ffmpeg({ source: this.testfile, nolog: true, timeout: 0.02 })
+ var testFile = path.join(__dirname, 'assets', 'testProcessKill.flv');
+
+ new Ffmpeg({ source: this.testfile, nolog: true, timeout: 0.01 })
.usingPreset('flashvideo')
.renice(19)
.saveToFile(testFile, function(code, err) {
code.should.equal(-99);
path.exists(testFile, function(exist) {
if (exist) {
- fs.unlinkSync(testFile);
+ setTimeout(function() {
+ fs.unlinkSync(testFile);
+ done();
+ }, 500);
}
- done();
});
});
});
it('should report codec data through event onCodecData', function(done) {
- var testFile = __dirname + '/assets/testOnCodecData.flv';
+ var testFile = path.join(__dirname, 'assets', 'testOnCodecData.flv');
+
new Ffmpeg({ source: this.testfile, nolog: true })
.onCodecData(function(data) {
data.should.have.property('audio');
@@ -93,7 +94,8 @@ describe('Processor', function() {
});
it('should report progress through event onProgress', function(done) {
- var testFile = __dirname + '/assets/testOnProgress.flv';
+ var testFile = path.join(__dirname, 'assets', 'testOnProgress.flv');
+
new Ffmpeg({ source: this.testfile, nolog: true })
.onProgress(function(data) {
// conversion is too fast to make any progress reporting on the test assets,
@@ -113,7 +115,7 @@ describe('Processor', function() {
});
it('should properly take a certain amount of screenshots at defined timemarks', function(done) {
- var testFolder = __dirname + '/assets/tntest_config';
+ var testFolder = path.join(__dirname, 'assets', 'tntest_config');
var args = new Ffmpeg({ source: this.testfile, nolog: true })
.withSize('150x?')
.renice(19)
@@ -139,7 +141,7 @@ describe('Processor', function() {
});
it('should report all generated filenames in the second callback argument', function(done) {
- var testFolder = __dirname + '/assets/tntest_config';
+ var testFolder = path.join(__dirname, 'assets', 'tntest_config');
var args = new Ffmpeg({ source: this.testfile, nolog: true })
.withSize('150x?')
.renice(19)
@@ -170,7 +172,7 @@ describe('Processor', function() {
describe('saveToFile', function() {
it('should save the output file properly to disk', function(done) {
- var testFile = __dirname + '/assets/testConvertToFile.flv';
+ var testFile = path.join(__dirname, 'assets', 'testConvertToFile.flv');
new Ffmpeg({ source: this.testfile, nolog: true })
.usingPreset('flashvideo')
.renice(19)
@@ -191,7 +193,7 @@ describe('Processor', function() {
});
});
it('should accept a stream as its source', function(done) {
- var testFile = __dirname + '/assets/testConvertFromStreamToFile.flv';
+ var testFile = path.join(__dirname, 'assets', 'testConvertFromStreamToFile.flv');
var instream = fs.createReadStream(this.testfile);
new Ffmpeg({ source: instream, nolog: true })
.usingPreset('flashvideo')
@@ -216,7 +218,7 @@ describe('Processor', function() {
describe('writeToStream', function() {
it('should save the output file properly to disk using a stream', function(done) {
- var testFile = __dirname + '/assets/testConvertToStream.flv';
+ var testFile = path.join(__dirname, 'assets', 'testConvertToStream.flv');
var outstream = fs.createWriteStream(testFile);
new Ffmpeg({ source: this.testfile, nolog: true })
.usingPreset('flashvideo')
@@ -237,7 +239,7 @@ describe('Processor', function() {
});
});
it('should accept a stream as its source', function(done) {
- var testFile = __dirname + '/assets/testConvertFromStreamToStream.flv';
+ var testFile = path.join(__dirname, 'assets', 'testConvertFromStreamToStream.flv');
var instream = fs.createReadStream(this.testfile);
var outstream = fs.createWriteStream(testFile);
new Ffmpeg({ source: instream, nolog: true })

0 comments on commit ed97c57

Please sign in to comment.