Skip to content

Commit 4306e4d

Browse files
authored
Merge pull request #159 from flore77/master
Integrate JsReporters
2 parents d14d048 + d86ffed commit 4306e4d

File tree

7 files changed

+106
-209
lines changed

7 files changed

+106
-209
lines changed

lib/_patch/jasmine2-plugin.js

Lines changed: 0 additions & 28 deletions
This file was deleted.

lib/_patch/mocha-plugin.js

Lines changed: 0 additions & 73 deletions
This file was deleted.

lib/_patch/qunit-plugin.js

Lines changed: 0 additions & 62 deletions
This file was deleted.

lib/_patch/reporter.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
(function() {
2+
var runner;
3+
var total = 0,
4+
passed = 0,
5+
failed = 0;
6+
7+
if (window.QUnit) {
8+
runner = new JsReporters.QUnitAdapter(QUnit);
9+
} else if (window.jasmine) {
10+
runner = new JsReporters.JasmineAdapter(jasmine.getEnv());
11+
} else if (window.mocha) {
12+
runner = new JsReporters.MochaAdapter(mocha);
13+
} else {
14+
throw new Error('JsReporters: No testing framework was found');
15+
}
16+
17+
runner.on('testEnd', function(test) {
18+
total = total + 1
19+
20+
passed = passed + (test.status === 'passed' ? 1 : 0);
21+
failed = failed + (test.status === 'failed' ? 1 : 0);
22+
23+
test.errors.forEach(function(error) {
24+
BrowserStack.post("/_progress", {
25+
tracebacks: [{
26+
actual: error.actual,
27+
expected: error.expected,
28+
message: error.message,
29+
source: error.source || error.stack,
30+
testName: test.testName
31+
}]
32+
}, function() {});
33+
});
34+
});
35+
36+
runner.on('runEnd', function(globalSuite) {
37+
var results = {};
38+
39+
results.runtime = globalSuite.runtime;
40+
results.total = total;
41+
results.passed = passed;
42+
results.failed = failed;
43+
results.url = window.location.pathname;
44+
45+
BrowserStack.post("/_report", results, function() {});
46+
});
47+
})();
48+

lib/server.js

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,17 @@ exports.Server = function Server(bsClient, workers) {
3939
];
4040

4141
var framework_scripts = {
42-
'qunit': ['qunit-plugin.js'],
43-
'jasmine': ['jasmine-jsreporter.js', 'jasmine-plugin.js'],
44-
'jasmine2': ['jasmine2-plugin.js'],
45-
'mocha': ['mocha-plugin.js']
42+
'jasmine': ['jasmine-jsreporter.js', 'jasmine-plugin.js']
4643
};
4744

4845
var filePath = path.relative(process.cwd(), filename);
4946
var pathMatches = (testFilePaths.indexOf(filePath) !== -1);
5047

48+
var jsReportersPath = path.join(__dirname, '../node_modules/js-reporters/dist/js-reporters.js');
49+
var jsReportersScript = fs.readFileSync(jsReportersPath, {
50+
encoding: 'utf8'
51+
});
52+
5153
if (pathMatches) {
5254
var framework = config['test_framework'];
5355
var tag_name = (framework === 'mocha') ? 'head' : 'body';
@@ -57,25 +59,16 @@ exports.Server = function Server(bsClient, workers) {
5759
patch += '<script type="text/javascript" src="/_patch/' + script + '"></script>\n';
5860
});
5961

