Permalink
Browse files

initial

  • Loading branch information...
0 parents commit 5df2bda0e631cf374565ac79bad8a43b4e95b526 @Raynos committed Jan 27, 2013
Showing with 337 additions and 0 deletions.
  1. +15 −0 .gitignore
  2. +14 −0 .npmignore
  3. +14 −0 .testem.json
  4. +4 −0 .travis.yml
  5. +19 −0 LICENCE
  6. +31 −0 README.md
  7. +80 −0 index.js
  8. +68 −0 package.json
  9. +28 −0 test/index.js
  10. +11 −0 test/static/index.html
  11. +53 −0 test/static/test-adapter.js
@@ -0,0 +1,15 @@
+.DS_Store
+.monitor
+.*.swp
+.nodemonignore
+releases
+*.log
+*.err
+fleet.json
+public/browserify
+bin/*.json
+.bin
+build
+compile
+.lock-wscript
+node_modules
@@ -0,0 +1,14 @@
+.DS_Store
+.monitor
+.*.swp
+.nodemonignore
+releases
+*.log
+*.err
+fleet.json
+public/browserify
+bin/*.json
+.bin
+build
+compile
+.lock-wscript
@@ -0,0 +1,14 @@
+{
+ "launchers": {
+ "node": {
+ "command": "npm test"
+ }
+ },
+ "src_files": [
+ "./**/*.js"
+ ],
+ "before_tests": "npm run build",
+ "on_exit": "rm test/static/bundle.js",
+ "test_page": "test/static/index.html",
+ "launch_in_dev": ["node", "phantomjs"]
+}
@@ -0,0 +1,4 @@
+language: node_js
+node_js:
+ - 0.8
+ - 0.9
19 LICENCE
@@ -0,0 +1,19 @@
+Copyright (c) 2012 Raynos.
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
@@ -0,0 +1,31 @@
+# console-browserify
+
+[![build status][1]][2]
+
+[![browser support][3]][4]
+
+Emulate console for all the browsers
+
+## Example
+
+```js
+var console = require("console-browserify")
+
+console.log("hello world!")
+```
+
+## Installation
+
+`npm install console-browserify`
+
+## Contributors
+
+ - Raynos
+
+## MIT Licenced
+
+
+ [1]: https://secure.travis-ci.org/Raynos/console-browserify.png
+ [2]: http://travis-ci.org/Raynos/console-browserify
+ [3]: http://ci.testling.com/Raynos/console-browserify.png
+ [4]: http://ci.testling.com/Raynos/console-browserify
@@ -0,0 +1,80 @@
+var now = require("date-now")
+var util = require("util")
+var assert = require("assert")
+
+var slice = Array.prototype.slice
+var console
+var times = {}
+
+if (typeof global !== "undefined" && global.console) {
+ console = global.console
+} else if (typeof window !== "undefined" && window.console) {
+ console = window.console
+} else {
+ console = consoleShim()
+}
+
+if (!console.time) {
+ console.time = time
+}
+
+if (!console.timeEnd) {
+ console.timeEnd = timeEnd
+}
+
+if (!console.trace) {
+ console.trace = trace
+}
+
+if (!console.dir) {
+ console.dir = dir
+}
+
+if (!console.assert) {
+ console.assert = assert
+}
+
+module.exports = console
+
+function consoleShim() {
+ return {
+ log: function () {}
+ , warn: function () {}
+ , error: function () {}
+ , info: function () {}
+ , dir: function () {}
+ , assert: function () {}
+ }
+}
+
+function time(label) {
+ times[label] = now()
+}
+
+function timeEnd(label) {
+ var time = times[label]
+ if (!time) {
+ throw new Error("No such label: " + label)
+ }
+
+ var duration = now() - time
+ console.log(label + ": " + duration + "ms")
+}
+
+function trace() {
+ var err = new Error()
+ err.name = "Trace"
+ err.message = util.format.apply(null, arguments)
+ console.error(err.stack)
+}
+
+function dir(object) {
+ console.log(util.inspect(object) + "\n")
+}
+
+function assert(expression) {
+ if (!expression) {
+ var arr = slice.call(arguments, 1)
+ assert.ok(false, util.format.apply(null, arr))
+ }
+}
@@ -0,0 +1,68 @@
+{
+ "name": "console-browserify",
+ "version": "0.1.0",
+ "description": "Emulate console for all the browsers",
+ "keywords": [],
+ "author": "Raynos <raynos2@gmail.com>",
+ "repository": "git://github.com/Raynos/console-browserify.git",
+ "main": "index",
+ "homepage": "https://github.com/Raynos/console-browserify",
+ "contributors": [
+ {
+ "name": "Raynos"
+ }
+ ],
+ "bugs": {
+ "url": "https://github.com/Raynos/console-browserify/issues",
+ "email": "raynos2@gmail.com"
+ },
+ "dependencies": {
+ "date-now": "~0.1.0"
+ },
+ "devDependencies": {
+ "tape": "~0.2.2",
+ "browserify": "https://github.com/raynos/node-browserify/tarball/master",
+ "testem": "~0.2.55"
+ },
+ "licenses": [
+ {
+ "type": "MIT",
+ "url": "http://github.com/Raynos/console-browserify/raw/master/LICENSE"
+ }
+ ],
+ "scripts": {
+ "test": "node ./test",
+ "build": "browserify test/index.js -o test/static/bundle.js",
+ "testem": "testem",
+ "postinstall": "npm dedup"
+ },
+ "testling": {
+ "files": "test/index.js",
+ "browsers": {
+ "ie": [
+ "6",
+ "7",
+ "8",
+ "9",
+ "10"
+ ],
+ "firefox": [
+ "16",
+ "17",
+ "nightly"
+ ],
+ "chrome": [
+ "22",
+ "23",
+ "canary"
+ ],
+ "opera": [
+ "12",
+ "next"
+ ],
+ "safari": [
+ "5.1"
+ ]
+ }
+ }
+}
@@ -0,0 +1,28 @@
+var console = require("../index")
+var test = require("tape")
+
+test("console has expected methods", function (assert) {
+ assert.ok(console.log)
+ assert.ok(console.info)
+ assert.ok(console.warn)
+ assert.ok(console.dir)
+ assert.ok(console.time, "time")
+ assert.ok(console.timeEnd, "timeEnd")
+ assert.ok(console.trace, "trace")
+ assert.ok(console.assert)
+
+ assert.end()
+})
+
+test("all the methods", function (assert) {
+ console.log("test-log")
+ console.info("test-info")
+ console.warn("test-warn")
+ console.dir("test-dir")
+ console.time("label")
+ console.timeEnd("label")
+ console.trace("test-trace")
+ console.assert(true)
+
+ assert.end()
+})
@@ -0,0 +1,11 @@
+<!doctype html>
+<html>
+<head>
+ <title>TAPE Example</title>
+ <script src="/testem.js"></script>
+ <script src="test-adapter.js"></script>
+ <script src="bundle.js"></script>
+</head>
+<body>
+</body>
+</html>
@@ -0,0 +1,53 @@
+(function () {
+ var Testem = window.Testem
+ var regex = /^((?:not )?ok) (\d+) (.+)$/
+
+ Testem.useCustomAdapter(tapAdapter)
+
+ function tapAdapter(socket){
+ var results = {
+ failed: 0
+ , passed: 0
+ , total: 0
+ , tests: []
+ }
+
+ socket.emit('tests-start')
+
+ Testem.handleConsoleMessage = function(msg){
+ var m = msg.match(regex)
+ if (m) {
+ var passed = m[1] === 'ok'
+ var test = {
+ passed: passed ? 1 : 0,
+ failed: passed ? 0 : 1,
+ total: 1,
+ id: m[2],
+ name: m[3],
+ items: []
+ }
+
+ if (passed) {
+ results.passed++
+ } else {
+ console.error("failure", m)
+
+ results.failed++
+ }
+
+ results.total++
+
+ // console.log("emitted test", test)
+ socket.emit('test-result', test)
+ results.tests.push(test)
+ } else if (msg === '# ok' || msg.match(/^# tests \d+/)){
+ // console.log("emitted all test")
+ socket.emit('all-test-results', results)
+ }
+
+ // return false if you want to prevent the console message from
+ // going to the console
+ // return false
+ }
+ }
+}())

0 comments on commit 5df2bda

Please sign in to comment.