Skip to content

Commit

Permalink
Enable non-inlined screenshots (#166)
Browse files Browse the repository at this point in the history
Apologies for the delay! It looks good
  • Loading branch information
tiborv authored and gkushang committed Feb 21, 2019
1 parent 389e7ff commit 0d29c4a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
8 changes: 8 additions & 0 deletions README.md
Expand Up @@ -201,6 +201,14 @@ Applicable if `storeScreenshots=true`. Relative path for directory where screens
} }
``` ```


#### `noInlineScreenshots`
Type: `Boolean`
Default: `undefined`

`true`: Applicable if `storeScreenshots=true`. Avoids inlining screenshots, uses relative path to screenshots instead (i.e. enables lazy loading of images).

`false` or `undefined`: Keeps screenshots inlined.

#### `metadata` #### `metadata`
Type: `JSON` (optional) Type: `JSON` (optional)
Default: `undefined` Default: `undefined`
Expand Down
3 changes: 2 additions & 1 deletion lib/reporter.js
Expand Up @@ -269,13 +269,14 @@ var generateReport = function (options) {
if ((options.storeScreenshots && options.storeScreenshots === true) || if ((options.storeScreenshots && options.storeScreenshots === true) ||
(options.storeScreenShots && options.storeScreenShots === true)) { (options.storeScreenShots && options.storeScreenShots === true)) {


var name = sanitize(step.name || step.keyword); var name = sanitize(step.name || step.keyword, /[^a-zA-Z0-9/-]+/g); // Only allow URL-friendly file names
if (!fs.existsSync(screenshotsDirectory)) { if (!fs.existsSync(screenshotsDirectory)) {
fs.mkdirSync(screenshotsDirectory); fs.mkdirSync(screenshotsDirectory);
} }
name = name + '_' + Math.round(Math.random() * 10000) + '.png'; //randomize the file name name = name + '_' + Math.round(Math.random() * 10000) + '.png'; //randomize the file name
var filename = path.join(screenshotsDirectory, name); var filename = path.join(screenshotsDirectory, name);
fs.writeFileSync(filename, embedding.data, 'base64'); fs.writeFileSync(filename, embedding.data, 'base64');
if (options.noInlineScreenshots) step.image = path.relative(path.join(options.output, '..'), filename);
} }
} else { } else {
var file = 'data:application/octet-stream;base64,' + embedding.data; var file = 'data:application/octet-stream;base64,' + embedding.data;
Expand Down

0 comments on commit 0d29c4a

Please sign in to comment.