|
| 1 | +/*1* KEEP THIS CODE AT THE TOP TO AVOID LINE NUMBER CHANGES */ |
| 2 | +/*2*/'use strict'; |
| 3 | +/*3*/function foo(a) { |
| 4 | +/*4*/ process.nextTick(function() { |
| 5 | +/*5*/ a = 0; |
| 6 | +/*6*/ }); |
| 7 | +/*7*/} |
| 8 | +/** |
| 9 | + * Copyright 2015 Google Inc. All Rights Reserved. |
| 10 | + * |
| 11 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 12 | + * you may not use this file except in compliance with the License. |
| 13 | + * You may obtain a copy of the License at |
| 14 | + * |
| 15 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 16 | + * |
| 17 | + * Unless required by applicable law or agreed to in writing, software |
| 18 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 19 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 20 | + * See the License for the specific language governing permissions and |
| 21 | + * limitations under the License. |
| 22 | + */ |
| 23 | + |
| 24 | +var breakpointInFoo = { |
| 25 | + id: 'fake-id-123', |
| 26 | + location: { path: 'test-duplicate-expressions.js', line: 4 } |
| 27 | +}; |
| 28 | + |
| 29 | +var assert = require('assert'); |
| 30 | +var v8debugapi = require('../../lib/v8debugapi.js'); |
| 31 | +var logModule = require('@google/cloud-diagnostics-common').logger; |
| 32 | +var config = require('../../config.js'); |
| 33 | +var scanner = require('../../lib/scanner.js'); |
| 34 | + |
| 35 | +function stateIsClean(api) { |
| 36 | + assert.equal(api.numBreakpoints_(), 0, |
| 37 | + 'there should be no breakpoints active'); |
| 38 | + assert.equal(api.numListeners_(), 0, |
| 39 | + 'there should be no listeners active'); |
| 40 | + return true; |
| 41 | +} |
| 42 | + |
| 43 | +describe('v8debugapi', function() { |
| 44 | + config.workingDirectory = process.cwd() + '/test/standalone'; |
| 45 | + var logger = logModule.create(config.logLevel); |
| 46 | + var api = null; |
| 47 | + |
| 48 | + beforeEach(function(done) { |
| 49 | + if (!api) { |
| 50 | + scanner.scan(config.workingDirectory, function(err, hash, fileStats) { |
| 51 | + assert(!err); |
| 52 | + api = v8debugapi.create(logger, config, fileStats); |
| 53 | + assert.ok(api, 'should be able to create the api'); |
| 54 | + done(); |
| 55 | + }); |
| 56 | + } else { |
| 57 | + assert(stateIsClean(api)); |
| 58 | + done(); |
| 59 | + } |
| 60 | + }); |
| 61 | + afterEach(function() { assert(stateIsClean(api)); }); |
| 62 | + |
| 63 | + it('should not duplicate expressions', function(done) { |
| 64 | + api.set(breakpointInFoo, function(err) { |
| 65 | + assert.ifError(err); |
| 66 | + api.wait(breakpointInFoo, function(err) { |
| 67 | + assert.ifError(err); |
| 68 | + var frames = breakpointInFoo.stackFrames[0]; |
| 69 | + var exprs = frames.arguments.concat(frames.locals); |
| 70 | + var varTableIndicesSeen = []; |
| 71 | + exprs.forEach(function(expr) { |
| 72 | + assert.equal(varTableIndicesSeen.indexOf(expr.varTableIndex), -1); |
| 73 | + varTableIndicesSeen.push(expr.varTableIndex); |
| 74 | + }); |
| 75 | + api.clear(breakpointInFoo); |
| 76 | + done(); |
| 77 | + }); |
| 78 | + process.nextTick(foo); |
| 79 | + }); |
| 80 | + }); |
| 81 | +}); |
0 commit comments