Skip to content

Commit

Permalink
further linting
Browse files Browse the repository at this point in the history
  • Loading branch information
keis committed Apr 24, 2015
1 parent e47ef55 commit 8713117
Show file tree
Hide file tree
Showing 10 changed files with 540 additions and 536 deletions.
1 change: 1 addition & 0 deletions .eslintrc
Expand Up @@ -16,5 +16,6 @@
eqeqeq: [2, allow-null]
no-underscore-dangle: 0
no-use-before-define: 0
no-return-assign: 0
comma-style: [2, first]
indent: [2, 2]
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -10,7 +10,7 @@
"author": "David Keijser <keijser@gmail.com>",
"license": "MIT",
"scripts": {
"lint": "eslint lib test",
"lint": "eslint lib test && coffeelint test",
"test": "mocha --require test/bootstrap.js --compilers coffee:coffee-script/register --recursive test/unit",
"bench": "coffee -c test/benchmark.coffee ; matcha test/benchmark.js",
"coverage": "istanbul cover _mocha --report lcovonly -- --require test/bootstrap.js --compilers coffee:coffee-script/register --recursive test/unit",
Expand All @@ -21,6 +21,7 @@
"billom": "^1.0.2",
"chai": "^2.1.2",
"coffee-script": "^1.7.1",
"coffeelint": "^1.9.4",
"coveralls": "^2.11.1",
"eslint": "^0.17.1",
"istanbul": "^0.3.5",
Expand Down
30 changes: 15 additions & 15 deletions test/benchmark.coffee
@@ -1,23 +1,23 @@

suite 'rapidus.format', ->
{createFormatter} = require '../lib/sinks'
{createFormatter} = require '../lib/sinks'

record =
foo: 'foo-text'
bar: 'bar-text'
level: -> 'WARNING'
record =
foo: 'foo-text'
bar: 'bar-text'
level: -> 'WARNING'

set 'iterations', 100000
set 'iterations', 100000

simple = createFormatter ':foo'
complex = createFormatter '[:foo] :bar :level'
big = createFormatter '-:foo-:bar-:foo-:foo-:bar-:foo-:bar-:foo-:bar'
simple = createFormatter ':foo'
complex = createFormatter '[:foo] :bar :level'
big = createFormatter '-:foo-:bar-:foo-:foo-:bar-:foo-:bar-:foo-:bar'

bench 'simple attribute', ->
simple record
bench 'simple attribute', ->
simple record

bench 'complex format string', ->
complex record
bench 'complex format string', ->
complex record

bench 'big format string', ->
big record
bench 'big format string', ->
big record
96 changes: 48 additions & 48 deletions test/unit/test.default.coffee
Expand Up @@ -2,65 +2,65 @@ net = require 'net'
sinon = require 'sinon'

describe "default logger hierarchy", ->
{Record, Sink} = logging = require '../../lib'
root = logging.getLogger()
hier = root.hier
{Record, Sink} = logging = require '../../lib'
root = logging.getLogger()
hier = root.hier

afterEach ->
hier.processors = []
hier.proxy = null
process.env.LOGGING_PROXY = ''
afterEach ->
hier.processors = []
hier.proxy = null
process.env.LOGGING_PROXY = ''

describe "getLogger", ->
it "creates a logger", ->
log = logging.getLogger 'foo'
assert.equal log.name, 'foo'
assert.strictEqual log.parent, root
describe "getLogger", ->
it "creates a logger", ->
log = logging.getLogger 'foo'
assert.equal log.name, 'foo'
assert.strictEqual log.parent, root

describe "addDefaultProcessor", ->
it "adds a processor to the default hierarchy", ->
proc = sinon.stub()
describe "addDefaultProcessor", ->
it "adds a processor to the default hierarchy", ->
proc = sinon.stub()

logging.addDefaultProcessor proc
log = logging.getLogger 'bar'
log.info 'test'
assert.calledOnce proc
assert.calledWith proc, sinon.match.instanceOf Record
logging.addDefaultProcessor proc
log = logging.getLogger 'bar'
log.info 'test'
assert.calledOnce proc
assert.calledWith proc, sinon.match.instanceOf Record

describe "enableProxy", ->
server = net.createServer()
describe "enableProxy", ->
server = net.createServer()

before (done) ->
server.listen done
before (done) ->
server.listen done

after (done) ->
server.close done
after (done) ->
server.close done

it "attaches a proxy client to the default hierarchy", ->
logging.enableProxy
port: server.address().port
assert.property hier, 'proxy'
assert.isFunction hier.proxy.on
hier.proxy.end()
it "attaches a proxy client to the default hierarchy", ->
logging.enableProxy
port: server.address().port
assert.property hier, 'proxy'
assert.isFunction hier.proxy.on
hier.proxy.end()

describe "createProxy", ->
it "creates a proxy server for the default hierarchy", ->
proxy = logging.createProxy()
assert.isFunction proxy.on
describe "createProxy", ->
it "creates a proxy server for the default hierarchy", ->
proxy = logging.createProxy()
assert.isFunction proxy.on

describe "createHierarchy", ->
it "creates a new hierarchy", ->
hier = logging.createHierarchy()
assert.instanceOf hier, logging.Hierarchy
describe "createHierarchy", ->
it "creates a new hierarchy", ->
hier = logging.createHierarchy()
assert.instanceOf hier, logging.Hierarchy

describe "resetSinks", ->
it "resets the sinks of the default hierarchy", ->
sink = new Sink
sink.reset = sinon.stub()
describe "resetSinks", ->
it "resets the sinks of the default hierarchy", ->
sink = new Sink
sink.reset = sinon.stub()

logging.getLogger 'foo'
.addSink sink
logging.getLogger 'foo'
.addSink sink

logging.resetSinks()
logging.resetSinks()

assert.calledOnce sink.reset
assert.calledOnce sink.reset
48 changes: 24 additions & 24 deletions test/unit/test.format.coffee
Expand Up @@ -2,33 +2,33 @@
{Sink, createFormatter} = require '../../lib/sinks'

describe "createFormatter", ->
record = new Record 'access', 10, new Date, "%s - %s", ['foo', 10]
record.headers =
'content-length': '500',
'content-type': 'application/json'
record = new Record 'access', 10, new Date, "%s - %s", ['foo', 10]
record.headers =
'content-length': '500',
'content-type': 'application/json'

it "creates a format function", ->
frmt = createFormatter ':message'
assert.isFunction frmt
it "creates a format function", ->
frmt = createFormatter ':message'
assert.isFunction frmt

it "resolves simple attributes", ->
frmt = createFormatter ':level:name'
str = frmt record
assert.equal str, '10access'
it "resolves simple attributes", ->
frmt = createFormatter ':level:name'
str = frmt record
assert.equal str, '10access'

it "calls attributes that are resolved to functions", ->
frmt = createFormatter ':levelName :message'
str = frmt record
assert.equal str, 'DEBUG foo - 10'
it "calls attributes that are resolved to functions", ->
frmt = createFormatter ':levelName :message'
str = frmt record
assert.equal str, 'DEBUG foo - 10'

it "formats undefined as a dash", ->
frmt = createFormatter ':levelName :badvariable'
str = frmt record
assert.equal str, 'DEBUG -'
it "formats undefined as a dash", ->
frmt = createFormatter ':levelName :badvariable'
str = frmt record
assert.equal str, 'DEBUG -'

describe "defaultFormatter", ->
record = new Record 'access', 10, new Date, "%s - %s", ['foo', 10]
sink = new Sink
str = sink.format record
# Starts with a timestamp but that's ignored by the assert
assert.match str, /.* - DEBUG - foo - 10/
record = new Record 'access', 10, new Date, "%s - %s", ['foo', 10]
sink = new Sink
str = sink.format record
# Starts with a timestamp but that's ignored by the assert
assert.match str, /.* - DEBUG - foo - 10/
112 changes: 56 additions & 56 deletions test/unit/test.hierarchy.coffee
Expand Up @@ -2,80 +2,80 @@
sinon = require 'sinon'

describe "Hierarchy", ->
hier = null
root = new Logger null, 'root'
hier = null
root = new Logger null, 'root'

beforeEach ->
hier = new Hierarchy root
root.hier = hier
beforeEach ->
hier = new Hierarchy root
root.hier = hier

it "gives access to the root logger", ->
log = hier.getLogger()
assert.strictEqual log, root
it "gives access to the root logger", ->
log = hier.getLogger()
assert.strictEqual log, root

it "creates a logger", ->
log = hier.getLogger 'foo'
assert.equal log.name, 'foo'
assert.strictEqual log.parent, root
it "creates a logger", ->
log = hier.getLogger 'foo'
assert.equal log.name, 'foo'
assert.strictEqual log.parent, root

it "adds default processors to logger", ->
proc = sinon.stub()
it "adds default processors to logger", ->
proc = sinon.stub()

hier.addDefaultProcessor proc
hier.addDefaultProcessor proc

log = hier.getLogger 'foo'
log.info 'test'
assert.calledOnce proc
assert.calledWith proc, sinon.match.instanceOf Record
log = hier.getLogger 'foo'
log.info 'test'
assert.calledOnce proc
assert.calledWith proc, sinon.match.instanceOf Record

it "returns the same logger when called twice", ->
frst = hier.getLogger 'foo'
scnd = hier.getLogger 'foo'
assert.strictEqual frst, scnd
it "returns the same logger when called twice", ->
frst = hier.getLogger 'foo'
scnd = hier.getLogger 'foo'
assert.strictEqual frst, scnd

it "configures parent of sublogger", ->
parent = hier.getLogger 'foo'
log = hier.getLogger 'foo.bar'
assert.equal log.name, 'foo.bar'
assert.strictEqual log.parent, parent
it "configures parent of sublogger", ->
parent = hier.getLogger 'foo'
log = hier.getLogger 'foo.bar'
assert.equal log.name, 'foo.bar'
assert.strictEqual log.parent, parent

it "patches existing loggers when replacing placeholder", ->
suba = hier.getLogger 'foo.bar'
subb = hier.getLogger 'foo.baz'
log = hier.getLogger 'foo'
it "patches existing loggers when replacing placeholder", ->
suba = hier.getLogger 'foo.bar'
subb = hier.getLogger 'foo.baz'
log = hier.getLogger 'foo'

assert.strictEqual suba.parent, log
assert.strictEqual subb.parent, log
assert.strictEqual suba.parent, log
assert.strictEqual subb.parent, log

it "resets the sinks of all attached loggers", ->
suba = hier.getLogger 'foo.bar'
subb = hier.getLogger 'foo.baz'
it "resets the sinks of all attached loggers", ->
suba = hier.getLogger 'foo.bar'
subb = hier.getLogger 'foo.baz'

sinka = new Sink
sinka.reset = sinon.stub()
sinka = new Sink
sinka.reset = sinon.stub()

sinkb = new Sink
sinkb.reset = sinon.stub()
sinkb = new Sink
sinkb.reset = sinon.stub()

suba.addSink sinka
suba.addSink sinkb
suba.addSink {}
suba.addSink sinka
suba.addSink sinkb
suba.addSink {}

hier.resetSinks()
hier.resetSinks()

assert.calledOnce sinka.reset
assert.calledOnce sinkb.reset
assert.calledOnce sinka.reset
assert.calledOnce sinkb.reset

it "resets a reused sink once", ->
suba = hier.getLogger 'foo'
subb = hier.getLogger 'bar'
it "resets a reused sink once", ->
suba = hier.getLogger 'foo'
subb = hier.getLogger 'bar'

sinka = new Sink
sinka.reset = sinon.stub()
sinka = new Sink
sinka.reset = sinon.stub()

suba.addSink sinka
subb.addSink sinka
suba.addSink sinka
subb.addSink sinka

hier.resetSinks()
hier.resetSinks()

assert.calledOnce sinka.reset
assert.calledOnce sinka.reset

0 comments on commit 8713117

Please sign in to comment.