-
Notifications
You must be signed in to change notification settings - Fork 293
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Log into browser window and other helpers.
- Loading branch information
Showing
5 changed files
with
152 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Test helpers. | ||
(function(exports) { | ||
|
||
// Compares bytes of an indexable something (Array, typed array). | ||
exports.bytesEqual = function(x, y) { | ||
if (x.length !== y.length) return false; | ||
for (var i = 0; i < x.length; i++) { | ||
if (x[i] !== y[i]) return false; | ||
} | ||
return true; | ||
}; | ||
|
||
function NodeLogger() { | ||
this.print = function() { | ||
console.log.apply(console, arguments); | ||
}; | ||
|
||
this.ok = function() { | ||
process.stdout.write('.'); | ||
}; | ||
|
||
this.error = function() { | ||
console.error.apply(console, arguments); | ||
}; | ||
|
||
this.start = this.print.bind(this, '\n'); | ||
} | ||
|
||
function BrowserLogger() { | ||
var el = document.createElement('pre'); | ||
document.body.appendChild(el); | ||
|
||
this.print = function() { | ||
var s = arguments.length ? Array.prototype.slice.call(arguments).join(' ') : ''; | ||
el.innerText += s + '\n'; | ||
}; | ||
|
||
this.ok = function() { | ||
el.innerText += '.'; | ||
}; | ||
|
||
this.error = function() { | ||
var s = arguments.length ? Array.prototype.slice.call(arguments) : ''; | ||
el.innerText += 'ERROR: ' + s + '\n'; | ||
}; | ||
|
||
this.start = this.print.bind(this, '\n'); | ||
} | ||
|
||
if (typeof window !== 'undefined') | ||
exports.log = new BrowserLogger(); | ||
else | ||
exports.log = new NodeLogger(); | ||
|
||
})(typeof exports !== 'undefined' ? exports : (window.helpers = window.helpers || {})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.