Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix '${BROWSER} resolves to undefined in screenshot pattern' (close #2742) #2794

Merged
merged 2 commits into from
Aug 31, 2018
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
2 changes: 1 addition & 1 deletion src/api/structure/testing-unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default class TestingUnit {

this.disablePageReloads = void 0;

var unit = this;
const unit = this;

this.apiOrigin = function apiOrigin (...args) {
return unit._add(...args);
Expand Down
4 changes: 2 additions & 2 deletions src/api/test-controller/assertion.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ export default class Assertion {
}

_enqueueAssertion (apiMethodName, assertionArgs) {
var options = assertionArgs.opts || {};
var message = assertionArgs.message;
let options = assertionArgs.opts || {};
let message = assertionArgs.message;

if (typeof message === 'object') {
options = assertionArgs.message;
Expand Down
22 changes: 11 additions & 11 deletions src/api/test-controller/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ export default class TestController {
// t.click('#btn2'); // <-- stores new callsiteWithoutAwait
// await t2.click('#btn3'); // <-- without check it will set callsiteWithoutAwait = null, so we will lost tracking
_createExtendedPromise (promise, callsite) {
var extendedPromise = promise.then(identity);
var originalThen = extendedPromise.then;
var markCallsiteAwaited = () => this.callsitesWithoutAwait.delete(callsite);
const extendedPromise = promise.then(identity);
const originalThen = extendedPromise.then;
const markCallsiteAwaited = () => this.callsitesWithoutAwait.delete(callsite);


extendedPromise.then = function () {
Expand All @@ -80,8 +80,8 @@ export default class TestController {
}

_enqueueTask (apiMethodName, createTaskExecutor) {
var callsite = getCallsiteForMethod(apiMethodName);
var executor = createTaskExecutor(callsite);
const callsite = getCallsiteForMethod(apiMethodName);
const executor = createTaskExecutor(callsite);

this.executionChain = this.executionChain.then(executor);

Expand All @@ -92,7 +92,7 @@ export default class TestController {

_enqueueCommand (apiMethodName, CmdCtor, cmdArgs) {
return this._enqueueTask(apiMethodName, callsite => {
var command = null;
let command = null;

try {
command = new CmdCtor(cmdArgs, this.testRun);
Expand Down Expand Up @@ -200,7 +200,7 @@ export default class TestController {
}

_takeElementScreenshot$ (selector, ...args) {
var commandArgs = { selector };
const commandArgs = { selector };

if (args[1]) {
commandArgs.path = args[0];
Expand Down Expand Up @@ -238,8 +238,8 @@ export default class TestController {
if (!isNullOrUndefined(options))
options = assign({}, options, { boundTestRun: this });

var builder = new ClientFunctionBuilder(fn, options, { instantiation: 'eval', execution: 'eval' });
var clientFn = builder.getFunction();
const builder = new ClientFunctionBuilder(fn, options, { instantiation: 'eval', execution: 'eval' });
const clientFn = builder.getFunction();

return clientFn();
}
Expand All @@ -251,13 +251,13 @@ export default class TestController {
}

_getNativeDialogHistory$ () {
var callsite = getCallsiteForMethod('getNativeDialogHistory');
const callsite = getCallsiteForMethod('getNativeDialogHistory');

return this.testRun.executeCommand(new GetNativeDialogHistoryCommand(), callsite);
}

_getBrowserConsoleMessages$ () {
var callsite = getCallsiteForMethod('getBrowserConsoleMessages');
const callsite = getCallsiteForMethod('getBrowserConsoleMessages');

return this.testRun.executeCommand(new GetBrowserConsoleMessagesCommand(), callsite);
}
Expand Down
6 changes: 3 additions & 3 deletions src/api/test-controller/proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import testRunTracker from '../test-run-tracker';
import { APIError } from '../../errors/runtime';
import MESSAGE from '../../errors/runtime/message';

var testControllerProxy = Object.create(null);
const testControllerProxy = Object.create(null);

delegateAPI(testControllerProxy, TestController.API_LIST, {
getHandler (propName, accessor) {
var testRun = testRunTracker.resolveContextTestRun();
const testRun = testRunTracker.resolveContextTestRun();

if (!testRun) {
var callsiteName = null;
let callsiteName = null;

if (accessor === 'getter')
callsiteName = 'get';
Expand Down
10 changes: 5 additions & 5 deletions src/api/test-page-url.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function isAbsolutePath (url) {
}

function resolveFileUrl (url, testFileName) {
var testFileDir = path.dirname(testFileName);
const testFileDir = path.dirname(testFileName);

if (RELATIVE_PATH_RE.test(url))
url = path.join(testFileDir, url);
Expand All @@ -25,9 +25,9 @@ function resolveFileUrl (url, testFileName) {
}

export function assertUrl (url, callsiteName) {
var protocol = url.match(PROTOCOL_RE);
var hasUnsupportedProtocol = protocol && !SUPPORTED_PROTOCOL_RE.test(url);
var isWinAbsolutePath = OS.win && WIN_ABSOLUTE_PATH_RE.test(url);
const protocol = url.match(PROTOCOL_RE);
const hasUnsupportedProtocol = protocol && !SUPPORTED_PROTOCOL_RE.test(url);
const isWinAbsolutePath = OS.win && WIN_ABSOLUTE_PATH_RE.test(url);

if (hasUnsupportedProtocol && !isWinAbsolutePath && url !== 'about:blank')
throw new APIError(callsiteName, MESSAGE.unsupportedUrlProtocol, url, protocol[0]);
Expand All @@ -40,7 +40,7 @@ export function resolvePageUrl (url, testFileName) {
if (isAbsolutePath(url) || RELATIVE_PATH_RE.test(url))
return resolveFileUrl(url, testFileName);

var protocol = IMPLICIT_PROTOCOL_RE.test(url) ? 'http:' : 'http://';
const protocol = IMPLICIT_PROTOCOL_RE.test(url) ? 'http:' : 'http://';

return protocol + url;
}
22 changes: 11 additions & 11 deletions src/api/test-run-tracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ export default {
activeTestRuns: {},

_createContextSwitchingFunctionHook (ctxSwitchingFn, patchedArgsCount) {
var tracker = this;
const tracker = this;

return function () {
var testRunId = tracker.getContextTestRunId();
const testRunId = tracker.getContextTestRunId();

if (testRunId) {
for (var i = 0; i < patchedArgsCount; i++) {
for (let i = 0; i < patchedArgsCount; i++) {
if (typeof arguments[i] === 'function')
arguments[i] = tracker.addTrackingMarkerToFunction(testRunId, arguments[i]);
}
Expand All @@ -29,11 +29,11 @@ export default {

_getStackFrames () {
// NOTE: increase stack capacity to seek deep stack entries
var savedLimit = Error.stackTraceLimit;
const savedLimit = Error.stackTraceLimit;

Error.stackTraceLimit = STACK_CAPACITY;

var frames = getStackFrames();
const frames = getStackFrames();

Error.stackTraceLimit = savedLimit;

Expand All @@ -60,7 +60,7 @@ export default {
},

addTrackingMarkerToFunction (testRunId, fn) {
var markerFactoryBody = `
const markerFactoryBody = `
return function $$testcafe_test_run$$${testRunId}$$ () {
switch (arguments.length) {
case 0: return fn.call(this);
Expand All @@ -77,16 +77,16 @@ export default {
},

getContextTestRunId () {
var frames = this._getStackFrames();
const frames = this._getStackFrames();

// OPTIMIZATION: we start traversing from the bottom of the stack,
// because we'll more likely encounter a marker there.
// Async/await and Promise machinery executes lots of intrinsics
// on timers (where we have a marker). And, since a timer initiates a new
// stack, the marker will be at the very bottom of it.
for (var i = frames.length - 1; i >= 0; i--) {
var fnName = frames[i].getFunctionName();
var match = fnName && fnName.match(TRACKING_MARK_RE);
for (let i = frames.length - 1; i >= 0; i--) {
const fnName = frames[i].getFunctionName();
const match = fnName && fnName.match(TRACKING_MARK_RE);

if (match)
return match[1];
Expand All @@ -96,7 +96,7 @@ export default {
},

resolveContextTestRun () {
var testRunId = this.getContextTestRunId();
const testRunId = this.getContextTestRunId();

return this.activeTestRuns[testRunId];
}
Expand Down
6 changes: 3 additions & 3 deletions src/api/wrap-test-function.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import { MissingAwaitError } from '../errors/test-run';

export default function wrapTestFunction (fn) {
return async testRun => {
var result = null;
var errList = new TestCafeErrorList();
var markeredfn = testRunTracker.addTrackingMarkerToFunction(testRun.id, fn);
let result = null;
const errList = new TestCafeErrorList();
const markeredfn = testRunTracker.addTrackingMarkerToFunction(testRun.id, fn);

testRun.controller = new TestController(testRun);

Expand Down
6 changes: 3 additions & 3 deletions src/assertions/executor.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ export default class AssertionExecutor extends EventEmitter {
this.passed = false;
this.inRetry = false;

var fn = getFn(this.command);
var actualCommand = this.command.actual;
const fn = getFn(this.command);
const actualCommand = this.command.actual;

if (actualCommand instanceof ReExecutablePromise)
this.fn = this._wrapFunction(fn);
Expand All @@ -41,7 +41,7 @@ export default class AssertionExecutor extends EventEmitter {

_wrapFunction (fn) {
return async () => {
var resultPromise = this.command.actual;
const resultPromise = this.command.actual;

while (!this.passed) {
this.command.actual = await resultPromise._reExecute();
Expand Down
22 changes: 11 additions & 11 deletions src/screenshots/crop.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import WARNING_MESSAGES from '../notifications/warning-message';


function readPng (filePath) {
var png = new PNG();
var parsedPromise = Promise.race([
const png = new PNG();
const parsedPromise = Promise.race([
promisifyEvent(png, 'parsed'),
promisifyEvent(png, 'error')
]);
Expand All @@ -24,8 +24,8 @@ function readPng (filePath) {
}

function writePng (filePath, png) {
var outStream = fs.createWriteStream(filePath);
var finishPromise = Promise.race([
const outStream = fs.createWriteStream(filePath);
const finishPromise = Promise.race([
promisifyEvent(outStream, 'finish'),
promisifyEvent(outStream, 'error')
]);
Expand Down Expand Up @@ -53,14 +53,14 @@ function detectClippingArea (srcImage, { markSeed, clientAreaDimensions, cropDim
let clipHeight = srcImage.height;

if (markSeed && clientAreaDimensions) {
var mark = Buffer.from(markSeed);
const mark = Buffer.from(markSeed);

var markIndex = srcImage.data.indexOf(mark);
const markIndex = srcImage.data.indexOf(mark);

if (markIndex < 0)
throw new Error(renderTemplate(WARNING_MESSAGES.screenshotMarkNotFound, screenshotPath, markSeedToId(markSeed)));

var endPosition = markIndex / MARK_BYTES_PER_PIXEL + MARK_LENGTH + MARK_RIGHT_MARGIN;
const endPosition = markIndex / MARK_BYTES_PER_PIXEL + MARK_LENGTH + MARK_RIGHT_MARGIN;

clipRight = endPosition % srcImage.width || srcImage.width;
clipBottom = (endPosition - clipRight) / srcImage.width + 1;
Expand Down Expand Up @@ -94,11 +94,11 @@ function detectClippingArea (srcImage, { markSeed, clientAreaDimensions, cropDim
}

function copyImagePart (srcImage, { left, top, width, height }) {
var dstImage = new PNG({ width, height });
var stride = dstImage.width * MARK_BYTES_PER_PIXEL;
const dstImage = new PNG({ width, height });
const stride = dstImage.width * MARK_BYTES_PER_PIXEL;

for (let i = 0; i < height; i++) {
var srcStartIndex = (srcImage.width * (i + top) + left) * MARK_BYTES_PER_PIXEL;
const srcStartIndex = (srcImage.width * (i + top) + left) * MARK_BYTES_PER_PIXEL;

srcImage.data.copy(dstImage.data, stride * i, srcStartIndex, srcStartIndex + stride);
}
Expand All @@ -107,7 +107,7 @@ function copyImagePart (srcImage, { left, top, width, height }) {
}

export default async function (screenshotPath, markSeed, clientAreaDimensions, cropDimensions) {
var srcImage = await readPng(screenshotPath);
const srcImage = await readPng(screenshotPath);

const clippingArea = detectClippingArea(srcImage, { markSeed, clientAreaDimensions, cropDimensions, screenshotPath });

Expand Down
12 changes: 6 additions & 6 deletions src/screenshots/generate-mark.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@ const ALPHABET = '01';

export default function () {
// NOTE: 32-bit id
var id = generateId(ALPHABET, MARK_LENGTH);
const id = generateId(ALPHABET, MARK_LENGTH);

// NOTE: array of RGB values
var markSeed = flatten(map(id, bit => bit === '0' ? [0, 0, 0, 255] : [255, 255, 255, 255]));
const markSeed = flatten(map(id, bit => bit === '0' ? [0, 0, 0, 255] : [255, 255, 255, 255]));

// NOTE: macOS browsers can't display an element, if it's CSS height is lesser than 1.
// It happens on Retina displays, because they have more than 1 physical pixel in a CSS pixel.
// So increase mark size by prepending transparent pixels before the actual mark.
var imageData = times(MARK_BYTES_PER_PIXEL * MARK_LENGTH * (MARK_HEIGHT - 1), constant(0)).concat(markSeed);
var imageDataBuffer = Buffer.from(imageData);
var pngImage = new PNG({ width: MARK_LENGTH, height: MARK_HEIGHT });
const imageData = times(MARK_BYTES_PER_PIXEL * MARK_LENGTH * (MARK_HEIGHT - 1), constant(0)).concat(markSeed);
const imageDataBuffer = Buffer.from(imageData);
const pngImage = new PNG({ width: MARK_LENGTH, height: MARK_HEIGHT });

imageDataBuffer.copy(pngImage.data);

var markData = 'data:image/png;base64,' + PNG.sync.write(pngImage).toString('base64');
const markData = 'data:image/png;base64,' + PNG.sync.write(pngImage).toString('base64');

return { markSeed, markData };
}
8 changes: 4 additions & 4 deletions src/screenshots/path-pattern.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ export default class PathPattern {
[PLACEHOLDERS.TEST]: this.data.test,
[PLACEHOLDERS.FILE_INDEX]: forError => forError ? this.data.errorFileIndex : this.data.fileIndex,
[PLACEHOLDERS.USERAGENT]: this.data.parsedUserAgent.toString(),
[PLACEHOLDERS.BROWSER]: this.data.parsedUserAgent.browser,
[PLACEHOLDERS.BROWSER_VERSION]: this.data.parsedUserAgent.browserVersion,
[PLACEHOLDERS.OS]: this.data.parsedUserAgent.os,
[PLACEHOLDERS.OS_VERSION]: this.data.parsedUserAgent.osVersion
[PLACEHOLDERS.BROWSER]: this.data.parsedUserAgent.family,
[PLACEHOLDERS.BROWSER_VERSION]: this.data.parsedUserAgent.toVersion(),
[PLACEHOLDERS.OS]: this.data.parsedUserAgent.os.family,
[PLACEHOLDERS.OS_VERSION]: this.data.parsedUserAgent.os.toVersion()
};
}

Expand Down
Loading