The data contained in this repository can be downloaded to your computer using one of several clients.
Please see the documentation of your version control software client for more information.
Please select the desired protocol below to get the URL.
This URL has Read-Only access.
main_repo / test / simple / test-debugger-client.js @ 916aebab
History | View | Annotate | Download (5.86 KB)
1 |
// Copyright Joyent, Inc. and other Node contributors.
|
---|---|
2 |
//
|
3 |
// Permission is hereby granted, free of charge, to any person obtaining a
|
4 |
// copy of this software and associated documentation files (the
|
5 |
// "Software"), to deal in the Software without restriction, including
|
6 |
// without limitation the rights to use, copy, modify, merge, publish,
|
7 |
// distribute, sublicense, and/or sell copies of the Software, and to permit
|
8 |
// persons to whom the Software is furnished to do so, subject to the
|
9 |
// following conditions:
|
10 |
//
|
11 |
// The above copyright notice and this permission notice shall be included
|
12 |
// in all copies or substantial portions of the Software.
|
13 |
//
|
14 |
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
15 |
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16 |
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
17 |
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
18 |
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
19 |
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
20 |
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
process.env.NODE_DEBUGGER_TIMEOUT = 200;
|
26 |
var common = require('../common'); |
27 |
var assert = require('assert'); |
28 |
var debug = require('_debugger'); |
29 |
|
30 |
var spawn = require('child_process').spawn; |
31 |
|
32 |
|
33 |
var resCount = 0; |
34 |
var p = new debug.Protocol(); |
35 |
p.onResponse = function(res) { |
36 |
resCount++; |
37 |
}; |
38 |
|
39 |
p.execute('Type: connect\r\n' +
|
40 |
'V8-Version: 3.0.4.1\r\n' +
|
41 |
'Protocol-Version: 1\r\n' +
|
42 |
'Embedding-Host: node v0.3.3-pre\r\n' +
|
43 |
'Content-Length: 0\r\n\r\n');
|
44 |
assert.equal(1, resCount);
|
45 |
|
46 |
// Make sure split messages go in.
|
47 |
|
48 |
var parts = [];
|
49 |
parts.push('Content-Length: 336\r\n');
|
50 |
assert.equal(21, parts[0].length); |
51 |
parts.push('\r\n');
|
52 |
assert.equal(2, parts[1].length); |
53 |
var bodyLength = 0; |
54 |
|
55 |
parts.push('{"seq":12,"type":"event","event":"break","body":' +
|
56 |
'{"invocationText":"#<a Server>');
|
57 |
assert.equal(78, parts[2].length); |
58 |
bodyLength += parts[2].length;
|
59 |
|
60 |
parts.push('.[anonymous](req=#<an IncomingMessage>, ' +
|
61 |
'res=#<a ServerResponse>)","sourceLine"');
|
62 |
assert.equal(78, parts[3].length); |
63 |
bodyLength += parts[3].length;
|
64 |
|
65 |
parts.push(':45,"sourceColumn":4,"sourceLineText":" debugger;",' +
|
66 |
'"script":{"id":24,"name":"/home/ryan/projects/node/' +
|
67 |
'benchmark/http_simple.js","lineOffset":0,"columnOffset":0,' +
|
68 |
'"lineCount":98}}}');
|
69 |
assert.equal(180, parts[4].length); |
70 |
bodyLength += parts[4].length;
|
71 |
|
72 |
assert.equal(336, bodyLength);
|
73 |
|
74 |
for (var i = 0; i < parts.length; i++) { |
75 |
p.execute(parts[i]); |
76 |
} |
77 |
assert.equal(2, resCount);
|
78 |
|
79 |
|
80 |
// Make sure that if we get backed up, we still manage to get all the
|
81 |
// messages
|
82 |
var d = 'Content-Length: 466\r\n\r\n' + |
83 |
'{"seq":10,"type":"event","event":"afterCompile","success":true,' +
|
84 |
'"body":{"script":{"handle":1,"type":"script","name":"dns.js",' +
|
85 |
'"id":34,"lineOffset":0,"columnOffset":0,"lineCount":241,' +
|
86 |
'"sourceStart":"(function (module, exports, require) {' +
|
87 |
'var dns = process.binding(\'cares\')' +
|
88 |
';\\nvar ne","sourceLength":6137,"scriptType":2,"compilationType":0,' +
|
89 |
'"context":{"ref":0},"text":"dns.js (lines: 241)"}},"refs":' +
|
90 |
'[{"handle":0' +
|
91 |
',"type":"context","text":"#<a ContextMirror>"}],"running":true}' +
|
92 |
'Content-Length: 119\r\n\r\n' +
|
93 |
'{"seq":11,"type":"event","event":"scriptCollected","success":true,' +
|
94 |
'"body":{"script":{"id":26}},"refs":[],"running":true}';
|
95 |
p.execute(d); |
96 |
assert.equal(4, resCount);
|
97 |
|
98 |
var expectedConnections = 0; |
99 |
var tests = [];
|
100 |
function addTest(cb) { |
101 |
expectedConnections++; |
102 |
tests.push(cb); |
103 |
} |
104 |
|
105 |
addTest(function(client, done) {
|
106 |
console.error('requesting version');
|
107 |
client.reqVersion(function(err, v) {
|
108 |
assert.ok(!err); |
109 |
console.log('version: %s', v);
|
110 |
assert.equal(process.versions.v8, v); |
111 |
done(); |
112 |
}); |
113 |
}); |
114 |
|
115 |
addTest(function(client, done) {
|
116 |
console.error('requesting scripts');
|
117 |
client.reqScripts(function(err) {
|
118 |
assert.ok(!err); |
119 |
console.error('got %d scripts', Object.keys(client.scripts).length);
|
120 |
|
121 |
var foundMainScript = false; |
122 |
for (var k in client.scripts) { |
123 |
var script = client.scripts[k];
|
124 |
if (script && script.name === 'node.js') { |
125 |
foundMainScript = true;
|
126 |
break;
|
127 |
} |
128 |
} |
129 |
assert.ok(foundMainScript); |
130 |
done(); |
131 |
}); |
132 |
}); |
133 |
|
134 |
addTest(function(client, done) {
|
135 |
console.error('eval 2+2');
|
136 |
client.reqEval('2+2', function(err, res) { |
137 |
console.error(res); |
138 |
assert.ok(!err); |
139 |
assert.equal('4', res.text);
|
140 |
assert.equal(4, res.value);
|
141 |
done(); |
142 |
}); |
143 |
}); |
144 |
|
145 |
|
146 |
var connectCount = 0; |
147 |
|
148 |
function doTest(cb, done) { |
149 |
var nodeProcess = spawn(process.execPath,
|
150 |
['-e', 'setInterval(function () { console.log("blah"); }, 100);']); |
151 |
|
152 |
nodeProcess.stdout.once('data', function() { |
153 |
console.log('>>> new node process: %d', nodeProcess.pid);
|
154 |
process._debugProcess(nodeProcess.pid); |
155 |
console.log('>>> starting debugger session');
|
156 |
}); |
157 |
|
158 |
var didTryConnect = false; |
159 |
nodeProcess.stderr.setEncoding('utf8');
|
160 |
var b = ''; |
161 |
nodeProcess.stderr.on('data', function(data) { |
162 |
b += data; |
163 |
if (didTryConnect == false && /debugger listening on port/.test(b)) { |
164 |
didTryConnect = true;
|
165 |
|
166 |
setTimeout(function() {
|
167 |
// Wait for some data before trying to connect
|
168 |
var c = new debug.Client(); |
169 |
process.stdout.write('>>> connecting...');
|
170 |
c.connect(debug.port); |
171 |
c.on('ready', function() { |
172 |
connectCount++; |
173 |
console.log('ready!');
|
174 |
cb(c, function() {
|
175 |
console.error('>>> killing node process %d\n\n', nodeProcess.pid);
|
176 |
nodeProcess.kill(); |
177 |
done(); |
178 |
}); |
179 |
}); |
180 |
}, 100);
|
181 |
} |
182 |
}); |
183 |
} |
184 |
|
185 |
|
186 |
function run() { |
187 |
var t = tests[0]; |
188 |
if (!t) return; |
189 |
|
190 |
doTest(t, function() {
|
191 |
tests.shift(); |
192 |
run(); |
193 |
}); |
194 |
} |
195 |
|
196 |
run(); |
197 |
|
198 |
process.on('exit', function() { |
199 |
assert.equal(expectedConnections, connectCount); |
200 |
}); |
201 |
|