diff --git a/lib/_patch/jasmine2-plugin.js b/lib/_patch/jasmine2-plugin.js
deleted file mode 100644
index a716cdc..0000000
--- a/lib/_patch/jasmine2-plugin.js
+++ /dev/null
@@ -1,28 +0,0 @@
-(function() {
- var checker = setInterval(function() {
- if (!jasmine.running) {
- var results = {};
- var specs = jsApiReporter.specs();
- results.runtime = jsApiReporter.executionTime();
- results.total = 0;
- results.passed = 0;
- results.failed = 0;
- results.tracebacks = [];
-
- for (var spec in specs) {
- if (specs[spec].status === 'passed') {
- results.passed++;
- } else {
- results.tracebacks.push(specs[spec].description);
- results.failed++;
- }
- }
-
- results.total = results.passed + results.failed;
- results.url = window.location.pathname;
- BrowserStack.post('/_report', results, function(){});
- }
- clearInterval(checker);
- }, 1000);
-})();
-
diff --git a/lib/_patch/mocha-plugin.js b/lib/_patch/mocha-plugin.js
deleted file mode 100644
index a102661..0000000
--- a/lib/_patch/mocha-plugin.js
+++ /dev/null
@@ -1,73 +0,0 @@
-(function() {
- function stack(err) {
- var str = err.stack || err.toString();
-
- if (!~str.indexOf(err.message)) {
- str = err.message + '\n' + str;
- }
-
- if ('[object Error]' == str) {
- str = err.message;
- }
-
- if (!err.stack && err.sourceURL && err.line !== undefined) {
- str += '\n(' + err.sourceURL + ':' + err.line + ')';
- }
- return str.replace(/^/gm, ' ');
- }
-
- function title(test) {
- return test.fullTitle().replace(/#/g, '');
- }
-
- var origReporter = mocha._reporter;
-
- Mocha.BrowserStack = function(runner, root) {
- origReporter.apply(this, arguments);
-
- var count = 1,
- that = this,
- failures = 0,
- passes = 0,
- start = 0,
- tracebacks = [];
-
- runner.on('start', function() {
- start = (new Date).getTime();
- });
-
- runner.on('test end', function(test) {
- count += 1;
- });
-
- runner.on('pass', function(test) {
- passes += 1;
- });
-
- runner.on('fail', function(test, err) {
- failures += 1;
-
- if (err) {
- tracebacks.push(stack(err));
- }
- });
-
- runner.on('end', function() {
- // delay posting results a little to capture "multiple-done" errors
- setTimeout(function () {
- results = {};
- results.runtime = (new Date).getTime() - start;
- results.total = passes + failures;
- results.passed = passes;
- results.failed = failures;
- results.tracebacks = tracebacks;
- results.url = window.location.pathname;
- BrowserStack.post("/_report", results, function(){});
- }, 1000);
- });
- };
-
- Mocha.BrowserStack.prototype = origReporter.prototype;
-
- return Mocha.BrowserStack;
-})();
diff --git a/lib/_patch/qunit-plugin.js b/lib/_patch/qunit-plugin.js
deleted file mode 100644
index 8ef3f10..0000000
--- a/lib/_patch/qunit-plugin.js
+++ /dev/null
@@ -1,62 +0,0 @@
-// For logging assertions on the console, here's what grunt-contrib-qunit uses:
-// https://github.com/gruntjs/grunt-contrib-qunit/blob/784597023e7235337ca9c0651aa45124a2d72341/tasks/qunit.js#L45
-(function (factory) {
- if (typeof define === 'function' && define.amd) {
- require(['qunit'], factory);
- } else {
- factory(QUnit);
- }
-}(function(QUnit) {
- var failedAssertions = [];
- var options,
- currentModule,
- currentTest,
- setTimeoutVariable;
- var pendingTest = {};
-
- var testTimeout = function() {
- var error = {
- testName: currentTest,
- message: "Stuck on this test for 60 sec."
- };
-
- BrowserStack.post('/_progress', {
- tracebacks: [error]
- }, function(){});
- };
-
- QUnit.testDone(function(details) {
- var ct = details.module + " - " + details.name;
- clearTimeout(pendingTest[ct]);
- });
-
- QUnit.testStart(function(details) {
- currentTest = details.module + " - " + details.name;
- pendingTest[currentTest] = setTimeout(function() {
- testTimeout(currentTest);
- }, 60000);
- });
-
- QUnit.log(function(details) {
- if (details.result) {
- return;
- }
-
- var error = {
- actual: details.actual,
- expected: details.expected,
- message: details.message,
- source: details.source,
- testName:( details.module + ": " + details.name)
- };
-
- BrowserStack.post('/_progress', {
- tracebacks: [error]
- }, function(){});
- });
-
- QUnit.done(function(results) {
- results.url = window.location.pathname;
- BrowserStack.post("/_report", results, function(){});
- });
-}));
diff --git a/lib/_patch/reporter.js b/lib/_patch/reporter.js
new file mode 100644
index 0000000..e8006ef
--- /dev/null
+++ b/lib/_patch/reporter.js
@@ -0,0 +1,48 @@
+(function() {
+ var runner;
+ var total = 0,
+ passed = 0,
+ failed = 0;
+
+ if (window.QUnit) {
+ runner = new JsReporters.QUnitAdapter(QUnit);
+ } else if (window.jasmine) {
+ runner = new JsReporters.JasmineAdapter(jasmine.getEnv());
+ } else if (window.mocha) {
+ runner = new JsReporters.MochaAdapter(mocha);
+ } else {
+ throw new Error('JsReporters: No testing framework was found');
+ }
+
+ runner.on('testEnd', function(test) {
+ total = total + 1
+
+ passed = passed + (test.status === 'passed' ? 1 : 0);
+ failed = failed + (test.status === 'failed' ? 1 : 0);
+
+ test.errors.forEach(function(error) {
+ BrowserStack.post("/_progress", {
+ tracebacks: [{
+ actual: error.actual,
+ expected: error.expected,
+ message: error.message,
+ source: error.source || error.stack,
+ testName: test.testName
+ }]
+ }, function() {});
+ });
+ });
+
+ runner.on('runEnd', function(globalSuite) {
+ var results = {};
+
+ results.runtime = globalSuite.runtime;
+ results.total = total;
+ results.passed = passed;
+ results.failed = failed;
+ results.url = window.location.pathname;
+
+ BrowserStack.post("/_report", results, function() {});
+ });
+})();
+
diff --git a/lib/server.js b/lib/server.js
index 180b442..88f2ca5 100644
--- a/lib/server.js
+++ b/lib/server.js
@@ -39,15 +39,17 @@ exports.Server = function Server(bsClient, workers) {
];
var framework_scripts = {
- 'qunit': ['qunit-plugin.js'],
- 'jasmine': ['jasmine-jsreporter.js', 'jasmine-plugin.js'],
- 'jasmine2': ['jasmine2-plugin.js'],
- 'mocha': ['mocha-plugin.js']
+ 'jasmine': ['jasmine-jsreporter.js', 'jasmine-plugin.js']
};
var filePath = path.relative(process.cwd(), filename);
var pathMatches = (testFilePaths.indexOf(filePath) !== -1);
+ var jsReportersPath = path.join(__dirname, '../node_modules/js-reporters/dist/js-reporters.js');
+ var jsReportersScript = fs.readFileSync(jsReportersPath, {
+ encoding: 'utf8'
+ });
+
if (pathMatches) {
var framework = config['test_framework'];
var tag_name = (framework === 'mocha') ? 'head' : 'body';
@@ -57,25 +59,16 @@ exports.Server = function Server(bsClient, workers) {
patch += '\n';
});
+ patch += '';
+
// adding framework scripts
if (framework === 'jasmine') {
framework_scripts['jasmine'].forEach(function(script) {
patch += '\n';
});
patch += '\n';
- } else if (framework === 'jasmine2') {
- framework_scripts['jasmine2'].forEach(function(script) {
- patch += '\n';
- });
- } else if (framework === 'mocha') {
- framework_scripts['mocha'].forEach(function(script) {
- patch += '\n';
- });
- patch += '\n';
- } else if (framework === 'qunit') {
- framework_scripts['qunit'].forEach(function(script) {
- patch += '\n';
- });
+ } else {
+ patch += '\n';
}
patch += '' + tag_name + '>';
return patch;
diff --git a/package.json b/package.json
index abc76b1..1032cb9 100644
--- a/package.json
+++ b/package.json
@@ -10,6 +10,7 @@
"dependencies": {
"browserstack": "1.3.0",
"chalk": "0.4.0",
+ "js-reporters": "^1.0.0",
"mime": "1.3.4",
"send": "0.13.0",
"tunnel": "0.0.3"
diff --git a/tests/external-tests.js b/tests/external-tests.js
index 053803f..e879f3f 100755
--- a/tests/external-tests.js
+++ b/tests/external-tests.js
@@ -13,6 +13,47 @@ var runnerPath = path.resolve(path.join(__dirname, '..', 'bin', 'cli.js'));
var testHome = path.resolve(__dirname);
process.chdir(testHome);
+/**
+ * Mocha v2.4.5 - to change with another Mocha version or
+ * something with Mocha tests
+ *
+ * index.html - 22 tests, 18 passed, 4 failed -> one test is displayed twice,
+ * so they are displayed 5 failing tests, but counted only 4
+ * large.html - 64 tests, 60 passed, 4 failed -> only 2 tests are failing, but
+ * they are displayed twice
+ * opts.html - 8 tests, 2 passed, 6 failed -> only 3 tests are failing, but
+ * they are displayed twice
+ *
+ * By "displayed" it is referred the Mocha HTML Reporter.
+ *
+ * From the above explanations it is clear that there are some inconsistencies,
+ * also because Mocha's HTML Reporter counted number of tests does not match
+ * the number of displyed tests.
+ *
+ * The cause is (snippet from Mocha's HTML reporter):
+ *
+ * runner.on('fail', function(test) {
+ * // For type = 'test' its possible that the test failed due to multiple
+ * // done() calls. So report the issue here.
+ * if (test.type === 'hook'
+ * || test.type === 'test') {
+ * runner.emit('test end', test);
+ * }
+ * });
+ *
+ * This is why failed tests are displayed twice...
+ *
+ * The JsReporters is counting the tests on the "test end" event, that's why
+ * it is capturing the failing tests twice, in the "index.html" it does not
+ * capture everything, because there is an async test, which failure is
+ * triggered after a timeout and the JsReporters is not waiting, because
+ * it cannot know how much to wait.
+ *
+ *
+ * This been said, the JsReporter MochaAdapter is functioning well, this
+ * version of Mocha is not reliable and should be changed.
+ */
+
var repositories = [
{
name: 'qunit',
@@ -31,8 +72,8 @@ var repositories = [
'test/index.html'
],
expected_results: {
- tests: 534,
- passed: 534,
+ tests: 133,
+ passed: 130,
failed: 0
}
},
@@ -55,9 +96,9 @@ var repositories = [
'test/browser/opts.html'
],
expected_results: {
- tests: 89,
+ tests: 94,
passed: 80,
- failed: 9
+ failed: 14
}
},
{
@@ -113,29 +154,6 @@ var repositories = [
];
var repositoriesOptional = [
- {
- name: 'qunit',
- tag: 'v1.0.0',
- url: 'https://github.com/jquery/qunit.git',
- test_framework: 'qunit',
- browsers: [
- {
- 'browser': 'firefox',
- 'browser_version': '44.0',
- 'os': 'OS X',
- 'os_version': 'Snow Leopard'
- }
- ],
- test_path: [
- 'test/index.html',
- 'test/logs.html'
- ],
- expected_results: {
- tests: 323,
- passed: 323,
- failed: 0
- }
- },
{
name: 'mocha',
tag: '1.21.5',
@@ -155,9 +173,9 @@ var repositoriesOptional = [
'test/browser/opts.html'
],
expected_results: {
- tests: 84,
+ tests: 83,
passed: 77,
- failed: 7
+ failed: 6
}
}
];