Skip to content

armgit / mocha

Public Imported from GitHub
0

☕️ Classic, reliable, trusted test framework for Node.js and the browser

Added support for arbitrary compilers via . Closes #338

Ian Young1f9fe050923a
diff --git a/Makefile b/Makefile
index 60b224cf..91a1da7b 100644
--- a/Makefile
+++ b/Makefile
@@ -32,7 +32,7 @@ lib-cov:
test: test-unit
-test-all: test-bdd test-tdd test-qunit test-exports test-unit test-grep test-jsapi
+test-all: test-bdd test-tdd test-qunit test-exports test-unit test-grep test-jsapi test-compilers
test-jsapi:
@node test/jsapi
@@ -43,6 +43,13 @@ test-unit:
test/acceptance/*.js \
test/*.js
+test-compilers:
+ @./bin/mocha \
+ --reporter $(REPORTER) \
+ --compilers coffee:coffee-script,foo:./test/compiler/foo \
+ test/acceptance/test.coffee \
+ test/acceptance/test.foo
+
test-bdd:
@./bin/mocha \
--reporter $(REPORTER) \
@@ -108,4 +115,4 @@ tm:
mkdir -p $(TM_DEST)/$(TM_BUNDLE)
cp -fr editors/$(TM_BUNDLE) $(TM_DEST)/$(TM_BUNDLE)
-.PHONY: test-cov test-jsapi watch test test-all test-bdd test-tdd test-qunit test-exports test-unit non-tty test-grep tm clean
+.PHONY: test-cov test-jsapi test-compilers watch test test-all test-bdd test-tdd test-qunit test-exports test-unit non-tty test-grep tm clean
diff --git a/bin/_mocha b/bin/_mocha
index a499e5fa..0e49e273 100755
--- a/bin/_mocha
+++ b/bin/_mocha
@@ -57,6 +57,7 @@ program
.option('--ignore-leaks', 'ignore global variable leaks')
.option('--interfaces', 'display available interfaces')
.option('--reporters', 'display available reporters')
+ .option('--compilers <ext>:<module>,...', 'use the given module(s) to compile files', list, [])
program.name = 'mocha';
@@ -158,19 +159,24 @@ if (program.timeout) suite.timeout(program.timeout);
suite.bail(program.bail);
-// files
+// custom compiler support
-var files = program.args
- , re = /\.js$/;
+var extensions = ['js'];
+program.compilers.forEach(function(c) {
+ var compiler = c.split(':')
+ , ext = compiler[0]
+ , mod = compiler[1];
-// coffee-script support
+ if (mod[0] == '.') mod = join(process.cwd(), mod);
+ require(mod);
+ extensions.push(ext);
+});
-try {
- require('coffee-script');
- re = /\.(js|coffee)$/;
-} catch (err) {
- // ignore
-}
+var re = new RegExp('\\.(' + extensions.join('|') + ')$');
+
+// files
+
+var files = program.args;
// default files to test/*.{js,coffee}
diff --git a/lib/reporters/index.js b/lib/reporters/index.js
index 1899ffca..be218ecf 100644
--- a/lib/reporters/index.js
+++ b/lib/reporters/index.js
@@ -13,3 +13,4 @@ exports.JSONCov = require('./json-cov');
exports.HTMLCov = require('./html-cov');
exports.JSONStream = require('./json-stream');
exports.XUnit = require('./xunit')
+exports.Teamcity = require('./teamcity')
diff --git a/mocha.js b/mocha.js
index da649c44..102475ce 100644
--- a/mocha.js
+++ b/mocha.js
@@ -1612,6 +1612,7 @@ exports.JSONCov = require('./json-cov');
exports.HTMLCov = require('./html-cov');
exports.JSONStream = require('./json-stream');
exports.XUnit = require('./xunit')
+exports.Teamcity = require('./teamcity')
}); // module: reporters/index.js
diff --git a/package.json b/package.json
index 41090984..a5ad6884 100644
--- a/package.json
+++ b/package.json
@@ -19,6 +19,7 @@
, "debug": "*"
}
, "devDependencies": {
- "should": "*"
+ "should": "*"
+ , "coffee-script": "1.2"
}
}
diff --git a/test/acceptance/test.foo b/test/acceptance/test.foo
new file mode 100644
index 00000000..d00491fd
--- /dev/null
+++ b/test/acceptance/test.foo
@@ -0,0 +1 @@
+1
diff --git a/test/compiler/foo.js b/test/compiler/foo.js
new file mode 100644
index 00000000..b13101a7
--- /dev/null
+++ b/test/compiler/foo.js
@@ -0,0 +1,8 @@
+var fs = require('fs');
+require.extensions['.foo'] = function(module, filename) {
+ var content;
+ content = fs.readFileSync(filename, 'utf8');
+ var test = 'describe("custom compiler",function(){ it("should work",function() { '
+ + content + '.should.eql(1); }); });';
+ return module._compile(test, filename);
+};