8000 Fix html report working with non-urlsafe chars by SevInf · Pull Request #565 · gemini-testing/gemini · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Sep 21, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions lib/reporters/html/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @ 8000 @ var _ = require('lodash'),

absolutePath = _.partial(path.resolve, REPORT_OUT_DIR);

const escapeSpecialChars = (path) => path.split('/').map((item) => encodeURIComponent(item)).join('/');

/**
* @param {String} kind - одно из значение 'ref', 'current', 'diff'
Expand All @@ -24,7 +23,7 @@ function createPath(kind, result) {
var components = [].concat('images', result.suite.path, result.state.name, result.browserId + '~' + kind + retrySuffix + '.png');
const pathToImage = path.join.apply(null, components);

return escapeSpecialChars(pathToImage);
return pathToImage;
}

module.exports = {
Expand Down
5 changes: 4 additions & 1 deletion lib/reporters/html/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ var _ = require('lodash'),

makeOutFilePath = _.partial(path.join, REPORT_DIR);

const pathToUrl = (filePath) => filePath.split(path.sep).map((item) => encodeURIComponent(item)).join('/');

Handlebars.registerHelper('section-status', function() {
if (this.result && this.result.skipped) {
return 'section_status_skip';
Expand Down Expand Up @@ -50,7 +52,8 @@ Handlebars.registerHelper('has-fails', function() {
});

Handlebars.registerHelper('image', function(kind) {
return new Handlebars.SafeString('<img data-src="' + this[kind + 'Path'] + '">');
const url = pathToUrl(this[kind + 'Path']);
return new Handlebars.SafeString('<img data-src="' + url + '">');
});

Handlebars.registerHelper('inc', function(value) {
Expand Down
16 changes: 6 additions & 10 deletions test/unit/reporters/html/html.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
const EventEmitter = require('events').EventEmitter;
const HtmlReporter = require('lib/reporters/html/index.js');
const RunnerEvents = require('lib/constants/runner-events');
const Handlebars = require('handlebars');
const logger = require('lib/utils').logger;
const chalk = require('chalk');
const path = require('path');
const view = require('lib/reporters/html/view');
const lib = require('lib/reporters/html/lib');

describe('HTML Reporter', () => {
const sandbox = sinon.sandbox.create();
Expand All @@ -33,17 +33,13 @@ describe('HTML Reporter', () => {
assert.calledWith(logger.log, `Your HTML report is here: ${chalk.yellow(reportPath)}`);
});

it('should escape special chars in paths', () => {
it('should escape special chars in urls', () => {
const data = {
suite: {
path: 'fake/long+path'
},
state: {
name: 'fakeName'
},
browserId: 'fakeId'
actualPath: 'images/fake/long+path/fakeName/fakeId~current.png'
};

assert.equal(lib.currentPath(data), 'images/fake/long%2Bpath/fakeName/fakeId~current.png');
const render = Handlebars.compile('{{image "actual"}}');

assert.equal(render(data), '<img data-src="images/fake/long%2Bpath/fakeName/fakeId~current.png">');
});
});
0