From 43220bd91c6470cb5c0280eef9c701ebe5160b02 Mon Sep 17 00:00:00 2001 From: Tom Yam Date: Tue, 10 Jan 2017 12:17:09 +0200 Subject: [PATCH] new option - singleVideoPath for customizing the path of single videos --- lib/VideoReporter.js | 28 ++++++++++++++++++++++------ package.json | 3 ++- readme.md | 21 +++++++++++++++++++-- 3 files changed, 43 insertions(+), 9 deletions(-) diff --git a/lib/VideoReporter.js b/lib/VideoReporter.js index 8542c90..b68e9a3 100644 --- a/lib/VideoReporter.js +++ b/lib/VideoReporter.js @@ -8,14 +8,15 @@ var Joi = require('joi'), Uuid = require('node-uuid'), Debug = require('debug'), SubtitlesParser = require('subtitles-parser'), - _ = require('lodash'); + _ = require('lodash'), + SanitizeFilename = require('sanitize-filename'); var debug = Debug('protractor-video-reporter'); function randomVideoName() { - return Uuid.v4() + '.mov'; -} + + } function VideoReporter(options) { @@ -24,6 +25,7 @@ function VideoReporter(options) { options = _.defaults({}, options, { saveSuccessVideos: false, singleVideo: true, + singleVideoPath: 'uuid', createSubtitles: true, ffmpegCmd: 'ffmpeg', ffmpegArgs: [ @@ -43,9 +45,12 @@ function VideoReporter(options) { .description('The path to the directory where videos are stored. If not existing, it gets created.'), saveSuccessVideos: Joi.boolean() .description('If true, will save the videos of the succussfull specs, as well as the failed specs.'), - singleVideo: Joi.boolean() .description('If true, will create a single video file for all the specs.'), + singleVideoPath: Joi.alternatives().try( + Joi.valid('uuid', 'fullName'), + Joi.func() + ), createSubtitles: Joi.boolean() .description('If true and singleVideo is also true, will create a SRT subtitles file with the name details of the currently running spec.'), @@ -123,11 +128,22 @@ VideoReporter.prototype._stopScreencast = function(removeVideo) { self._ffmpeg = null; }; +VideoReporter.prototype._singleVideoPath = function(result) { + var self = this; + if (self.options.singleVideoPath === 'uuid') { + return Uuid.v4() + '.mov'; + } else if (self.options.singleVideoPath === 'fullName') { + return SanitizeFilename(result.fullName + '.mov'); + } else { + return self.options.singleVideoPath(result); + } +} + -VideoReporter.prototype.specStarted = function() { +VideoReporter.prototype.specStarted = function(result) { var self = this; if (!self.options.singleVideo) { - var videoPath = Path.join(self.options.baseDirectory, randomVideoName()); + var videoPath = Path.join(self.options.baseDirectory, self._singleVideoPath(result)); self._startScreencast(videoPath); } else if (self.options.createSubtitles) { diff --git a/package.json b/package.json index 42fdfc8..d8621cc 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ "lodash": "^4.6.0", "mkdirp": "^0.5.1", "node-uuid": "^1.4.3", - "subtitles-parser": "0.0.2" + "subtitles-parser": "0.0.2", + "sanitize-filename": "^1.6.1" } } diff --git a/readme.md b/readme.md index ed9d2d9..88809fb 100644 --- a/readme.md +++ b/readme.md @@ -36,9 +36,26 @@ In the protractor configuration file: * `singleVideo` (bool): If `true`, will create a single video file for all the specs. Defaults to `true`. The file will be saved to `baseDirectory/protractor-specs.mov`. -If `singleVideo` is false, the reporter will create a separate video file for every spec and place it at `baseDirectory/{some random UUID}.mov`. +If `singleVideo` is false, the reporter will create a separate video file for every spec and place it under the `baseDirectory`. +The exact location is determined by `singleVideoPath`. + +* `singleVideoPath`: (string, function): + +When `uuid` (default): Each spec video file will be placed at `baseDirectory/{some random UUID}.mov`. If you prefer this option, you would have to look at the "Spec video is in: ..." messages that are printed to the console. +When `fullName`: Each spec video will be placed at `baseDirectory/{spec full name} - {spec status}.mov`. +The full name of the spec will be sanitized to be a valid file name + +If you want to determine the full name yourself you can pass a function. +The function recieves a single argument, the result object passed to `specStarted`. +For example, you can do: + + singleVideoPath: function (result) { + // don't actually do this, you need to make sure fullName is a valid file name + result.fullName + '.mov'; + } + * `createSubtitles` (bool): If `true` and singleVideo is also true, will create a SRT subtitles file with the name details of the currently running spec. Defaults to `true`. The file will be saves to `baseDirectory/protractor-specs.srt`. @@ -63,4 +80,4 @@ The file will be saves to `baseDirectory/protractor-specs.srt`. # Debugging If you encouter any issues with the reporter, e.g. video files are not created, -turn on debugging by settings the `DEBUG` environment to `protractor-video-reporter`. \ No newline at end of file +turn on debugging by settings the `DEBUG` environment to `protractor-video-reporter`.