Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: Good day. This patch adds optional `jasmine 2.x` support to `jest`. Benefits: * bundled `jasmine` is not modified, it can be updated any time * `done` callback support * whatever you need from `jasmine-2.x` TODOs: - [ ] make jeffmo/jasmine-pit#12 work, so I can remove dependency on my fork of `jasmine-pit` - [x] extract base code for both runners - [x] update matchers as I haven't tested them after update - [x] fix all TODO's - [x] add note about `jasmine 1.x` and `jasmine 2.x` differences Patches are welcome. Closes #330 Reviewed By: zpao Differential Revision: D2662964 fb-gh-sync-id: 13e3b9116a350e46a0271f6ceb26cf2af316f20e
- Loading branch information
Showing
18 changed files
with
3,988 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/** | ||
* 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.3.4.js'); | ||
var jasmine = jasmineRequire.core(jasmineRequire); | ||
var JasmineFormatter = require('./jasmineFormatter'); | ||
|
||
function Jasmine2Reporter(config) { | ||
this._config = config || {}; | ||
this._formatter = new JasmineFormatter(jasmine, config); | ||
this._resultsDeferred = Promise.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(failed => { | ||
if (!failed.matcherName) { // exception | ||
|
||
results.failureMessages.push( | ||
this._formatter.formatException(failed.stack) | ||
); | ||
|
||
} else { // match failure | ||
|
||
results.failureMessages.push( | ||
this._formatter.formatMatchFailure(failed) | ||
); | ||
|
||
} | ||
}); | ||
|
||
return results; | ||
}; | ||
|
||
module.exports = Jasmine2Reporter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.