Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More jasmine2 updates #2

Merged
merged 10 commits into from Jun 2, 2015
Expand Up @@ -62,7 +62,7 @@ describe('HasteModuleLoader', function() {
return buildLoader().then(function(loader) {
expect(function() {
loader.requireModule(null, 'DoesntExist');
}).toThrow('Cannot find module \'DoesntExist\' from \'.\'');
}).toThrow(new Error('Cannot find module \'DoesntExist\' from \'.\''));
});
});

Expand Down Expand Up @@ -90,9 +90,9 @@ describe('HasteModuleLoader', function() {
return buildLoader().then(function(loader) {
expect(function() {
loader.requireModule(__filename, './DoesntExist');
}).toThrow(
}).toThrow(new Error(
'Cannot find module \'./DoesntExist\' from \'' + __filename + '\''
);
));
});
});

Expand Down
204 changes: 0 additions & 204 deletions src/jasmine2TestRunner/JasmineReporter.js

This file was deleted.

89 changes: 89 additions & 0 deletions src/jasmineTestRunner/Jasmine2Reporter.js
@@ -0,0 +1,89 @@
/**
* Copyright (c) 2014, Facebook, Inc. All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
'use strict';

var jasmineRequire = require('../../vendor/jasmine/jasmine-2.2.0');
var jasmine = jasmineRequire.core(jasmineRequire);
var Q = require('q');
var JasmineFormatter = require('./jasmineFormatter');

function Jasmine2Reporter(config) {
this._config = config || {};
this._formatter = new JasmineFormatter(jasmine, config);
this._resultsDeferred = Q.defer();
this._testResults = [];
this._currentSuites = [];
}

Jasmine2Reporter.prototype.specDone = function(result) {
this._testResults.push(this._extractSpecResults(result,
this._currentSuites.slice(0)));
};

Jasmine2Reporter.prototype.suiteStarted = function(suite) {
this._currentSuites.push(suite.description);
};

Jasmine2Reporter.prototype.suiteDone = function() {
this._currentSuites.pop();
};

Jasmine2Reporter.prototype.jasmineDone = function() {

var numFailingTests = 0;
var numPassingTests = 0;

this._testResults.forEach(function(testResult) {
if (testResult.failureMessages.length > 0) {
numFailingTests++;
} else {
numPassingTests++;
}
});

this._resultsDeferred.resolve({
numFailingTests: numFailingTests,
numPassingTests: numPassingTests,
testResults: this._testResults
});
};

Jasmine2Reporter.prototype.getResults = function() {
return this._resultsDeferred.promise;
};

Jasmine2Reporter.prototype._extractSpecResults =
function(specResult, currentSuites) {
var results = {
title: 'it ' + specResult.description,
ancestorTitles: currentSuites,
failureMessages: [],
logMessages: [], // Jasmine 2 does not have a logging interface
numPassingAsserts: 0 // Jasmine 2 only returns an array of failed asserts.
};

specResult.failedExpectations.forEach(function(failed) {
if (!failed.matcherName) { // exception

results.failureMessages.push(
this._formatter.formatException(failed.stack)
);

} else { // match failure

results.failureMessages.push(
this._formatter.formatMatchFailure(failed)
);

}
}.bind(this));

return results;
};

module.exports = Jasmine2Reporter;