Skip to content

Commit

Permalink
try to fix tests2
Browse files Browse the repository at this point in the history
  • Loading branch information
[email protected] authored and [email protected] committed Jul 3, 2018
1 parent abd2386 commit 5f761de
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/screenshots/capturer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
};
Expand Down
8 changes: 2 additions & 6 deletions src/screenshots/path-pattern.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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;

Expand All @@ -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];
Expand Down
5 changes: 5 additions & 0 deletions src/utils/escape-user-agent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import sanitizeFilename from 'sanitize-filename';

export default function escapeUserAgent (userAgent) {
return sanitizeFilename(userAgent.toString()).replace(/\s+/g, '_');
}
5 changes: 5 additions & 0 deletions test/server/util-test.js
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand All @@ -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');
});
});

0 comments on commit 5f761de

Please sign in to comment.