Skip to content

Commit

Permalink
Update custom "callsite-record" module
Browse files Browse the repository at this point in the history
  • Loading branch information
Georgiy Abbasov committed Mar 30, 2017
1 parent d21548c commit 846e125
Show file tree
Hide file tree
Showing 57 changed files with 87 additions and 77 deletions.
19 changes: 10 additions & 9 deletions modules/callsite-record/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ var stackParser = require('error-stack-parser');
var padStart = require('lodash').padStart;
var defaults = require('lodash').defaults;
var highlight = require('highlight-es');
var wrapCallSite = require('source-map-support').wrapCallSite;

var renderers = {
default: require('./renderers/default'),
Expand Down Expand Up @@ -283,21 +282,23 @@ CallsiteRecord.fromError = function (error, isCallsiteFrame) {
};

// API
module.exports = function createCallsiteRecord (/* err, isCallsiteFrame || fnName, typeName */) {
if (arguments[0] instanceof Error)
return CallsiteRecord.fromError(arguments[0], arguments[1]);
module.exports = function createCallsiteRecord (options) { /*{ forError, isCallsiteFrame, byFunctionName, typeName, processFrameFn }*/
if (options.forError)
return CallsiteRecord.fromError(options.forError, options.isCallsiteFrame);

else if (typeof arguments[0] === 'string') {
else if (options.byFunctionName) {
var stackFrames = callsite();

stackFrames = stackFrames.map(function (frame) {
return wrapCallSite(frame)
});
if (options.processFrameFn) {
stackFrames = stackFrames.map(function (frame) {
return options.processFrameFn(frame);
});
}

// NOTE: remove API call
stackFrames.shift();

return CallsiteRecord.fromStackFrames(stackFrames, arguments[0], arguments[1]);
return CallsiteRecord.fromStackFrames(stackFrames, options.byFunctionName, options.typeName);
}

return null;
Expand Down
6 changes: 3 additions & 3 deletions src/api/test-controller/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Promise from 'pinkie';
import { identity, assign, isNil as isNullOrUndefined } from 'lodash';
import { MissingAwaitError } from '../../errors/test-run';
import getCallsite from '../../errors/get-callsite';
import { getCallsiteForMethod } from '../../errors/get-callsite';
import ClientFunctionBuilder from '../../client-functions/client-function-builder';
import Assertion from './assertion';
import { getDelegatedAPIList, delegateAPI } from '../../utils/delegated-api';
Expand Down Expand Up @@ -82,7 +82,7 @@ export default class TestController {
_enqueueTask (apiMethodName, createTaskExecutor) {
this._checkForMissingAwait();

var callsite = getCallsite(apiMethodName);
var callsite = getCallsiteForMethod(apiMethodName);
var executor = createTaskExecutor(callsite);

this.executionChain = this.executionChain.then(executor);
Expand Down Expand Up @@ -242,7 +242,7 @@ export default class TestController {
}

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

return this.testRun.executeCommand(new GetNativeDialogHistoryCommand(), callsite);
}
Expand Down
4 changes: 2 additions & 2 deletions src/client-functions/client-function-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import compileClientFunction from '../compiler/es-next/compile-client-function';
import { APIError, ClientFunctionAPIError } from '../errors/runtime';
import { assertType, is } from '../errors/runtime/type-assertions';
import MESSAGE from '../errors/runtime/message';
import getCallsite from '../errors/get-callsite';
import { getCallsiteForMethod } from '../errors/get-callsite';
import ClientFunctionResultPromise from './result-promise';
import testRunMarker from '../test-run/marker-symbol';

Expand Down Expand Up @@ -64,7 +64,7 @@ export default class ClientFunctionBuilder {

var clientFn = function __$$clientFunction$$ () {
var testRun = builder.getBoundTestRun() || testRunTracker.resolveContextTestRun();
var callsite = getCallsite(builder.callsiteNames.execution);
var callsite = getCallsiteForMethod(builder.callsiteNames.execution);
var args = [];

// OPTIMIZATION: don't leak `arguments` object.
Expand Down
14 changes: 7 additions & 7 deletions src/client-functions/selectors/add-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { assign } from 'lodash';
import clientFunctionBuilderSymbol from '../builder-symbol';
import { ELEMENT_SNAPSHOT_PROPERTIES, NODE_SNAPSHOT_PROPERTIES } from './snapshot-properties';
import { CantObtainInfoForElementSpecifiedBySelectorError } from '../../errors/test-run';
import getCallsite from '../../errors/get-callsite';
import { getCallsiteForMethod } from '../../errors/get-callsite';
import ClientFunctionBuilder from '../client-function-builder';
import ClientFunctionResultPromise from '../result-promise';
import { assertType, is } from '../../errors/runtime/type-assertions';
Expand Down Expand Up @@ -106,7 +106,7 @@ function addSnapshotProperties (obj, getSelector, properties) {
properties.forEach(prop => {
Object.defineProperty(obj, prop, {
get: () => {
var callsite = getCallsite('get');
var callsite = getCallsiteForMethod('get');

return ClientFunctionResultPromise.fromFn(async () => {
var snapshot = await getSnapshot(getSelector, callsite);
Expand Down Expand Up @@ -149,7 +149,7 @@ function addSnapshotPropertyShorthands (obj, getSelector, customDOMProperties, c
addCustomMethods(obj, getSelector, customMethods);

obj.getStyleProperty = prop => {
var callsite = getCallsite('getStyleProperty');
var callsite = getCallsiteForMethod('getStyleProperty');

return ClientFunctionResultPromise.fromFn(async () => {
var snapshot = await getSnapshot(getSelector, callsite);
Expand All @@ -159,7 +159,7 @@ function addSnapshotPropertyShorthands (obj, getSelector, customDOMProperties, c
};

obj.getAttribute = attrName => {
var callsite = getCallsite('getAttribute');
var callsite = getCallsiteForMethod('getAttribute');

return ClientFunctionResultPromise.fromFn(async () => {
var snapshot = await getSnapshot(getSelector, callsite);
Expand All @@ -169,7 +169,7 @@ function addSnapshotPropertyShorthands (obj, getSelector, customDOMProperties, c
};

obj.getBoundingClientRectProperty = prop => {
var callsite = getCallsite('getBoundingClientRectProperty');
var callsite = getCallsiteForMethod('getBoundingClientRectProperty');

return ClientFunctionResultPromise.fromFn(async () => {
var snapshot = await getSnapshot(getSelector, callsite);
Expand All @@ -179,7 +179,7 @@ function addSnapshotPropertyShorthands (obj, getSelector, customDOMProperties, c
};

obj.hasClass = name => {
var callsite = getCallsite('hasClass');
var callsite = getCallsiteForMethod('hasClass');

return ClientFunctionResultPromise.fromFn(async () => {
var snapshot = await getSnapshot(getSelector, callsite);
Expand All @@ -192,7 +192,7 @@ function addSnapshotPropertyShorthands (obj, getSelector, customDOMProperties, c
function createCounter (getSelector, SelectorBuilder) {
var builder = new SelectorBuilder(getSelector(), { counterMode: true }, { instantiation: 'Selector' });
var counter = builder.getFunction();
var callsite = getCallsite('get');
var callsite = getCallsiteForMethod('get');

return async () => {
try {
Expand Down
13 changes: 11 additions & 2 deletions src/errors/get-callsite.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
import createCallsiteRecord from '../../modules/callsite-record';
import stackCleaningHook from './stack-cleaning-hook';
import { wrapCallSite } from 'source-map-support';

const STACK_TRACE_LIMIT = 2000;

export default function getCallsite (methodName, typeName) {
function getCallsite (options) {
var originalStackCleaningEnabled = stackCleaningHook.enabled;
var originalStackTraceLimit = Error.stackTraceLimit;

stackCleaningHook.enabled = false;
Error.stackTraceLimit = STACK_TRACE_LIMIT;

var callsiteRecord = createCallsiteRecord(methodName, typeName);
var callsiteRecord = createCallsiteRecord(options);

Error.stackTraceLimit = originalStackTraceLimit;
stackCleaningHook.enabled = originalStackCleaningEnabled;

return callsiteRecord;
}

export function getCallsiteForMethod (methodName, typeName) {
return getCallsite({ byFunctionName: methodName, typeName, processFrameFn: wrapCallSite });
}

export function getCallsiteForError (error, isCallsiteFrame) {
return getCallsite({ forError: error, isCallsiteFrame });
}
4 changes: 2 additions & 2 deletions src/errors/process-test-fn-error.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { sep } from 'path';
import getCallsite from './get-callsite';
import { getCallsiteForError } from './get-callsite';
import { APIError } from './runtime';

import {
Expand Down Expand Up @@ -34,7 +34,7 @@ export default function processTestFnError (err) {

// NOTE: assertion libraries can add their source files to the error stack frames.
// We should skip them to create a correct callsite for the assertion error.
var callsite = isAssertionError ? getCallsite(err, isAssertionErrorCallsiteFrame) : getCallsite(err);
var callsite = isAssertionError ? getCallsiteForError(err, isAssertionErrorCallsiteFrame) : getCallsiteForError(err);

return isAssertionError ?
new ExternalAssertionLibraryError(err, callsite) :
Expand Down
4 changes: 2 additions & 2 deletions src/errors/runtime/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { renderers } from 'callsite-record';
import MESSAGE from './message';
import createStackFilter from '../create-stack-filter';
import getCallsite from '../get-callsite';
import { getCallsiteForMethod } from '../get-callsite';
import renderTemplate from '../../utils/render-template';

// Errors
Expand Down Expand Up @@ -34,7 +34,7 @@ export class APIError extends Error {

// NOTE: `rawMessage` is used in error substitution if it occurs in test run.
this.rawMessage = rawMessage;
this.callsite = getCallsite(methodName);
this.callsite = getCallsiteForMethod(methodName);
this.constructor = APIError;

// HACK: prototype properties don't work with built-in subclasses
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Browser: Chrome 15.0.874 / Mac OS X 10.8.1
Screenshot: /unix/path/with/<tag>

18 |function func1 () {
19 | record = createCallsiteRecord('func1');
19 | record = createCallsiteRecord({ byFunctionName: 'func1' });
20 |}
21 |
22 |(function func2 () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Browser: Chrome 15.0.874 / Mac OS X 10.8.1
Screenshot: /unix/path/with/<tag>

18 |function func1 () {
19 | record = createCallsiteRecord('func1');
19 | record = createCallsiteRecord({ byFunctionName: 'func1' });
20 |}
21 |
22 |(function func2 () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Browser: Chrome 15.0.874 / Mac OS X 10.8.1
Screenshot: /unix/path/with/<tag>

18 |function func1 () {
19 | record = createCallsiteRecord('func1');
19 | record = createCallsiteRecord({ byFunctionName: 'func1' });
20 |}
21 |
22 |(function func2 () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Browser: Chrome 15.0.874 / Mac OS X 10.8.1
Screenshot: /unix/path/with/<tag>

18 |function func1 () {
19 | record = createCallsiteRecord('func1');
19 | record = createCallsiteRecord({ byFunctionName: 'func1' });
20 |}
21 |
22 |(function func2 () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Browser: Chrome 15.0.874 / Mac OS X 10.8.1
Screenshot: /unix/path/with/<tag>

18 |function func1 () {
19 | record = createCallsiteRecord('func1');
19 | record = createCallsiteRecord({ byFunctionName: 'func1' });
20 |}
21 |
22 |(function func2 () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Browser: Chrome 15.0.874 / Mac OS X 10.8.1
Screenshot: /unix/path/with/<tag>

18 |function func1 () {
19 | record = createCallsiteRecord('func1');
19 | record = createCallsiteRecord({ byFunctionName: 'func1' });
20 |}
21 |
22 |(function func2 () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Browser: Chrome 15.0.874 / Mac OS X 10.8.1
Screenshot: /unix/path/with/<tag>

18 |function func1 () {
19 | record = createCallsiteRecord('func1');
19 | record = createCallsiteRecord({ byFunctionName: 'func1' });
20 |}
21 |
22 |(function func2 () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Browser: Chrome 15.0.874 / Mac OS X 10.8.1
Screenshot: /unix/path/with/<tag>

18 |function func1 () {
19 | record = createCallsiteRecord('func1');
19 | record = createCallsiteRecord({ byFunctionName: 'func1' });
20 |}
21 |
22 |(function func2 () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Browser: Chrome 15.0.874 / Mac OS X 10.8.1
Screenshot: /unix/path/with/<tag>

18 |function func1 () {
19 | record = createCallsiteRecord('func1');
19 | record = createCallsiteRecord({ byFunctionName: 'func1' });
20 |}
21 |
22 |(function func2 () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Browser: Chrome 15.0.874 / Mac OS X 10.8.1
Screenshot: /unix/path/with/<tag>

18 |function func1 () {
19 | record = createCallsiteRecord('func1');
19 | record = createCallsiteRecord({ byFunctionName: 'func1' });
20 |}
21 |
22 |(function func2 () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Browser: Chrome 15.0.874 / Mac OS X 10.8.1
Screenshot: /unix/path/with/<tag>

18 |function func1 () {
19 | record = createCallsiteRecord('func1');
19 | record = createCallsiteRecord({ byFunctionName: 'func1' });
20 |}
21 |
22 |(function func2 () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Browser: Chrome 15.0.874 / Mac OS X 10.8.1
Screenshot: /unix/path/with/<tag>

18 |function func1 () {
19 | record = createCallsiteRecord('func1');
19 | record = createCallsiteRecord({ byFunctionName: 'func1' });
20 |}
21 |
22 |(function func2 () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Browser: Chrome 15.0.874 / Mac OS X 10.8.1
Screenshot: /unix/path/with/<tag>

18 |function func1 () {
19 | record = createCallsiteRecord('func1');
19 | record = createCallsiteRecord({ byFunctionName: 'func1' });
20 |}
21 |
22 |(function func2 () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Browser: Chrome 15.0.874 / Mac OS X 10.8.1
Screenshot: /unix/path/with/<tag>

18 |function func1 () {
19 | record = createCallsiteRecord('func1');
19 | record = createCallsiteRecord({ byFunctionName: 'func1' });
20 |}
21 |
22 |(function func2 () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Browser: Chrome 15.0.874 / Mac OS X 10.8.1
Screenshot: /unix/path/with/<tag>

18 |function func1 () {
19 | record = createCallsiteRecord('func1');
19 | record = createCallsiteRecord({ byFunctionName: 'func1' });
20 |}
21 |
22 |(function func2 () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Browser: Chrome 15.0.874 / Mac OS X 10.8.1
Screenshot: /unix/path/with/<tag>

18 |function func1 () {
19 | record = createCallsiteRecord('func1');
19 | record = createCallsiteRecord({ byFunctionName: 'func1' });
20 |}
21 |
22 |(function func2 () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Browser: Chrome 15.0.874 / Mac OS X 10.8.1
Screenshot: /unix/path/with/<tag>

18 |function func1 () {
19 | record = createCallsiteRecord('func1');
19 | record = createCallsiteRecord({ byFunctionName: 'func1' });
20 |}
21 |
22 |(function func2 () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Browser: Chrome 15.0.874 / Mac OS X 10.8.1
Screenshot: /unix/path/with/<tag>

18 |function func1 () {
19 | record = createCallsiteRecord('func1');
19 | record = createCallsiteRecord({ byFunctionName: 'func1' });
20 |}
21 |
22 |(function func2 () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Browser: Chrome 15.0.874 / Mac OS X 10.8.1
Screenshot: /unix/path/with/<tag>

18 |function func1 () {
19 | record = createCallsiteRecord('func1');
19 | record = createCallsiteRecord({ byFunctionName: 'func1' });
20 |}
21 |
22 |(function func2 () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Browser: Chrome 15.0.874 / Mac OS X 10.8.1
Screenshot: /unix/path/with/<tag>

18 |function func1 () {
19 | record = createCallsiteRecord('func1');
19 | record = createCallsiteRecord({ byFunctionName: 'func1' });
20 |}
21 |
22 |(function func2 () {
Expand Down
Loading

0 comments on commit 846e125

Please sign in to comment.