Skip to content
This repository has been archived by the owner on Apr 3, 2024. It is now read-only.

Commit

Permalink
test: include context in circular reference tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kjin committed Sep 17, 2018
1 parent e19be5f commit 24fa3ba
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 22 deletions.
18 changes: 10 additions & 8 deletions test/test-circular-code.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
/*1* KEEP THIS CODE AT THE TOP TO AVOID LINE NUMBER CHANGES */ /* jshint shadow:true */
/*2*/'use strict';
/*3*/module.exports.foo = function () {
/*4*/ const a = {};
/*5*/ const b = { a };
/*6*/ a.b = b;
/*7*/ return a;
/*8*/}
/* 1* KEEP THIS CODE AT THE TOP TO AVOID LINE NUMBER CHANGES */ /* jshint shadow:true */
/* 2*/'use strict';
/* 3*/module.exports.foo = function () {
/* 4*/ const a = {};
/* 5*/ const b = { a, c: this };
/* 6*/ a.b = b;
/* 7*/ this.x = this;
/* 8*/ this.y = a;
/* 9*/ return this;
/*10*/}
40 changes: 26 additions & 14 deletions test/test-circular.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ describe(__filename, () => {
// TODO: Have this actually implement Breakpoint
const brk: stackdriver.Breakpoint = {
id: 'fake-id-123',
location: {path: 'test-circular-code.js', line: 7}
location: {path: 'test-circular-code.js', line: 9}
} as stackdriver.Breakpoint;
api.set(brk, (err1) => {
assert.ifError(err1);
Expand All @@ -87,24 +87,36 @@ describe(__filename, () => {
const nonStatusVars =
brk.variableTable.filter(entry => entry && !!entry.members) as
Variable[];
assert.strictEqual(locals.length, 2);
assert.strictEqual(locals[0].name, 'a');
assert.strictEqual(locals[1].name, 'b');
assert.strictEqual(
nonStatusVars.length, 2,
'There should be two non-status variables in brk.variableTable');
assert.ok(nonStatusVars[0].members); // a
assert.ok(nonStatusVars[0].members!.find(
entry => entry.name === 'b')); // a.b = b
assert.ok(nonStatusVars[1].members); // b
assert.ok(nonStatusVars[1].members!.find(
entry => entry.name === 'a')); // b.a = a
assert.strictEqual(locals.length, 3);
// Three locals: a, b, and this (named context here).
assert.deepStrictEqual(locals[0], {name: 'a', varTableIndex: 4});
assert.deepStrictEqual(locals[1], {name: 'b', varTableIndex: 5});
assert.deepStrictEqual(
locals[2], {name: 'context', varTableIndex: 6});
// All three non-status entries in the varTable correspond to each
// of the locals, respectively.
assert.strictEqual(nonStatusVars.length, 3);
// Every entry has a truthy members field.
assert.ok(!nonStatusVars.some(e => !e.members));
assert.strictEqual(nonStatusVars[0].members!.length, 1); // a
assert.deepStrictEqual(
nonStatusVars[0].members![0], {name: 'b', varTableIndex: 5});
assert.strictEqual(nonStatusVars[1].members!.length, 2); // b
assert.deepStrictEqual(
nonStatusVars[1].members![0], {name: 'a', varTableIndex: 4});
assert.deepStrictEqual(
nonStatusVars[1].members![1], {name: 'c', varTableIndex: 6});
assert.strictEqual(nonStatusVars[2].members!.length, 2); // context
assert.deepStrictEqual(
nonStatusVars[2].members![0], {name: 'x', varTableIndex: 6});
assert.deepStrictEqual(
nonStatusVars[2].members![1], {name: 'y', varTableIndex: 4});
api.clear(brk, (err3) => {
assert.ifError(err3);
done();
});
});
process.nextTick(code.foo);
process.nextTick(code.foo.bind({}));
});
});
});

0 comments on commit 24fa3ba

Please sign in to comment.