Skip to content

Commit

Permalink
test(tasks): add extra mocha-globals for tasks test
Browse files Browse the repository at this point in the history
Because we can't reuse the same file for both unit and tasks tests. When all tests are run by grunt, it's run inside a single VM and Node.js caches the module and evaluate only once.
  • Loading branch information
vojtajina committed Mar 1, 2013
1 parent b5286f8 commit 7d3c4e6
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 38 deletions.
4 changes: 2 additions & 2 deletions Gruntfile.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ module.exports = (grunt) ->
reporter: 'dot'
unit:
src: [
'test/mocha-common.js'
'test/unit/mocha-globals.coffee'
'test/unit/**/*.coffee'
]
tasks:
src: [
'test/mocha-common.js'
'test/tasks/mocha-globals.coffee'
'test/tasks/**/*.coffee'
]

Expand Down
36 changes: 0 additions & 36 deletions test/mocha-common.js

This file was deleted.

12 changes: 12 additions & 0 deletions test/tasks/mocha-globals.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
sinon = require 'sinon'
chai = require 'chai'

global.expect = chai.expect
global.sinon = null


beforeEach ->
global.sinon = sinon.sandbox.create()

afterEach ->
global.sinon.restore()
26 changes: 26 additions & 0 deletions test/unit/mocha-globals.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
sinon = require 'sinon'
chai = require 'chai'
logger = require '../../lib/logger'

# publish globals that all specs can use
global.timer = require 'timer-shim'
global.expect = chai.expect
global.should = chai.should()
global.sinon = sinon

# chai plugins
chai.use(require 'chai-as-promised')
chai.use(require 'sinon-chai')

# TODO(vojta): remove this global stub
sinon.stub(timer, 'setTimeout').callsArg 0

beforeEach ->
global.sinon = sinon.sandbox.create()

# set logger to log INFO, but do not append to console
# so that we can assert logs by logger.on('info', ...)
logger.setup 'INFO', false, []

afterEach ->
global.sinon.restore()

0 comments on commit 7d3c4e6

Please sign in to comment.