From 5f761de85156cc4864f8cbd99818bbf68b55fa32 Mon Sep 17 00:00:00 2001 From: "miherlosev@mail.ru" Date: Tue, 3 Jul 2018 13:09:16 +0300 Subject: [PATCH] try to fix tests2 --- src/screenshots/capturer.js | 4 ++-- src/screenshots/path-pattern.js | 8 ++------ src/utils/escape-user-agent.js | 5 +++++ test/server/util-test.js | 5 +++++ 4 files changed, 14 insertions(+), 8 deletions(-) create mode 100644 src/utils/escape-user-agent.js diff --git a/src/screenshots/capturer.js b/src/screenshots/capturer.js index 4f5562a09ab..777c5513486 100644 --- a/src/screenshots/capturer.js +++ b/src/screenshots/capturer.js @@ -4,7 +4,7 @@ import cropScreenshot from './crop'; import { ensureDir } from '../utils/promisified-functions'; import { isInQueue, addToQueue } from '../utils/async-queue'; import WARNING_MESSAGE from '../notifications/warning-message'; -import correctFilePath from '../utils/correct-file-path'; +import escapeUserAgent from '../utils/escape-user-agent'; export default class Capturer { constructor (baseScreenshotsPath, testEntry, connection, pathPattern, warningLog) { @@ -128,7 +128,7 @@ export default class Capturer { const screenshot = { screenshotPath, thumbnailPath, - userAgent: this.pathPattern.data.parsedUserAgent.toString(), + userAgent: escapeUserAgent(this.pathPattern.data.parsedUserAgent), quarantineAttemptID: this.pathPattern.data.quarantineAttempt, takenOnFail: forError, }; diff --git a/src/screenshots/path-pattern.js b/src/screenshots/path-pattern.js index 15c95ccf106..fd241d3296f 100644 --- a/src/screenshots/path-pattern.js +++ b/src/screenshots/path-pattern.js @@ -1,6 +1,6 @@ import { escapeRegExp as escapeRe } from 'lodash'; -import sanitizeFilename from 'sanitize-filename'; import correctFilePath from '../utils/correct-file-path'; +import escapeUserAgent from '../utils/escape-user-agent'; const DATE_FORMAT = 'YYYY-MM-DD'; const TIME_FORMAT = 'HH-mm-ss'; @@ -70,10 +70,6 @@ export default class PathPattern { }; } - static _escapeUserAgent (userAgent) { - return sanitizeFilename(userAgent.toString()).replace(/\s+/g, '_'); - } - static _buildPath (pattern, placeholderToDataMap, forError) { let resultFilePath = pattern; @@ -94,7 +90,7 @@ export default class PathPattern { else if (placeholder === PLACEHOLDERS.USERAGENT) { const userAgent = placeholderToDataMap[placeholder]; - return PathPattern._escapeUserAgent(userAgent); + return escapeUserAgent(userAgent); } return placeholderToDataMap[placeholder]; diff --git a/src/utils/escape-user-agent.js b/src/utils/escape-user-agent.js new file mode 100644 index 00000000000..6c9a7a05cc8 --- /dev/null +++ b/src/utils/escape-user-agent.js @@ -0,0 +1,5 @@ +import sanitizeFilename from 'sanitize-filename'; + +export default function escapeUserAgent (userAgent) { + return sanitizeFilename(userAgent.toString()).replace(/\s+/g, '_'); +} diff --git a/test/server/util-test.js b/test/server/util-test.js index d92bba6b574..a27d888643c 100644 --- a/test/server/util-test.js +++ b/test/server/util-test.js @@ -1,5 +1,6 @@ const expect = require('chai').expect; const correctFilePath = require('../../lib/utils/correct-file-path'); +const escapeUserAgent = require('../../lib/utils/escape-user-agent'); describe('Utils', () => { it('Correct File Path', () => { @@ -8,4 +9,8 @@ describe('Utils', () => { expect(correctFilePath('test.png', 'test.png')); expect(correctFilePath('test', 'png')).eql('test.png'); }); + + it('Escape user agent', () => { + expect(escapeUserAgent('Chrome 67.0.3396 / Windows 8.1.0.0')).eql('Chrome_67.0.3396_Windows_8.1.0.0'); + }); });