Skip to content
Permalink
Browse files

Expose mocha to window in renderer context

There are some libraries, such as
[angular-mocks](https://github.com/angular/bower-angular-mocks) that
rely on mocha exposing itself to `window` to detect a testing
environment.

`angular-mocks` for example, has the following code which uses to
determine if `angular.mocks.module` and `angular.mocks.inject` should be
declared, which are essential testing utilities in angular:

  if (window.jasmine || window.mocha) { ... }

See
https://github.com/angular/bower-angular-mocks/blob/master/angular-mocks.js#L2448

Currently, `electron-mocha` doesn't expose mocha to `window`, therefore
libraries like `angular-mocks` fail to detect a testing environment and
lack expected functionality.

[mocha](http://mochajs.org) exposes itself like this:

  window.mocha = mocha

See https://github.com/mochajs/mocha/blob/master/mocha.js#L12414

We replicate this behaviour here.
  • Loading branch information...
Juan Cruz Viotti
Juan Cruz Viotti committed Oct 30, 2015
1 parent f75baab commit 0f6d2e3dc7a0ffd4386b701ea1bd6071bd9c0dfe
Showing with 13 additions and 0 deletions.
  1. +3 −0 renderer/run.js
  2. +10 −0 test/test3.js
@@ -2,6 +2,9 @@ require('./console')
var ipc = require('ipc')
var mocha = require('../mocha')

// Expose mocha
window.mocha = require('mocha')

// consider hooking up to mocha
/* window.onerror = function (message, filename, lineno, colno, err) {
console.log(err.message)
@@ -0,0 +1,10 @@
var assert = require('assert')
var mocha = require('mocha')

/* global describe it */

describe('describe: test 3', function () {
it('it: test 3', function () {
assert.strictEqual(window.mocha, mocha)
})
})

0 comments on commit 0f6d2e3

Please sign in to comment.
You can’t perform that action at this time.