forked from googleapis/cloud-debug-nodejs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-duplicate-nested-expressions.ts
181 lines (172 loc) · 6.37 KB
/
test-duplicate-nested-expressions.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
// Copyright 2015 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import * as assert from 'assert';
import {afterEach, beforeEach, describe, it} from 'mocha';
import * as extend from 'extend';
import {defaultConfig} from '../src/agent/config';
import {Debuglet} from '../src/agent/debuglet';
import * as scanner from '../src/agent/io/scanner';
import * as SourceMapper from '../src/agent/io/sourcemapper';
import * as debugapi from '../src/agent/v8/debugapi';
import consoleLogLevel = require('console-log-level');
import * as stackdriver from '../src/types/stackdriver';
// eslint-disable-next-line @typescript-eslint/no-var-requires
const foo = require('./test-duplicate-nested-expressions-code.js');
// TODO: Determine why this must be named `_stateIsClean`.
function stateIsClean2(api: debugapi.DebugApi): boolean {
assert.strictEqual(
api.numBreakpoints_(),
0,
'there should be no breakpoints active'
);
assert.strictEqual(
api.numListeners_(),
0,
'there should be no listeners active'
);
return true;
}
describe(__filename, () => {
const config = extend({}, defaultConfig, {
workingDirectory: __dirname,
forceNewAgent_: true,
});
const logger = consoleLogLevel({
level: Debuglet.logLevelToName(config.logLevel),
});
let api: debugapi.DebugApi;
beforeEach(done => {
if (!api) {
scanner.scan(config.workingDirectory, /.js$/).then(async fileStats => {
assert.strictEqual(fileStats.errors().size, 0);
const jsStats = fileStats.selectStats(/.js$/);
const mapFiles = fileStats.selectFiles(/.map$/, process.cwd());
const mapper = await SourceMapper.create(mapFiles, logger);
// TODO: Handle the case when mapper is undefined
// TODO: Handle the case when v8debugapi.create returns null
api = debugapi.create(
logger,
config,
jsStats,
mapper as SourceMapper.SourceMapper
) as debugapi.DebugApi;
assert.ok(api, 'should be able to create the api');
done();
});
} else {
assert(stateIsClean2(api));
done();
}
});
afterEach(() => {
assert(stateIsClean2(api));
});
it('Should read the argument before the name is confounded', done => {
// TODO: Have this actually implement Breakpoint
const brk: stackdriver.Breakpoint = {
id: 'fake-id-123',
location: {path: 'test-duplicate-nested-expressions-code.js', line: 4},
} as stackdriver.Breakpoint;
api.set(brk, err1 => {
assert.ifError(err1);
api.wait(brk, err2 => {
assert.ifError(err2);
const frame = brk.stackFrames[0];
const args = frame.arguments;
const locals = frame.locals;
assert.strictEqual(args.length, 0, 'There should be zero arguments');
assert.strictEqual(locals.length, 1, 'There should be one locals');
assert.deepStrictEqual(locals[0], {name: 'a', value: 'test'});
api.clear(brk, err3 => {
assert.ifError(err3);
done();
});
});
process.nextTick(foo.bind(null, 'test'));
});
});
it('Should read an argument after the name is confounded', done => {
// TODO: Have this actually implement Breakpoint
const brk: stackdriver.Breakpoint = {
id: 'fake-id-1234',
location: {path: 'test-duplicate-nested-expressions-code.js', line: 5},
} as stackdriver.Breakpoint;
api.set(brk, err1 => {
assert.ifError(err1);
api.wait(brk, err2 => {
assert.ifError(err2);
const frame = brk.stackFrames[0];
const args = frame.arguments;
const locals = frame.locals;
assert.strictEqual(args.length, 0, 'There should be zero arguments');
assert.strictEqual(locals.length, 1, 'There should be one local');
assert.deepStrictEqual(locals[0], {name: 'a', value: '10'});
api.clear(brk, err3 => {
assert.ifError(err3);
done();
});
});
process.nextTick(foo.bind(null, 'test'));
});
});
it('Should read an argument value after its value is modified', done => {
// TODO: Have this actually implement Breakpoint
const brk: stackdriver.Breakpoint = {
id: 'fake-id-1234',
location: {path: 'test-duplicate-nested-expressions-code.js', line: 6},
} as stackdriver.Breakpoint;
api.set(brk, err1 => {
assert.ifError(err1);
api.wait(brk, err2 => {
assert.ifError(err2);
const frame = brk.stackFrames[0];
const args = frame.arguments;
const locals = frame.locals;
assert.strictEqual(args.length, 0, 'There should be zero arguments');
assert.strictEqual(locals.length, 1, 'There should be one local');
assert.deepStrictEqual(locals[0], {name: 'a', value: '11'});
api.clear(brk, err3 => {
assert.ifError(err3);
done();
});
});
process.nextTick(foo.bind(null, 'test'));
});
});
it('Should represent a const name at its local-scope when clearly defined', done => {
// TODO: Have this actually implement Breakpoint
const brk: stackdriver.Breakpoint = {
id: 'fake-id-1234',
location: {path: 'test-duplicate-nested-expressions-code.js', line: 8},
} as stackdriver.Breakpoint;
api.set(brk, err1 => {
assert.ifError(err1);
api.wait(brk, err2 => {
assert.ifError(err2);
const frame = brk.stackFrames[0];
const args = frame.arguments;
const locals = frame.locals;
assert.strictEqual(args.length, 0, 'There should be zero arguments');
assert.strictEqual(locals.length, 2, 'There should be two locals');
assert.deepStrictEqual(locals[0], {name: 'b', value: 'undefined'});
assert.deepStrictEqual(locals[1], {name: 'a', value: 'true'});
api.clear(brk, err3 => {
assert.ifError(err3);
done();
});
});
process.nextTick(foo.bind(null, 'test'));
});
});
});