Skip to content

Commit

Permalink
Update report structure
Browse files Browse the repository at this point in the history
  • Loading branch information
vedharish committed Aug 9, 2016
1 parent 43c2b6e commit 87f4392
Show file tree
Hide file tree
Showing 7 changed files with 232 additions and 174 deletions.
166 changes: 104 additions & 62 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# BrowserStack Runner

[![Build Status](https://travis-ci.org/browserstack/browserstack-runner.svg?branch=master)](https://travis-ci.org/browserstack/browserstack-runner)

A command line interface to run browser tests over BrowserStack.

## Usage
Expand Down Expand Up @@ -28,7 +32,6 @@ Where `[user]` is replaced with a local user with enough permissions.
```node
var browserstackRunner = require('browserstack-runner');

global.logLevel = 'info';
var config = require('./browserstack.json');

browserstackRunner.run(config, function(error, report) {
Expand All @@ -42,76 +45,115 @@ browserstackRunner.run(config, function(error, report) {
```

The callback to `browserstackRunner.run` is called with two params -
1. `error`: This parameter is either `null` or an `Error` object (if test execution failed) with message as the reason of why executing the tests on `BrowserStack` failed.
2. `report`: This is an object which can be used to keep track of the `failed assertions` and the total count of `passed/failed` tests specific to a browser instance.
- `error`: This parameter is either `null` or an `Error` object (if test execution failed) with message as the reason of why executing the tests on `BrowserStack` failed.
- `report`: This is an array which can be used to keep track of the executed tests and suites in a run. Each object in the array has the following keys -
- `browser`: The name of the browser the test executed on.
- `tests`: An array of `Test` objects. The `Test` Objects are described [here](https://github.com/js-reporters/js-reporters#event-data)
- `suites`: A global Suite Object as described [here](https://github.com/js-reporters/js-reporters#event-data)

The structure of the `report` object is as follows -

```json
{
"OS X Lion, Firefox 44.0": {
"assertions": [
{
"actual": false,
"expected": true,
"message": "One is an odd number",
"source": "@http://localhost:8888/tests/test.js:4:1"
},
{
"actual": false,
"expected": true,
"message": "Zero is not odd number",
"source": "@http://localhost:8888/tests/test.js:6:3"
},
{
"actual": false,
"expected": true,
"message": "Three is an odd number",
"source": "@http://localhost:8888/tests/test.js:5:1"
}
],
"tests": [
[
{
"browser": "Windows 7, Firefox 47.0",
"tests": [
{
"runtime": 3,
"total": 1,
"passed": 0,
"failed": 1,
"url": "/sample.html"
"name": "isOdd()",
"suiteName": "Odd Tests",
"fullName": [
"Odd Tests",
"isOdd()"
],
"status": "passed",
"runtime": 2,
"errors": [],
"assertions": [
{
"passed": true,
"actual": true,
"expected": true,
"message": "One is an odd number"
},
{
"passed": true,
"actual": true,
"expected": true,
"message": "Three is an odd number"
},
{
"passed": true,
"actual": true,
"expected": true,
"message": "Zero is not odd number"
}
]
}
]
},
"OS X Mountain Lion, Chrome 49.0": {
"assertions": [
{
"actual": false,
"expected": true,
"message": "Three is an odd number",
"source": " at Object.<anonymous> (http://localhost:8888/tests/test.js:5:10)"
},
{
"actual": false,
"expected": true,
"message": "One is an odd number",
"source": " at Object.<anonymous> (http://localhost:8888/tests/test.js:4:10)"
},
{
"actual": false,
"expected": true,
"message": "Zero is not odd number",
"source": " at Object.<anonymous> (http://localhost:8888/tests/test.js:6:10)"
}
],
"tests": [
],
"suites": {
"fullName": [],
"childSuites": [
{
"runtime": 9,
"total": 1,
"passed": 0,
"failed": 1,
"url": "/sample.html"
"name": "Odd Tests",
"fullName": [
"Odd Tests"
],
"childSuites": [],
"tests": [
{
"name": "isOdd()",
"suiteName": "Odd Tests",
"fullName": [
"Odd Tests",
"isOdd()"
],
"status": "passed",
"runtime": 2,
"errors": [],
"assertions": [
{
"passed": true,
"actual": true,
"expected": true,
"message": "One is an odd number"
},
{
"passed": true,
"actual": true,
"expected": true,
"message": "Three is an odd number"
},
{
"passed": true,
"actual": true,
"expected": true,
"message": "Zero is not odd number"
}
]
}
],
"status": "passed",
"testCounts": {
"passed": 1,
"failed": 0,
"skipped": 0,
"total": 1
},
"runtime": 2
}
]
],
"tests": [],
"status": "passed",
"testCounts": {
"passed": 1,
"failed": 0,
"skipped": 0,
"total": 1
},
"runtime": 2
}
}
}
]
```

## Configuration
Expand Down
10 changes: 5 additions & 5 deletions bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ function terminateAllWorkers(callback) {
function cleanUpAndExit(signal, error, report, callback) {
ConfigParser.finalBrowsers = [];
callback = callback || function() {};
report = report || {};
report = report || [];
logger.trace('cleanUpAndExit: signal: %s', signal);

try {
Expand Down Expand Up @@ -306,8 +306,8 @@ var statusPoller = {
}

logger.trace('[%s] worker.activityTimeout: all tests done', worker.id, config.status && 'with failures');
if(server && server.report) {
callback(null, server.report);
if(server && server.reports) {
callback(null, server.reports);
} else {
callback(null, {});
}
Expand Down Expand Up @@ -336,8 +336,8 @@ var statusPoller = {
}

logger.trace('[%s] worker.testActivityTimeout: all tests done', worker.id, config.status && 'with failures');
if(server && server.report) {
callback(null, server.report);
if(server && server.reports) {
callback(null, server.reports);
} else {
callback(null, {});
}
Expand Down
30 changes: 3 additions & 27 deletions lib/_patch/reporter.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
(function() {
var runner;
var total = 0,
passed = 0,
failed = 0;

if (window.QUnit) {
runner = new JsReporters.QUnitAdapter(QUnit);
Expand All @@ -15,34 +12,13 @@
}

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() {});
BrowserStack.post("/_progress", {
test: test
});
});

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() {});
BrowserStack.post("/_report", globalSuite, function() {});
});
})();

2 changes: 1 addition & 1 deletion lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ exports.config = function(config) {
fallback_project = 'Anonymous OpenSource Project';
}

this.project = process.env.TRAVIS_REPO_SLUG || package_json.name;
this.project = process.env.TRAVIS_REPO_SLUG || fallback_project || package_json.name;
}

var commit_id = process.env.TRAVIS_COMMIT;
Expand Down
Loading

0 comments on commit 87f4392

Please sign in to comment.