Skip to content

Commit

Permalink
Revert "refactor methods to use options objects"
Browse files Browse the repository at this point in the history
This reverts commit 307716f.
  • Loading branch information
jamestalmage committed Jan 7, 2016
1 parent 4492833 commit 68707fd
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 16 deletions.
27 changes: 17 additions & 10 deletions index.js
Expand Up @@ -57,10 +57,14 @@ StackUtils.prototype.clean = function (stack) {
return null;
};

StackUtils.prototype.captureString = function (options) {
options = options || {};
var limit = options.limit || Infinity;
var fn = options.startStackFunction || this.captureString;
StackUtils.prototype.captureString = function (limit, fn) {
if (typeof limit === 'function') {
fn = limit;
limit = Infinity;
}
if (!fn) {
fn = this.captureString;
}

var limitBefore = Error.stackTraceLimit;
if (limit) {
Expand All @@ -76,11 +80,14 @@ StackUtils.prototype.captureString = function (options) {
return this.clean(stack);
};

StackUtils.prototype.capture = function (options) {
options = options || {};
var limit = options.limit || Infinity;
var fn = options.startStackFunction || this.capture;

StackUtils.prototype.capture = function (limit, fn) {
if (typeof limit === 'function') {
fn = limit;
limit = Infinity;
}
if (!fn) {
fn = this.capture;
}
var prepBefore = Error.prepareStackTrace;
var limitBefore = Error.stackTraceLimit;

Expand All @@ -106,7 +113,7 @@ StackUtils.prototype.at = function at(fn) {
fn = at;
}

var site = this.capture({limit: 1, startStackFunction: fn})[0];
var site = this.capture(1, fn)[0];

if (!site) {
return {};
Expand Down
12 changes: 6 additions & 6 deletions test.js
Expand Up @@ -80,7 +80,7 @@ test('captureString: with startStack function', t => {
const stack = new StackUtils({internals: internals(), cwd: fixtureDir});
const capture = new CaptureFixture(stack);

const capturedString = capture.redirect1('redirect2', 'call', 'captureString', {startStackFunction: capture.call});
const capturedString = capture.redirect1('redirect2', 'call', 'captureString', capture.call);
t.is(capturedString, join([
'CaptureFixture.redirect2 (capture-fixture.js:17:22)',
'CaptureFixture.redirect1 (capture-fixture.js:11:22)'
Expand All @@ -91,7 +91,7 @@ test('captureString: with limit', t => {
const stack = new StackUtils({internals: internals(), cwd: fixtureDir});
const capture = new CaptureFixture(stack);

const capturedString = capture.redirect1('redirect2', 'call', 'captureString', {limit: 1});
const capturedString = capture.redirect1('redirect2', 'call', 'captureString', 1);
t.is(capturedString, join([
'CaptureFixture.call (capture-fixture.js:23:28)'
]));
Expand All @@ -101,7 +101,7 @@ test('captureString: with limit and startStack', t => {
const stack = new StackUtils({internals: internals(), cwd: fixtureDir});
const capture = new CaptureFixture(stack);

const capturedString = capture.redirect1('redirect2', 'call', 'captureString', {limit: 1, startStackFunction: capture.call});
const capturedString = capture.redirect1('redirect2', 'call', 'captureString', 1, capture.call);
t.is(capturedString, join([
'CaptureFixture.redirect2 (capture-fixture.js:17:22)'
]));
Expand All @@ -119,23 +119,23 @@ test('capture returns an array of call sites', t => {
test('capture: with limit', t => {
const stackUtil = new StackUtils({internals: internals(), cwd: fixtureDir});
const capture = new CaptureFixture(stackUtil);
const stack = capture.redirect1('redirect2', 'call', 'capture', {limit: 1});
const stack = capture.redirect1('redirect2', 'call', 'capture', 1);
t.is(stack.length, 1);
t.is(stack[0].getFunctionName(), 'CaptureFixture.call');
});

test('capture: with stackStart function', t => {
const stackUtil = new StackUtils({internals: internals(), cwd: fixtureDir});
const capture = new CaptureFixture(stackUtil);
const stack = capture.redirect1('redirect2', 'call', 'capture', {startStackFunction: capture.call});
const stack = capture.redirect1('redirect2', 'call', 'capture', capture.call);
t.true(stack.length > 1);
t.is(stack[0].getFunctionName(), 'CaptureFixture.redirect2');
});

test('capture: with limit and stackStart function', t => {
const stackUtil = new StackUtils({internals: internals(), cwd: fixtureDir});
const capture = new CaptureFixture(stackUtil);
const stack = capture.redirect1('redirect2', 'call', 'capture', {limit: 1, startStackFunction: capture.call});
const stack = capture.redirect1('redirect2', 'call', 'capture', 1, capture.call);
t.is(stack.length, 1);
t.is(stack[0].getFunctionName(), 'CaptureFixture.redirect2');
});
Expand Down

0 comments on commit 68707fd

Please sign in to comment.