2017-04-22 22:49:49 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
2017-04-25 22:21:31 +00:00
|
|
|
var websocket = null
|
2017-04-22 22:49:49 +00:00
|
|
|
|
2017-04-26 22:01:48 +00:00
|
|
|
var logger = (function () { // eslint-disable-line no-unused-vars
|
2017-05-02 14:17:36 +00:00
|
|
|
const sep = '\n/* ### NEXT TESTCASE ############################## */'
|
2017-05-02 14:26:49 +00:00
|
|
|
const color = {
|
2017-04-25 22:21:31 +00:00
|
|
|
red: '\u0033[1;31m',
|
|
|
|
green: '\u0033[1;32m',
|
|
|
|
clear: '\u0033[0m'
|
|
|
|
}
|
2017-04-25 17:59:34 +00:00
|
|
|
if (utils.platform.isWindows) {
|
2017-05-02 14:26:49 +00:00
|
|
|
color.red = ''
|
|
|
|
color.green = ''
|
|
|
|
color.clear = ''
|
2017-04-22 22:49:49 +00:00
|
|
|
}
|
|
|
|
|
2017-04-25 22:21:31 +00:00
|
|
|
function console (msg) {
|
2017-04-22 22:49:49 +00:00
|
|
|
if (websocket) {
|
2017-04-25 22:21:31 +00:00
|
|
|
websocket.send(msg)
|
2017-04-22 22:49:49 +00:00
|
|
|
}
|
2017-04-25 15:22:15 +00:00
|
|
|
if (typeof window === 'undefined') {
|
2017-05-02 19:32:03 +00:00
|
|
|
print(msg) // eslint-disable-line no-undef
|
2017-04-22 22:49:49 +00:00
|
|
|
} else if (window.dump) {
|
2017-04-25 22:21:31 +00:00
|
|
|
window.dump(msg)
|
2017-04-22 22:49:49 +00:00
|
|
|
} else if (window.console && window.console.log) {
|
2017-04-25 22:21:31 +00:00
|
|
|
window.console.log(msg)
|
2017-04-22 22:49:49 +00:00
|
|
|
} else {
|
2017-04-25 22:21:31 +00:00
|
|
|
throw new Error('Unable to run console logger.')
|
2017-04-22 22:49:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-25 22:21:31 +00:00
|
|
|
function dump (msg) {
|
|
|
|
console(msg)
|
2017-04-22 22:49:49 +00:00
|
|
|
}
|
|
|
|
|
2017-04-25 22:21:31 +00:00
|
|
|
function testcase (msg) {
|
|
|
|
dump('/*L*/ ' + JSON.stringify(msg) + '\n')
|
2017-04-22 22:49:49 +00:00
|
|
|
}
|
|
|
|
|
2017-04-25 22:21:31 +00:00
|
|
|
function dumpln (msg) {
|
|
|
|
dump(msg + '\n')
|
2017-04-22 22:49:49 +00:00
|
|
|
}
|
|
|
|
|
2017-04-25 22:21:31 +00:00
|
|
|
function error (msg) {
|
|
|
|
dumpln(color.red + msg + color.clear)
|
2017-04-22 22:49:49 +00:00
|
|
|
}
|
|
|
|
|
2017-04-25 22:21:31 +00:00
|
|
|
function JSError (msg) {
|
2017-04-22 22:49:49 +00:00
|
|
|
error(comment(msg))
|
|
|
|
}
|
|
|
|
|
2017-04-25 22:21:31 +00:00
|
|
|
function comment (msg) {
|
|
|
|
return '/* ' + msg + ' */'
|
2017-04-22 22:49:49 +00:00
|
|
|
}
|
|
|
|
|
2017-04-25 22:21:31 +00:00
|
|
|
function separator () {
|
|
|
|
dumpln(color.green + sep + color.clear)
|
2017-04-22 22:49:49 +00:00
|
|
|
}
|
|
|
|
|
2017-04-25 22:21:31 +00:00
|
|
|
function traceback () {
|
|
|
|
error('===[ Traceback ]')
|
2017-04-22 22:49:49 +00:00
|
|
|
try {
|
2017-04-25 22:21:31 +00:00
|
|
|
throw new Error()
|
2017-04-22 22:49:49 +00:00
|
|
|
} catch (e) {
|
2017-04-25 22:21:31 +00:00
|
|
|
dump(e.stack || e.stacktrace || '')
|
2017-04-22 22:49:49 +00:00
|
|
|
}
|
2017-04-25 22:21:31 +00:00
|
|
|
error('===')
|
2017-04-22 22:49:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
console: console,
|
|
|
|
dump: dump,
|
|
|
|
error: error,
|
|
|
|
JSError: JSError,
|
|
|
|
dumpln: dumpln,
|
|
|
|
comment: comment,
|
|
|
|
testcase: testcase,
|
|
|
|
separator: separator,
|
|
|
|
traceback: traceback
|
2017-04-25 22:21:31 +00:00
|
|
|
}
|
|
|
|
})()
|