Skip to content

Commit

Permalink
Build using Browserify
Browse files Browse the repository at this point in the history
Signed-off-by: Joshua Appelman <jappelman@xebia.com>

Closes #1193
  • Loading branch information
ndhoule authored and Joshua Appelman committed Jul 5, 2015
1 parent 2b2c576 commit a81e555
Show file tree
Hide file tree
Showing 16 changed files with 9,461 additions and 2,994 deletions.
25 changes: 11 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
BROWSERIFY := node_modules/.bin/browserify
ESLINT := node_modules/.bin/eslint

REPORTER ?= spec
TM_BUNDLE = JavaScript\ mocha.tmbundle
SRC = $(shell find lib -name "*.js" -type f | sort)
SUPPORT = $(wildcard support/*.js)

all: mocha.js

lib/browser/diff.js: node_modules/diff/diff.js
cp node_modules/diff/diff.js lib/browser/diff.js

lib/browser/escape-string-regexp.js: node_modules/escape-string-regexp/index.js
cp node_modules/escape-string-regexp/index.js lib/browser/escape-string-regexp.js

mocha.js: $(SRC) $(SUPPORT) lib/browser/diff.js lib/browser/escape-string-regexp.js
@node support/compile $(SRC)
@cat \
support/head.js \
_mocha.js \
support/tail.js \
support/foot.js \
> mocha.js
# TODO: Remove filesize echos, just for comparison during browserify transition
mocha.js: $(SRC) $(SUPPORT)
@$(BROWSERIFY) ./support/browser-entry \
--ignore 'fs' \
--ignore 'glob' \
--ignore 'jade' \
--ignore 'path' \
--ignore 'supports-color' \
--exclude './lib-cov/mocha' > $@

clean:
rm -f mocha.js
Expand Down
21 changes: 0 additions & 21 deletions lib/browser/escape-string-regexp.js

This file was deleted.

Empty file removed lib/browser/fs.js
Empty file.
Empty file removed lib/browser/glob.js
Empty file.
Empty file removed lib/browser/path.js
Empty file.
13 changes: 7 additions & 6 deletions lib/mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

var escapeRe = require('escape-string-regexp');
var path = require('path');
var reporters = require('./reporters');
var utils = require('./utils');

/**
Expand All @@ -22,7 +23,7 @@ exports = module.exports = Mocha;
* To require local UIs and reporters when running in node.
*/

if (typeof process !== 'undefined' && typeof process.cwd === 'function') {
if (!process.browser) {
var cwd = process.cwd();
module.paths.push(cwd, path.join(cwd, 'node_modules'));
}
Expand All @@ -33,7 +34,7 @@ if (typeof process !== 'undefined' && typeof process.cwd === 'function') {

exports.utils = utils;
exports.interfaces = require('./interfaces');
exports.reporters = require('./reporters');
exports.reporters = reporters;
exports.Runnable = require('./runnable');
exports.Context = require('./context');
exports.Runner = require('./runner');
Expand Down Expand Up @@ -150,11 +151,11 @@ Mocha.prototype.reporter = function(reporter, reporterOptions) {
} else {
reporter = reporter || 'spec';
var _reporter;
try {
_reporter = require('./reporters/' + reporter);
} catch (err) {
// Ignore
// Try to load a built-in reporter.
if (reporters[reporter]) {
_reporter = reporters[reporter];
}
// Try to load reporters from process.cwd() and node_modules
if (!_reporter) {
try {
_reporter = require(reporter);
Expand Down
6 changes: 2 additions & 4 deletions lib/reporters/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var tty = require('tty');
var diff = require('diff');
var ms = require('../ms');
var utils = require('../utils');
var supportsColor = process.env ? require('supports-color') : null;
var supportsColor = process.browser ? null : require('supports-color');

/**
* Expose `Base`.
Expand Down Expand Up @@ -37,9 +37,7 @@ var isatty = tty.isatty(1) && tty.isatty(2);
* Enable coloring by default, except in the browser interface.
*/

exports.useColors = process.env
? (supportsColor || (process.env.MOCHA_COLORS !== undefined))
: false;
exports.useColors = !process.browser && (supportsColor || (process.env.MOCHA_COLORS !== undefined));

/**
* Inline diffs instead of +/-
Expand Down
2 changes: 1 addition & 1 deletion lib/reporters/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
var Base = require('./base');
var utils = require('../utils');
var Progress = require('../browser/progress');
var escapeRe = require('../browser/escape-string-regexp');
var escapeRe = require('escape-string-regexp');
var escape = utils.escape;

/**
Expand Down
36 changes: 19 additions & 17 deletions lib/reporters/index.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
exports.Base = require('./base');
exports.Dot = require('./dot');
exports.Doc = require('./doc');
exports.TAP = require('./tap');
exports.JSON = require('./json');
exports.HTML = require('./html');
exports.List = require('./list');
exports.Min = require('./min');
exports.Spec = require('./spec');
exports.Nyan = require('./nyan');
exports.XUnit = require('./xunit');
exports.Markdown = require('./markdown');
exports.Progress = require('./progress');
exports.Landing = require('./landing');
exports.JSONCov = require('./json-cov');
exports.HTMLCov = require('./html-cov');
exports.JSONStream = require('./json-stream');
// Alias exports to a their normalized format Mocha#reporter to prevent a need
// for dynamic (try/catch) requires, which Browserify doesn't handle.
exports.Base = exports.base = require('./base');
exports.Dot = exports.dot = require('./dot');
exports.Doc = exports.doc = require('./doc');
exports.TAP = exports.tap = require('./tap');
exports.JSON = exports.json = require('./json');
exports.HTML = exports.html = require('./html');
exports.List = exports.list = require('./list');
exports.Min = exports.min = require('./min');
exports.Spec = exports.spec = require('./spec');
exports.Nyan = exports.nyan = require('./nyan');
exports.XUnit = exports.xunit = require('./xunit');
exports.Markdown = exports.markdown = require('./markdown');
exports.Progress = exports.progress = require('./progress');
exports.Landing = exports.landing = require('./landing');
exports.JSONCov = exports['json-cov'] = require('./json-cov');
exports.HTMLCov = exports['html-cov'] = require('./html-cov');
exports.JSONStream = exports['json-stream'] = require('./json-stream');
2 changes: 1 addition & 1 deletion lib/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@ function filterLeaks(ok, globals) {
* @return {Array}
*/
function extraGlobals() {
if (typeof process === 'object' && typeof process.version === 'string') {
if (!process.browser) {
var nodeVersion = process.version.split('.').reduce(function(a, v) {
return a << 8 | v;
});
Expand Down
Loading

0 comments on commit a81e555

Please sign in to comment.