mirror of
https://github.com/socketio/socket.io.git
synced 2026-04-30 03:00:39 -04:00
Added instrumentation support for the client during tests.
This commit is contained in:
@@ -1,4 +1,36 @@
|
||||
|
||||
/**
|
||||
* Instrument.
|
||||
*/
|
||||
|
||||
var fs = require('fs');
|
||||
|
||||
if (process.env.DEBUG) {
|
||||
require.extensions['.js'] = function(mod, filename){
|
||||
var js = fs.readFileSync(filename, 'utf8');
|
||||
|
||||
// Profiling support
|
||||
js = js.replace(/^ *\/\/ *(start|end): *([^\n]+)/gm, function(_, type, expr){
|
||||
switch (type) {
|
||||
case 'start': return 'console.time(' + expr + ');';
|
||||
case 'end': return 'console.timeEnd(' + expr + ');';
|
||||
}
|
||||
});
|
||||
|
||||
// Debugging
|
||||
js = js.replace(/^ *\/\/ *debug: *([^\n,]+) *([^\n]+)?/gm, function(_, fmt, args){
|
||||
fmt = fmt.replace(/"/g, '\\"');
|
||||
return 'console.error(" client\033[90m ' + fmt + '\033[0m"' + (args || '') + ');';
|
||||
});
|
||||
|
||||
js = js.replace(/^ *\/\/ *assert: ([^,]+) *, *([^\n]+)/gm, function(_, expr, msg){
|
||||
return 'if (!(' + expr + ')) console.error(" client assert\033[31m %s. (%s)\033[0m", ' + msg + ', "' + expr + '");';
|
||||
});
|
||||
|
||||
mod._compile(js, filename);
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Expose `eio` global.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user