62+
patch += '<script type="text/javascript">' + jsReportersScript + '</script>';
63+
6064
// adding framework scripts
6165
if (framework === 'jasmine') {
6266
framework_scripts['jasmine'].forEach(function(script) {
6367
patch += '<script type="text/javascript" src="/_patch/' + script + '"></script>\n';
6468
});
6569
patch += '<script type="text/javascript">jasmine.getEnv().addReporter(new jasmine.JSReporter());</script>\n';
66-
} else if (framework === 'jasmine2') {
67-
framework_scripts['jasmine2'].forEach(function(script) {
68-
patch += '<script type="text/javascript" src="/_patch/' + script + '"></script>\n';
69-
});
70-
} else if (framework === 'mocha') {
71-
framework_scripts['mocha'].forEach(function(script) {
72-
patch += '<script type="text/javascript" src="/_patch/' + script + '"></script>\n';
73-
});
74-
patch += '<script type="text/javascript">mocha.reporter(Mocha.BrowserStack);</script>\n';
75-
} else if (framework === 'qunit') {
76-
framework_scripts['qunit'].forEach(function(script) {
77-
patch += '<script type="text/javascript" src="/_patch/' + script + '"></script>\n';
78-
});
70+
} else {
71+
patch += '<script type="text/javascript" src="/_patch/reporter.js"></script>\n';
7972
}
8073
patch += '</' + tag_name + '>';
8174
return patch;

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"dependencies": {
1111
"browserstack": "1.3.0",
1212
"chalk": "0.4.0",
13+
"js-reporters": "^1.0.0",
1314
"mime": "1.3.4",
1415
"send": "0.13.0",
1516
"tunnel": "0.0.3"

tests/external-tests.js

Lines changed: 47 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,47 @@ var runnerPath = path.resolve(path.join(__dirname, '..', 'bin', 'cli.js'));
1313
var testHome = path.resolve(__dirname);
1414
process.chdir(testHome);
1515

16+
/**
17+
* Mocha v2.4.5 - to change with another Mocha version or
18+
* something with Mocha tests
19+
*
20+
* index.html - 22 tests, 18 passed, 4 failed -> one test is displayed twice,
21+
* so they are displayed 5 failing tests, but counted only 4
22+
* large.html - 64 tests, 60 passed, 4 failed -> only 2 tests are failing, but
23+
* they are displayed twice
24+
* opts.html - 8 tests, 2 passed, 6 failed -> only 3 tests are failing, but
25+
* they are displayed twice
26+
*
27+
* By "displayed" it is referred the Mocha HTML Reporter.
28+
*
29+
* From the above explanations it is clear that there are some inconsistencies,
30+
* also because Mocha's HTML Reporter counted number of tests does not match
31+
* the number of displyed tests.
32+
*
33+
* The cause is (snippet from Mocha's HTML reporter):
34+
*
35+
* runner.on('fail', function(test) {
36+
* // For type = 'test' its possible that the test failed due to multiple
37+
* // done() calls. So report the issue here.
38+
* if (test.type === 'hook'
39+
* || test.type === 'test') {
40+
* runner.emit('test end', test);
41+
* }
42+
* });
43+
*
44+
* This is why failed tests are displayed twice...
45+
*
46+
* The JsReporters is counting the tests on the "test end" event, that's why
47+
* it is capturing the failing tests twice, in the "index.html" it does not
48+
* capture everything, because there is an async test, which failure is
49+
* triggered after a timeout and the JsReporters is not waiting, because
50+
* it cannot know how much to wait.
51+
*
52+
*
53+
* This been said, the JsReporter MochaAdapter is functioning well, this
54+
* version of Mocha is not reliable and should be changed.
55+
*/
56+
1657
var repositories = [
1758
{
1859
name: 'qunit',
@@ -31,8 +72,8 @@ var repositories = [
3172
'test/index.html'
3273
],
3374
expected_results: {
34-
tests: 534,
35-
passed: 534,
75+
tests: 133,
76+
passed: 130,
3677
failed: 0
3778
}
3879
},
@@ -55,9 +96,9 @@ var repositories = [
5596
'test/browser/opts.html'
5697
],
5798
expected_results: {
58-
tests: 89,
99+
tests: 94,
59100
passed: 80,
60-
failed: 9
101+
failed: 14
61102
}
62103
},
63104
{
@@ -113,29 +154,6 @@ var repositories = [
113154
];
114155

115156
var repositoriesOptional = [
116-
{
117-
name: 'qunit',
118-
tag: 'v1.0.0',
119-
url: 'https://github.com/jquery/qunit.git',
120-
test_framework: 'qunit',
121-
browsers: [
122-
{
123-
'browser': 'firefox',
124-
'browser_version': '44.0',
125-
'os': 'OS X',
126-
'os_version': 'Snow Leopard'
127-
}
128-
],
129-
test_path: [
130-
'test/index.html',
131-
'test/logs.html'
132-
],
133-
expected_results: {
134-
tests: 323,
135-
passed: 323,
136-
failed: 0
137-
}
138-
},
139157
{
140158
name: 'mocha',
141159
tag: '1.21.5',
@@ -155,9 +173,9 @@ var repositoriesOptional = [
155173
'test/browser/opts.html'
156174
],
157175
expected_results: {
158-
tests: 84,
176+
tests: 83,
159177
passed: 77,
160-
failed: 7
178+
failed: 6
161179
}
162180
}
163181
];

0 commit comments

Comments
 (0)