Skip to content

Commit

Permalink
Merge pull request #42 from thefrontside/ww/mocha-shim
Browse files Browse the repository at this point in the history
Disable requiring mocha directly in browser environments
  • Loading branch information
wwilsman authored Feb 6, 2018
2 parents a68c61e + 35cb830 commit e284065
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 9 deletions.
3 changes: 3 additions & 0 deletions packages/mocha/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
"repository": "https://github.com/thefrontside/bigtest/tree/master/packages/mocha",
"main": "dist/index.js",
"module": "src/index.js",
"browser": {
"mocha": false
},
"scripts": {
"build": "rollup --config",
"test": "mocha --opts ./tests/mocha.opts ./tests",
Expand Down
17 changes: 8 additions & 9 deletions packages/mocha/src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as mocha from 'mocha';
import * as mocha from './mocha';
import Convergence from '@bigtest/convergence';

/**
Expand Down Expand Up @@ -194,26 +194,25 @@ function afterEach(teardown) {
return mocha.afterEach(handleRunnable(teardown));
}

// destructure this for exporting
let { describe } = mocha;

// export our convergent it, wrapped hooks, and their aliases
export {
it,
before,
beforeEach,
after,
afterEach,
describe,
// TDD interface aliases
it as test,
describe as context,
// BDD interface aliases
it as specify,
before as suiteSetup,
beforeEach as setup,
after as suiteTeardown,
afterEach as teardown
afterEach as teardown,
describe as suite
};

// export other mocha functions used for testing
export {
describe,
context,
suite
} from 'mocha';
32 changes: 32 additions & 0 deletions packages/mocha/src/mocha.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// This file exports any globally defined mocha functions, otherwise
// it exports them from the mocha module directly.
//
// In a browser environment, mocha is usually included before the
// tests and has defined it's functions within the global context.
// Requiring mocha directly is currently disabled in browser
// environments via the `browser` field in this package's
// `package.json` file. This is because the mocha entrypoint has not
// yet been optimized to work with browser bundles without first
// disabling certain node modules.
//
// @see https://github.com/mochajs/mocha/issues/2448

import * as mocha from 'mocha';

let {
describe = global.describe,
before = global.before,
beforeEach = global.beforeEach,
after = global.before,
afterEach = global.afterEach,
it = global.it
} = mocha;

export {
describe,
before,
beforeEach,
after,
afterEach,
it
};

0 comments on commit e284065

Please sign in to comment.