Compare commits
37 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e022e6199c | ||
|
|
140c12e8fc | ||
|
|
d0e1bd96fb | ||
|
|
6c56ebc984 | ||
|
|
d0a9931ae6 | ||
|
|
93c5f654d9 | ||
|
|
d8b65028a1 | ||
|
|
d6cdc1841c | ||
|
|
72b39220e5 | ||
|
|
55dce7d119 | ||
|
|
789736dd02 | ||
|
|
c7ca3b0101 | ||
|
|
96000220b1 | ||
|
|
e2e2275d41 | ||
|
|
135ff20123 | ||
|
|
4af86f5398 | ||
|
|
e5e0e6481d | ||
|
|
bcf69b86b4 | ||
|
|
a5f79fac81 | ||
|
|
18a00822c5 | ||
|
|
4cc8437f79 | ||
|
|
8e58305b0a | ||
|
|
bd368aceee | ||
|
|
8f16021887 | ||
|
|
bbb1b69b2e | ||
|
|
9ea8a2096f | ||
|
|
66340e2b19 | ||
|
|
fe29dfa89c | ||
|
|
41f7fabe2f | ||
|
|
856a040a2d | ||
|
|
f7eaa5ec29 | ||
|
|
0c87d47318 | ||
|
|
c24b2f5a73 | ||
|
|
774c83a36e | ||
|
|
751cf6ab5b | ||
|
|
2fd76c954c | ||
|
|
bb4d18f959 |
25
README.md
25
README.md
@@ -2,17 +2,12 @@
|
|||||||
|
|
||||||
[](https://circleci.com/gh/jasmine/jasmine)
|
[](https://circleci.com/gh/jasmine/jasmine)
|
||||||
[](https://www.codetriage.com/jasmine/jasmine)
|
[](https://www.codetriage.com/jasmine/jasmine)
|
||||||
[](https://app.fossa.io/projects/git%2Bgithub.com%2Fjasmine%2Fjasmine?ref=badge_shield)
|
|
||||||
|
|
||||||
# A JavaScript Testing Framework
|
# A JavaScript Testing Framework
|
||||||
|
|
||||||
Jasmine is a Behavior Driven Development testing framework for JavaScript. It does not rely on browsers, DOM, or any JavaScript framework. Thus it's suited for websites, [Node.js](http://nodejs.org) projects, or anywhere that JavaScript can run.
|
Jasmine is a Behavior Driven Development testing framework for JavaScript. It does not rely on browsers, DOM, or any JavaScript framework. Thus it's suited for websites, [Node.js](http://nodejs.org) projects, or anywhere that JavaScript can run.
|
||||||
|
|
||||||
Documentation & guides live here: [http://jasmine.github.io](http://jasmine.github.io/)
|
Upgrading from Jasmine 3.x? Check out the [upgrade guide](https://jasmine.github.io/tutorials/upgrading_to_Jasmine_4.0).
|
||||||
For a quick start guide of Jasmine, see the beginning of [http://jasmine.github.io/edge/introduction.html](http://jasmine.github.io/edge/introduction.html).
|
|
||||||
|
|
||||||
Upgrading from Jasmine 3.x? Check out the 4.0 release notes for a list of
|
|
||||||
what's new (including breaking changes). You can also read the [upgrade guide](https://jasmine.github.io/tutorials/upgrading_to_Jasmine_4.0).
|
|
||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
|
|
||||||
@@ -28,7 +23,7 @@ for details.
|
|||||||
|
|
||||||
See the [documentation site](https://jasmine.github.io/pages/docs_home.html),
|
See the [documentation site](https://jasmine.github.io/pages/docs_home.html),
|
||||||
particularly the [Your First Suite tutorial](https://jasmine.github.io/tutorials/your_first_suite)
|
particularly the [Your First Suite tutorial](https://jasmine.github.io/tutorials/your_first_suite)
|
||||||
for information on writing specs.
|
for information on writing specs, and [the FAQ](https://jasmine.github.io/pages/faq.html).
|
||||||
|
|
||||||
## Supported environments
|
## Supported environments
|
||||||
|
|
||||||
@@ -47,15 +42,7 @@ For evergreen browsers, each version of Jasmine is tested against the version of
|
|||||||
at the time of release. Other browsers, as well as older & newer versions of some supported browsers, are likely to work.
|
at the time of release. Other browsers, as well as older & newer versions of some supported browsers, are likely to work.
|
||||||
However, Jasmine isn't tested against them and they aren't actively supported.
|
However, Jasmine isn't tested against them and they aren't actively supported.
|
||||||
|
|
||||||
See the [release notes](https://github.com/jasmine/jasmine/tree/main/release_notes)
|
To find out what environments work with a particular Jasmine release, see the [release notes](https://github.com/jasmine/jasmine/tree/main/release_notes).
|
||||||
for the supported environments for each Jasmine release.
|
|
||||||
|
|
||||||
## Support
|
|
||||||
|
|
||||||
* Search past discussions: [http://groups.google.com/group/jasmine-js](http://groups.google.com/group/jasmine-js).
|
|
||||||
* Send an email to the list: [jasmine-js@googlegroups.com](mailto:jasmine-js@googlegroups.com).
|
|
||||||
* View the project backlog at Pivotal Tracker: [http://www.pivotaltracker.com/projects/10606](http://www.pivotaltracker.com/projects/10606).
|
|
||||||
* Follow us on Twitter: [@JasmineBDD](http://twitter.com/JasmineBDD).
|
|
||||||
|
|
||||||
## Maintainers
|
## Maintainers
|
||||||
|
|
||||||
@@ -71,8 +58,4 @@ for the supported environments for each Jasmine release.
|
|||||||
* [Christian Williams](mailto:antixian666@gmail.com)
|
* [Christian Williams](mailto:antixian666@gmail.com)
|
||||||
* Sheel Choksi
|
* Sheel Choksi
|
||||||
|
|
||||||
Copyright (c) 2008-2022 Jasmine Maintainers. This software is licensed under the MIT License.
|
Copyright (c) 2008-2022 Jasmine Maintainers. This software is licensed under the [MIT License](https://github.com/jasmine/jasmine/blob/main/MIT.LICENSE).
|
||||||
|
|
||||||
|
|
||||||
## License
|
|
||||||
[](https://app.fossa.io/projects/git%2Bgithub.com%2Fjasmine%2Fjasmine?ref=badge_large)
|
|
||||||
|
|||||||
12
RELEASE.md
12
RELEASE.md
@@ -35,10 +35,10 @@ When ready to release - specs are all green and the stories are done:
|
|||||||
|
|
||||||
### Commit and push core changes
|
### Commit and push core changes
|
||||||
|
|
||||||
1. Run the browser tests using `scripts/run-all-browsers`.
|
|
||||||
1. Commit release notes and version changes (jasmine.js, package.json)
|
1. Commit release notes and version changes (jasmine.js, package.json)
|
||||||
1. Push
|
2. Push
|
||||||
1. Wait for Circle CI to go green
|
3. Tag the release and push the tag.
|
||||||
|
4. Wait for Circle CI to go green
|
||||||
|
|
||||||
### Build standalone distribution
|
### Build standalone distribution
|
||||||
|
|
||||||
@@ -47,13 +47,14 @@ When ready to release - specs are all green and the stories are done:
|
|||||||
|
|
||||||
### Release the core NPM module
|
### Release the core NPM module
|
||||||
|
|
||||||
1. Run the tests on Windows. (CI only tests on Linux.)
|
|
||||||
1. `npm adduser` to save your credentials locally
|
1. `npm adduser` to save your credentials locally
|
||||||
1. `npm publish .` to publish what's in `package.json`
|
1. `npm publish .` to publish what's in `package.json`
|
||||||
|
|
||||||
### Release the docs
|
### Release the docs
|
||||||
|
|
||||||
Probably only need to do this when releasing a minor version, and not a patch version.
|
Probably only need to do this when releasing a minor version, and not a patch
|
||||||
|
version. See [the README file in the docs repo](https://github.com/jasmine/jasmine.github.io/blob/master/README.md)
|
||||||
|
for instructions.
|
||||||
|
|
||||||
1. `rake update_edge_jasmine`
|
1. `rake update_edge_jasmine`
|
||||||
1. `npm run jsdoc`
|
1. `npm run jsdoc`
|
||||||
@@ -68,7 +69,6 @@ Probably only need to do this when releasing a minor version, and not a patch ve
|
|||||||
1. In `package.json`, update both the package version and the jasmine-core dependency version
|
1. In `package.json`, update both the package version and the jasmine-core dependency version
|
||||||
1. Commit and push.
|
1. Commit and push.
|
||||||
1. Wait for Circle CI to go green again.
|
1. Wait for Circle CI to go green again.
|
||||||
1. Run the tests on Windows locally.
|
|
||||||
1. `grunt release `. (Note: This will publish the package by running `npm publish`.)
|
1. `grunt release `. (Note: This will publish the package by running `npm publish`.)
|
||||||
|
|
||||||
### Finally
|
### Finally
|
||||||
|
|||||||
@@ -37,16 +37,16 @@ module.exports.noGlobals = (function() {
|
|||||||
};
|
};
|
||||||
}());
|
}());
|
||||||
|
|
||||||
var path = require('path'),
|
const path = require('path'),
|
||||||
fs = require('fs');
|
fs = require('fs');
|
||||||
|
|
||||||
var rootPath = path.join(__dirname, "jasmine-core"),
|
const rootPath = path.join(__dirname, 'jasmine-core'),
|
||||||
bootFiles = ['boot0.js', 'boot1.js'],
|
bootFiles = ['boot0.js', 'boot1.js'],
|
||||||
legacyBootFiles = ['boot.js'],
|
legacyBootFiles = ['boot.js'],
|
||||||
nodeBootFiles = ['node_boot.js'],
|
nodeBootFiles = ['node_boot.js'],
|
||||||
cssFiles = [],
|
cssFiles = [],
|
||||||
jsFiles = [],
|
jsFiles = [],
|
||||||
jsFilesToSkip = ['jasmine.js'].concat(bootFiles, legacyBootFiles, nodeBootFiles);
|
jsFilesToSkip = ['jasmine.js'].concat(bootFiles, legacyBootFiles, nodeBootFiles);
|
||||||
|
|
||||||
fs.readdirSync(rootPath).forEach(function(file) {
|
fs.readdirSync(rootPath).forEach(function(file) {
|
||||||
if(fs.statSync(path.join(rootPath, file)).isFile()) {
|
if(fs.statSync(path.join(rootPath, file)).isFile()) {
|
||||||
|
|||||||
@@ -27,14 +27,14 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||||||
source files or spec files are loaded.
|
source files or spec files are loaded.
|
||||||
*/
|
*/
|
||||||
(function() {
|
(function() {
|
||||||
var jasmineRequire = window.jasmineRequire || require('./jasmine.js');
|
const jasmineRequire = window.jasmineRequire || require('./jasmine.js');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ## Require & Instantiate
|
* ## Require & Instantiate
|
||||||
*
|
*
|
||||||
* Require Jasmine's core files. Specifically, this requires and attaches all of Jasmine's code to the `jasmine` reference.
|
* Require Jasmine's core files. Specifically, this requires and attaches all of Jasmine's code to the `jasmine` reference.
|
||||||
*/
|
*/
|
||||||
var jasmine = jasmineRequire.core(jasmineRequire),
|
const jasmine = jasmineRequire.core(jasmineRequire),
|
||||||
global = jasmine.getGlobal();
|
global = jasmine.getGlobal();
|
||||||
global.jasmine = jasmine;
|
global.jasmine = jasmine;
|
||||||
|
|
||||||
@@ -46,19 +46,19 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||||||
/**
|
/**
|
||||||
* Create the Jasmine environment. This is used to run all specs in a project.
|
* Create the Jasmine environment. This is used to run all specs in a project.
|
||||||
*/
|
*/
|
||||||
var env = jasmine.getEnv();
|
const env = jasmine.getEnv();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ## The Global Interface
|
* ## The Global Interface
|
||||||
*
|
*
|
||||||
* Build up the functions that will be exposed as the Jasmine public interface. A project can customize, rename or alias any of these functions as desired, provided the implementation remains unchanged.
|
* Build up the functions that will be exposed as the Jasmine public interface. A project can customize, rename or alias any of these functions as desired, provided the implementation remains unchanged.
|
||||||
*/
|
*/
|
||||||
var jasmineInterface = jasmineRequire.interface(jasmine, env);
|
const jasmineInterface = jasmineRequire.interface(jasmine, env);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add all of the Jasmine global/public interface to the global scope, so a project can use the public interface directly. For example, calling `describe` in specs instead of `jasmine.getEnv().describe`.
|
* Add all of the Jasmine global/public interface to the global scope, so a project can use the public interface directly. For example, calling `describe` in specs instead of `jasmine.getEnv().describe`.
|
||||||
*/
|
*/
|
||||||
for (var property in jasmineInterface) {
|
for (const property in jasmineInterface) {
|
||||||
global[property] = jasmineInterface[property];
|
global[property] = jasmineInterface[property];
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
var env = jasmine.getEnv();
|
const env = jasmine.getEnv();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ## Runner Parameters
|
* ## Runner Parameters
|
||||||
@@ -42,15 +42,15 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||||||
* More browser specific code - wrap the query string in an object and to allow for getting/setting parameters from the runner user interface.
|
* More browser specific code - wrap the query string in an object and to allow for getting/setting parameters from the runner user interface.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var queryString = new jasmine.QueryString({
|
const queryString = new jasmine.QueryString({
|
||||||
getWindowLocation: function() {
|
getWindowLocation: function() {
|
||||||
return window.location;
|
return window.location;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
var filterSpecs = !!queryString.getParam('spec');
|
const filterSpecs = !!queryString.getParam('spec');
|
||||||
|
|
||||||
var config = {
|
const config = {
|
||||||
stopOnSpecFailure: queryString.getParam('stopOnSpecFailure'),
|
stopOnSpecFailure: queryString.getParam('stopOnSpecFailure'),
|
||||||
stopSpecOnExpectationFailure: queryString.getParam(
|
stopSpecOnExpectationFailure: queryString.getParam(
|
||||||
'stopSpecOnExpectationFailure'
|
'stopSpecOnExpectationFailure'
|
||||||
@@ -58,13 +58,13 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||||||
hideDisabled: queryString.getParam('hideDisabled')
|
hideDisabled: queryString.getParam('hideDisabled')
|
||||||
};
|
};
|
||||||
|
|
||||||
var random = queryString.getParam('random');
|
const random = queryString.getParam('random');
|
||||||
|
|
||||||
if (random !== undefined && random !== '') {
|
if (random !== undefined && random !== '') {
|
||||||
config.random = random;
|
config.random = random;
|
||||||
}
|
}
|
||||||
|
|
||||||
var seed = queryString.getParam('seed');
|
const seed = queryString.getParam('seed');
|
||||||
if (seed) {
|
if (seed) {
|
||||||
config.seed = seed;
|
config.seed = seed;
|
||||||
}
|
}
|
||||||
@@ -73,7 +73,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||||||
* ## Reporters
|
* ## Reporters
|
||||||
* The `HtmlReporter` builds all of the HTML UI for the runner page. This reporter paints the dots, stars, and x's for specs, as well as all spec names and all failures (if any).
|
* The `HtmlReporter` builds all of the HTML UI for the runner page. This reporter paints the dots, stars, and x's for specs, as well as all spec names and all failures (if any).
|
||||||
*/
|
*/
|
||||||
var htmlReporter = new jasmine.HtmlReporter({
|
const htmlReporter = new jasmine.HtmlReporter({
|
||||||
env: env,
|
env: env,
|
||||||
navigateWithNewParam: function(key, value) {
|
navigateWithNewParam: function(key, value) {
|
||||||
return queryString.navigateWithNewParam(key, value);
|
return queryString.navigateWithNewParam(key, value);
|
||||||
@@ -103,7 +103,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||||||
/**
|
/**
|
||||||
* Filter which specs will be run by matching the start of the full name against the `spec` query param.
|
* Filter which specs will be run by matching the start of the full name against the `spec` query param.
|
||||||
*/
|
*/
|
||||||
var specFilter = new jasmine.HtmlSpecFilter({
|
const specFilter = new jasmine.HtmlSpecFilter({
|
||||||
filterString: function() {
|
filterString: function() {
|
||||||
return queryString.getParam('spec');
|
return queryString.getParam('spec');
|
||||||
}
|
}
|
||||||
@@ -120,7 +120,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||||||
*
|
*
|
||||||
* Replace the browser window's `onload`, ensure it's called, and then run all of the loaded specs. This includes initializing the `HtmlReporter` instance and then executing the loaded Jasmine environment. All of this will happen after all of the specs are loaded.
|
* Replace the browser window's `onload`, ensure it's called, and then run all of the loaded specs. This includes initializing the `HtmlReporter` instance and then executing the loaded Jasmine environment. All of this will happen after all of the specs are loaded.
|
||||||
*/
|
*/
|
||||||
var currentWindowOnload = window.onload;
|
const currentWindowOnload = window.onload;
|
||||||
|
|
||||||
window.onload = function() {
|
window.onload = function() {
|
||||||
if (currentWindowOnload) {
|
if (currentWindowOnload) {
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|||||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
// eslint-disable-next-line no-var
|
||||||
var jasmineRequire = window.jasmineRequire || require('./jasmine.js');
|
var jasmineRequire = window.jasmineRequire || require('./jasmine.js');
|
||||||
|
|
||||||
jasmineRequire.html = function(j$) {
|
jasmineRequire.html = function(j$) {
|
||||||
@@ -79,19 +80,21 @@ jasmineRequire.HtmlReporter = function(j$) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function HtmlReporter(options) {
|
function HtmlReporter(options) {
|
||||||
var config = function() {
|
function config() {
|
||||||
return (options.env && options.env.configuration()) || {};
|
return (options.env && options.env.configuration()) || {};
|
||||||
},
|
}
|
||||||
getContainer = options.getContainer,
|
|
||||||
createElement = options.createElement,
|
const getContainer = options.getContainer;
|
||||||
createTextNode = options.createTextNode,
|
const createElement = options.createElement;
|
||||||
navigateWithNewParam = options.navigateWithNewParam || function() {},
|
const createTextNode = options.createTextNode;
|
||||||
addToExistingQueryString =
|
const navigateWithNewParam = options.navigateWithNewParam || function() {};
|
||||||
options.addToExistingQueryString || defaultQueryString,
|
const addToExistingQueryString =
|
||||||
filterSpecs = options.filterSpecs,
|
options.addToExistingQueryString || defaultQueryString;
|
||||||
htmlReporterMain,
|
const filterSpecs = options.filterSpecs;
|
||||||
symbols,
|
let htmlReporterMain;
|
||||||
deprecationWarnings = [];
|
let symbols;
|
||||||
|
const deprecationWarnings = [];
|
||||||
|
const failures = [];
|
||||||
|
|
||||||
this.initialize = function() {
|
this.initialize = function() {
|
||||||
clearPrior();
|
clearPrior();
|
||||||
@@ -119,14 +122,14 @@ jasmineRequire.HtmlReporter = function(j$) {
|
|||||||
getContainer().appendChild(htmlReporterMain);
|
getContainer().appendChild(htmlReporterMain);
|
||||||
};
|
};
|
||||||
|
|
||||||
var totalSpecsDefined;
|
let totalSpecsDefined;
|
||||||
this.jasmineStarted = function(options) {
|
this.jasmineStarted = function(options) {
|
||||||
totalSpecsDefined = options.totalSpecsDefined || 0;
|
totalSpecsDefined = options.totalSpecsDefined || 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
var summary = createDom('div', { className: 'jasmine-summary' });
|
const summary = createDom('div', { className: 'jasmine-summary' });
|
||||||
|
|
||||||
var stateBuilder = new ResultsStateBuilder();
|
const stateBuilder = new ResultsStateBuilder();
|
||||||
|
|
||||||
this.suiteStarted = function(result) {
|
this.suiteStarted = function(result) {
|
||||||
stateBuilder.suiteStarted(result);
|
stateBuilder.suiteStarted(result);
|
||||||
@@ -145,12 +148,11 @@ jasmineRequire.HtmlReporter = function(j$) {
|
|||||||
stateBuilder.specStarted(result);
|
stateBuilder.specStarted(result);
|
||||||
};
|
};
|
||||||
|
|
||||||
var failures = [];
|
|
||||||
this.specDone = function(result) {
|
this.specDone = function(result) {
|
||||||
stateBuilder.specDone(result);
|
stateBuilder.specDone(result);
|
||||||
|
|
||||||
if (noExpectations(result)) {
|
if (noExpectations(result)) {
|
||||||
var noSpecMsg = "Spec '" + result.fullName + "' has no expectations.";
|
const noSpecMsg = "Spec '" + result.fullName + "' has no expectations.";
|
||||||
if (result.status === 'failed') {
|
if (result.status === 'failed') {
|
||||||
console.error(noSpecMsg);
|
console.error(noSpecMsg);
|
||||||
} else {
|
} else {
|
||||||
@@ -194,10 +196,10 @@ jasmineRequire.HtmlReporter = function(j$) {
|
|||||||
|
|
||||||
this.jasmineDone = function(doneResult) {
|
this.jasmineDone = function(doneResult) {
|
||||||
stateBuilder.jasmineDone(doneResult);
|
stateBuilder.jasmineDone(doneResult);
|
||||||
var banner = find('.jasmine-banner');
|
const banner = find('.jasmine-banner');
|
||||||
var alert = find('.jasmine-alert');
|
const alert = find('.jasmine-alert');
|
||||||
var order = doneResult && doneResult.order;
|
const order = doneResult && doneResult.order;
|
||||||
var i;
|
|
||||||
alert.appendChild(
|
alert.appendChild(
|
||||||
createDom(
|
createDom(
|
||||||
'span',
|
'span',
|
||||||
@@ -209,14 +211,14 @@ jasmineRequire.HtmlReporter = function(j$) {
|
|||||||
banner.appendChild(optionsMenu(config()));
|
banner.appendChild(optionsMenu(config()));
|
||||||
|
|
||||||
if (stateBuilder.specsExecuted < totalSpecsDefined) {
|
if (stateBuilder.specsExecuted < totalSpecsDefined) {
|
||||||
var skippedMessage =
|
const skippedMessage =
|
||||||
'Ran ' +
|
'Ran ' +
|
||||||
stateBuilder.specsExecuted +
|
stateBuilder.specsExecuted +
|
||||||
' of ' +
|
' of ' +
|
||||||
totalSpecsDefined +
|
totalSpecsDefined +
|
||||||
' specs - run all';
|
' specs - run all';
|
||||||
// include window.location.pathname to fix issue with karma-jasmine-html-reporter in angular: see https://github.com/jasmine/jasmine/issues/1906
|
// include window.location.pathname to fix issue with karma-jasmine-html-reporter in angular: see https://github.com/jasmine/jasmine/issues/1906
|
||||||
var skippedLink =
|
const skippedLink =
|
||||||
(window.location.pathname || '') +
|
(window.location.pathname || '') +
|
||||||
addToExistingQueryString('spec', '');
|
addToExistingQueryString('spec', '');
|
||||||
alert.appendChild(
|
alert.appendChild(
|
||||||
@@ -231,10 +233,11 @@ jasmineRequire.HtmlReporter = function(j$) {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
var statusBarMessage = '';
|
let statusBarMessage = '';
|
||||||
var statusBarClassName = 'jasmine-overall-result jasmine-bar ';
|
let statusBarClassName = 'jasmine-overall-result jasmine-bar ';
|
||||||
var globalFailures = (doneResult && doneResult.failedExpectations) || [];
|
const globalFailures =
|
||||||
var failed = stateBuilder.failureCount + globalFailures.length > 0;
|
(doneResult && doneResult.failedExpectations) || [];
|
||||||
|
const failed = stateBuilder.failureCount + globalFailures.length > 0;
|
||||||
|
|
||||||
if (totalSpecsDefined > 0 || failed) {
|
if (totalSpecsDefined > 0 || failed) {
|
||||||
statusBarMessage +=
|
statusBarMessage +=
|
||||||
@@ -260,7 +263,7 @@ jasmineRequire.HtmlReporter = function(j$) {
|
|||||||
statusBarClassName += ' jasmine-failed ';
|
statusBarClassName += ' jasmine-failed ';
|
||||||
}
|
}
|
||||||
|
|
||||||
var seedBar;
|
let seedBar;
|
||||||
if (order && order.random) {
|
if (order && order.random) {
|
||||||
seedBar = createDom(
|
seedBar = createDom(
|
||||||
'span',
|
'span',
|
||||||
@@ -286,10 +289,10 @@ jasmineRequire.HtmlReporter = function(j$) {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
var errorBarClassName = 'jasmine-bar jasmine-errored';
|
const errorBarClassName = 'jasmine-bar jasmine-errored';
|
||||||
var afterAllMessagePrefix = 'AfterAll ';
|
const afterAllMessagePrefix = 'AfterAll ';
|
||||||
|
|
||||||
for (i = 0; i < globalFailures.length; i++) {
|
for (let i = 0; i < globalFailures.length; i++) {
|
||||||
alert.appendChild(
|
alert.appendChild(
|
||||||
createDom(
|
createDom(
|
||||||
'span',
|
'span',
|
||||||
@@ -301,7 +304,7 @@ jasmineRequire.HtmlReporter = function(j$) {
|
|||||||
|
|
||||||
function globalFailureMessage(failure) {
|
function globalFailureMessage(failure) {
|
||||||
if (failure.globalErrorType === 'load') {
|
if (failure.globalErrorType === 'load') {
|
||||||
var prefix = 'Error during loading: ' + failure.message;
|
const prefix = 'Error during loading: ' + failure.message;
|
||||||
|
|
||||||
if (failure.filename) {
|
if (failure.filename) {
|
||||||
return (
|
return (
|
||||||
@@ -319,9 +322,9 @@ jasmineRequire.HtmlReporter = function(j$) {
|
|||||||
|
|
||||||
addDeprecationWarnings(doneResult);
|
addDeprecationWarnings(doneResult);
|
||||||
|
|
||||||
for (i = 0; i < deprecationWarnings.length; i++) {
|
for (let i = 0; i < deprecationWarnings.length; i++) {
|
||||||
var children = [],
|
const children = [];
|
||||||
context;
|
let context;
|
||||||
|
|
||||||
switch (deprecationWarnings[i].runnableType) {
|
switch (deprecationWarnings[i].runnableType) {
|
||||||
case 'spec':
|
case 'spec':
|
||||||
@@ -355,7 +358,7 @@ jasmineRequire.HtmlReporter = function(j$) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
var results = find('.jasmine-results');
|
const results = find('.jasmine-results');
|
||||||
results.appendChild(summary);
|
results.appendChild(summary);
|
||||||
|
|
||||||
summaryList(stateBuilder.topResults, summary);
|
summaryList(stateBuilder.topResults, summary);
|
||||||
@@ -397,8 +400,8 @@ jasmineRequire.HtmlReporter = function(j$) {
|
|||||||
|
|
||||||
setMenuModeTo('jasmine-failure-list');
|
setMenuModeTo('jasmine-failure-list');
|
||||||
|
|
||||||
var failureNode = find('.jasmine-failures');
|
const failureNode = find('.jasmine-failures');
|
||||||
for (i = 0; i < failures.length; i++) {
|
for (let i = 0; i < failures.length; i++) {
|
||||||
failureNode.appendChild(failures[i]);
|
failureNode.appendChild(failures[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -407,16 +410,16 @@ jasmineRequire.HtmlReporter = function(j$) {
|
|||||||
return this;
|
return this;
|
||||||
|
|
||||||
function failureDom(result) {
|
function failureDom(result) {
|
||||||
var failure = createDom(
|
const failure = createDom(
|
||||||
'div',
|
'div',
|
||||||
{ className: 'jasmine-spec-detail jasmine-failed' },
|
{ className: 'jasmine-spec-detail jasmine-failed' },
|
||||||
failureDescription(result, stateBuilder.currentParent),
|
failureDescription(result, stateBuilder.currentParent),
|
||||||
createDom('div', { className: 'jasmine-messages' })
|
createDom('div', { className: 'jasmine-messages' })
|
||||||
);
|
);
|
||||||
var messages = failure.childNodes[1];
|
const messages = failure.childNodes[1];
|
||||||
|
|
||||||
for (var i = 0; i < result.failedExpectations.length; i++) {
|
for (let i = 0; i < result.failedExpectations.length; i++) {
|
||||||
var expectation = result.failedExpectations[i];
|
const expectation = result.failedExpectations[i];
|
||||||
messages.appendChild(
|
messages.appendChild(
|
||||||
createDom(
|
createDom(
|
||||||
'div',
|
'div',
|
||||||
@@ -451,7 +454,7 @@ jasmineRequire.HtmlReporter = function(j$) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function debugLogTable(debugLogs) {
|
function debugLogTable(debugLogs) {
|
||||||
var tbody = createDom('tbody');
|
const tbody = createDom('tbody');
|
||||||
|
|
||||||
debugLogs.forEach(function(entry) {
|
debugLogs.forEach(function(entry) {
|
||||||
tbody.appendChild(
|
tbody.appendChild(
|
||||||
@@ -491,14 +494,14 @@ jasmineRequire.HtmlReporter = function(j$) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function summaryList(resultsTree, domParent) {
|
function summaryList(resultsTree, domParent) {
|
||||||
var specListNode;
|
let specListNode;
|
||||||
for (var i = 0; i < resultsTree.children.length; i++) {
|
for (let i = 0; i < resultsTree.children.length; i++) {
|
||||||
var resultNode = resultsTree.children[i];
|
const resultNode = resultsTree.children[i];
|
||||||
if (filterSpecs && !hasActiveSpec(resultNode)) {
|
if (filterSpecs && !hasActiveSpec(resultNode)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (resultNode.type === 'suite') {
|
if (resultNode.type === 'suite') {
|
||||||
var suiteListNode = createDom(
|
const suiteListNode = createDom(
|
||||||
'ul',
|
'ul',
|
||||||
{ className: 'jasmine-suite', id: 'suite-' + resultNode.result.id },
|
{ className: 'jasmine-suite', id: 'suite-' + resultNode.result.id },
|
||||||
createDom(
|
createDom(
|
||||||
@@ -523,7 +526,7 @@ jasmineRequire.HtmlReporter = function(j$) {
|
|||||||
specListNode = createDom('ul', { className: 'jasmine-specs' });
|
specListNode = createDom('ul', { className: 'jasmine-specs' });
|
||||||
domParent.appendChild(specListNode);
|
domParent.appendChild(specListNode);
|
||||||
}
|
}
|
||||||
var specDescription = resultNode.result.description;
|
let specDescription = resultNode.result.description;
|
||||||
if (noExpectations(resultNode.result)) {
|
if (noExpectations(resultNode.result)) {
|
||||||
specDescription = 'SPEC HAS NO EXPECTATIONS ' + specDescription;
|
specDescription = 'SPEC HAS NO EXPECTATIONS ' + specDescription;
|
||||||
}
|
}
|
||||||
@@ -555,7 +558,7 @@ jasmineRequire.HtmlReporter = function(j$) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function optionsMenu(config) {
|
function optionsMenu(config) {
|
||||||
var optionsMenuDom = createDom(
|
const optionsMenuDom = createDom(
|
||||||
'div',
|
'div',
|
||||||
{ className: 'jasmine-run-options' },
|
{ className: 'jasmine-run-options' },
|
||||||
createDom('span', { className: 'jasmine-trigger' }, 'Options'),
|
createDom('span', { className: 'jasmine-trigger' }, 'Options'),
|
||||||
@@ -621,13 +624,15 @@ jasmineRequire.HtmlReporter = function(j$) {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
var failFastCheckbox = optionsMenuDom.querySelector('#jasmine-fail-fast');
|
const failFastCheckbox = optionsMenuDom.querySelector(
|
||||||
|
'#jasmine-fail-fast'
|
||||||
|
);
|
||||||
failFastCheckbox.checked = config.stopOnSpecFailure;
|
failFastCheckbox.checked = config.stopOnSpecFailure;
|
||||||
failFastCheckbox.onclick = function() {
|
failFastCheckbox.onclick = function() {
|
||||||
navigateWithNewParam('stopOnSpecFailure', !config.stopOnSpecFailure);
|
navigateWithNewParam('stopOnSpecFailure', !config.stopOnSpecFailure);
|
||||||
};
|
};
|
||||||
|
|
||||||
var throwCheckbox = optionsMenuDom.querySelector(
|
const throwCheckbox = optionsMenuDom.querySelector(
|
||||||
'#jasmine-throw-failures'
|
'#jasmine-throw-failures'
|
||||||
);
|
);
|
||||||
throwCheckbox.checked = config.stopSpecOnExpectationFailure;
|
throwCheckbox.checked = config.stopSpecOnExpectationFailure;
|
||||||
@@ -638,7 +643,7 @@ jasmineRequire.HtmlReporter = function(j$) {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
var randomCheckbox = optionsMenuDom.querySelector(
|
const randomCheckbox = optionsMenuDom.querySelector(
|
||||||
'#jasmine-random-order'
|
'#jasmine-random-order'
|
||||||
);
|
);
|
||||||
randomCheckbox.checked = config.random;
|
randomCheckbox.checked = config.random;
|
||||||
@@ -646,13 +651,15 @@ jasmineRequire.HtmlReporter = function(j$) {
|
|||||||
navigateWithNewParam('random', !config.random);
|
navigateWithNewParam('random', !config.random);
|
||||||
};
|
};
|
||||||
|
|
||||||
var hideDisabled = optionsMenuDom.querySelector('#jasmine-hide-disabled');
|
const hideDisabled = optionsMenuDom.querySelector(
|
||||||
|
'#jasmine-hide-disabled'
|
||||||
|
);
|
||||||
hideDisabled.checked = config.hideDisabled;
|
hideDisabled.checked = config.hideDisabled;
|
||||||
hideDisabled.onclick = function() {
|
hideDisabled.onclick = function() {
|
||||||
navigateWithNewParam('hideDisabled', !config.hideDisabled);
|
navigateWithNewParam('hideDisabled', !config.hideDisabled);
|
||||||
};
|
};
|
||||||
|
|
||||||
var optionsTrigger = optionsMenuDom.querySelector('.jasmine-trigger'),
|
const optionsTrigger = optionsMenuDom.querySelector('.jasmine-trigger'),
|
||||||
optionsPayload = optionsMenuDom.querySelector('.jasmine-payload'),
|
optionsPayload = optionsMenuDom.querySelector('.jasmine-payload'),
|
||||||
isOpen = /\bjasmine-open\b/;
|
isOpen = /\bjasmine-open\b/;
|
||||||
|
|
||||||
@@ -671,7 +678,7 @@ jasmineRequire.HtmlReporter = function(j$) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function failureDescription(result, suite) {
|
function failureDescription(result, suite) {
|
||||||
var wrapper = createDom(
|
const wrapper = createDom(
|
||||||
'div',
|
'div',
|
||||||
{ className: 'jasmine-description' },
|
{ className: 'jasmine-description' },
|
||||||
createDom(
|
createDom(
|
||||||
@@ -680,7 +687,7 @@ jasmineRequire.HtmlReporter = function(j$) {
|
|||||||
result.description
|
result.description
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
var suiteLink;
|
let suiteLink;
|
||||||
|
|
||||||
while (suite && suite.parent) {
|
while (suite && suite.parent) {
|
||||||
wrapper.insertBefore(createTextNode(' > '), wrapper.firstChild);
|
wrapper.insertBefore(createTextNode(' > '), wrapper.firstChild);
|
||||||
@@ -698,7 +705,7 @@ jasmineRequire.HtmlReporter = function(j$) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function suiteHref(suite) {
|
function suiteHref(suite) {
|
||||||
var els = [];
|
const els = [];
|
||||||
|
|
||||||
while (suite && suite.parent) {
|
while (suite && suite.parent) {
|
||||||
els.unshift(suite.result.description);
|
els.unshift(suite.result.description);
|
||||||
@@ -714,8 +721,8 @@ jasmineRequire.HtmlReporter = function(j$) {
|
|||||||
|
|
||||||
function addDeprecationWarnings(result, runnableType) {
|
function addDeprecationWarnings(result, runnableType) {
|
||||||
if (result && result.deprecationWarnings) {
|
if (result && result.deprecationWarnings) {
|
||||||
for (var i = 0; i < result.deprecationWarnings.length; i++) {
|
for (let i = 0; i < result.deprecationWarnings.length; i++) {
|
||||||
var warning = result.deprecationWarnings[i].message;
|
const warning = result.deprecationWarnings[i].message;
|
||||||
deprecationWarnings.push({
|
deprecationWarnings.push({
|
||||||
message: warning,
|
message: warning,
|
||||||
stack: result.deprecationWarnings[i].stack,
|
stack: result.deprecationWarnings[i].stack,
|
||||||
@@ -727,8 +734,8 @@ jasmineRequire.HtmlReporter = function(j$) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function createExpander(stackTrace) {
|
function createExpander(stackTrace) {
|
||||||
var expandLink = createDom('a', { href: '#' }, 'Show stack trace');
|
const expandLink = createDom('a', { href: '#' }, 'Show stack trace');
|
||||||
var root = createDom(
|
const root = createDom(
|
||||||
'div',
|
'div',
|
||||||
{ className: 'jasmine-expander' },
|
{ className: 'jasmine-expander' },
|
||||||
expandLink,
|
expandLink,
|
||||||
@@ -759,8 +766,7 @@ jasmineRequire.HtmlReporter = function(j$) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function clearPrior() {
|
function clearPrior() {
|
||||||
// return the reporter
|
const oldReporter = find('');
|
||||||
var oldReporter = find('');
|
|
||||||
|
|
||||||
if (oldReporter) {
|
if (oldReporter) {
|
||||||
getContainer().removeChild(oldReporter);
|
getContainer().removeChild(oldReporter);
|
||||||
@@ -768,22 +774,21 @@ jasmineRequire.HtmlReporter = function(j$) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function createDom(type, attrs, childrenArrayOrVarArgs) {
|
function createDom(type, attrs, childrenArrayOrVarArgs) {
|
||||||
var el = createElement(type),
|
const el = createElement(type);
|
||||||
children,
|
let children;
|
||||||
i;
|
|
||||||
|
|
||||||
if (j$.isArray_(childrenArrayOrVarArgs)) {
|
if (j$.isArray_(childrenArrayOrVarArgs)) {
|
||||||
children = childrenArrayOrVarArgs;
|
children = childrenArrayOrVarArgs;
|
||||||
} else {
|
} else {
|
||||||
children = [];
|
children = [];
|
||||||
|
|
||||||
for (i = 2; i < arguments.length; i++) {
|
for (let i = 2; i < arguments.length; i++) {
|
||||||
children.push(arguments[i]);
|
children.push(arguments[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < children.length; i++) {
|
for (let i = 0; i < children.length; i++) {
|
||||||
var child = children[i];
|
const child = children[i];
|
||||||
|
|
||||||
if (typeof child === 'string') {
|
if (typeof child === 'string') {
|
||||||
el.appendChild(createTextNode(child));
|
el.appendChild(createTextNode(child));
|
||||||
@@ -794,7 +799,7 @@ jasmineRequire.HtmlReporter = function(j$) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var attr in attrs) {
|
for (const attr in attrs) {
|
||||||
if (attr == 'className') {
|
if (attr == 'className') {
|
||||||
el[attr] = attrs[attr];
|
el[attr] = attrs[attr];
|
||||||
} else {
|
} else {
|
||||||
@@ -806,7 +811,7 @@ jasmineRequire.HtmlReporter = function(j$) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function pluralize(singular, count) {
|
function pluralize(singular, count) {
|
||||||
var word = count == 1 ? singular : singular + 's';
|
const word = count == 1 ? singular : singular + 's';
|
||||||
|
|
||||||
return '' + count + ' ' + word;
|
return '' + count + ' ' + word;
|
||||||
}
|
}
|
||||||
@@ -836,7 +841,7 @@ jasmineRequire.HtmlReporter = function(j$) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function noExpectations(result) {
|
function noExpectations(result) {
|
||||||
var allExpectations =
|
const allExpectations =
|
||||||
result.failedExpectations.length + result.passedExpectations.length;
|
result.failedExpectations.length + result.passedExpectations.length;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -851,7 +856,7 @@ jasmineRequire.HtmlReporter = function(j$) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (resultNode.type == 'suite') {
|
if (resultNode.type == 'suite') {
|
||||||
for (var i = 0, j = resultNode.children.length; i < j; i++) {
|
for (let i = 0, j = resultNode.children.length; i < j; i++) {
|
||||||
if (hasActiveSpec(resultNode.children[i])) {
|
if (hasActiveSpec(resultNode.children[i])) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -865,11 +870,11 @@ jasmineRequire.HtmlReporter = function(j$) {
|
|||||||
|
|
||||||
jasmineRequire.HtmlSpecFilter = function() {
|
jasmineRequire.HtmlSpecFilter = function() {
|
||||||
function HtmlSpecFilter(options) {
|
function HtmlSpecFilter(options) {
|
||||||
var filterString =
|
const filterString =
|
||||||
options &&
|
options &&
|
||||||
options.filterString() &&
|
options.filterString() &&
|
||||||
options.filterString().replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
|
options.filterString().replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
|
||||||
var filterPattern = new RegExp(filterString);
|
const filterPattern = new RegExp(filterString);
|
||||||
|
|
||||||
this.matches = function(specName) {
|
this.matches = function(specName) {
|
||||||
return filterPattern.test(specName);
|
return filterPattern.test(specName);
|
||||||
@@ -913,7 +918,7 @@ jasmineRequire.QueryString = function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.fullStringWithNewParam = function(key, value) {
|
this.fullStringWithNewParam = function(key, value) {
|
||||||
var paramMap = queryStringToParamMap();
|
const paramMap = queryStringToParamMap();
|
||||||
paramMap[key] = value;
|
paramMap[key] = value;
|
||||||
return toQueryString(paramMap);
|
return toQueryString(paramMap);
|
||||||
};
|
};
|
||||||
@@ -925,8 +930,8 @@ jasmineRequire.QueryString = function() {
|
|||||||
return this;
|
return this;
|
||||||
|
|
||||||
function toQueryString(paramMap) {
|
function toQueryString(paramMap) {
|
||||||
var qStrPairs = [];
|
const qStrPairs = [];
|
||||||
for (var prop in paramMap) {
|
for (const prop in paramMap) {
|
||||||
qStrPairs.push(
|
qStrPairs.push(
|
||||||
encodeURIComponent(prop) + '=' + encodeURIComponent(paramMap[prop])
|
encodeURIComponent(prop) + '=' + encodeURIComponent(paramMap[prop])
|
||||||
);
|
);
|
||||||
@@ -935,15 +940,15 @@ jasmineRequire.QueryString = function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function queryStringToParamMap() {
|
function queryStringToParamMap() {
|
||||||
var paramStr = options.getWindowLocation().search.substring(1),
|
const paramStr = options.getWindowLocation().search.substring(1);
|
||||||
params = [],
|
let params = [];
|
||||||
paramMap = {};
|
const paramMap = {};
|
||||||
|
|
||||||
if (paramStr.length > 0) {
|
if (paramStr.length > 0) {
|
||||||
params = paramStr.split('&');
|
params = paramStr.split('&');
|
||||||
for (var i = 0; i < params.length; i++) {
|
for (let i = 0; i < params.length; i++) {
|
||||||
var p = params[i].split('=');
|
const p = params[i].split('=');
|
||||||
var value = decodeURIComponent(p[1]);
|
let value = decodeURIComponent(p[1]);
|
||||||
if (value === 'true' || value === 'false') {
|
if (value === 'true' || value === 'false') {
|
||||||
value = JSON.parse(value);
|
value = JSON.parse(value);
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -21,16 +21,16 @@ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|||||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
module.exports = function(jasmineRequire) {
|
module.exports = function(jasmineRequire) {
|
||||||
var jasmine = jasmineRequire.core(jasmineRequire);
|
const jasmine = jasmineRequire.core(jasmineRequire);
|
||||||
|
|
||||||
var env = jasmine.getEnv({ suppressLoadErrors: true });
|
const env = jasmine.getEnv({ suppressLoadErrors: true });
|
||||||
|
|
||||||
var jasmineInterface = jasmineRequire.interface(jasmine, env);
|
const jasmineInterface = jasmineRequire.interface(jasmine, env);
|
||||||
|
|
||||||
extend(global, jasmineInterface);
|
extend(global, jasmineInterface);
|
||||||
|
|
||||||
function extend(destination, source) {
|
function extend(destination, source) {
|
||||||
for (var property in source) destination[property] = source[property];
|
for (const property in source) destination[property] = source[property];
|
||||||
return destination;
|
return destination;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
14
package.json
14
package.json
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "jasmine-core",
|
"name": "jasmine-core",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"version": "4.1.1",
|
"version": "4.3.0",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/jasmine/jasmine.git"
|
"url": "https://github.com/jasmine/jasmine.git"
|
||||||
@@ -43,8 +43,8 @@
|
|||||||
"grunt-contrib-concat": "^2.0.0",
|
"grunt-contrib-concat": "^2.0.0",
|
||||||
"grunt-css-url-embed": "^1.11.1",
|
"grunt-css-url-embed": "^1.11.1",
|
||||||
"grunt-sass": "^3.0.2",
|
"grunt-sass": "^3.0.2",
|
||||||
"jasmine": "github:jasmine/jasmine-npm#main",
|
"jasmine": "^4.1.0",
|
||||||
"jasmine-browser-runner": "github:jasmine/jasmine-browser#main",
|
"jasmine-browser-runner": "^1.0.0",
|
||||||
"jsdom": "^19.0.0",
|
"jsdom": "^19.0.0",
|
||||||
"load-grunt-tasks": "^5.1.0",
|
"load-grunt-tasks": "^5.1.0",
|
||||||
"prettier": "1.17.1",
|
"prettier": "1.17.1",
|
||||||
@@ -95,14 +95,16 @@
|
|||||||
"error",
|
"error",
|
||||||
"always"
|
"always"
|
||||||
],
|
],
|
||||||
"space-before-blocks": "error"
|
"space-before-blocks": "error",
|
||||||
|
"no-eval": "error",
|
||||||
|
"no-var": "error"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"browserslist": [
|
"browserslist": [
|
||||||
"Safari >= 13",
|
"Safari >= 14",
|
||||||
"last 2 Chrome versions",
|
"last 2 Chrome versions",
|
||||||
"last 2 Firefox versions",
|
"last 2 Firefox versions",
|
||||||
"Firefox >= 68",
|
"Firefox >= 91",
|
||||||
"last 2 Edge versions"
|
"last 2 Edge versions"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
41
release_notes/4.2.0.md
Normal file
41
release_notes/4.2.0.md
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
# Jasmine 4.2.0 Release Notes
|
||||||
|
|
||||||
|
## New Features
|
||||||
|
|
||||||
|
* Added a jasmine.is asymmetric equality tester
|
||||||
|
* Allows the use of === comparisons for specific fields of an object that
|
||||||
|
should otherwise be compared with the default deep value equality logic.
|
||||||
|
|
||||||
|
## Bug Fixes
|
||||||
|
|
||||||
|
* More reliably report errors that occur late in the suite/spec lifecycle
|
||||||
|
* Previously, an error that occurred after Jasmine started to report the
|
||||||
|
suiteDone or specDone event for the current runable would not be reliably
|
||||||
|
reported. Now such an error is reported on the nearest ancestor suite whose
|
||||||
|
suiteDone event has not yet been reported.
|
||||||
|
|
||||||
|
* Don't report a deprecation when a runnable uses two forms of async
|
||||||
|
* This was made into an error in 4.0, so the deprecation is redundant.
|
||||||
|
|
||||||
|
* Include property getter values in pretty-printed objects
|
||||||
|
|
||||||
|
## Documentation Updates
|
||||||
|
|
||||||
|
* Removed duplicate Suite and Spec jsdocs
|
||||||
|
|
||||||
|
## Supported environments
|
||||||
|
|
||||||
|
jasmine-core 4.2.0 has been tested in the following environments.
|
||||||
|
|
||||||
|
| Environment | Supported versions |
|
||||||
|
|-------------------|--------------------|
|
||||||
|
| Node | 12.17+, 14, 16, 18 |
|
||||||
|
| Safari | 14-15 |
|
||||||
|
| Chrome | 102 |
|
||||||
|
| Firefox | 91, 101 |
|
||||||
|
| Edge | 101 |
|
||||||
|
|
||||||
|
|
||||||
|
------
|
||||||
|
|
||||||
|
_Release Notes generated with _[Anchorman](http://github.com/infews/anchorman)_
|
||||||
40
release_notes/4.3.0.md
Normal file
40
release_notes/4.3.0.md
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
# Jasmine 4.3.0 Release Notes
|
||||||
|
|
||||||
|
## New Features
|
||||||
|
|
||||||
|
* Added [`jasmine.spyOnGlobalErrorsAsync`](https://jasmine.github.io/api/4.3/jasmine.html#.spyOnGlobalErrorsAsync),
|
||||||
|
to better support testing code that's
|
||||||
|
expected to produce unhandled exceptions or unhandled promise rejections
|
||||||
|
* Fixes [#1843](https://github.com/jasmine/jasmine/issues/1843)
|
||||||
|
* Fixes [#1453](https://github.com/jasmine/jasmine/issues/1453)
|
||||||
|
|
||||||
|
## Documentation updates
|
||||||
|
|
||||||
|
* Updated the README to reduce redundancy and update support links
|
||||||
|
|
||||||
|
## Internal improvements
|
||||||
|
|
||||||
|
* Split `Env` into several smaller classes
|
||||||
|
* Replaced uses of `var` with `const`/`let`
|
||||||
|
* Replaced most uses of `self = this` with arrow fns
|
||||||
|
* Removed obsolete and unused utility fns
|
||||||
|
* Separated reporter- and runable-specific queue runner configuration
|
||||||
|
* Added more test coverage for default spy strategies
|
||||||
|
* Converted integration specs to `async`/`await`
|
||||||
|
|
||||||
|
## Supported environments
|
||||||
|
|
||||||
|
jasmine-core 4.3.0 has been tested in the following environments.
|
||||||
|
|
||||||
|
| Environment | Supported versions |
|
||||||
|
|-------------------|--------------------|
|
||||||
|
| Node | 12.17+, 14, 16, 18 |
|
||||||
|
| Safari | 14-15 |
|
||||||
|
| Chrome | 103 |
|
||||||
|
| Firefox | 91, 102 |
|
||||||
|
| Edge | 103 |
|
||||||
|
|
||||||
|
|
||||||
|
------
|
||||||
|
|
||||||
|
_Release Notes generated with _[Anchorman](http://github.com/infews/anchorman)_
|
||||||
@@ -25,6 +25,7 @@ passfile=`mktemp -t jasmine-results.XXXXXX` || exit 1
|
|||||||
failfile=`mktemp -t jasmine-results.XXXXXX` || exit 1
|
failfile=`mktemp -t jasmine-results.XXXXXX` || exit 1
|
||||||
run_browser chrome latest
|
run_browser chrome latest
|
||||||
run_browser firefox latest
|
run_browser firefox latest
|
||||||
|
run_browser firefox 102
|
||||||
run_browser firefox 91
|
run_browser firefox 91
|
||||||
run_browser safari 15
|
run_browser safari 15
|
||||||
run_browser safari 14
|
run_browser safari 14
|
||||||
|
|||||||
@@ -14,8 +14,6 @@ module.exports = {
|
|||||||
// TODO: consider doing this in src files as well as specs
|
// TODO: consider doing this in src files as well as specs
|
||||||
'no-unused-vars': ['error', { args: 'after-used' }],
|
'no-unused-vars': ['error', { args: 'after-used' }],
|
||||||
|
|
||||||
'no-var': 'error',
|
|
||||||
|
|
||||||
// Since linting is done at the end of the process and doesn't stop us
|
// Since linting is done at the end of the process and doesn't stop us
|
||||||
// from running tests, it makes sense to fail if debugger statements
|
// from running tests, it makes sense to fail if debugger statements
|
||||||
// or console references are present.
|
// or console references are present.
|
||||||
|
|||||||
@@ -316,7 +316,7 @@ describe('Env', function() {
|
|||||||
|
|
||||||
it('calls spec.exclude with "Temporarily disabled with xit"', function() {
|
it('calls spec.exclude with "Temporarily disabled with xit"', function() {
|
||||||
const excludeSpy = jasmine.createSpy();
|
const excludeSpy = jasmine.createSpy();
|
||||||
spyOn(env, 'it_').and.returnValue({
|
spyOn(jasmineUnderTest.SuiteBuilder.prototype, 'it_').and.returnValue({
|
||||||
exclude: excludeSpy
|
exclude: excludeSpy
|
||||||
});
|
});
|
||||||
env.xit('foo', function() {});
|
env.xit('foo', function() {});
|
||||||
@@ -327,7 +327,7 @@ describe('Env', function() {
|
|||||||
const pendSpy = jasmine.createSpy();
|
const pendSpy = jasmine.createSpy();
|
||||||
const realExclude = jasmineUnderTest.Spec.prototype.exclude;
|
const realExclude = jasmineUnderTest.Spec.prototype.exclude;
|
||||||
|
|
||||||
spyOn(env, 'it_').and.returnValue({
|
spyOn(jasmineUnderTest.SuiteBuilder.prototype, 'it_').and.returnValue({
|
||||||
exclude: realExclude,
|
exclude: realExclude,
|
||||||
pend: pendSpy
|
pend: pendSpy
|
||||||
});
|
});
|
||||||
@@ -468,7 +468,8 @@ describe('Env', function() {
|
|||||||
'install',
|
'install',
|
||||||
'uninstall',
|
'uninstall',
|
||||||
'pushListener',
|
'pushListener',
|
||||||
'popListener'
|
'popListener',
|
||||||
|
'removeOverrideListener'
|
||||||
]);
|
]);
|
||||||
spyOn(jasmineUnderTest, 'GlobalErrors').and.returnValue(globalErrors);
|
spyOn(jasmineUnderTest, 'GlobalErrors').and.returnValue(globalErrors);
|
||||||
env.cleanup_();
|
env.cleanup_();
|
||||||
@@ -483,7 +484,8 @@ describe('Env', function() {
|
|||||||
'install',
|
'install',
|
||||||
'uninstall',
|
'uninstall',
|
||||||
'pushListener',
|
'pushListener',
|
||||||
'popListener'
|
'popListener',
|
||||||
|
'removeOverrideListener'
|
||||||
]);
|
]);
|
||||||
spyOn(jasmineUnderTest, 'GlobalErrors').and.returnValue(globalErrors);
|
spyOn(jasmineUnderTest, 'GlobalErrors').and.returnValue(globalErrors);
|
||||||
env.cleanup_();
|
env.cleanup_();
|
||||||
@@ -494,7 +496,7 @@ describe('Env', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('creates an expectationFactory that uses the current custom equality testers and object formatters', function(done) {
|
it('creates an expectationFactory that uses the current custom equality testers and object formatters', async function() {
|
||||||
function customEqualityTester() {}
|
function customEqualityTester() {}
|
||||||
function customObjectFormatter() {}
|
function customObjectFormatter() {}
|
||||||
function prettyPrinter() {}
|
function prettyPrinter() {}
|
||||||
@@ -515,19 +517,17 @@ describe('Env', function() {
|
|||||||
expectationFactory('actual', specInstance);
|
expectationFactory('actual', specInstance);
|
||||||
});
|
});
|
||||||
|
|
||||||
env.execute(null, function() {
|
await env.execute();
|
||||||
expect(jasmineUnderTest.makePrettyPrinter).toHaveBeenCalledWith([
|
expect(jasmineUnderTest.makePrettyPrinter).toHaveBeenCalledWith([
|
||||||
customObjectFormatter
|
customObjectFormatter
|
||||||
]);
|
]);
|
||||||
expect(jasmineUnderTest.MatchersUtil).toHaveBeenCalledWith({
|
expect(jasmineUnderTest.MatchersUtil).toHaveBeenCalledWith({
|
||||||
customTesters: [customEqualityTester],
|
customTesters: [customEqualityTester],
|
||||||
pp: prettyPrinter
|
pp: prettyPrinter
|
||||||
});
|
|
||||||
done();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('creates an asyncExpectationFactory that uses the current custom equality testers and object formatters', function(done) {
|
it('creates an asyncExpectationFactory that uses the current custom equality testers and object formatters', async function() {
|
||||||
function customEqualityTester() {}
|
function customEqualityTester() {}
|
||||||
function customObjectFormatter() {}
|
function customObjectFormatter() {}
|
||||||
function prettyPrinter() {}
|
function prettyPrinter() {}
|
||||||
@@ -548,15 +548,14 @@ describe('Env', function() {
|
|||||||
asyncExpectationFactory('actual', specInstance);
|
asyncExpectationFactory('actual', specInstance);
|
||||||
});
|
});
|
||||||
|
|
||||||
env.execute(null, function() {
|
await env.execute();
|
||||||
expect(jasmineUnderTest.makePrettyPrinter).toHaveBeenCalledWith([
|
|
||||||
customObjectFormatter
|
expect(jasmineUnderTest.makePrettyPrinter).toHaveBeenCalledWith([
|
||||||
]);
|
customObjectFormatter
|
||||||
expect(jasmineUnderTest.MatchersUtil).toHaveBeenCalledWith({
|
]);
|
||||||
customTesters: [customEqualityTester],
|
expect(jasmineUnderTest.MatchersUtil).toHaveBeenCalledWith({
|
||||||
pp: prettyPrinter
|
customTesters: [customEqualityTester],
|
||||||
});
|
pp: prettyPrinter
|
||||||
done();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -594,4 +593,19 @@ describe('Env', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('#spyOnGlobalErrorsAsync', function() {
|
||||||
|
it('throws if the callback does not return a promise', async function() {
|
||||||
|
const msg =
|
||||||
|
'The callback to spyOnGlobalErrorsAsync must be an async or ' +
|
||||||
|
'promise-returning function';
|
||||||
|
|
||||||
|
await expectAsync(
|
||||||
|
env.spyOnGlobalErrorsAsync(() => undefined)
|
||||||
|
).toBeRejectedWithError(msg);
|
||||||
|
await expectAsync(
|
||||||
|
env.spyOnGlobalErrorsAsync(() => 'not a promise')
|
||||||
|
).toBeRejectedWithError(msg);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ describe('Exceptions:', function() {
|
|||||||
env.cleanup_();
|
env.cleanup_();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle exceptions thrown, but continue', function(done) {
|
it('should handle exceptions thrown, but continue', async function() {
|
||||||
const secondTest = jasmine.createSpy('second test');
|
const secondTest = jasmine.createSpy('second test');
|
||||||
env.describe('Suite for handles exceptions', function() {
|
env.describe('Suite for handles exceptions', function() {
|
||||||
env.it(
|
env.it(
|
||||||
@@ -24,15 +24,12 @@ describe('Exceptions:', function() {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
const expectations = function() {
|
await env.execute();
|
||||||
expect(secondTest).toHaveBeenCalled();
|
|
||||||
done();
|
|
||||||
};
|
|
||||||
|
|
||||||
env.execute(null, expectations);
|
expect(secondTest).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle exceptions thrown directly in top-level describe blocks and continue', function(done) {
|
it('should handle exceptions thrown directly in top-level describe blocks and continue', async function() {
|
||||||
const secondDescribe = jasmine
|
const secondDescribe = jasmine
|
||||||
.createSpy('second describe')
|
.createSpy('second describe')
|
||||||
.and.callFake(function() {
|
.and.callFake(function() {
|
||||||
@@ -47,11 +44,8 @@ describe('Exceptions:', function() {
|
|||||||
});
|
});
|
||||||
env.describe("a suite that doesn't throw an exception", secondDescribe);
|
env.describe("a suite that doesn't throw an exception", secondDescribe);
|
||||||
|
|
||||||
const expectations = function() {
|
await env.execute();
|
||||||
expect(secondDescribe).toHaveBeenCalled();
|
|
||||||
done();
|
|
||||||
};
|
|
||||||
|
|
||||||
env.execute(null, expectations);
|
expect(secondDescribe).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -404,4 +404,158 @@ describe('GlobalErrors', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('#setOverrideListener', function() {
|
||||||
|
it('overrides the existing handlers in browsers until removed', function() {
|
||||||
|
const fakeGlobal = { onerror: null };
|
||||||
|
const handler0 = jasmine.createSpy('handler0');
|
||||||
|
const handler1 = jasmine.createSpy('handler1');
|
||||||
|
const overrideHandler = jasmine.createSpy('overrideHandler');
|
||||||
|
const errors = new jasmineUnderTest.GlobalErrors(fakeGlobal);
|
||||||
|
|
||||||
|
errors.install();
|
||||||
|
errors.pushListener(handler0);
|
||||||
|
errors.setOverrideListener(overrideHandler, () => {});
|
||||||
|
errors.pushListener(handler1);
|
||||||
|
fakeGlobal.onerror('foo');
|
||||||
|
fakeGlobal.onerror(null, null, null, null, new Error('bar'));
|
||||||
|
|
||||||
|
expect(overrideHandler).toHaveBeenCalledWith('foo');
|
||||||
|
expect(overrideHandler).toHaveBeenCalledWith(new Error('bar'));
|
||||||
|
expect(handler0).not.toHaveBeenCalled();
|
||||||
|
expect(handler1).not.toHaveBeenCalled();
|
||||||
|
|
||||||
|
errors.removeOverrideListener();
|
||||||
|
|
||||||
|
fakeGlobal.onerror('baz');
|
||||||
|
expect(overrideHandler).not.toHaveBeenCalledWith('baz');
|
||||||
|
expect(handler1).toHaveBeenCalledWith('baz');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('overrides the existing handlers in Node until removed', function() {
|
||||||
|
const globalEventListeners = {};
|
||||||
|
const fakeGlobal = {
|
||||||
|
process: {
|
||||||
|
on: (name, listener) => (globalEventListeners[name] = listener),
|
||||||
|
removeListener: () => {},
|
||||||
|
listeners: name => globalEventListeners[name],
|
||||||
|
removeAllListeners: name => (globalEventListeners[name] = [])
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const handler0 = jasmine.createSpy('handler0');
|
||||||
|
const handler1 = jasmine.createSpy('handler1');
|
||||||
|
const overrideHandler = jasmine.createSpy('overrideHandler');
|
||||||
|
const errors = new jasmineUnderTest.GlobalErrors(fakeGlobal);
|
||||||
|
|
||||||
|
errors.install();
|
||||||
|
errors.pushListener(handler0);
|
||||||
|
errors.setOverrideListener(overrideHandler);
|
||||||
|
errors.pushListener(handler1);
|
||||||
|
|
||||||
|
globalEventListeners['uncaughtException'](new Error('foo'));
|
||||||
|
|
||||||
|
expect(overrideHandler).toHaveBeenCalledWith(new Error('foo'));
|
||||||
|
expect(handler0).not.toHaveBeenCalled();
|
||||||
|
expect(handler1).not.toHaveBeenCalled();
|
||||||
|
|
||||||
|
errors.removeOverrideListener();
|
||||||
|
|
||||||
|
globalEventListeners['uncaughtException'](new Error('bar'));
|
||||||
|
expect(overrideHandler).not.toHaveBeenCalledWith(new Error('bar'));
|
||||||
|
expect(handler1).toHaveBeenCalledWith(new Error('bar'));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('handles unhandled promise rejections in browsers', function() {
|
||||||
|
const globalEventListeners = {};
|
||||||
|
const fakeGlobal = {
|
||||||
|
addEventListener(name, listener) {
|
||||||
|
globalEventListeners[name] = listener;
|
||||||
|
},
|
||||||
|
removeEventListener() {}
|
||||||
|
};
|
||||||
|
const handler = jasmine.createSpy('handler');
|
||||||
|
const overrideHandler = jasmine.createSpy('overrideHandler');
|
||||||
|
const errors = new jasmineUnderTest.GlobalErrors(fakeGlobal);
|
||||||
|
|
||||||
|
errors.install();
|
||||||
|
errors.pushListener(handler);
|
||||||
|
errors.setOverrideListener(overrideHandler, () => {});
|
||||||
|
|
||||||
|
const reason = new Error('bar');
|
||||||
|
|
||||||
|
globalEventListeners['unhandledrejection']({ reason: reason });
|
||||||
|
|
||||||
|
expect(overrideHandler).toHaveBeenCalledWith(
|
||||||
|
jasmine.objectContaining({
|
||||||
|
jasmineMessage: 'Unhandled promise rejection: Error: bar',
|
||||||
|
message: reason.message,
|
||||||
|
stack: reason.stack
|
||||||
|
})
|
||||||
|
);
|
||||||
|
expect(handler).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('handles unhandled promise rejections in Node', function() {
|
||||||
|
const globalEventListeners = {};
|
||||||
|
const fakeGlobal = {
|
||||||
|
process: {
|
||||||
|
on(name, listener) {
|
||||||
|
globalEventListeners[name] = listener;
|
||||||
|
},
|
||||||
|
removeListener() {},
|
||||||
|
listeners(name) {
|
||||||
|
return globalEventListeners[name];
|
||||||
|
},
|
||||||
|
removeAllListeners(name) {
|
||||||
|
globalEventListeners[name] = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const handler0 = jasmine.createSpy('handler0');
|
||||||
|
const handler1 = jasmine.createSpy('handler1');
|
||||||
|
const overrideHandler = jasmine.createSpy('overrideHandler');
|
||||||
|
const errors = new jasmineUnderTest.GlobalErrors(fakeGlobal);
|
||||||
|
|
||||||
|
errors.install();
|
||||||
|
errors.pushListener(handler0);
|
||||||
|
errors.setOverrideListener(overrideHandler, () => {});
|
||||||
|
errors.pushListener(handler1);
|
||||||
|
|
||||||
|
globalEventListeners['unhandledRejection'](new Error('nope'));
|
||||||
|
|
||||||
|
expect(overrideHandler).toHaveBeenCalledWith(new Error('nope'));
|
||||||
|
expect(handler0).not.toHaveBeenCalled();
|
||||||
|
expect(handler1).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('throws if there is already an override handler', function() {
|
||||||
|
const fakeGlobal = { onerror: null };
|
||||||
|
const errors = new jasmineUnderTest.GlobalErrors(fakeGlobal);
|
||||||
|
|
||||||
|
errors.setOverrideListener(() => {}, () => {});
|
||||||
|
expect(function() {
|
||||||
|
errors.setOverrideListener(() => {}, () => {});
|
||||||
|
}).toThrowError("Can't set more than one override listener at a time");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('#removeOverrideListener', function() {
|
||||||
|
it("calls the handler's onRemove callback", function() {
|
||||||
|
const fakeGlobal = { onerror: null };
|
||||||
|
const onRemove = jasmine.createSpy('onRemove');
|
||||||
|
const errors = new jasmineUnderTest.GlobalErrors(fakeGlobal);
|
||||||
|
|
||||||
|
errors.setOverrideListener(() => {}, onRemove);
|
||||||
|
errors.removeOverrideListener();
|
||||||
|
|
||||||
|
expect(onRemove).toHaveBeenCalledWith();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('does not throw if there is no handler', function() {
|
||||||
|
const fakeGlobal = { onerror: null };
|
||||||
|
const errors = new jasmineUnderTest.GlobalErrors(fakeGlobal);
|
||||||
|
|
||||||
|
expect(() => errors.removeOverrideListener()).not.toThrow();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -323,16 +323,16 @@ describe('PrettyPrinter', function() {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should indicate getters on objects as such', function() {
|
it('should use the return value of getters', function() {
|
||||||
const pp = jasmineUnderTest.makePrettyPrinter();
|
const pp = jasmineUnderTest.makePrettyPrinter();
|
||||||
const sampleValue = {
|
const sampleValue = {
|
||||||
id: 1,
|
id: 1,
|
||||||
get calculatedValue() {
|
get calculatedValue() {
|
||||||
throw new Error("don't call me!");
|
return 'the getter return value';
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
expect(pp(sampleValue)).toEqual(
|
expect(pp(sampleValue)).toEqual(
|
||||||
'Object({ id: 1, calculatedValue: <getter> })'
|
"Object({ id: 1, calculatedValue: 'the getter return value' })"
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -632,7 +632,8 @@ describe('QueueRunner', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('issues a more specific error if the function is `async`', function() {
|
it('issues a more specific error if the function is `async`', function() {
|
||||||
eval('var fn = async function(done){};');
|
// eslint-disable-next-line no-unused-vars
|
||||||
|
async function fn(done) {}
|
||||||
const onException = jasmine.createSpy('onException'),
|
const onException = jasmine.createSpy('onException'),
|
||||||
queueRunner = new jasmineUnderTest.QueueRunner({
|
queueRunner = new jasmineUnderTest.QueueRunner({
|
||||||
queueableFns: [{ fn: fn }],
|
queueableFns: [{ fn: fn }],
|
||||||
|
|||||||
557
spec/core/RunableResourcesSpec.js
Normal file
557
spec/core/RunableResourcesSpec.js
Normal file
@@ -0,0 +1,557 @@
|
|||||||
|
describe('RunableResources', function() {
|
||||||
|
describe('#spies', function() {
|
||||||
|
behavesLikeAPerRunableMutableArray(
|
||||||
|
'spies',
|
||||||
|
'Spies must be created in a before function or a spec',
|
||||||
|
false
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('#customSpyStrategies', function() {
|
||||||
|
behavesLikeAPerRunableMutableObject(
|
||||||
|
'customSpyStrategies',
|
||||||
|
'Custom spy strategies must be added in a before function or a spec'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('#customEqualityTesters', function() {
|
||||||
|
behavesLikeAPerRunableMutableArray(
|
||||||
|
'customEqualityTesters',
|
||||||
|
'Custom Equalities must be added in a before function or a spec'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('#customObjectFormatters', function() {
|
||||||
|
behavesLikeAPerRunableMutableArray(
|
||||||
|
'customObjectFormatters',
|
||||||
|
'Custom object formatters must be added in a before function or a spec'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('#customMatchers', function() {
|
||||||
|
behavesLikeAPerRunableMutableObject(
|
||||||
|
'customMatchers',
|
||||||
|
'Matchers must be added in a before function or a spec'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('#addCustomMatchers', function() {
|
||||||
|
it("adds all properties to the current runable's matchers", function() {
|
||||||
|
const currentRunableId = 1;
|
||||||
|
const runableResources = new jasmineUnderTest.RunableResources({
|
||||||
|
globalErrors: stubGlobalErrors(),
|
||||||
|
getCurrentRunableId: () => currentRunableId
|
||||||
|
});
|
||||||
|
runableResources.initForRunable(1);
|
||||||
|
|
||||||
|
function toBeFoo() {}
|
||||||
|
function toBeBar() {}
|
||||||
|
function toBeBaz() {}
|
||||||
|
|
||||||
|
runableResources.addCustomMatchers({ toBeFoo });
|
||||||
|
expect(runableResources.customMatchers()).toEqual({ toBeFoo });
|
||||||
|
|
||||||
|
runableResources.addCustomMatchers({ toBeBar, toBeBaz });
|
||||||
|
expect(runableResources.customMatchers()).toEqual({
|
||||||
|
toBeFoo,
|
||||||
|
toBeBar,
|
||||||
|
toBeBaz
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('#customAsyncMatchers', function() {
|
||||||
|
behavesLikeAPerRunableMutableObject(
|
||||||
|
'customAsyncMatchers',
|
||||||
|
'Async Matchers must be added in a before function or a spec'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('#addCustomAsyncMatchers', function() {
|
||||||
|
it("adds all properties to the current runable's matchers", function() {
|
||||||
|
const currentRunableId = 1;
|
||||||
|
const runableResources = new jasmineUnderTest.RunableResources({
|
||||||
|
globalErrors: stubGlobalErrors(),
|
||||||
|
getCurrentRunableId: () => currentRunableId
|
||||||
|
});
|
||||||
|
runableResources.initForRunable(1);
|
||||||
|
|
||||||
|
function toBeFoo() {}
|
||||||
|
function toBeBar() {}
|
||||||
|
function toBeBaz() {}
|
||||||
|
|
||||||
|
runableResources.addCustomAsyncMatchers({ toBeFoo });
|
||||||
|
expect(runableResources.customAsyncMatchers()).toEqual({ toBeFoo });
|
||||||
|
|
||||||
|
runableResources.addCustomAsyncMatchers({ toBeBar, toBeBaz });
|
||||||
|
expect(runableResources.customAsyncMatchers()).toEqual({
|
||||||
|
toBeFoo,
|
||||||
|
toBeBar,
|
||||||
|
toBeBaz
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('#defaultSpyStrategy', function() {
|
||||||
|
it('returns undefined for a newly initialized resource', function() {
|
||||||
|
let currentRunableId = 1;
|
||||||
|
const runableResources = new jasmineUnderTest.RunableResources({
|
||||||
|
globalErrors: stubGlobalErrors(),
|
||||||
|
getCurrentRunableId: () => currentRunableId
|
||||||
|
});
|
||||||
|
runableResources.initForRunable(1);
|
||||||
|
|
||||||
|
expect(runableResources.defaultSpyStrategy()).toBeUndefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns the value previously set by #setDefaultSpyStrategy', function() {
|
||||||
|
let currentRunableId = 1;
|
||||||
|
const runableResources = new jasmineUnderTest.RunableResources({
|
||||||
|
globalErrors: stubGlobalErrors(),
|
||||||
|
getCurrentRunableId: () => currentRunableId
|
||||||
|
});
|
||||||
|
runableResources.initForRunable(1);
|
||||||
|
const fn = () => {};
|
||||||
|
runableResources.setDefaultSpyStrategy(fn);
|
||||||
|
|
||||||
|
expect(runableResources.defaultSpyStrategy()).toBe(fn);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('is per-runable', function() {
|
||||||
|
let currentRunableId = 1;
|
||||||
|
const runableResources = new jasmineUnderTest.RunableResources({
|
||||||
|
globalErrors: stubGlobalErrors(),
|
||||||
|
getCurrentRunableId: () => currentRunableId
|
||||||
|
});
|
||||||
|
runableResources.initForRunable(1);
|
||||||
|
runableResources.setDefaultSpyStrategy(() => {});
|
||||||
|
currentRunableId = 2;
|
||||||
|
runableResources.initForRunable(2);
|
||||||
|
|
||||||
|
expect(runableResources.defaultSpyStrategy()).toBeUndefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('does not require a current runable', function() {
|
||||||
|
const runableResources = new jasmineUnderTest.RunableResources({
|
||||||
|
globalErrors: stubGlobalErrors(),
|
||||||
|
getCurrentRunableId: () => null
|
||||||
|
});
|
||||||
|
expect(runableResources.defaultSpyStrategy()).toBeUndefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("inherits the parent runable's value", function() {
|
||||||
|
let currentRunableId = 1;
|
||||||
|
const runableResources = new jasmineUnderTest.RunableResources({
|
||||||
|
globalErrors: stubGlobalErrors(),
|
||||||
|
getCurrentRunableId: () => currentRunableId
|
||||||
|
});
|
||||||
|
runableResources.initForRunable(1);
|
||||||
|
const fn = () => {};
|
||||||
|
runableResources.setDefaultSpyStrategy(fn);
|
||||||
|
currentRunableId = 2;
|
||||||
|
runableResources.initForRunable(2, 1);
|
||||||
|
|
||||||
|
expect(runableResources.defaultSpyStrategy()).toBe(fn);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('#setDefaultSpyStrategy', function() {
|
||||||
|
it('throws a user-facing error when there is no current runable', function() {
|
||||||
|
const runableResources = new jasmineUnderTest.RunableResources({
|
||||||
|
globalErrors: stubGlobalErrors(),
|
||||||
|
getCurrentRunableId: () => null
|
||||||
|
});
|
||||||
|
expect(function() {
|
||||||
|
runableResources.setDefaultSpyStrategy();
|
||||||
|
}).toThrowError(
|
||||||
|
'Default spy strategy must be set in a before function or a spec'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('#makePrettyPrinter', function() {
|
||||||
|
it('returns a pretty printer configured with the current customObjectFormatters', function() {
|
||||||
|
const runableResources = new jasmineUnderTest.RunableResources({
|
||||||
|
globalErrors: stubGlobalErrors(),
|
||||||
|
getCurrentRunableId: () => 1
|
||||||
|
});
|
||||||
|
runableResources.initForRunable(1);
|
||||||
|
function cof() {}
|
||||||
|
runableResources.customObjectFormatters().push(cof);
|
||||||
|
spyOn(jasmineUnderTest, 'makePrettyPrinter').and.callThrough();
|
||||||
|
const pp = runableResources.makePrettyPrinter();
|
||||||
|
|
||||||
|
expect(jasmineUnderTest.makePrettyPrinter).toHaveBeenCalledOnceWith([
|
||||||
|
cof
|
||||||
|
]);
|
||||||
|
expect(pp).toBe(
|
||||||
|
jasmineUnderTest.makePrettyPrinter.calls.first().returnValue
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('#makeMatchersUtil', function() {
|
||||||
|
describe('When there is a current runable', function() {
|
||||||
|
it('returns a MatchersUtil configured with the current resources', function() {
|
||||||
|
const runableResources = new jasmineUnderTest.RunableResources({
|
||||||
|
globalErrors: stubGlobalErrors(),
|
||||||
|
getCurrentRunableId: () => 1
|
||||||
|
});
|
||||||
|
runableResources.initForRunable(1);
|
||||||
|
function cof() {}
|
||||||
|
runableResources.customObjectFormatters().push(cof);
|
||||||
|
function ceq() {}
|
||||||
|
runableResources.customEqualityTesters().push(ceq);
|
||||||
|
const expectedPP = {};
|
||||||
|
const expectedMatchersUtil = {};
|
||||||
|
spyOn(jasmineUnderTest, 'makePrettyPrinter').and.returnValue(
|
||||||
|
expectedPP
|
||||||
|
);
|
||||||
|
spyOn(jasmineUnderTest, 'MatchersUtil').and.returnValue(
|
||||||
|
expectedMatchersUtil
|
||||||
|
);
|
||||||
|
|
||||||
|
const matchersUtil = runableResources.makeMatchersUtil();
|
||||||
|
|
||||||
|
expect(matchersUtil).toBe(expectedMatchersUtil);
|
||||||
|
expect(jasmineUnderTest.makePrettyPrinter).toHaveBeenCalledOnceWith([
|
||||||
|
cof
|
||||||
|
]);
|
||||||
|
// We need === equality on the pp passed to MatchersUtil
|
||||||
|
expect(jasmineUnderTest.MatchersUtil).toHaveBeenCalledOnceWith(
|
||||||
|
jasmine.objectContaining({
|
||||||
|
customTesters: [ceq]
|
||||||
|
})
|
||||||
|
);
|
||||||
|
expect(jasmineUnderTest.MatchersUtil.calls.argsFor(0)[0].pp).toBe(
|
||||||
|
expectedPP
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('When there is no current runable', function() {
|
||||||
|
it('returns a MatchersUtil configured with defaults', function() {
|
||||||
|
const runableResources = new jasmineUnderTest.RunableResources({
|
||||||
|
globalErrors: stubGlobalErrors(),
|
||||||
|
getCurrentRunableId: () => null
|
||||||
|
});
|
||||||
|
const expectedMatchersUtil = {};
|
||||||
|
spyOn(jasmineUnderTest, 'MatchersUtil').and.returnValue(
|
||||||
|
expectedMatchersUtil
|
||||||
|
);
|
||||||
|
|
||||||
|
const matchersUtil = runableResources.makeMatchersUtil();
|
||||||
|
|
||||||
|
expect(matchersUtil).toBe(expectedMatchersUtil);
|
||||||
|
// We need === equality on the pp passed to MatchersUtil
|
||||||
|
expect(jasmineUnderTest.MatchersUtil).toHaveBeenCalledTimes(1);
|
||||||
|
expect(jasmineUnderTest.MatchersUtil.calls.argsFor(0)[0].pp).toBe(
|
||||||
|
jasmineUnderTest.basicPrettyPrinter_
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
jasmineUnderTest.MatchersUtil.calls.argsFor(0)[0].customTesters
|
||||||
|
).toBeUndefined();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('.spyFactory', function() {
|
||||||
|
describe('When there is no current runable', function() {
|
||||||
|
it('is configured with default strategies and matchersUtil', function() {
|
||||||
|
const runableResources = new jasmineUnderTest.RunableResources({
|
||||||
|
globalErrors: stubGlobalErrors(),
|
||||||
|
getCurrentRunableId: () => null
|
||||||
|
});
|
||||||
|
spyOn(jasmineUnderTest, 'Spy');
|
||||||
|
const matchersUtil = {};
|
||||||
|
spyOn(runableResources, 'makeMatchersUtil').and.returnValue(
|
||||||
|
matchersUtil
|
||||||
|
);
|
||||||
|
|
||||||
|
runableResources.spyFactory.createSpy('foo');
|
||||||
|
|
||||||
|
expect(jasmineUnderTest.Spy).toHaveBeenCalledWith(
|
||||||
|
'foo',
|
||||||
|
is(matchersUtil),
|
||||||
|
jasmine.objectContaining({
|
||||||
|
customStrategies: {},
|
||||||
|
defaultStrategyFn: undefined
|
||||||
|
})
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('When there is a current runable', function() {
|
||||||
|
it("is configured with the current runable's strategies and matchersUtil", function() {
|
||||||
|
const runableResources = new jasmineUnderTest.RunableResources({
|
||||||
|
globalErrors: stubGlobalErrors(),
|
||||||
|
getCurrentRunableId: () => 1
|
||||||
|
});
|
||||||
|
runableResources.initForRunable(1);
|
||||||
|
function customStrategy() {}
|
||||||
|
function defaultStrategy() {}
|
||||||
|
runableResources.customSpyStrategies().foo = customStrategy;
|
||||||
|
runableResources.setDefaultSpyStrategy(defaultStrategy);
|
||||||
|
spyOn(jasmineUnderTest, 'Spy');
|
||||||
|
const matchersUtil = {};
|
||||||
|
spyOn(runableResources, 'makeMatchersUtil').and.returnValue(
|
||||||
|
matchersUtil
|
||||||
|
);
|
||||||
|
|
||||||
|
runableResources.spyFactory.createSpy('foo');
|
||||||
|
|
||||||
|
expect(jasmineUnderTest.Spy).toHaveBeenCalledWith(
|
||||||
|
'foo',
|
||||||
|
is(matchersUtil),
|
||||||
|
jasmine.objectContaining({
|
||||||
|
customStrategies: { foo: customStrategy },
|
||||||
|
defaultStrategyFn: defaultStrategy
|
||||||
|
})
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
function is(expected) {
|
||||||
|
return {
|
||||||
|
asymmetricMatch: function(actual) {
|
||||||
|
return actual === expected;
|
||||||
|
},
|
||||||
|
jasmineToString: function(pp) {
|
||||||
|
return '<same instance as ' + pp(expected) + '>';
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('.spyRegistry', function() {
|
||||||
|
it("writes to the current runable's spies", function() {
|
||||||
|
const runableResources = new jasmineUnderTest.RunableResources({
|
||||||
|
globalErrors: stubGlobalErrors(),
|
||||||
|
getCurrentRunableId: () => 1
|
||||||
|
});
|
||||||
|
runableResources.initForRunable(1);
|
||||||
|
function foo() {}
|
||||||
|
const spyObj = { foo };
|
||||||
|
runableResources.spyRegistry.spyOn(spyObj, 'foo');
|
||||||
|
|
||||||
|
expect(runableResources.spies()).toEqual([
|
||||||
|
jasmine.objectContaining({
|
||||||
|
restoreObjectToOriginalState: jasmine.any(Function)
|
||||||
|
})
|
||||||
|
]);
|
||||||
|
expect(jasmineUnderTest.isSpy(spyObj.foo)).toBeTrue();
|
||||||
|
|
||||||
|
runableResources.spyRegistry.clearSpies();
|
||||||
|
expect(spyObj.foo).toBe(foo);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('#clearForRunable', function() {
|
||||||
|
it('removes resources for the specified runable', function() {
|
||||||
|
const runableResources = new jasmineUnderTest.RunableResources({
|
||||||
|
globalErrors: stubGlobalErrors(),
|
||||||
|
getCurrentRunableId: () => 1
|
||||||
|
});
|
||||||
|
runableResources.initForRunable(1);
|
||||||
|
expect(function() {
|
||||||
|
runableResources.spies();
|
||||||
|
}).not.toThrow();
|
||||||
|
runableResources.clearForRunable(1);
|
||||||
|
expect(function() {
|
||||||
|
runableResources.spies();
|
||||||
|
}).toThrowError('Spies must be created in a before function or a spec');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('clears spies', function() {
|
||||||
|
const runableResources = new jasmineUnderTest.RunableResources({
|
||||||
|
globalErrors: stubGlobalErrors(),
|
||||||
|
getCurrentRunableId: () => 1
|
||||||
|
});
|
||||||
|
runableResources.initForRunable(1);
|
||||||
|
function foo() {}
|
||||||
|
const spyObj = { foo };
|
||||||
|
runableResources.spyRegistry.spyOn(spyObj, 'foo');
|
||||||
|
expect(spyObj.foo).not.toBe(foo);
|
||||||
|
|
||||||
|
runableResources.clearForRunable(1);
|
||||||
|
expect(spyObj.foo).toBe(foo);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('clears the global error spy', function() {
|
||||||
|
const globalErrors = jasmine.createSpyObj('globalErrors', [
|
||||||
|
'removeOverrideListener'
|
||||||
|
]);
|
||||||
|
const runableResources = new jasmineUnderTest.RunableResources({
|
||||||
|
getCurrentRunableId: () => 1,
|
||||||
|
globalErrors
|
||||||
|
});
|
||||||
|
runableResources.initForRunable(1);
|
||||||
|
|
||||||
|
runableResources.clearForRunable(1);
|
||||||
|
expect(globalErrors.removeOverrideListener).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('does not remove resources for other runables', function() {
|
||||||
|
const runableResources = new jasmineUnderTest.RunableResources({
|
||||||
|
globalErrors: stubGlobalErrors(),
|
||||||
|
getCurrentRunableId: () => 1
|
||||||
|
});
|
||||||
|
runableResources.initForRunable(1);
|
||||||
|
function cof() {}
|
||||||
|
runableResources.customObjectFormatters().push(cof);
|
||||||
|
runableResources.clearForRunable(2);
|
||||||
|
expect(runableResources.customObjectFormatters()).toEqual([cof]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
function behavesLikeAPerRunableMutableArray(
|
||||||
|
methodName,
|
||||||
|
errorMsg,
|
||||||
|
inherits = true
|
||||||
|
) {
|
||||||
|
it('is initially empty', function() {
|
||||||
|
const currentRunableId = 1;
|
||||||
|
const runableResources = new jasmineUnderTest.RunableResources({
|
||||||
|
globalErrors: stubGlobalErrors(),
|
||||||
|
getCurrentRunableId: () => currentRunableId
|
||||||
|
});
|
||||||
|
runableResources.initForRunable(1);
|
||||||
|
|
||||||
|
expect(runableResources[methodName]()).toEqual([]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('is mutable', function() {
|
||||||
|
const currentRunableId = 1;
|
||||||
|
const runableResources = new jasmineUnderTest.RunableResources({
|
||||||
|
globalErrors: stubGlobalErrors(),
|
||||||
|
getCurrentRunableId: () => currentRunableId
|
||||||
|
});
|
||||||
|
runableResources.initForRunable(1);
|
||||||
|
function newItem() {}
|
||||||
|
runableResources[methodName]().push(newItem);
|
||||||
|
expect(runableResources[methodName]()).toEqual([newItem]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('is per-runable', function() {
|
||||||
|
let currentRunableId = 1;
|
||||||
|
const runableResources = new jasmineUnderTest.RunableResources({
|
||||||
|
globalErrors: stubGlobalErrors(),
|
||||||
|
getCurrentRunableId: () => currentRunableId
|
||||||
|
});
|
||||||
|
runableResources.initForRunable(1);
|
||||||
|
runableResources[methodName]().push(() => {});
|
||||||
|
runableResources.initForRunable(2);
|
||||||
|
currentRunableId = 2;
|
||||||
|
expect(runableResources[methodName]()).toEqual([]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('throws a user-facing error when there is no current runable', function() {
|
||||||
|
const runableResources = new jasmineUnderTest.RunableResources({
|
||||||
|
globalErrors: stubGlobalErrors(),
|
||||||
|
getCurrentRunableId: () => null
|
||||||
|
});
|
||||||
|
expect(function() {
|
||||||
|
runableResources[methodName]();
|
||||||
|
}).toThrowError(errorMsg);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (inherits) {
|
||||||
|
it('inherits from the parent runable', function() {
|
||||||
|
let currentRunableId = 1;
|
||||||
|
const runableResources = new jasmineUnderTest.RunableResources({
|
||||||
|
globalErrors: stubGlobalErrors(),
|
||||||
|
getCurrentRunableId: () => currentRunableId
|
||||||
|
});
|
||||||
|
runableResources.initForRunable(1);
|
||||||
|
function parentItem() {}
|
||||||
|
runableResources[methodName]().push(parentItem);
|
||||||
|
runableResources.initForRunable(2, 1);
|
||||||
|
currentRunableId = 2;
|
||||||
|
function childItem() {}
|
||||||
|
runableResources[methodName]().push(childItem);
|
||||||
|
expect(runableResources[methodName]()).toEqual([parentItem, childItem]);
|
||||||
|
|
||||||
|
currentRunableId = 1;
|
||||||
|
expect(runableResources[methodName]()).toEqual([parentItem]);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function behavesLikeAPerRunableMutableObject(methodName, errorMsg) {
|
||||||
|
it('is initially empty', function() {
|
||||||
|
const currentRunableId = 1;
|
||||||
|
const runableResources = new jasmineUnderTest.RunableResources({
|
||||||
|
globalErrors: stubGlobalErrors(),
|
||||||
|
getCurrentRunableId: () => currentRunableId
|
||||||
|
});
|
||||||
|
runableResources.initForRunable(1);
|
||||||
|
|
||||||
|
expect(runableResources[methodName]()).toEqual({});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('is mutable', function() {
|
||||||
|
const currentRunableId = 1;
|
||||||
|
const runableResources = new jasmineUnderTest.RunableResources({
|
||||||
|
globalErrors: stubGlobalErrors(),
|
||||||
|
getCurrentRunableId: () => currentRunableId
|
||||||
|
});
|
||||||
|
runableResources.initForRunable(1);
|
||||||
|
function newItem() {}
|
||||||
|
runableResources[methodName]().foo = newItem;
|
||||||
|
expect(runableResources[methodName]()).toEqual({ foo: newItem });
|
||||||
|
});
|
||||||
|
|
||||||
|
it('is per-runable', function() {
|
||||||
|
let currentRunableId = 1;
|
||||||
|
const runableResources = new jasmineUnderTest.RunableResources({
|
||||||
|
globalErrors: stubGlobalErrors(),
|
||||||
|
getCurrentRunableId: () => currentRunableId
|
||||||
|
});
|
||||||
|
runableResources.initForRunable(1);
|
||||||
|
runableResources[methodName]().foo = function() {};
|
||||||
|
runableResources.initForRunable(2);
|
||||||
|
currentRunableId = 2;
|
||||||
|
expect(runableResources[methodName]()).toEqual({});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('throws a user-facing error when there is no current runable', function() {
|
||||||
|
const runableResources = new jasmineUnderTest.RunableResources({
|
||||||
|
globalErrors: stubGlobalErrors(),
|
||||||
|
getCurrentRunableId: () => null
|
||||||
|
});
|
||||||
|
expect(function() {
|
||||||
|
runableResources[methodName]();
|
||||||
|
}).toThrowError(errorMsg);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('inherits from the parent runable', function() {
|
||||||
|
let currentRunableId = 1;
|
||||||
|
const runableResources = new jasmineUnderTest.RunableResources({
|
||||||
|
globalErrors: stubGlobalErrors(),
|
||||||
|
getCurrentRunableId: () => currentRunableId
|
||||||
|
});
|
||||||
|
runableResources.initForRunable(1);
|
||||||
|
function parentItem() {}
|
||||||
|
runableResources[methodName]().parentName = parentItem;
|
||||||
|
runableResources.initForRunable(2, 1);
|
||||||
|
currentRunableId = 2;
|
||||||
|
function childItem() {}
|
||||||
|
runableResources[methodName]().childName = childItem;
|
||||||
|
expect(runableResources[methodName]()).toEqual({
|
||||||
|
parentName: parentItem,
|
||||||
|
childName: childItem
|
||||||
|
});
|
||||||
|
|
||||||
|
currentRunableId = 1;
|
||||||
|
expect(runableResources[methodName]()).toEqual({
|
||||||
|
parentName: parentItem
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function stubGlobalErrors() {
|
||||||
|
return {
|
||||||
|
removeOverrideListener() {}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
});
|
||||||
@@ -38,11 +38,10 @@ describe('Spec', function() {
|
|||||||
spec = new jasmineUnderTest.Spec({
|
spec = new jasmineUnderTest.Spec({
|
||||||
description: 'my test',
|
description: 'my test',
|
||||||
id: 'some-id',
|
id: 'some-id',
|
||||||
queueableFn: { fn: function() {} },
|
queueableFn: { fn: function() {} }
|
||||||
queueRunnerFactory: fakeQueueRunner
|
|
||||||
});
|
});
|
||||||
|
|
||||||
spec.execute();
|
spec.execute(fakeQueueRunner);
|
||||||
|
|
||||||
expect(fakeQueueRunner).toHaveBeenCalled();
|
expect(fakeQueueRunner).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
@@ -54,11 +53,10 @@ describe('Spec', function() {
|
|||||||
id: 123,
|
id: 123,
|
||||||
description: 'foo bar',
|
description: 'foo bar',
|
||||||
queueableFn: { fn: function() {} },
|
queueableFn: { fn: function() {} },
|
||||||
onStart: startCallback,
|
onStart: startCallback
|
||||||
queueRunnerFactory: fakeQueueRunner
|
|
||||||
});
|
});
|
||||||
|
|
||||||
spec.execute();
|
spec.execute(fakeQueueRunner);
|
||||||
|
|
||||||
fakeQueueRunner.calls.mostRecent().args[0].queueableFns[0].fn();
|
fakeQueueRunner.calls.mostRecent().args[0].queueableFns[0].fn();
|
||||||
expect(startCallback).toHaveBeenCalled();
|
expect(startCallback).toHaveBeenCalled();
|
||||||
@@ -82,11 +80,10 @@ describe('Spec', function() {
|
|||||||
}
|
}
|
||||||
];
|
];
|
||||||
},
|
},
|
||||||
onStart: startCallback,
|
onStart: startCallback
|
||||||
queueRunnerFactory: fakeQueueRunner
|
|
||||||
});
|
});
|
||||||
|
|
||||||
spec.execute();
|
spec.execute(fakeQueueRunner);
|
||||||
|
|
||||||
fakeQueueRunner.calls.mostRecent().args[0].queueableFns[0].fn();
|
fakeQueueRunner.calls.mostRecent().args[0].queueableFns[0].fn();
|
||||||
expect(startCallback).toHaveBeenCalled();
|
expect(startCallback).toHaveBeenCalled();
|
||||||
@@ -106,11 +103,10 @@ describe('Spec', function() {
|
|||||||
queueableFn: queueableFn,
|
queueableFn: queueableFn,
|
||||||
beforeAndAfterFns: function() {
|
beforeAndAfterFns: function() {
|
||||||
return { befores: [before], afters: [after] };
|
return { befores: [before], afters: [after] };
|
||||||
},
|
}
|
||||||
queueRunnerFactory: fakeQueueRunner
|
|
||||||
});
|
});
|
||||||
|
|
||||||
spec.execute();
|
spec.execute(fakeQueueRunner);
|
||||||
|
|
||||||
const options = fakeQueueRunner.calls.mostRecent().args[0];
|
const options = fakeQueueRunner.calls.mostRecent().args[0];
|
||||||
expect(options.queueableFns).toEqual([
|
expect(options.queueableFns).toEqual([
|
||||||
@@ -131,11 +127,10 @@ describe('Spec', function() {
|
|||||||
queueableFn: { fn: function() {} },
|
queueableFn: { fn: function() {} },
|
||||||
beforeAndAfterFns: function() {
|
beforeAndAfterFns: function() {
|
||||||
return { befores: [], afters: [] };
|
return { befores: [], afters: [] };
|
||||||
},
|
}
|
||||||
queueRunnerFactory: fakeQueueRunner
|
|
||||||
});
|
});
|
||||||
|
|
||||||
spec.execute();
|
spec.execute(fakeQueueRunner);
|
||||||
|
|
||||||
expect(fakeQueueRunner).toHaveBeenCalledWith(
|
expect(fakeQueueRunner).toHaveBeenCalledWith(
|
||||||
jasmine.objectContaining({
|
jasmine.objectContaining({
|
||||||
@@ -145,14 +140,12 @@ describe('Spec', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('is marked pending if created without a function body', function() {
|
it('is marked pending if created without a function body', function() {
|
||||||
const fakeQueueRunner = jasmine.createSpy('fakeQueueRunner'),
|
const startCallback = jasmine.createSpy('startCallback'),
|
||||||
startCallback = jasmine.createSpy('startCallback'),
|
|
||||||
resultCallback = jasmine.createSpy('resultCallback'),
|
resultCallback = jasmine.createSpy('resultCallback'),
|
||||||
spec = new jasmineUnderTest.Spec({
|
spec = new jasmineUnderTest.Spec({
|
||||||
onStart: startCallback,
|
onStart: startCallback,
|
||||||
queueableFn: { fn: null },
|
queueableFn: { fn: null },
|
||||||
resultCallback: resultCallback,
|
resultCallback: resultCallback
|
||||||
queueRunnerFactory: fakeQueueRunner
|
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(spec.status()).toBe('pending');
|
expect(spec.status()).toBe('pending');
|
||||||
@@ -166,11 +159,10 @@ describe('Spec', function() {
|
|||||||
spec = new jasmineUnderTest.Spec({
|
spec = new jasmineUnderTest.Spec({
|
||||||
onStart: startCallback,
|
onStart: startCallback,
|
||||||
queueableFn: { fn: specBody },
|
queueableFn: { fn: specBody },
|
||||||
resultCallback: resultCallback,
|
resultCallback: resultCallback
|
||||||
queueRunnerFactory: fakeQueueRunner
|
|
||||||
});
|
});
|
||||||
|
|
||||||
spec.execute('cally-back', true);
|
spec.execute(fakeQueueRunner, 'cally-back', true);
|
||||||
|
|
||||||
expect(fakeQueueRunner).toHaveBeenCalledWith(
|
expect(fakeQueueRunner).toHaveBeenCalledWith(
|
||||||
jasmine.objectContaining({
|
jasmine.objectContaining({
|
||||||
@@ -206,7 +198,6 @@ describe('Spec', function() {
|
|||||||
getSpecName: function() {
|
getSpecName: function() {
|
||||||
return 'a suite with a spec';
|
return 'a suite with a spec';
|
||||||
},
|
},
|
||||||
queueRunnerFactory: fakeQueueRunner,
|
|
||||||
queueableFn: { fn: null }
|
queueableFn: { fn: null }
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -214,7 +205,7 @@ describe('Spec', function() {
|
|||||||
|
|
||||||
expect(spec.status()).toBe('pending');
|
expect(spec.status()).toBe('pending');
|
||||||
|
|
||||||
spec.execute();
|
spec.execute(fakeQueueRunner);
|
||||||
|
|
||||||
expect(fakeQueueRunner).toHaveBeenCalled();
|
expect(fakeQueueRunner).toHaveBeenCalled();
|
||||||
|
|
||||||
@@ -247,13 +238,10 @@ describe('Spec', function() {
|
|||||||
catchExceptions: function() {
|
catchExceptions: function() {
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
resultCallback: function() {},
|
resultCallback: function() {}
|
||||||
queueRunnerFactory: function(attrs) {
|
|
||||||
attrs.onComplete();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
spec.execute(done);
|
spec.execute(attrs => attrs.onComplete(), done);
|
||||||
|
|
||||||
expect(done).toHaveBeenCalled();
|
expect(done).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
@@ -265,14 +253,14 @@ describe('Spec', function() {
|
|||||||
catchExceptions: function() {
|
catchExceptions: function() {
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
resultCallback: function() {},
|
resultCallback: function() {}
|
||||||
queueRunnerFactory: function(attrs) {
|
|
||||||
spec.result.status = 'failed';
|
|
||||||
attrs.onComplete();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
spec.execute(done);
|
function queueRunnerFactory(attrs) {
|
||||||
|
spec.result.status = 'failed';
|
||||||
|
attrs.onComplete();
|
||||||
|
}
|
||||||
|
spec.execute(queueRunnerFactory, done);
|
||||||
|
|
||||||
expect(done).toHaveBeenCalledWith(
|
expect(done).toHaveBeenCalledWith(
|
||||||
jasmine.any(jasmineUnderTest.StopExecutionError)
|
jasmine.any(jasmineUnderTest.StopExecutionError)
|
||||||
@@ -293,16 +281,17 @@ describe('Spec', function() {
|
|||||||
resultCallback: function(result) {
|
resultCallback: function(result) {
|
||||||
duration = result.duration;
|
duration = result.duration;
|
||||||
},
|
},
|
||||||
queueRunnerFactory: function(config) {
|
|
||||||
config.queueableFns.forEach(function(qf) {
|
|
||||||
qf.fn();
|
|
||||||
});
|
|
||||||
config.onComplete();
|
|
||||||
},
|
|
||||||
timer: timer
|
timer: timer
|
||||||
});
|
});
|
||||||
|
|
||||||
spec.execute(function() {});
|
function queueRunnerFactory(config) {
|
||||||
|
config.queueableFns.forEach(function(qf) {
|
||||||
|
qf.fn();
|
||||||
|
});
|
||||||
|
config.onComplete();
|
||||||
|
}
|
||||||
|
|
||||||
|
spec.execute(queueRunnerFactory, function() {});
|
||||||
expect(duration).toBe(77000);
|
expect(duration).toBe(77000);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -313,13 +302,10 @@ describe('Spec', function() {
|
|||||||
catchExceptions: function() {
|
catchExceptions: function() {
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
resultCallback: function() {},
|
resultCallback: function() {}
|
||||||
queueRunnerFactory: function(attrs) {
|
|
||||||
attrs.onComplete();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
spec.setSpecProperty('a', 4);
|
spec.setSpecProperty('a', 4);
|
||||||
spec.execute(done);
|
spec.execute(attrs => attrs.onComplete(), done);
|
||||||
expect(spec.result.properties).toEqual({ a: 4 });
|
expect(spec.result.properties).toEqual({ a: 4 });
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -334,7 +320,7 @@ describe('Spec', function() {
|
|||||||
const spec = new jasmineUnderTest.Spec({
|
const spec = new jasmineUnderTest.Spec({
|
||||||
queueableFn: { fn: jasmine.createSpy('spec body') }
|
queueableFn: { fn: jasmine.createSpy('spec body') }
|
||||||
});
|
});
|
||||||
spec.addExpectationResult(true);
|
spec.addExpectationResult(true, {});
|
||||||
expect(spec.status()).toBe('passed');
|
expect(spec.status()).toBe('passed');
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -342,8 +328,8 @@ describe('Spec', function() {
|
|||||||
const spec = new jasmineUnderTest.Spec({
|
const spec = new jasmineUnderTest.Spec({
|
||||||
queueableFn: { fn: jasmine.createSpy('spec body') }
|
queueableFn: { fn: jasmine.createSpy('spec body') }
|
||||||
});
|
});
|
||||||
spec.addExpectationResult(true);
|
spec.addExpectationResult(true, {});
|
||||||
spec.addExpectationResult(false);
|
spec.addExpectationResult(false, {});
|
||||||
expect(spec.status()).toBe('failed');
|
expect(spec.status()).toBe('failed');
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -352,25 +338,21 @@ describe('Spec', function() {
|
|||||||
resultCallback = jasmine.createSpy('resultCallback'),
|
resultCallback = jasmine.createSpy('resultCallback'),
|
||||||
spec = new jasmineUnderTest.Spec({
|
spec = new jasmineUnderTest.Spec({
|
||||||
queueableFn: { fn: jasmine.createSpy('spec body') },
|
queueableFn: { fn: jasmine.createSpy('spec body') },
|
||||||
expectationResultFactory: function(data) {
|
|
||||||
return data;
|
|
||||||
},
|
|
||||||
queueRunnerFactory: fakeQueueRunner,
|
|
||||||
resultCallback: resultCallback
|
resultCallback: resultCallback
|
||||||
});
|
});
|
||||||
spec.addExpectationResult(true, 'expectation1');
|
spec.addExpectationResult(true, { message: 'expectation1' });
|
||||||
spec.addExpectationResult(false, 'expectation2');
|
spec.addExpectationResult(false, { message: 'expectation2' });
|
||||||
|
|
||||||
spec.execute();
|
spec.execute(fakeQueueRunner);
|
||||||
|
|
||||||
const fns = fakeQueueRunner.calls.mostRecent().args[0].queueableFns;
|
const fns = fakeQueueRunner.calls.mostRecent().args[0].queueableFns;
|
||||||
fns[fns.length - 1].fn();
|
fns[fns.length - 1].fn();
|
||||||
|
|
||||||
expect(resultCallback.calls.first().args[0].passedExpectations).toEqual([
|
expect(resultCallback.calls.first().args[0].passedExpectations).toEqual([
|
||||||
'expectation1'
|
jasmine.objectContaining({ message: 'expectation1' })
|
||||||
]);
|
]);
|
||||||
expect(resultCallback.calls.first().args[0].failedExpectations).toEqual([
|
expect(resultCallback.calls.first().args[0].failedExpectations).toEqual([
|
||||||
'expectation2'
|
jasmine.objectContaining({ message: 'expectation2' })
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -379,46 +361,123 @@ describe('Spec', function() {
|
|||||||
resultCallback = jasmine.createSpy('resultCallback'),
|
resultCallback = jasmine.createSpy('resultCallback'),
|
||||||
spec = new jasmineUnderTest.Spec({
|
spec = new jasmineUnderTest.Spec({
|
||||||
queueableFn: { fn: function() {} },
|
queueableFn: { fn: function() {} },
|
||||||
expectationResultFactory: function(data) {
|
|
||||||
return data;
|
|
||||||
},
|
|
||||||
queueRunnerFactory: fakeQueueRunner,
|
|
||||||
resultCallback: resultCallback,
|
resultCallback: resultCallback,
|
||||||
throwOnExpectationFailure: true
|
throwOnExpectationFailure: true
|
||||||
});
|
});
|
||||||
|
|
||||||
spec.addExpectationResult(true, 'passed');
|
spec.addExpectationResult(true, { message: 'passed' });
|
||||||
expect(function() {
|
expect(function() {
|
||||||
spec.addExpectationResult(false, 'failed');
|
spec.addExpectationResult(false, { message: 'failed' });
|
||||||
}).toThrowError(jasmineUnderTest.errors.ExpectationFailed);
|
}).toThrowError(jasmineUnderTest.errors.ExpectationFailed);
|
||||||
|
|
||||||
spec.execute();
|
spec.execute(fakeQueueRunner);
|
||||||
|
|
||||||
const fns = fakeQueueRunner.calls.mostRecent().args[0].queueableFns;
|
const fns = fakeQueueRunner.calls.mostRecent().args[0].queueableFns;
|
||||||
fns[fns.length - 1].fn();
|
fns[fns.length - 1].fn();
|
||||||
expect(resultCallback.calls.first().args[0].passedExpectations).toEqual([
|
expect(resultCallback.calls.first().args[0].passedExpectations).toEqual([
|
||||||
'passed'
|
jasmine.objectContaining({ message: 'passed' })
|
||||||
]);
|
]);
|
||||||
expect(resultCallback.calls.first().args[0].failedExpectations).toEqual([
|
expect(resultCallback.calls.first().args[0].failedExpectations).toEqual([
|
||||||
'failed'
|
jasmine.objectContaining({ message: 'failed' })
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('forwards late expectation failures to onLateError', function() {
|
||||||
|
const onLateError = jasmine.createSpy('onLateError');
|
||||||
|
const spec = new jasmineUnderTest.Spec({
|
||||||
|
onLateError,
|
||||||
|
queueableFn: { fn: function() {} }
|
||||||
|
});
|
||||||
|
const data = {
|
||||||
|
matcherName: '',
|
||||||
|
passed: false,
|
||||||
|
expected: '',
|
||||||
|
actual: '',
|
||||||
|
error: new Error('nope')
|
||||||
|
};
|
||||||
|
|
||||||
|
spec.reportedDone = true;
|
||||||
|
spec.addExpectationResult(false, data, true);
|
||||||
|
|
||||||
|
expect(onLateError).toHaveBeenCalledWith(
|
||||||
|
jasmine.objectContaining({
|
||||||
|
message: jasmine.stringMatching(/^Error: nope/)
|
||||||
|
})
|
||||||
|
);
|
||||||
|
expect(spec.result.failedExpectations).toEqual([]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('does not forward non-late expectation failures to onLateError', function() {
|
||||||
|
const onLateError = jasmine.createSpy('onLateError');
|
||||||
|
const spec = new jasmineUnderTest.Spec({
|
||||||
|
onLateError,
|
||||||
|
queueableFn: { fn: function() {} }
|
||||||
|
});
|
||||||
|
const data = {
|
||||||
|
matcherName: '',
|
||||||
|
passed: false,
|
||||||
|
expected: '',
|
||||||
|
actual: '',
|
||||||
|
error: new Error('nope')
|
||||||
|
};
|
||||||
|
|
||||||
|
spec.addExpectationResult(false, data, true);
|
||||||
|
|
||||||
|
expect(onLateError).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('forwards late handleException calls to onLateError', function() {
|
||||||
|
const onLateError = jasmine.createSpy('onLateError');
|
||||||
|
const spec = new jasmineUnderTest.Spec({
|
||||||
|
onLateError,
|
||||||
|
queueableFn: { fn: function() {} }
|
||||||
|
});
|
||||||
|
|
||||||
|
spec.reportedDone = true;
|
||||||
|
spec.handleException(new Error('oops'));
|
||||||
|
|
||||||
|
expect(onLateError).toHaveBeenCalledWith(
|
||||||
|
jasmine.objectContaining({
|
||||||
|
message: jasmine.stringMatching(/^Error: oops/)
|
||||||
|
})
|
||||||
|
);
|
||||||
|
expect(spec.result.failedExpectations).toEqual([]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('does not forward non-late handleException calls to onLateError', function() {
|
||||||
|
const onLateError = jasmine.createSpy('onLateError');
|
||||||
|
const spec = new jasmineUnderTest.Spec({
|
||||||
|
onLateError,
|
||||||
|
queueableFn: { fn: function() {} }
|
||||||
|
});
|
||||||
|
const error = new Error('oops');
|
||||||
|
|
||||||
|
spec.handleException(error);
|
||||||
|
|
||||||
|
expect(onLateError).not.toHaveBeenCalled();
|
||||||
|
expect(spec.result.failedExpectations.length).toEqual(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('clears the reportedDone flag when reset', function() {
|
||||||
|
const spec = new jasmineUnderTest.Spec({
|
||||||
|
queueableFn: { fn: function() {} }
|
||||||
|
});
|
||||||
|
spec.reportedDone = true;
|
||||||
|
|
||||||
|
spec.reset();
|
||||||
|
|
||||||
|
expect(spec.reportedDone).toBeFalse();
|
||||||
|
});
|
||||||
|
|
||||||
it('does not throw an ExpectationFailed error when handling an error', function() {
|
it('does not throw an ExpectationFailed error when handling an error', function() {
|
||||||
const resultCallback = jasmine.createSpy('resultCallback'),
|
const resultCallback = jasmine.createSpy('resultCallback'),
|
||||||
spec = new jasmineUnderTest.Spec({
|
spec = new jasmineUnderTest.Spec({
|
||||||
queueableFn: { fn: function() {} },
|
queueableFn: { fn: function() {} },
|
||||||
expectationResultFactory: function(data) {
|
|
||||||
return data;
|
|
||||||
},
|
|
||||||
queueRunnerFactory: function(attrs) {
|
|
||||||
attrs.onComplete();
|
|
||||||
},
|
|
||||||
resultCallback: resultCallback,
|
resultCallback: resultCallback,
|
||||||
throwOnExpectationFailure: true
|
throwOnExpectationFailure: true
|
||||||
});
|
});
|
||||||
|
|
||||||
spec.onException('failing exception');
|
spec.handleException('failing exception');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('can return its full name', function() {
|
it('can return its full name', function() {
|
||||||
@@ -445,11 +504,10 @@ describe('Spec', function() {
|
|||||||
spec = new jasmineUnderTest.Spec({
|
spec = new jasmineUnderTest.Spec({
|
||||||
description: 'my test',
|
description: 'my test',
|
||||||
id: 'some-id',
|
id: 'some-id',
|
||||||
queueableFn: { fn: function() {} },
|
queueableFn: { fn: function() {} }
|
||||||
queueRunnerFactory: fakeQueueRunner
|
|
||||||
});
|
});
|
||||||
|
|
||||||
spec.execute();
|
spec.execute(fakeQueueRunner);
|
||||||
|
|
||||||
expect(spec.status()).toEqual('pending');
|
expect(spec.status()).toEqual('pending');
|
||||||
expect(spec.result.pendingReason).toEqual('');
|
expect(spec.result.pendingReason).toEqual('');
|
||||||
@@ -467,11 +525,10 @@ describe('Spec', function() {
|
|||||||
spec = new jasmineUnderTest.Spec({
|
spec = new jasmineUnderTest.Spec({
|
||||||
description: 'my test',
|
description: 'my test',
|
||||||
id: 'some-id',
|
id: 'some-id',
|
||||||
queueableFn: { fn: function() {} },
|
queueableFn: { fn: function() {} }
|
||||||
queueRunnerFactory: fakeQueueRunner
|
|
||||||
});
|
});
|
||||||
|
|
||||||
spec.execute();
|
spec.execute(fakeQueueRunner);
|
||||||
|
|
||||||
expect(spec.status()).toEqual('pending');
|
expect(spec.status()).toEqual('pending');
|
||||||
expect(spec.result.pendingReason).toEqual('custom message');
|
expect(spec.result.pendingReason).toEqual('custom message');
|
||||||
@@ -483,25 +540,22 @@ describe('Spec', function() {
|
|||||||
resultCallback = jasmine.createSpy('resultCallback'),
|
resultCallback = jasmine.createSpy('resultCallback'),
|
||||||
spec = new jasmineUnderTest.Spec({
|
spec = new jasmineUnderTest.Spec({
|
||||||
queueableFn: { fn: function() {} },
|
queueableFn: { fn: function() {} },
|
||||||
expectationResultFactory: function(data) {
|
|
||||||
return data;
|
|
||||||
},
|
|
||||||
queueRunnerFactory: fakeQueueRunner,
|
|
||||||
resultCallback: resultCallback
|
resultCallback: resultCallback
|
||||||
});
|
});
|
||||||
|
|
||||||
spec.onException('foo');
|
spec.handleException('foo');
|
||||||
spec.execute();
|
spec.execute(fakeQueueRunner);
|
||||||
|
|
||||||
const args = fakeQueueRunner.calls.mostRecent().args[0];
|
const args = fakeQueueRunner.calls.mostRecent().args[0];
|
||||||
args.queueableFns[args.queueableFns.length - 1].fn();
|
args.queueableFns[args.queueableFns.length - 1].fn();
|
||||||
expect(resultCallback.calls.first().args[0].failedExpectations).toEqual([
|
expect(resultCallback.calls.first().args[0].failedExpectations).toEqual([
|
||||||
{
|
{
|
||||||
error: 'foo',
|
message: 'foo thrown',
|
||||||
matcherName: '',
|
matcherName: '',
|
||||||
passed: false,
|
passed: false,
|
||||||
expected: '',
|
expected: '',
|
||||||
actual: ''
|
actual: '',
|
||||||
|
stack: null
|
||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
@@ -511,15 +565,11 @@ describe('Spec', function() {
|
|||||||
resultCallback = jasmine.createSpy('resultCallback'),
|
resultCallback = jasmine.createSpy('resultCallback'),
|
||||||
spec = new jasmineUnderTest.Spec({
|
spec = new jasmineUnderTest.Spec({
|
||||||
queueableFn: { fn: function() {} },
|
queueableFn: { fn: function() {} },
|
||||||
expectationResultFactory: function(data) {
|
|
||||||
return data;
|
|
||||||
},
|
|
||||||
queueRunnerFactory: fakeQueueRunner,
|
|
||||||
resultCallback: resultCallback
|
resultCallback: resultCallback
|
||||||
});
|
});
|
||||||
|
|
||||||
spec.onException(new jasmineUnderTest.errors.ExpectationFailed());
|
spec.handleException(new jasmineUnderTest.errors.ExpectationFailed());
|
||||||
spec.execute();
|
spec.execute(fakeQueueRunner);
|
||||||
|
|
||||||
const args = fakeQueueRunner.calls.mostRecent().args[0];
|
const args = fakeQueueRunner.calls.mostRecent().args[0];
|
||||||
args.queueableFns[args.queueableFns.length - 1].fn();
|
args.queueableFns[args.queueableFns.length - 1].fn();
|
||||||
@@ -532,13 +582,12 @@ describe('Spec', function() {
|
|||||||
spec = new jasmineUnderTest.Spec({
|
spec = new jasmineUnderTest.Spec({
|
||||||
onLateError: onLateError,
|
onLateError: onLateError,
|
||||||
queueableFn: { fn: function() {} },
|
queueableFn: { fn: function() {} },
|
||||||
queueRunnerFactory: queueRunnerFactory,
|
|
||||||
getSpecName: function() {
|
getSpecName: function() {
|
||||||
return 'a spec';
|
return 'a spec';
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
spec.execute();
|
spec.execute(queueRunnerFactory);
|
||||||
|
|
||||||
expect(queueRunnerFactory).toHaveBeenCalled();
|
expect(queueRunnerFactory).toHaveBeenCalled();
|
||||||
queueRunnerFactory.calls.argsFor(0)[0].onMultipleDone();
|
queueRunnerFactory.calls.argsFor(0)[0].onMultipleDone();
|
||||||
@@ -558,13 +607,12 @@ describe('Spec', function() {
|
|||||||
queueableFn: {
|
queueableFn: {
|
||||||
fn: function() {}
|
fn: function() {}
|
||||||
},
|
},
|
||||||
queueRunnerFactory: function() {},
|
|
||||||
timer: timer
|
timer: timer
|
||||||
}),
|
}),
|
||||||
t1 = 123,
|
t1 = 123,
|
||||||
t2 = 456;
|
t2 = 456;
|
||||||
|
|
||||||
spec.execute();
|
spec.execute(() => {});
|
||||||
expect(spec.result.debugLogs).toBeNull();
|
expect(spec.result.debugLogs).toBeNull();
|
||||||
timer.elapsed.and.returnValue(t1);
|
timer.elapsed.and.returnValue(t1);
|
||||||
spec.debugLog('msg 1');
|
spec.debugLog('msg 1');
|
||||||
@@ -586,17 +634,18 @@ describe('Spec', function() {
|
|||||||
queueableFn: {
|
queueableFn: {
|
||||||
fn: function() {}
|
fn: function() {}
|
||||||
},
|
},
|
||||||
resultCallback: resultCallback,
|
resultCallback: resultCallback
|
||||||
queueRunnerFactory: function(config) {
|
|
||||||
spec.debugLog('msg');
|
|
||||||
for (const fn of config.queueableFns) {
|
|
||||||
fn.fn();
|
|
||||||
}
|
|
||||||
config.onComplete(false);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
spec.execute(function() {});
|
function queueRunnerFactory(config) {
|
||||||
|
spec.debugLog('msg');
|
||||||
|
for (const fn of config.queueableFns) {
|
||||||
|
fn.fn();
|
||||||
|
}
|
||||||
|
config.onComplete(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
spec.execute(queueRunnerFactory, function() {});
|
||||||
expect(resultCallback).toHaveBeenCalledWith(
|
expect(resultCallback).toHaveBeenCalledWith(
|
||||||
jasmine.objectContaining({ debugLogs: null }),
|
jasmine.objectContaining({ debugLogs: null }),
|
||||||
undefined
|
undefined
|
||||||
@@ -609,17 +658,18 @@ describe('Spec', function() {
|
|||||||
queueableFn: {
|
queueableFn: {
|
||||||
fn: function() {}
|
fn: function() {}
|
||||||
},
|
},
|
||||||
resultCallback: resultCallback,
|
resultCallback: resultCallback
|
||||||
queueRunnerFactory: function(config) {
|
|
||||||
spec.debugLog('msg');
|
|
||||||
for (const fn of config.queueableFns) {
|
|
||||||
fn.fn();
|
|
||||||
}
|
|
||||||
config.onComplete(false);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
spec.execute(function() {});
|
function queueRunnerFactory(config) {
|
||||||
|
spec.debugLog('msg');
|
||||||
|
for (const fn of config.queueableFns) {
|
||||||
|
fn.fn();
|
||||||
|
}
|
||||||
|
config.onComplete(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
spec.execute(queueRunnerFactory, function() {});
|
||||||
expect(resultCallback).toHaveBeenCalled();
|
expect(resultCallback).toHaveBeenCalled();
|
||||||
expect(spec.result.debugLogs).toBeNull();
|
expect(spec.result.debugLogs).toBeNull();
|
||||||
});
|
});
|
||||||
@@ -634,21 +684,22 @@ describe('Spec', function() {
|
|||||||
fn: function() {}
|
fn: function() {}
|
||||||
},
|
},
|
||||||
resultCallback: resultCallback,
|
resultCallback: resultCallback,
|
||||||
queueRunnerFactory: function(config) {
|
|
||||||
spec.debugLog('msg');
|
|
||||||
spec.onException(new Error('nope'));
|
|
||||||
for (const fn of config.queueableFns) {
|
|
||||||
fn.fn();
|
|
||||||
}
|
|
||||||
config.onComplete(true);
|
|
||||||
},
|
|
||||||
timer: timer
|
timer: timer
|
||||||
}),
|
}),
|
||||||
timestamp = 12345;
|
timestamp = 12345;
|
||||||
|
|
||||||
timer.elapsed.and.returnValue(timestamp);
|
timer.elapsed.and.returnValue(timestamp);
|
||||||
|
|
||||||
spec.execute(function() {});
|
function queueRunnerFactory(config) {
|
||||||
|
spec.debugLog('msg');
|
||||||
|
spec.handleException(new Error('nope'));
|
||||||
|
for (const fn of config.queueableFns) {
|
||||||
|
fn.fn();
|
||||||
|
}
|
||||||
|
config.onComplete(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
spec.execute(queueRunnerFactory, function() {});
|
||||||
expect(resultCallback).toHaveBeenCalledWith(
|
expect(resultCallback).toHaveBeenCalledWith(
|
||||||
jasmine.objectContaining({
|
jasmine.objectContaining({
|
||||||
debugLogs: [{ message: 'msg', timestamp: timestamp }]
|
debugLogs: [{ message: 'msg', timestamp: timestamp }]
|
||||||
|
|||||||
@@ -106,9 +106,9 @@ describe('SpyStrategy', function() {
|
|||||||
|
|
||||||
it('allows a fake async function to be called instead', function(done) {
|
it('allows a fake async function to be called instead', function(done) {
|
||||||
const originalFn = jasmine.createSpy('original'),
|
const originalFn = jasmine.createSpy('original'),
|
||||||
fakeFn = jasmine
|
fakeFn = jasmine.createSpy('fake').and.callFake(async () => {
|
||||||
.createSpy('fake')
|
return 67;
|
||||||
.and.callFake(eval('async () => { return 67; }')),
|
}),
|
||||||
spyStrategy = new jasmineUnderTest.SpyStrategy({ fn: originalFn });
|
spyStrategy = new jasmineUnderTest.SpyStrategy({ fn: originalFn });
|
||||||
|
|
||||||
spyStrategy.callFake(fakeFn);
|
spyStrategy.callFake(fakeFn);
|
||||||
|
|||||||
178
spec/core/SuiteBuilderSpec.js
Normal file
178
spec/core/SuiteBuilderSpec.js
Normal file
@@ -0,0 +1,178 @@
|
|||||||
|
describe('SuiteBuilder', function() {
|
||||||
|
beforeEach(function() {
|
||||||
|
// Rethrow exceptions to ease debugging
|
||||||
|
spyOn(jasmineUnderTest.Suite.prototype, 'handleException').and.callFake(
|
||||||
|
function(e) {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
spyOn(jasmineUnderTest.Spec.prototype, 'handleException').and.callFake(
|
||||||
|
function(e) {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('creates the top suite', function() {
|
||||||
|
const env = { configuration: () => ({}) };
|
||||||
|
const suiteBuilder = new jasmineUnderTest.SuiteBuilder({ env });
|
||||||
|
|
||||||
|
expect(suiteBuilder.topSuite).toBeInstanceOf(jasmineUnderTest.Suite);
|
||||||
|
expect(suiteBuilder.topSuite.description).toEqual(
|
||||||
|
'Jasmine__TopLevel__Suite'
|
||||||
|
);
|
||||||
|
expect(suiteBuilder.topSuite.parentSuite).toBeUndefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('#describe', function() {
|
||||||
|
definesSuites('describe');
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('#fdescribe', function() {
|
||||||
|
definesSuites('fdescribe');
|
||||||
|
|
||||||
|
it('focuses the suite', function() {
|
||||||
|
const env = { configuration: () => ({}) };
|
||||||
|
const suiteBuilder = new jasmineUnderTest.SuiteBuilder({ env });
|
||||||
|
|
||||||
|
const suite = suiteBuilder.fdescribe('a suite', function() {
|
||||||
|
suiteBuilder.it('a spec');
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(suite.isFocused).toBeTrue();
|
||||||
|
expect(suiteBuilder.focusedRunables).toEqual([suite.id]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('unfocuses any focused ancestor suite', function() {
|
||||||
|
const env = { configuration: () => ({}) };
|
||||||
|
const suiteBuilder = new jasmineUnderTest.SuiteBuilder({ env });
|
||||||
|
|
||||||
|
const grandparent = suiteBuilder.fdescribe('a suite', function() {
|
||||||
|
suiteBuilder.describe('another suite', function() {
|
||||||
|
suiteBuilder.fdescribe('the focused suite', function() {
|
||||||
|
suiteBuilder.it('a spec');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(suiteBuilder.focusedRunables).not.toContain(grandparent.id);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('#xdescribe', function() {
|
||||||
|
definesSuites('xdescribe');
|
||||||
|
|
||||||
|
it('excludes the suite', function() {
|
||||||
|
const env = { configuration: () => ({}) };
|
||||||
|
const suiteBuilder = new jasmineUnderTest.SuiteBuilder({ env });
|
||||||
|
|
||||||
|
const suite = suiteBuilder.xdescribe('a suite', function() {
|
||||||
|
suiteBuilder.it('a spec');
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(suite.markedExcluding).toBeTrue();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('causes child suites to be marked excluded', function() {
|
||||||
|
const env = { configuration: () => ({}) };
|
||||||
|
const suiteBuilder = new jasmineUnderTest.SuiteBuilder({ env });
|
||||||
|
|
||||||
|
let suite;
|
||||||
|
suiteBuilder.xdescribe('a suite', function() {
|
||||||
|
suite = suiteBuilder.describe('another suite', function() {
|
||||||
|
suiteBuilder.it('a spec');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(suite.markedExcluding).toBeTrue();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('#it', function() {
|
||||||
|
definesSpecs('it');
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('#fit', function() {
|
||||||
|
definesSpecs('fit');
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('#xit', function() {
|
||||||
|
definesSpecs('xit');
|
||||||
|
});
|
||||||
|
|
||||||
|
function definesSuites(fnName) {
|
||||||
|
it('links suites to their parents and children', function() {
|
||||||
|
const env = { configuration: () => ({}) };
|
||||||
|
const suiteBuilder = new jasmineUnderTest.SuiteBuilder({ env });
|
||||||
|
|
||||||
|
let child;
|
||||||
|
const parent = suiteBuilder[fnName]('parent', function() {
|
||||||
|
child = suiteBuilder[fnName]('child', function() {
|
||||||
|
suiteBuilder.it('a spec');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(suiteBuilder.topSuite.children).toEqual([sameInstanceAs(parent)]);
|
||||||
|
expect(parent.children).toEqual([sameInstanceAs(child)]);
|
||||||
|
expect(child.parentSuite).toBe(parent);
|
||||||
|
expect(parent.parentSuite).toBe(suiteBuilder.topSuite);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('gives each suite a unique ID', function() {
|
||||||
|
const env = { configuration: () => ({}) };
|
||||||
|
const suiteBuilder = new jasmineUnderTest.SuiteBuilder({ env });
|
||||||
|
|
||||||
|
let child;
|
||||||
|
const parent = suiteBuilder[fnName]('parent', function() {
|
||||||
|
child = suiteBuilder[fnName]('child', function() {
|
||||||
|
suiteBuilder.it('a spec');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
const ids = [suiteBuilder.topSuite.id, parent.id, child.id];
|
||||||
|
|
||||||
|
for (const id of ids) {
|
||||||
|
expect(id).toMatch(/^suite[0-9]$/);
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(new Set(ids).size).toEqual(3);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function definesSpecs(fnName) {
|
||||||
|
it('adds the spec to its suite', function() {
|
||||||
|
const env = { configuration: () => ({}) };
|
||||||
|
const suiteBuilder = new jasmineUnderTest.SuiteBuilder({ env });
|
||||||
|
|
||||||
|
let spec;
|
||||||
|
const suite = suiteBuilder.describe('a suite', function() {
|
||||||
|
spec = suiteBuilder[fnName]('a spec', function() {});
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(suite.children).toEqual([sameInstanceAs(spec)]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('gives each spec a unique ID', function() {
|
||||||
|
const env = { configuration: () => ({}) };
|
||||||
|
const suiteBuilder = new jasmineUnderTest.SuiteBuilder({ env });
|
||||||
|
|
||||||
|
const spec1 = suiteBuilder[fnName]('a spec', function() {});
|
||||||
|
const spec2 = suiteBuilder[fnName]('another spec', function() {});
|
||||||
|
|
||||||
|
expect(spec1.id).toMatch(/^spec[0-9]+$/);
|
||||||
|
expect(spec2.id).toMatch(/^spec[0-9]+$/);
|
||||||
|
expect(spec1.id).not.toEqual(spec2.id);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function sameInstanceAs(expected) {
|
||||||
|
return {
|
||||||
|
asymmetricMatch: function(actual) {
|
||||||
|
return actual === expected;
|
||||||
|
},
|
||||||
|
jasmineToString: function(pp) {
|
||||||
|
return '<same instance as ' + pp(expected) + '>';
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
});
|
||||||
@@ -71,20 +71,9 @@ describe('Suite', function() {
|
|||||||
suite.beforeAll(outerBefore);
|
suite.beforeAll(outerBefore);
|
||||||
suite.beforeAll(innerBefore);
|
suite.beforeAll(innerBefore);
|
||||||
|
|
||||||
function sameInstance(expected) {
|
|
||||||
return {
|
|
||||||
asymmetricMatch: function(actual) {
|
|
||||||
return actual === expected;
|
|
||||||
},
|
|
||||||
jasmineToString: function() {
|
|
||||||
return `<same instance as ${expected}>`;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
expect(suite.beforeAllFns).toEqual([
|
expect(suite.beforeAllFns).toEqual([
|
||||||
{ fn: outerBefore.fn, type: 'beforeAll', suite: sameInstance(suite) },
|
{ fn: outerBefore.fn, type: 'beforeAll', suite: jasmine.is(suite) },
|
||||||
{ fn: innerBefore.fn, type: 'beforeAll', suite: sameInstance(suite) }
|
{ fn: innerBefore.fn, type: 'beforeAll', suite: jasmine.is(suite) }
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -123,13 +112,9 @@ describe('Suite', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('has a status of failed if any expectations have failed', function() {
|
it('has a status of failed if any expectations have failed', function() {
|
||||||
const suite = new jasmineUnderTest.Suite({
|
const suite = new jasmineUnderTest.Suite({});
|
||||||
expectationResultFactory: function() {
|
|
||||||
return 'hi';
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
suite.addExpectationResult(false);
|
suite.addExpectationResult(false, {});
|
||||||
expect(suite.status()).toBe('failed');
|
expect(suite.status()).toBe('failed');
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -148,28 +133,110 @@ describe('Suite', function() {
|
|||||||
|
|
||||||
it('throws an ExpectationFailed when receiving a failed expectation when throwOnExpectationFailure is set', function() {
|
it('throws an ExpectationFailed when receiving a failed expectation when throwOnExpectationFailure is set', function() {
|
||||||
const suite = new jasmineUnderTest.Suite({
|
const suite = new jasmineUnderTest.Suite({
|
||||||
expectationResultFactory: function(data) {
|
|
||||||
return data;
|
|
||||||
},
|
|
||||||
throwOnExpectationFailure: true
|
throwOnExpectationFailure: true
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(function() {
|
expect(function() {
|
||||||
suite.addExpectationResult(false, 'failed');
|
suite.addExpectationResult(false, { message: 'failed' });
|
||||||
}).toThrowError(jasmineUnderTest.errors.ExpectationFailed);
|
}).toThrowError(jasmineUnderTest.errors.ExpectationFailed);
|
||||||
|
|
||||||
expect(suite.status()).toBe('failed');
|
expect(suite.status()).toBe('failed');
|
||||||
expect(suite.result.failedExpectations).toEqual(['failed']);
|
expect(suite.result.failedExpectations).toEqual([
|
||||||
|
jasmine.objectContaining({ message: 'failed' })
|
||||||
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not add an additional failure when an expectation fails', function() {
|
it('does not add an additional failure when an expectation fails', function() {
|
||||||
const suite = new jasmineUnderTest.Suite({});
|
const suite = new jasmineUnderTest.Suite({});
|
||||||
|
|
||||||
suite.onException(new jasmineUnderTest.errors.ExpectationFailed());
|
suite.handleException(new jasmineUnderTest.errors.ExpectationFailed());
|
||||||
|
|
||||||
expect(suite.getResult().failedExpectations).toEqual([]);
|
expect(suite.getResult().failedExpectations).toEqual([]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('forwards late expectation failures to onLateError', function() {
|
||||||
|
const onLateError = jasmine.createSpy('onLateError');
|
||||||
|
const suite = new jasmineUnderTest.Suite({ onLateError });
|
||||||
|
const data = {
|
||||||
|
matcherName: '',
|
||||||
|
passed: false,
|
||||||
|
expected: '',
|
||||||
|
actual: '',
|
||||||
|
error: new Error('nope')
|
||||||
|
};
|
||||||
|
|
||||||
|
suite.reportedDone = true;
|
||||||
|
suite.addExpectationResult(false, data, true);
|
||||||
|
|
||||||
|
expect(onLateError).toHaveBeenCalledWith(
|
||||||
|
jasmine.objectContaining({
|
||||||
|
message: jasmine.stringMatching(/^Error: nope/)
|
||||||
|
})
|
||||||
|
);
|
||||||
|
expect(suite.result.failedExpectations).toEqual([]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('does not forward non-late expectation failures to onLateError', function() {
|
||||||
|
const onLateError = jasmine.createSpy('onLateError');
|
||||||
|
const suite = new jasmineUnderTest.Suite({
|
||||||
|
onLateError
|
||||||
|
});
|
||||||
|
const data = {
|
||||||
|
matcherName: '',
|
||||||
|
passed: false,
|
||||||
|
expected: '',
|
||||||
|
actual: '',
|
||||||
|
error: new Error('nope')
|
||||||
|
};
|
||||||
|
|
||||||
|
suite.addExpectationResult(false, data, true);
|
||||||
|
|
||||||
|
expect(onLateError).not.toHaveBeenCalled();
|
||||||
|
expect(suite.result.failedExpectations.length).toEqual(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('forwards late handleException calls to onLateError', function() {
|
||||||
|
const onLateError = jasmine.createSpy('onLateError');
|
||||||
|
const suite = new jasmineUnderTest.Suite({
|
||||||
|
onLateError
|
||||||
|
});
|
||||||
|
const error = new Error('oops');
|
||||||
|
|
||||||
|
suite.reportedDone = true;
|
||||||
|
suite.handleException(error);
|
||||||
|
|
||||||
|
expect(onLateError).toHaveBeenCalledWith(
|
||||||
|
jasmine.objectContaining({
|
||||||
|
message: jasmine.stringMatching(/^Error: oops/)
|
||||||
|
})
|
||||||
|
);
|
||||||
|
expect(suite.result.failedExpectations).toEqual([]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('does not forward non-late handleException calls to onLateError', function() {
|
||||||
|
const onLateError = jasmine.createSpy('onLateError');
|
||||||
|
const suite = new jasmineUnderTest.Suite({
|
||||||
|
onLateError
|
||||||
|
});
|
||||||
|
const error = new Error('oops');
|
||||||
|
|
||||||
|
suite.handleException(error);
|
||||||
|
|
||||||
|
expect(onLateError).not.toHaveBeenCalled();
|
||||||
|
expect(suite.result.failedExpectations.length).toEqual(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('clears the reportedDone flag when reset', function() {
|
||||||
|
const suite = new jasmineUnderTest.Suite({
|
||||||
|
queueableFn: { fn: function() {} }
|
||||||
|
});
|
||||||
|
suite.reportedDone = true;
|
||||||
|
|
||||||
|
suite.reset();
|
||||||
|
|
||||||
|
expect(suite.reportedDone).toBeFalse();
|
||||||
|
});
|
||||||
|
|
||||||
it('calls timer to compute duration', function() {
|
it('calls timer to compute duration', function() {
|
||||||
const suite = new jasmineUnderTest.Suite({
|
const suite = new jasmineUnderTest.Suite({
|
||||||
env: env,
|
env: env,
|
||||||
@@ -261,12 +328,8 @@ describe('Suite', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should reset the failedExpectations', function() {
|
it('should reset the failedExpectations', function() {
|
||||||
const suite = new jasmineUnderTest.Suite({
|
const suite = new jasmineUnderTest.Suite({});
|
||||||
expectationResultFactory: function(error) {
|
suite.handleException(new Error());
|
||||||
return error;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
suite.onException(new Error());
|
|
||||||
|
|
||||||
suite.reset();
|
suite.reset();
|
||||||
|
|
||||||
|
|||||||
@@ -297,7 +297,7 @@ describe('TreeProcessor', function() {
|
|||||||
|
|
||||||
queueRunner.calls.mostRecent().args[0].queueableFns[0].fn('foo');
|
queueRunner.calls.mostRecent().args[0].queueableFns[0].fn('foo');
|
||||||
|
|
||||||
expect(leaf.execute).toHaveBeenCalledWith('foo', false, false);
|
expect(leaf.execute).toHaveBeenCalledWith(queueRunner, 'foo', false, false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('runs a node with no children', function() {
|
it('runs a node with no children', function() {
|
||||||
@@ -372,10 +372,20 @@ describe('TreeProcessor', function() {
|
|||||||
expect(queueableFns.length).toBe(3);
|
expect(queueableFns.length).toBe(3);
|
||||||
|
|
||||||
queueableFns[1].fn('foo');
|
queueableFns[1].fn('foo');
|
||||||
expect(leaf1.execute).toHaveBeenCalledWith('foo', false, false);
|
expect(leaf1.execute).toHaveBeenCalledWith(
|
||||||
|
queueRunner,
|
||||||
|
'foo',
|
||||||
|
false,
|
||||||
|
false
|
||||||
|
);
|
||||||
|
|
||||||
queueableFns[2].fn('bar');
|
queueableFns[2].fn('bar');
|
||||||
expect(leaf2.execute).toHaveBeenCalledWith('bar', false, false);
|
expect(leaf2.execute).toHaveBeenCalledWith(
|
||||||
|
queueRunner,
|
||||||
|
'bar',
|
||||||
|
false,
|
||||||
|
false
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('cascades errors up the tree', function() {
|
it('cascades errors up the tree', function() {
|
||||||
@@ -401,7 +411,7 @@ describe('TreeProcessor', function() {
|
|||||||
expect(queueableFns.length).toBe(2);
|
expect(queueableFns.length).toBe(2);
|
||||||
|
|
||||||
queueableFns[1].fn('foo');
|
queueableFns[1].fn('foo');
|
||||||
expect(leaf.execute).toHaveBeenCalledWith('foo', false, false);
|
expect(leaf.execute).toHaveBeenCalledWith(queueRunner, 'foo', false, false);
|
||||||
|
|
||||||
queueRunner.calls.mostRecent().args[0].onComplete('things');
|
queueRunner.calls.mostRecent().args[0].onComplete('things');
|
||||||
expect(nodeComplete).toHaveBeenCalled();
|
expect(nodeComplete).toHaveBeenCalled();
|
||||||
@@ -437,7 +447,7 @@ describe('TreeProcessor', function() {
|
|||||||
expect(nodeStart).toHaveBeenCalledWith(node, 'bar');
|
expect(nodeStart).toHaveBeenCalledWith(node, 'bar');
|
||||||
|
|
||||||
queueableFns[1].fn('foo');
|
queueableFns[1].fn('foo');
|
||||||
expect(leaf1.execute).toHaveBeenCalledWith('foo', true, false);
|
expect(leaf1.execute).toHaveBeenCalledWith(queueRunner, 'foo', true, false);
|
||||||
|
|
||||||
node.getResult.and.returnValue({ im: 'disabled' });
|
node.getResult.and.returnValue({ im: 'disabled' });
|
||||||
|
|
||||||
@@ -475,7 +485,7 @@ describe('TreeProcessor', function() {
|
|||||||
expect(queueableFns.length).toBe(2);
|
expect(queueableFns.length).toBe(2);
|
||||||
|
|
||||||
queueableFns[1].fn('foo');
|
queueableFns[1].fn('foo');
|
||||||
expect(leaf.execute).toHaveBeenCalledWith('foo', true, true);
|
expect(leaf.execute).toHaveBeenCalledWith(queueRunner, 'foo', true, true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('runs beforeAlls for a node with children', function() {
|
it('runs beforeAlls for a node with children', function() {
|
||||||
@@ -637,11 +647,21 @@ describe('TreeProcessor', function() {
|
|||||||
queueableFns[0].fn();
|
queueableFns[0].fn();
|
||||||
|
|
||||||
expect(nonSpecified.execute).not.toHaveBeenCalled();
|
expect(nonSpecified.execute).not.toHaveBeenCalled();
|
||||||
expect(specified.execute).toHaveBeenCalledWith(undefined, false, false);
|
expect(specified.execute).toHaveBeenCalledWith(
|
||||||
|
queueRunner,
|
||||||
|
undefined,
|
||||||
|
false,
|
||||||
|
false
|
||||||
|
);
|
||||||
|
|
||||||
queueableFns[1].fn();
|
queueableFns[1].fn();
|
||||||
|
|
||||||
expect(nonSpecified.execute).toHaveBeenCalledWith(undefined, true, false);
|
expect(nonSpecified.execute).toHaveBeenCalledWith(
|
||||||
|
queueRunner,
|
||||||
|
undefined,
|
||||||
|
true,
|
||||||
|
false
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('runs nodes and leaves with a specified order', function() {
|
it('runs nodes and leaves with a specified order', function() {
|
||||||
|
|||||||
30
spec/core/asymmetric_equality/IsSpec.js
Normal file
30
spec/core/asymmetric_equality/IsSpec.js
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
describe('Is', function() {
|
||||||
|
it('passes for primitives that are ===', function() {
|
||||||
|
const exactly = new jasmineUnderTest.Is(17);
|
||||||
|
expect(exactly.asymmetricMatch(17)).toBeTrue();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('fails for primitives that are not ===', function() {
|
||||||
|
const exactly = new jasmineUnderTest.Is(42);
|
||||||
|
expect(exactly.asymmetricMatch('42')).toBeFalse();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('passes for the same object instance', function() {
|
||||||
|
const obj = {};
|
||||||
|
const exactly = new jasmineUnderTest.Is(obj);
|
||||||
|
expect(exactly.asymmetricMatch(obj)).toBeTrue();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('fails for different object instances, even if they are deep value equal', function() {
|
||||||
|
const exactly = new jasmineUnderTest.Is({});
|
||||||
|
expect(exactly.asymmetricMatch({})).toBeFalse();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('describes itself for use in diffs and pretty printing', function() {
|
||||||
|
const exactly = new jasmineUnderTest.Is({ foo: ['bar'] });
|
||||||
|
const pp = jasmineUnderTest.basicPrettyPrinter_;
|
||||||
|
expect(exactly.jasmineToString(pp)).toEqual(
|
||||||
|
"<jasmine.is(Object({ foo: [ 'bar' ] }))>"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -22,56 +22,38 @@ describe('buildExpectationResult', function() {
|
|||||||
expect(result.message).toBe('some-value');
|
expect(result.message).toBe('some-value');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('delegates message formatting to the provided formatter if there was an Error', function() {
|
describe('When the error property is provided', function() {
|
||||||
const fakeError = { message: 'foo' },
|
it('sets the message to the formatted error', function() {
|
||||||
messageFormatter = jasmine
|
const result = jasmineUnderTest.buildExpectationResult({
|
||||||
.createSpy('exception message formatter')
|
passed: false,
|
||||||
.and.returnValue(fakeError.message);
|
error: { message: 'foo', fileName: 'somefile.js' }
|
||||||
|
});
|
||||||
|
|
||||||
const result = jasmineUnderTest.buildExpectationResult({
|
expect(result.message).toEqual('foo in somefile.js');
|
||||||
passed: false,
|
|
||||||
error: fakeError,
|
|
||||||
messageFormatter: messageFormatter
|
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(messageFormatter).toHaveBeenCalledWith(fakeError);
|
it('delegates stack formatting to the provided formatter', function() {
|
||||||
expect(result.message).toEqual('foo');
|
const result = jasmineUnderTest.buildExpectationResult({
|
||||||
|
passed: false,
|
||||||
|
error: { stack: 'foo', extra: 'wombat' }
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(result.stack).toEqual(
|
||||||
|
"error properties: Object({ extra: 'wombat' })\nfoo"
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('delegates stack formatting to the provided formatter if there was an Error', function() {
|
describe('When the errorForStack property is provided', function() {
|
||||||
const fakeError = { stack: 'foo' },
|
it('builds the stack trace using errorForStack instead of Error', function() {
|
||||||
stackFormatter = jasmine
|
const result = jasmineUnderTest.buildExpectationResult({
|
||||||
.createSpy('stack formatter')
|
passed: false,
|
||||||
.and.returnValue(fakeError.stack);
|
errorForStack: { stack: 'foo' },
|
||||||
|
error: { stack: 'bar' }
|
||||||
|
});
|
||||||
|
|
||||||
const result = jasmineUnderTest.buildExpectationResult({
|
expect(result.stack).toEqual('bar');
|
||||||
passed: false,
|
|
||||||
error: fakeError,
|
|
||||||
stackFormatter: stackFormatter
|
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(stackFormatter).toHaveBeenCalledWith(fakeError, {
|
|
||||||
omitMessage: true
|
|
||||||
});
|
|
||||||
expect(result.stack).toEqual('foo');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('delegates stack formatting to the provided formatter if there was a provided errorForStack', function() {
|
|
||||||
const fakeError = { stack: 'foo' },
|
|
||||||
stackFormatter = jasmine
|
|
||||||
.createSpy('stack formatter')
|
|
||||||
.and.returnValue(fakeError.stack);
|
|
||||||
|
|
||||||
const result = jasmineUnderTest.buildExpectationResult({
|
|
||||||
passed: false,
|
|
||||||
errorForStack: fakeError,
|
|
||||||
stackFormatter: stackFormatter
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(stackFormatter).toHaveBeenCalledWith(fakeError, {
|
|
||||||
omitMessage: true
|
|
||||||
});
|
|
||||||
expect(result.stack).toEqual('foo');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('matcherName returns passed matcherName', function() {
|
it('matcherName returns passed matcherName', function() {
|
||||||
@@ -1,55 +1,57 @@
|
|||||||
describe('Asymmetric equality testers (Integration)', function() {
|
describe('Asymmetric equality testers (Integration)', function() {
|
||||||
function verifyPasses(expectations) {
|
function verifyPasses(expectations) {
|
||||||
it('passes', function(done) {
|
it('passes', async function() {
|
||||||
const env = new jasmineUnderTest.Env();
|
const env = new jasmineUnderTest.Env();
|
||||||
env.it('a spec', function() {
|
env.it('a spec', function() {
|
||||||
expectations(env);
|
expectations(env);
|
||||||
});
|
});
|
||||||
|
|
||||||
const specExpectations = function(result) {
|
const reporter = jasmine.createSpyObj('reporter', ['specDone']);
|
||||||
expect(result.status).toEqual('passed');
|
env.addReporter(reporter);
|
||||||
expect(result.passedExpectations.length)
|
await env.execute();
|
||||||
.withContext('Number of passed expectations')
|
|
||||||
.toEqual(1);
|
|
||||||
expect(result.failedExpectations.length)
|
|
||||||
.withContext('Number of failed expectations')
|
|
||||||
.toEqual(0);
|
|
||||||
expect(
|
|
||||||
result.failedExpectations[0] && result.failedExpectations[0].message
|
|
||||||
)
|
|
||||||
.withContext('Failure message')
|
|
||||||
.toBeUndefined();
|
|
||||||
};
|
|
||||||
|
|
||||||
env.addReporter({ specDone: specExpectations });
|
expect(reporter.specDone).toHaveBeenCalledTimes(1);
|
||||||
env.execute(null, done);
|
const result = reporter.specDone.calls.argsFor(0)[0];
|
||||||
|
|
||||||
|
expect(result.status).toEqual('passed');
|
||||||
|
expect(result.passedExpectations.length)
|
||||||
|
.withContext('Number of passed expectations')
|
||||||
|
.toEqual(1);
|
||||||
|
expect(result.failedExpectations.length)
|
||||||
|
.withContext('Number of failed expectations')
|
||||||
|
.toEqual(0);
|
||||||
|
expect(
|
||||||
|
result.failedExpectations[0] && result.failedExpectations[0].message
|
||||||
|
)
|
||||||
|
.withContext('Failure message')
|
||||||
|
.toBeUndefined();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function verifyFails(expectations) {
|
function verifyFails(expectations) {
|
||||||
it('fails', function(done) {
|
it('fails', async function() {
|
||||||
const env = new jasmineUnderTest.Env();
|
const env = new jasmineUnderTest.Env();
|
||||||
env.it('a spec', function() {
|
env.it('a spec', function() {
|
||||||
expectations(env);
|
expectations(env);
|
||||||
});
|
});
|
||||||
|
|
||||||
const specExpectations = function(result) {
|
const reporter = jasmine.createSpyObj('reporter', ['specDone']);
|
||||||
expect(result.status).toEqual('failed');
|
env.addReporter(reporter);
|
||||||
expect(result.failedExpectations.length)
|
await env.execute();
|
||||||
.withContext('Number of failed expectations')
|
|
||||||
.toEqual(1);
|
|
||||||
expect(result.failedExpectations[0].message)
|
|
||||||
.withContext(
|
|
||||||
'Failed with a thrown error rather than a matcher failure'
|
|
||||||
)
|
|
||||||
.not.toMatch(/^Error: /);
|
|
||||||
expect(result.failedExpectations[0].matcherName)
|
|
||||||
.withContext('Matcher name')
|
|
||||||
.not.toEqual('');
|
|
||||||
};
|
|
||||||
|
|
||||||
env.addReporter({ specDone: specExpectations });
|
expect(reporter.specDone).toHaveBeenCalledTimes(1);
|
||||||
env.execute(null, done);
|
const result = reporter.specDone.calls.argsFor(0)[0];
|
||||||
|
|
||||||
|
expect(result.status).toEqual('failed');
|
||||||
|
expect(result.failedExpectations.length)
|
||||||
|
.withContext('Number of failed expectations')
|
||||||
|
.toEqual(1);
|
||||||
|
expect(result.failedExpectations[0].message)
|
||||||
|
.withContext('Failed with a thrown error rather than a matcher failure')
|
||||||
|
.not.toMatch(/^Error: /);
|
||||||
|
expect(result.failedExpectations[0].matcherName)
|
||||||
|
.withContext('Matcher name')
|
||||||
|
.not.toEqual('');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ describe('Custom Async Matchers (Integration)', function() {
|
|||||||
env.cleanup_();
|
env.cleanup_();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('passes the spec if the custom async matcher passes', function(done) {
|
it('passes the spec if the custom async matcher passes', async function() {
|
||||||
env.it('spec using custom async matcher', function() {
|
env.it('spec using custom async matcher', function() {
|
||||||
env.addAsyncMatchers({
|
env.addAsyncMatchers({
|
||||||
toBeReal: function() {
|
toBeReal: function() {
|
||||||
@@ -30,10 +30,10 @@ describe('Custom Async Matchers (Integration)', function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
env.addReporter({ specDone: specExpectations });
|
env.addReporter({ specDone: specExpectations });
|
||||||
env.execute(null, done);
|
await env.execute();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('uses the negative compare function for a negative comparison, if provided', function(done) {
|
it('uses the negative compare function for a negative comparison, if provided', async function() {
|
||||||
env.it('spec with custom negative comparison matcher', function() {
|
env.it('spec with custom negative comparison matcher', function() {
|
||||||
env.addAsyncMatchers({
|
env.addAsyncMatchers({
|
||||||
toBeReal: function() {
|
toBeReal: function() {
|
||||||
@@ -56,10 +56,10 @@ describe('Custom Async Matchers (Integration)', function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
env.addReporter({ specDone: specExpectations });
|
env.addReporter({ specDone: specExpectations });
|
||||||
env.execute(null, done);
|
await env.execute();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('generates messages with the same rules as built in matchers absent a custom message', function(done) {
|
it('generates messages with the same rules as built in matchers absent a custom message', async function() {
|
||||||
env.it('spec with an expectation', function() {
|
env.it('spec with an expectation', function() {
|
||||||
env.addAsyncMatchers({
|
env.addAsyncMatchers({
|
||||||
toBeReal: function() {
|
toBeReal: function() {
|
||||||
@@ -81,10 +81,10 @@ describe('Custom Async Matchers (Integration)', function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
env.addReporter({ specDone: specExpectations });
|
env.addReporter({ specDone: specExpectations });
|
||||||
env.execute(null, done);
|
await env.execute();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('passes the jasmine utility to the matcher factory', function(done) {
|
it('passes the jasmine utility to the matcher factory', async function() {
|
||||||
const matcherFactory = function() {
|
const matcherFactory = function() {
|
||||||
return {
|
return {
|
||||||
compare: function() {
|
compare: function() {
|
||||||
@@ -112,10 +112,10 @@ describe('Custom Async Matchers (Integration)', function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
env.addReporter({ specDone: specExpectations });
|
env.addReporter({ specDone: specExpectations });
|
||||||
env.execute(null, done);
|
await env.execute();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('provides custom equality testers to the matcher factory via matchersUtil', function(done) {
|
it('provides custom equality testers to the matcher factory via matchersUtil', async function() {
|
||||||
const matcherFactory = function(matchersUtil) {
|
const matcherFactory = function(matchersUtil) {
|
||||||
return {
|
return {
|
||||||
compare: function(actual, expected) {
|
compare: function(actual, expected) {
|
||||||
@@ -146,6 +146,6 @@ describe('Custom Async Matchers (Integration)', function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
env.addReporter({ specDone: specExpectations });
|
env.addReporter({ specDone: specExpectations });
|
||||||
env.execute(null, done);
|
await env.execute();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ describe('Custom Matchers (Integration)', function() {
|
|||||||
env.cleanup_();
|
env.cleanup_();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('allows adding more matchers local to a spec', function(done) {
|
it('allows adding more matchers local to a spec', async function() {
|
||||||
env.it('spec defining a custom matcher', function() {
|
env.it('spec defining a custom matcher', function() {
|
||||||
env.addMatchers({
|
env.addMatchers({
|
||||||
matcherForSpec: function() {
|
matcherForSpec: function() {
|
||||||
@@ -37,20 +37,18 @@ describe('Custom Matchers (Integration)', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const specDoneSpy = jasmine.createSpy('specDoneSpy');
|
const specDoneSpy = jasmine.createSpy('specDoneSpy');
|
||||||
const expectations = function() {
|
|
||||||
const firstSpecResult = specDoneSpy.calls.first().args[0];
|
|
||||||
expect(firstSpecResult.status).toEqual('failed');
|
|
||||||
expect(firstSpecResult.failedExpectations[0].message).toEqual(
|
|
||||||
'matcherForSpec: actual: zzz; expected: yyy'
|
|
||||||
);
|
|
||||||
done();
|
|
||||||
};
|
|
||||||
env.addReporter({ specDone: specDoneSpy });
|
env.addReporter({ specDone: specDoneSpy });
|
||||||
|
|
||||||
env.execute(null, expectations);
|
await env.execute();
|
||||||
|
|
||||||
|
const firstSpecResult = specDoneSpy.calls.first().args[0];
|
||||||
|
expect(firstSpecResult.status).toEqual('failed');
|
||||||
|
expect(firstSpecResult.failedExpectations[0].message).toEqual(
|
||||||
|
'matcherForSpec: actual: zzz; expected: yyy'
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('passes the spec if the custom matcher passes', function(done) {
|
it('passes the spec if the custom matcher passes', async function() {
|
||||||
env.it('spec using custom matcher', function() {
|
env.it('spec using custom matcher', function() {
|
||||||
env.addMatchers({
|
env.addMatchers({
|
||||||
toBeReal: function() {
|
toBeReal: function() {
|
||||||
@@ -65,15 +63,16 @@ describe('Custom Matchers (Integration)', function() {
|
|||||||
env.expect(true).toBeReal();
|
env.expect(true).toBeReal();
|
||||||
});
|
});
|
||||||
|
|
||||||
const specExpectations = function(result) {
|
const reporter = jasmine.createSpyObj('reporter', ['specDone']);
|
||||||
expect(result.status).toEqual('passed');
|
env.addReporter(reporter);
|
||||||
};
|
await env.execute();
|
||||||
|
|
||||||
env.addReporter({ specDone: specExpectations });
|
expect(reporter.specDone).toHaveBeenCalledTimes(1);
|
||||||
env.execute(null, done);
|
const result = reporter.specDone.calls.argsFor(0)[0];
|
||||||
|
expect(result.status).toEqual('passed');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('passes the spec if the custom equality matcher passes for types nested inside asymmetric equality testers', function(done) {
|
it('passes the spec if the custom equality matcher passes for types nested inside asymmetric equality testers', async function() {
|
||||||
env.it('spec using custom equality matcher', function() {
|
env.it('spec using custom equality matcher', function() {
|
||||||
const customEqualityFn = function(a, b) {
|
const customEqualityFn = function(a, b) {
|
||||||
// All "foo*" strings match each other.
|
// All "foo*" strings match each other.
|
||||||
@@ -99,15 +98,16 @@ describe('Custom Matchers (Integration)', function() {
|
|||||||
.toEqual(jasmineUnderTest.arrayWithExactContents(['fooBar']));
|
.toEqual(jasmineUnderTest.arrayWithExactContents(['fooBar']));
|
||||||
});
|
});
|
||||||
|
|
||||||
const specExpectations = function(result) {
|
const reporter = jasmine.createSpyObj('reporter', ['specDone']);
|
||||||
expect(result.status).toEqual('passed');
|
env.addReporter(reporter);
|
||||||
};
|
await env.execute();
|
||||||
|
|
||||||
env.addReporter({ specDone: specExpectations });
|
expect(reporter.specDone).toHaveBeenCalledTimes(1);
|
||||||
env.execute(null, done);
|
const result = reporter.specDone.calls.argsFor(0)[0];
|
||||||
|
expect(result.status).toEqual('passed');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('displays an appropriate failure message if a custom equality matcher fails', function(done) {
|
it('displays an appropriate failure message if a custom equality matcher fails', async function() {
|
||||||
env.it('spec using custom equality matcher', function() {
|
env.it('spec using custom equality matcher', function() {
|
||||||
const customEqualityFn = function(a, b) {
|
const customEqualityFn = function(a, b) {
|
||||||
// "foo" is not equal to anything
|
// "foo" is not equal to anything
|
||||||
@@ -120,18 +120,19 @@ describe('Custom Matchers (Integration)', function() {
|
|||||||
env.expect({ foo: 'foo' }).toEqual({ foo: 'foo' });
|
env.expect({ foo: 'foo' }).toEqual({ foo: 'foo' });
|
||||||
});
|
});
|
||||||
|
|
||||||
const specExpectations = function(result) {
|
const reporter = jasmine.createSpyObj('reporter', ['specDone']);
|
||||||
expect(result.status).toEqual('failed');
|
env.addReporter(reporter);
|
||||||
expect(result.failedExpectations[0].message).toEqual(
|
await env.execute();
|
||||||
"Expected $.foo = 'foo' to equal 'foo'."
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
env.addReporter({ specDone: specExpectations });
|
expect(reporter.specDone).toHaveBeenCalledTimes(1);
|
||||||
env.execute(null, done);
|
const result = reporter.specDone.calls.argsFor(0)[0];
|
||||||
|
expect(result.status).toEqual('failed');
|
||||||
|
expect(result.failedExpectations[0].message).toEqual(
|
||||||
|
"Expected $.foo = 'foo' to equal 'foo'."
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('uses the negative compare function for a negative comparison, if provided', function(done) {
|
it('uses the negative compare function for a negative comparison, if provided', async function() {
|
||||||
env.it('spec with custom negative comparison matcher', function() {
|
env.it('spec with custom negative comparison matcher', function() {
|
||||||
env.addMatchers({
|
env.addMatchers({
|
||||||
toBeReal: function() {
|
toBeReal: function() {
|
||||||
@@ -149,15 +150,16 @@ describe('Custom Matchers (Integration)', function() {
|
|||||||
env.expect(true).not.toBeReal();
|
env.expect(true).not.toBeReal();
|
||||||
});
|
});
|
||||||
|
|
||||||
const specExpectations = function(result) {
|
const reporter = jasmine.createSpyObj('reporter', ['specDone']);
|
||||||
expect(result.status).toEqual('passed');
|
env.addReporter(reporter);
|
||||||
};
|
await env.execute();
|
||||||
|
|
||||||
env.addReporter({ specDone: specExpectations });
|
expect(reporter.specDone).toHaveBeenCalledTimes(1);
|
||||||
env.execute(null, done);
|
const result = reporter.specDone.calls.argsFor(0)[0];
|
||||||
|
expect(result.status).toEqual('passed');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('generates messages with the same rules as built in matchers absent a custom message', function(done) {
|
it('generates messages with the same rules as built in matchers absent a custom message', async function() {
|
||||||
env.it('spec with an expectation', function() {
|
env.it('spec with an expectation', function() {
|
||||||
env.addMatchers({
|
env.addMatchers({
|
||||||
toBeReal: function() {
|
toBeReal: function() {
|
||||||
@@ -172,17 +174,18 @@ describe('Custom Matchers (Integration)', function() {
|
|||||||
env.expect('a').toBeReal();
|
env.expect('a').toBeReal();
|
||||||
});
|
});
|
||||||
|
|
||||||
const specExpectations = function(result) {
|
const reporter = jasmine.createSpyObj('reporter', ['specDone']);
|
||||||
expect(result.failedExpectations[0].message).toEqual(
|
env.addReporter(reporter);
|
||||||
"Expected 'a' to be real."
|
await env.execute();
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
env.addReporter({ specDone: specExpectations });
|
expect(reporter.specDone).toHaveBeenCalledTimes(1);
|
||||||
env.execute(null, done);
|
const result = reporter.specDone.calls.argsFor(0)[0];
|
||||||
|
expect(result.failedExpectations[0].message).toEqual(
|
||||||
|
"Expected 'a' to be real."
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('passes the expected and actual arguments to the comparison function', function(done) {
|
it('passes the expected and actual arguments to the comparison function', async function() {
|
||||||
const argumentSpy = jasmine
|
const argumentSpy = jasmine
|
||||||
.createSpy('argument spy')
|
.createSpy('argument spy')
|
||||||
.and.returnValue({ pass: true });
|
.and.returnValue({ pass: true });
|
||||||
@@ -199,17 +202,13 @@ describe('Custom Matchers (Integration)', function() {
|
|||||||
env.expect(true).toBeReal('arg1', 'arg2');
|
env.expect(true).toBeReal('arg1', 'arg2');
|
||||||
});
|
});
|
||||||
|
|
||||||
const specExpectations = function() {
|
await env.execute();
|
||||||
expect(argumentSpy).toHaveBeenCalledWith(true);
|
expect(argumentSpy).toHaveBeenCalledWith(true);
|
||||||
expect(argumentSpy).toHaveBeenCalledWith(true, 'arg');
|
expect(argumentSpy).toHaveBeenCalledWith(true, 'arg');
|
||||||
expect(argumentSpy).toHaveBeenCalledWith(true, 'arg1', 'arg2');
|
expect(argumentSpy).toHaveBeenCalledWith(true, 'arg1', 'arg2');
|
||||||
};
|
|
||||||
|
|
||||||
env.addReporter({ specDone: specExpectations });
|
|
||||||
env.execute(null, done);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('passes the jasmine utility to the matcher factory', function(done) {
|
it('passes the jasmine utility to the matcher factory', async function() {
|
||||||
const matcherFactory = function() {
|
const matcherFactory = function() {
|
||||||
return {
|
return {
|
||||||
compare: function() {
|
compare: function() {
|
||||||
@@ -229,17 +228,13 @@ describe('Custom Matchers (Integration)', function() {
|
|||||||
env.expect(true).toBeReal();
|
env.expect(true).toBeReal();
|
||||||
});
|
});
|
||||||
|
|
||||||
const specExpectations = function() {
|
await env.execute();
|
||||||
expect(matcherFactorySpy).toHaveBeenCalledWith(
|
expect(matcherFactorySpy).toHaveBeenCalledWith(
|
||||||
jasmine.any(jasmineUnderTest.MatchersUtil)
|
jasmine.any(jasmineUnderTest.MatchersUtil)
|
||||||
);
|
);
|
||||||
};
|
|
||||||
|
|
||||||
env.addReporter({ specDone: specExpectations });
|
|
||||||
env.execute(null, done);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('provides custom equality testers to the matcher factory via matchersUtil', function(done) {
|
it('provides custom equality testers to the matcher factory via matchersUtil', async function() {
|
||||||
const matcherFactory = function(matchersUtil) {
|
const matcherFactory = function(matchersUtil) {
|
||||||
return {
|
return {
|
||||||
compare: function(actual, expected) {
|
compare: function(actual, expected) {
|
||||||
@@ -262,12 +257,13 @@ describe('Custom Matchers (Integration)', function() {
|
|||||||
env.expect([1, 2]).toBeArrayWithFirstElement('1');
|
env.expect([1, 2]).toBeArrayWithFirstElement('1');
|
||||||
});
|
});
|
||||||
|
|
||||||
const specExpectations = function(result) {
|
const reporter = jasmine.createSpyObj('reporter', ['specDone']);
|
||||||
expect(customEqualityFn).toHaveBeenCalledWith(1, '1');
|
env.addReporter(reporter);
|
||||||
expect(result.failedExpectations).toEqual([]);
|
await env.execute();
|
||||||
};
|
|
||||||
|
|
||||||
env.addReporter({ specDone: specExpectations });
|
expect(reporter.specDone).toHaveBeenCalledTimes(1);
|
||||||
env.execute(null, done);
|
const result = reporter.specDone.calls.argsFor(0)[0];
|
||||||
|
expect(customEqualityFn).toHaveBeenCalledWith(1, '1');
|
||||||
|
expect(result.failedExpectations).toEqual([]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ describe('Custom object formatters', function() {
|
|||||||
env.configure({ random: false });
|
env.configure({ random: false });
|
||||||
});
|
});
|
||||||
|
|
||||||
it('scopes custom object formatters to a spec', function(done) {
|
it('scopes custom object formatters to a spec', async function() {
|
||||||
env.it('a spec with custom pretty-printer', function() {
|
env.it('a spec with custom pretty-printer', function() {
|
||||||
env.addCustomObjectFormatter(function(obj) {
|
env.addCustomObjectFormatter(function(obj) {
|
||||||
return 'custom(' + obj + ')';
|
return 'custom(' + obj + ')';
|
||||||
@@ -22,21 +22,19 @@ describe('Custom object formatters', function() {
|
|||||||
const specDone = function(result) {
|
const specDone = function(result) {
|
||||||
specResults.push(result);
|
specResults.push(result);
|
||||||
};
|
};
|
||||||
const expectations = function() {
|
|
||||||
expect(specResults[0].failedExpectations[0].message).toEqual(
|
|
||||||
'Expected custom(42) to be undefined.'
|
|
||||||
);
|
|
||||||
expect(specResults[1].failedExpectations[0].message).toEqual(
|
|
||||||
'Expected 42 to be undefined.'
|
|
||||||
);
|
|
||||||
done();
|
|
||||||
};
|
|
||||||
env.addReporter({ specDone: specDone });
|
env.addReporter({ specDone: specDone });
|
||||||
|
|
||||||
env.execute(null, expectations);
|
await env.execute();
|
||||||
|
|
||||||
|
expect(specResults[0].failedExpectations[0].message).toEqual(
|
||||||
|
'Expected custom(42) to be undefined.'
|
||||||
|
);
|
||||||
|
expect(specResults[1].failedExpectations[0].message).toEqual(
|
||||||
|
'Expected 42 to be undefined.'
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('scopes custom object formatters to a suite', function(done) {
|
it('scopes custom object formatters to a suite', async function() {
|
||||||
env.it('a spec without custom pretty-printer', function() {
|
env.it('a spec without custom pretty-printer', function() {
|
||||||
env.expect(42).toBeUndefined();
|
env.expect(42).toBeUndefined();
|
||||||
});
|
});
|
||||||
@@ -57,18 +55,16 @@ describe('Custom object formatters', function() {
|
|||||||
const specDone = function(result) {
|
const specDone = function(result) {
|
||||||
specResults.push(result);
|
specResults.push(result);
|
||||||
};
|
};
|
||||||
const expectations = function() {
|
|
||||||
expect(specResults[0].failedExpectations[0].message).toEqual(
|
|
||||||
'Expected 42 to be undefined.'
|
|
||||||
);
|
|
||||||
expect(specResults[1].failedExpectations[0].message).toEqual(
|
|
||||||
'Expected custom(42) to be undefined.'
|
|
||||||
);
|
|
||||||
done();
|
|
||||||
};
|
|
||||||
env.addReporter({ specDone: specDone });
|
env.addReporter({ specDone: specDone });
|
||||||
|
|
||||||
env.execute(null, expectations);
|
await env.execute();
|
||||||
|
|
||||||
|
expect(specResults[0].failedExpectations[0].message).toEqual(
|
||||||
|
'Expected 42 to be undefined.'
|
||||||
|
);
|
||||||
|
expect(specResults[1].failedExpectations[0].message).toEqual(
|
||||||
|
'Expected custom(42) to be undefined.'
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('throws an exception if you try to add a custom object formatter outside a runable', function() {
|
it('throws an exception if you try to add a custom object formatter outside a runable', function() {
|
||||||
|
|||||||
@@ -33,6 +33,67 @@ describe('Default Spy Strategy (Integration)', function() {
|
|||||||
expect(result.overallStatus).toEqual('passed');
|
expect(result.overallStatus).toEqual('passed');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('inherits the default spy strategy set in a parent suite', async function() {
|
||||||
|
env.describe('suite with default strategy', function() {
|
||||||
|
env.beforeAll(function() {
|
||||||
|
env.setDefaultSpyStrategy(function(and) {
|
||||||
|
and.returnValue(42);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
env.describe('child suite', function() {
|
||||||
|
env.it('spec in suite', function() {
|
||||||
|
const spy = env.createSpy('something');
|
||||||
|
expect(spy()).toBe(42);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
let overallStatus;
|
||||||
|
env.addReporter({
|
||||||
|
jasmineDone: r => (overallStatus = r.overallStatus)
|
||||||
|
});
|
||||||
|
await env.execute();
|
||||||
|
expect(overallStatus).toEqual('passed');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('restores the previous default strategy when exiting a runnable', async function() {
|
||||||
|
env.describe('outer suite', function() {
|
||||||
|
env.describe('inner suite', function() {
|
||||||
|
env.beforeAll(function() {
|
||||||
|
env.setDefaultSpyStrategy(function(and) {
|
||||||
|
and.returnValue(42);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
env.it('spec in suite', function() {
|
||||||
|
env.setDefaultSpyStrategy(function(and) {
|
||||||
|
and.returnValue(17);
|
||||||
|
});
|
||||||
|
const spy = env.createSpy('something');
|
||||||
|
expect(spy()).toBe(17);
|
||||||
|
});
|
||||||
|
|
||||||
|
env.afterAll(function() {
|
||||||
|
const spy = env.createSpy('something');
|
||||||
|
expect(spy()).toBe(42);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
env.afterAll(function() {
|
||||||
|
const spy = env.createSpy('something');
|
||||||
|
expect(spy()).toBeUndefined();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
let overallStatus;
|
||||||
|
env.addReporter({
|
||||||
|
jasmineDone: r => (overallStatus = r.overallStatus)
|
||||||
|
});
|
||||||
|
await env.execute();
|
||||||
|
expect(overallStatus).toEqual('passed');
|
||||||
|
});
|
||||||
|
|
||||||
it('uses the default spy strategy defined when the spy is created', async function() {
|
it('uses the default spy strategy defined when the spy is created', async function() {
|
||||||
env.it('spec', function() {
|
env.it('spec', function() {
|
||||||
const a = env.createSpy('a');
|
const a = env.createSpy('a');
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ describe('Deprecation (integration)', function() {
|
|||||||
env.cleanup_();
|
env.cleanup_();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('reports a deprecation on the top suite', function(done) {
|
it('reports a deprecation on the top suite', async function() {
|
||||||
const reporter = jasmine.createSpyObj('reporter', ['jasmineDone']);
|
const reporter = jasmine.createSpyObj('reporter', ['jasmineDone']);
|
||||||
env.addReporter(reporter);
|
env.addReporter(reporter);
|
||||||
spyOn(console, 'error');
|
spyOn(console, 'error');
|
||||||
@@ -20,24 +20,23 @@ describe('Deprecation (integration)', function() {
|
|||||||
});
|
});
|
||||||
env.it('a spec', function() {});
|
env.it('a spec', function() {});
|
||||||
|
|
||||||
env.execute(null, function() {
|
await env.execute();
|
||||||
expect(reporter.jasmineDone).toHaveBeenCalledWith(
|
|
||||||
jasmine.objectContaining({
|
expect(reporter.jasmineDone).toHaveBeenCalledWith(
|
||||||
deprecationWarnings: [
|
jasmine.objectContaining({
|
||||||
jasmine.objectContaining({
|
deprecationWarnings: [
|
||||||
message: jasmine.stringMatching(/^the message/)
|
jasmine.objectContaining({
|
||||||
})
|
message: jasmine.stringMatching(/^the message/)
|
||||||
]
|
})
|
||||||
})
|
]
|
||||||
);
|
})
|
||||||
expect(console.error).toHaveBeenCalledWith(
|
);
|
||||||
jasmine.stringMatching(/^DEPRECATION: the message/)
|
expect(console.error).toHaveBeenCalledWith(
|
||||||
);
|
jasmine.stringMatching(/^DEPRECATION: the message/)
|
||||||
done();
|
);
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('reports a deprecation on a descendent suite', function(done) {
|
it('reports a deprecation on a descendent suite', async function() {
|
||||||
const reporter = jasmine.createSpyObj('reporter', ['suiteDone']);
|
const reporter = jasmine.createSpyObj('reporter', ['suiteDone']);
|
||||||
env.addReporter(reporter);
|
env.addReporter(reporter);
|
||||||
spyOn(console, 'error');
|
spyOn(console, 'error');
|
||||||
@@ -49,26 +48,23 @@ describe('Deprecation (integration)', function() {
|
|||||||
env.it('a spec', function() {});
|
env.it('a spec', function() {});
|
||||||
});
|
});
|
||||||
|
|
||||||
env.execute(null, function() {
|
await env.execute();
|
||||||
expect(reporter.suiteDone).toHaveBeenCalledWith(
|
|
||||||
jasmine.objectContaining({
|
expect(reporter.suiteDone).toHaveBeenCalledWith(
|
||||||
deprecationWarnings: [
|
jasmine.objectContaining({
|
||||||
jasmine.objectContaining({
|
deprecationWarnings: [
|
||||||
message: jasmine.stringMatching(/^the message/)
|
jasmine.objectContaining({
|
||||||
})
|
message: jasmine.stringMatching(/^the message/)
|
||||||
]
|
})
|
||||||
})
|
]
|
||||||
);
|
})
|
||||||
expect(console.error).toHaveBeenCalledWith(
|
);
|
||||||
jasmine.stringMatching(
|
expect(console.error).toHaveBeenCalledWith(
|
||||||
/^DEPRECATION: the message \(in suite: a suite\)/
|
jasmine.stringMatching(/^DEPRECATION: the message \(in suite: a suite\)/)
|
||||||
)
|
);
|
||||||
);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('reports a deprecation on a spec', function(done) {
|
it('reports a deprecation on a spec', async function() {
|
||||||
const reporter = jasmine.createSpyObj('reporter', ['specDone']);
|
const reporter = jasmine.createSpyObj('reporter', ['specDone']);
|
||||||
env.addReporter(reporter);
|
env.addReporter(reporter);
|
||||||
spyOn(console, 'error');
|
spyOn(console, 'error');
|
||||||
@@ -79,26 +75,25 @@ describe('Deprecation (integration)', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
env.execute(null, function() {
|
await env.execute();
|
||||||
expect(reporter.specDone).toHaveBeenCalledWith(
|
|
||||||
jasmine.objectContaining({
|
expect(reporter.specDone).toHaveBeenCalledWith(
|
||||||
deprecationWarnings: [
|
jasmine.objectContaining({
|
||||||
jasmine.objectContaining({
|
deprecationWarnings: [
|
||||||
message: jasmine.stringMatching(/^the message/)
|
jasmine.objectContaining({
|
||||||
})
|
message: jasmine.stringMatching(/^the message/)
|
||||||
]
|
})
|
||||||
})
|
]
|
||||||
);
|
})
|
||||||
expect(console.error).toHaveBeenCalledWith(
|
);
|
||||||
jasmine.stringMatching(
|
expect(console.error).toHaveBeenCalledWith(
|
||||||
/^DEPRECATION: the message \(in spec: a suite a spec\)/
|
jasmine.stringMatching(
|
||||||
)
|
/^DEPRECATION: the message \(in spec: a suite a spec\)/
|
||||||
);
|
)
|
||||||
done();
|
);
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('omits the suite or spec context when ignoreRunnable is true', function(done) {
|
it('omits the suite or spec context when ignoreRunnable is true', async function() {
|
||||||
const reporter = jasmine.createSpyObj('reporter', ['jasmineDone']);
|
const reporter = jasmine.createSpyObj('reporter', ['jasmineDone']);
|
||||||
env.addReporter(reporter);
|
env.addReporter(reporter);
|
||||||
spyOn(console, 'error');
|
spyOn(console, 'error');
|
||||||
@@ -107,27 +102,26 @@ describe('Deprecation (integration)', function() {
|
|||||||
env.deprecated('the message', { ignoreRunnable: true });
|
env.deprecated('the message', { ignoreRunnable: true });
|
||||||
});
|
});
|
||||||
|
|
||||||
env.execute(null, function() {
|
await env.execute();
|
||||||
expect(reporter.jasmineDone).toHaveBeenCalledWith(
|
|
||||||
jasmine.objectContaining({
|
expect(reporter.jasmineDone).toHaveBeenCalledWith(
|
||||||
deprecationWarnings: [
|
jasmine.objectContaining({
|
||||||
jasmine.objectContaining({
|
deprecationWarnings: [
|
||||||
message: jasmine.stringMatching(/^the message/)
|
jasmine.objectContaining({
|
||||||
})
|
message: jasmine.stringMatching(/^the message/)
|
||||||
]
|
})
|
||||||
})
|
]
|
||||||
);
|
})
|
||||||
expect(console.error).toHaveBeenCalledWith(
|
);
|
||||||
jasmine.stringMatching(/the message/)
|
expect(console.error).toHaveBeenCalledWith(
|
||||||
);
|
jasmine.stringMatching(/the message/)
|
||||||
expect(console.error).not.toHaveBeenCalledWith(
|
);
|
||||||
jasmine.stringMatching(/a spec/)
|
expect(console.error).not.toHaveBeenCalledWith(
|
||||||
);
|
jasmine.stringMatching(/a spec/)
|
||||||
done();
|
);
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('includes the stack trace', function(done) {
|
it('includes the stack trace', async function() {
|
||||||
const reporter = jasmine.createSpyObj('reporter', ['specDone']);
|
const reporter = jasmine.createSpyObj('reporter', ['specDone']);
|
||||||
env.addReporter(reporter);
|
env.addReporter(reporter);
|
||||||
spyOn(console, 'error');
|
spyOn(console, 'error');
|
||||||
@@ -138,25 +132,24 @@ describe('Deprecation (integration)', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
env.execute(null, function() {
|
await env.execute();
|
||||||
expect(reporter.specDone).toHaveBeenCalledWith(
|
|
||||||
jasmine.objectContaining({
|
expect(reporter.specDone).toHaveBeenCalledWith(
|
||||||
deprecationWarnings: [
|
jasmine.objectContaining({
|
||||||
jasmine.objectContaining({
|
deprecationWarnings: [
|
||||||
stack: jasmine.stringMatching(/DeprecationSpec.js/)
|
jasmine.objectContaining({
|
||||||
})
|
stack: jasmine.stringMatching(/DeprecationSpec.js/)
|
||||||
]
|
})
|
||||||
})
|
]
|
||||||
);
|
})
|
||||||
expect(console.error).toHaveBeenCalled();
|
);
|
||||||
expect(console.error.calls.argsFor(0)[0].replace(/\n/g, 'NL')).toMatch(
|
expect(console.error).toHaveBeenCalled();
|
||||||
/^DEPRECATION: the message \(in spec: a suite a spec\)NL.*DeprecationSpec.js/
|
expect(console.error.calls.argsFor(0)[0].replace(/\n/g, 'NL')).toMatch(
|
||||||
);
|
/^DEPRECATION: the message \(in spec: a suite a spec\)NL.*DeprecationSpec.js/
|
||||||
done();
|
);
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('excludes the stack trace when omitStackTrace is true', function(done) {
|
it('excludes the stack trace when omitStackTrace is true', async function() {
|
||||||
const reporter = jasmine.createSpyObj('reporter', ['specDone']);
|
const reporter = jasmine.createSpyObj('reporter', ['specDone']);
|
||||||
env.addReporter(reporter);
|
env.addReporter(reporter);
|
||||||
spyOn(console, 'error');
|
spyOn(console, 'error');
|
||||||
@@ -167,25 +160,24 @@ describe('Deprecation (integration)', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
env.execute(null, function() {
|
await env.execute();
|
||||||
expect(reporter.specDone).toHaveBeenCalledWith(
|
|
||||||
jasmine.objectContaining({
|
expect(reporter.specDone).toHaveBeenCalledWith(
|
||||||
deprecationWarnings: [
|
jasmine.objectContaining({
|
||||||
jasmine.objectContaining({
|
deprecationWarnings: [
|
||||||
stack: jasmine.falsy()
|
jasmine.objectContaining({
|
||||||
})
|
stack: jasmine.falsy()
|
||||||
]
|
})
|
||||||
})
|
]
|
||||||
);
|
})
|
||||||
expect(console.error).toHaveBeenCalled();
|
);
|
||||||
expect(console.error).not.toHaveBeenCalledWith(
|
expect(console.error).toHaveBeenCalled();
|
||||||
jasmine.stringMatching(/DeprecationSpec.js/)
|
expect(console.error).not.toHaveBeenCalledWith(
|
||||||
);
|
jasmine.stringMatching(/DeprecationSpec.js/)
|
||||||
done();
|
);
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('emits a given deprecation only once', function(done) {
|
it('emits a given deprecation only once', async function() {
|
||||||
const reporter = jasmine.createSpyObj('reporter', [
|
const reporter = jasmine.createSpyObj('reporter', [
|
||||||
'specDone',
|
'specDone',
|
||||||
'suiteDone'
|
'suiteDone'
|
||||||
@@ -205,43 +197,40 @@ describe('Deprecation (integration)', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
env.execute(null, function() {
|
await env.execute();
|
||||||
expect(reporter.suiteDone).toHaveBeenCalledWith(
|
|
||||||
jasmine.objectContaining({
|
expect(reporter.suiteDone).toHaveBeenCalledWith(
|
||||||
deprecationWarnings: [
|
jasmine.objectContaining({
|
||||||
// only one
|
deprecationWarnings: [
|
||||||
jasmine.objectContaining({
|
// only one
|
||||||
message: jasmine.stringMatching(/^the message/)
|
jasmine.objectContaining({
|
||||||
})
|
message: jasmine.stringMatching(/^the message/)
|
||||||
]
|
})
|
||||||
})
|
]
|
||||||
);
|
})
|
||||||
expect(reporter.specDone).toHaveBeenCalledWith(
|
);
|
||||||
jasmine.objectContaining({
|
expect(reporter.specDone).toHaveBeenCalledWith(
|
||||||
deprecationWarnings: [
|
jasmine.objectContaining({
|
||||||
// only the other one
|
deprecationWarnings: [
|
||||||
jasmine.objectContaining({
|
// only the other one
|
||||||
message: jasmine.stringMatching(/^a different message/)
|
jasmine.objectContaining({
|
||||||
})
|
message: jasmine.stringMatching(/^a different message/)
|
||||||
]
|
})
|
||||||
})
|
]
|
||||||
);
|
})
|
||||||
expect(console.error).toHaveBeenCalledTimes(2);
|
);
|
||||||
expect(console.error).toHaveBeenCalledWith(
|
expect(console.error).toHaveBeenCalledTimes(2);
|
||||||
jasmine.stringMatching(
|
expect(console.error).toHaveBeenCalledWith(
|
||||||
/^DEPRECATION: the message \(in suite: a suite\)/
|
jasmine.stringMatching(/^DEPRECATION: the message \(in suite: a suite\)/)
|
||||||
)
|
);
|
||||||
);
|
expect(console.error).toHaveBeenCalledWith(
|
||||||
expect(console.error).toHaveBeenCalledWith(
|
jasmine.stringMatching(
|
||||||
jasmine.stringMatching(
|
/^DEPRECATION: a different message \(in spec: a suite a spec\)/
|
||||||
/^DEPRECATION: a different message \(in spec: a suite a spec\)/
|
)
|
||||||
)
|
);
|
||||||
);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('emits a given deprecation each time when config.verboseDeprecations is true', function(done) {
|
it('emits a given deprecation each time when config.verboseDeprecations is true', async function() {
|
||||||
const reporter = jasmine.createSpyObj('reporter', [
|
const reporter = jasmine.createSpyObj('reporter', [
|
||||||
'specDone',
|
'specDone',
|
||||||
'suiteDone'
|
'suiteDone'
|
||||||
@@ -262,46 +251,45 @@ describe('Deprecation (integration)', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
env.execute(null, function() {
|
await env.execute();
|
||||||
expect(reporter.suiteDone).toHaveBeenCalledWith(
|
|
||||||
jasmine.objectContaining({
|
expect(reporter.suiteDone).toHaveBeenCalledWith(
|
||||||
deprecationWarnings: [
|
jasmine.objectContaining({
|
||||||
jasmine.objectContaining({
|
deprecationWarnings: [
|
||||||
message: jasmine.stringMatching(/^the message/)
|
jasmine.objectContaining({
|
||||||
}),
|
message: jasmine.stringMatching(/^the message/)
|
||||||
jasmine.objectContaining({
|
}),
|
||||||
message: jasmine.stringMatching(/^the message/)
|
jasmine.objectContaining({
|
||||||
})
|
message: jasmine.stringMatching(/^the message/)
|
||||||
]
|
})
|
||||||
})
|
]
|
||||||
);
|
})
|
||||||
expect(reporter.specDone).toHaveBeenCalledWith(
|
);
|
||||||
jasmine.objectContaining({
|
expect(reporter.specDone).toHaveBeenCalledWith(
|
||||||
deprecationWarnings: [
|
jasmine.objectContaining({
|
||||||
jasmine.objectContaining({
|
deprecationWarnings: [
|
||||||
message: jasmine.stringMatching(/^the message/)
|
jasmine.objectContaining({
|
||||||
})
|
message: jasmine.stringMatching(/^the message/)
|
||||||
]
|
})
|
||||||
})
|
]
|
||||||
);
|
})
|
||||||
expect(console.error).toHaveBeenCalledTimes(3);
|
);
|
||||||
expect(console.error.calls.argsFor(0)[0]).toMatch(
|
expect(console.error).toHaveBeenCalledTimes(3);
|
||||||
/^DEPRECATION: the message \(in suite: a suite\)/
|
expect(console.error.calls.argsFor(0)[0]).toMatch(
|
||||||
);
|
/^DEPRECATION: the message \(in suite: a suite\)/
|
||||||
expect(console.error.calls.argsFor(1)[0]).toMatch(
|
);
|
||||||
/^DEPRECATION: the message \(in suite: a suite\)/
|
expect(console.error.calls.argsFor(1)[0]).toMatch(
|
||||||
);
|
/^DEPRECATION: the message \(in suite: a suite\)/
|
||||||
expect(console.error.calls.argsFor(2)[0]).toMatch(
|
);
|
||||||
/^DEPRECATION: the message \(in spec: a suite a spec\)/
|
expect(console.error.calls.argsFor(2)[0]).toMatch(
|
||||||
);
|
/^DEPRECATION: the message \(in spec: a suite a spec\)/
|
||||||
expect(console.error.calls.argsFor(2)[0]).toMatch(
|
);
|
||||||
/^DEPRECATION: the message \(in spec: a suite a spec\)/
|
expect(console.error.calls.argsFor(2)[0]).toMatch(
|
||||||
);
|
/^DEPRECATION: the message \(in spec: a suite a spec\)/
|
||||||
done();
|
);
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles deprecations that occur before execute() is called', function(done) {
|
it('handles deprecations that occur before execute() is called', async function() {
|
||||||
const reporter = jasmine.createSpyObj('reporter', ['jasmineDone']);
|
const reporter = jasmine.createSpyObj('reporter', ['jasmineDone']);
|
||||||
env.addReporter(reporter);
|
env.addReporter(reporter);
|
||||||
spyOn(console, 'error');
|
spyOn(console, 'error');
|
||||||
@@ -309,20 +297,19 @@ describe('Deprecation (integration)', function() {
|
|||||||
env.deprecated('the message');
|
env.deprecated('the message');
|
||||||
env.it('a spec', function() {});
|
env.it('a spec', function() {});
|
||||||
|
|
||||||
env.execute(null, function() {
|
await env.execute();
|
||||||
expect(reporter.jasmineDone).toHaveBeenCalledWith(
|
|
||||||
jasmine.objectContaining({
|
expect(reporter.jasmineDone).toHaveBeenCalledWith(
|
||||||
deprecationWarnings: [
|
jasmine.objectContaining({
|
||||||
jasmine.objectContaining({
|
deprecationWarnings: [
|
||||||
message: jasmine.stringMatching(/^the message/)
|
jasmine.objectContaining({
|
||||||
})
|
message: jasmine.stringMatching(/^the message/)
|
||||||
]
|
})
|
||||||
})
|
]
|
||||||
);
|
})
|
||||||
expect(console.error).toHaveBeenCalledWith(
|
);
|
||||||
jasmine.stringMatching(/^DEPRECATION: the message/)
|
expect(console.error).toHaveBeenCalledWith(
|
||||||
);
|
jasmine.stringMatching(/^DEPRECATION: the message/)
|
||||||
done();
|
);
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -10,156 +10,158 @@ describe('Matchers (Integration)', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
function verifyPasses(expectations) {
|
function verifyPasses(expectations) {
|
||||||
it('passes', function(done) {
|
it('passes', async function() {
|
||||||
env.it('a spec', function() {
|
env.it('a spec', function() {
|
||||||
expectations(env);
|
expectations(env);
|
||||||
});
|
});
|
||||||
|
|
||||||
const specExpectations = function(result) {
|
const reporter = jasmine.createSpyObj('reporter', ['specDone']);
|
||||||
expect(result.status).toEqual('passed');
|
env.addReporter(reporter);
|
||||||
expect(result.passedExpectations.length)
|
await env.execute();
|
||||||
.withContext('Number of passed expectations')
|
|
||||||
.toEqual(1);
|
|
||||||
expect(result.failedExpectations.length)
|
|
||||||
.withContext('Number of failed expectations')
|
|
||||||
.toEqual(0);
|
|
||||||
expect(
|
|
||||||
result.failedExpectations[0] && result.failedExpectations[0].message
|
|
||||||
)
|
|
||||||
.withContext('Failure message')
|
|
||||||
.toBeUndefined();
|
|
||||||
};
|
|
||||||
|
|
||||||
env.addReporter({ specDone: specExpectations });
|
expect(reporter.specDone).toHaveBeenCalledTimes(1);
|
||||||
env.execute(null, done);
|
const result = reporter.specDone.calls.argsFor(0)[0];
|
||||||
|
expect(result.status).toEqual('passed');
|
||||||
|
expect(result.passedExpectations.length)
|
||||||
|
.withContext('Number of passed expectations')
|
||||||
|
.toEqual(1);
|
||||||
|
expect(result.failedExpectations.length)
|
||||||
|
.withContext('Number of failed expectations')
|
||||||
|
.toEqual(0);
|
||||||
|
expect(
|
||||||
|
result.failedExpectations[0] && result.failedExpectations[0].message
|
||||||
|
)
|
||||||
|
.withContext('Failure message')
|
||||||
|
.toBeUndefined();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function verifyFails(expectations) {
|
function verifyFails(expectations) {
|
||||||
it('fails', function(done) {
|
it('fails', async function() {
|
||||||
env.it('a spec', function() {
|
env.it('a spec', function() {
|
||||||
expectations(env);
|
expectations(env);
|
||||||
});
|
});
|
||||||
|
|
||||||
const specExpectations = function(result) {
|
const reporter = jasmine.createSpyObj('reporter', ['specDone']);
|
||||||
expect(result.status).toEqual('failed');
|
env.addReporter(reporter);
|
||||||
expect(result.failedExpectations.length)
|
await env.execute();
|
||||||
.withContext('Number of failed expectations')
|
|
||||||
.toEqual(1);
|
|
||||||
expect(result.failedExpectations[0].message)
|
|
||||||
.withContext(
|
|
||||||
'Failed with a thrown error rather than a matcher failure'
|
|
||||||
)
|
|
||||||
.not.toMatch(/^Error: /);
|
|
||||||
expect(result.failedExpectations[0].message)
|
|
||||||
.withContext(
|
|
||||||
'Failed with a thrown type error rather than a matcher failure'
|
|
||||||
)
|
|
||||||
.not.toMatch(/^TypeError: /);
|
|
||||||
expect(result.failedExpectations[0].matcherName)
|
|
||||||
.withContext('Matcher name')
|
|
||||||
.not.toEqual('');
|
|
||||||
};
|
|
||||||
|
|
||||||
env.addReporter({ specDone: specExpectations });
|
expect(reporter.specDone).toHaveBeenCalledTimes(1);
|
||||||
env.execute(null, done);
|
const result = reporter.specDone.calls.argsFor(0)[0];
|
||||||
|
expect(result.status).toEqual('failed');
|
||||||
|
expect(result.failedExpectations.length)
|
||||||
|
.withContext('Number of failed expectations')
|
||||||
|
.toEqual(1);
|
||||||
|
expect(result.failedExpectations[0].message)
|
||||||
|
.withContext('Failed with a thrown error rather than a matcher failure')
|
||||||
|
.not.toMatch(/^Error: /);
|
||||||
|
expect(result.failedExpectations[0].message)
|
||||||
|
.withContext(
|
||||||
|
'Failed with a thrown type error rather than a matcher failure'
|
||||||
|
)
|
||||||
|
.not.toMatch(/^TypeError: /);
|
||||||
|
expect(result.failedExpectations[0].matcherName)
|
||||||
|
.withContext('Matcher name')
|
||||||
|
.not.toEqual('');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function verifyFailsWithCustomObjectFormatters(config) {
|
function verifyFailsWithCustomObjectFormatters(config) {
|
||||||
it('uses custom object formatters', function(done) {
|
it('uses custom object formatters', async function() {
|
||||||
env.it('a spec', function() {
|
env.it('a spec', function() {
|
||||||
env.addCustomObjectFormatter(config.formatter);
|
env.addCustomObjectFormatter(config.formatter);
|
||||||
config.expectations(env);
|
config.expectations(env);
|
||||||
});
|
});
|
||||||
|
|
||||||
const specExpectations = function(result) {
|
const reporter = jasmine.createSpyObj('reporter', ['specDone']);
|
||||||
expect(result.status).toEqual('failed');
|
env.addReporter(reporter);
|
||||||
expect(result.failedExpectations.length)
|
await env.execute();
|
||||||
.withContext('Number of failed expectations')
|
|
||||||
.toEqual(1);
|
|
||||||
expect(result.failedExpectations[0].message).toEqual(
|
|
||||||
config.expectedMessage
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
env.addReporter({ specDone: specExpectations });
|
expect(reporter.specDone).toHaveBeenCalledTimes(1);
|
||||||
env.execute(null, done);
|
const result = reporter.specDone.calls.argsFor(0)[0];
|
||||||
|
expect(result.status).toEqual('failed');
|
||||||
|
expect(result.failedExpectations.length)
|
||||||
|
.withContext('Number of failed expectations')
|
||||||
|
.toEqual(1);
|
||||||
|
expect(result.failedExpectations[0].message).toEqual(
|
||||||
|
config.expectedMessage
|
||||||
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function verifyPassesAsync(expectations) {
|
function verifyPassesAsync(expectations) {
|
||||||
it('passes', function(done) {
|
it('passes', async function() {
|
||||||
env.it('a spec', function() {
|
env.it('a spec', function() {
|
||||||
return expectations(env);
|
return expectations(env);
|
||||||
});
|
});
|
||||||
|
|
||||||
const specExpectations = function(result) {
|
const reporter = jasmine.createSpyObj('reporter', ['specDone']);
|
||||||
expect(result.status).toEqual('passed');
|
env.addReporter(reporter);
|
||||||
expect(result.passedExpectations.length)
|
await env.execute();
|
||||||
.withContext('Number of passed expectations')
|
|
||||||
.toEqual(1);
|
|
||||||
expect(result.failedExpectations.length)
|
|
||||||
.withContext('Number of failed expectations')
|
|
||||||
.toEqual(0);
|
|
||||||
expect(
|
|
||||||
result.failedExpectations[0] && result.failedExpectations[0].message
|
|
||||||
)
|
|
||||||
.withContext('Failure message')
|
|
||||||
.toBeUndefined();
|
|
||||||
};
|
|
||||||
|
|
||||||
env.addReporter({ specDone: specExpectations });
|
expect(reporter.specDone).toHaveBeenCalledTimes(1);
|
||||||
env.execute(null, done);
|
const result = reporter.specDone.calls.argsFor(0)[0];
|
||||||
|
expect(result.status).toEqual('passed');
|
||||||
|
expect(result.passedExpectations.length)
|
||||||
|
.withContext('Number of passed expectations')
|
||||||
|
.toEqual(1);
|
||||||
|
expect(result.failedExpectations.length)
|
||||||
|
.withContext('Number of failed expectations')
|
||||||
|
.toEqual(0);
|
||||||
|
expect(
|
||||||
|
result.failedExpectations[0] && result.failedExpectations[0].message
|
||||||
|
)
|
||||||
|
.withContext('Failure message')
|
||||||
|
.toBeUndefined();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function verifyFailsAsync(expectations) {
|
function verifyFailsAsync(expectations) {
|
||||||
it('fails', function(done) {
|
it('fails', async function() {
|
||||||
env.it('a spec', function() {
|
env.it('a spec', function() {
|
||||||
return expectations(env);
|
return expectations(env);
|
||||||
});
|
});
|
||||||
|
|
||||||
const specExpectations = function(result) {
|
const reporter = jasmine.createSpyObj('reporter', ['specDone']);
|
||||||
expect(result.status).toEqual('failed');
|
env.addReporter(reporter);
|
||||||
expect(result.failedExpectations.length)
|
await env.execute();
|
||||||
.withContext('Number of failed expectations')
|
|
||||||
.toEqual(1);
|
|
||||||
expect(result.failedExpectations[0].message)
|
|
||||||
.withContext(
|
|
||||||
'Failed with a thrown error rather than a matcher failure'
|
|
||||||
)
|
|
||||||
.not.toMatch(/^Error: /);
|
|
||||||
expect(result.failedExpectations[0].matcherName)
|
|
||||||
.withContext('Matcher name')
|
|
||||||
.not.toEqual('');
|
|
||||||
};
|
|
||||||
|
|
||||||
env.addReporter({ specDone: specExpectations });
|
expect(reporter.specDone).toHaveBeenCalledTimes(1);
|
||||||
env.execute(null, done);
|
const result = reporter.specDone.calls.argsFor(0)[0];
|
||||||
|
expect(result.status).toEqual('failed');
|
||||||
|
expect(result.failedExpectations.length)
|
||||||
|
.withContext('Number of failed expectations')
|
||||||
|
.toEqual(1);
|
||||||
|
expect(result.failedExpectations[0].message)
|
||||||
|
.withContext('Failed with a thrown error rather than a matcher failure')
|
||||||
|
.not.toMatch(/^Error: /);
|
||||||
|
expect(result.failedExpectations[0].matcherName)
|
||||||
|
.withContext('Matcher name')
|
||||||
|
.not.toEqual('');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function verifyFailsWithCustomObjectFormattersAsync(config) {
|
function verifyFailsWithCustomObjectFormattersAsync(config) {
|
||||||
it('uses custom object formatters', function(done) {
|
it('uses custom object formatters', async function() {
|
||||||
const env = new jasmineUnderTest.Env();
|
const env = new jasmineUnderTest.Env();
|
||||||
env.it('a spec', function() {
|
env.it('a spec', function() {
|
||||||
env.addCustomObjectFormatter(config.formatter);
|
env.addCustomObjectFormatter(config.formatter);
|
||||||
return config.expectations(env);
|
return config.expectations(env);
|
||||||
});
|
});
|
||||||
|
|
||||||
const specExpectations = function(result) {
|
const reporter = jasmine.createSpyObj('reporter', ['specDone']);
|
||||||
expect(result.status).toEqual('failed');
|
env.addReporter(reporter);
|
||||||
expect(result.failedExpectations.length)
|
await env.execute();
|
||||||
.withContext('Number of failed expectations')
|
|
||||||
.toEqual(1);
|
|
||||||
expect(result.failedExpectations[0].message).toEqual(
|
|
||||||
config.expectedMessage
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
env.addReporter({ specDone: specExpectations });
|
expect(reporter.specDone).toHaveBeenCalledTimes(1);
|
||||||
env.execute(null, done);
|
const result = reporter.specDone.calls.argsFor(0)[0];
|
||||||
|
expect(result.status).toEqual('failed');
|
||||||
|
expect(result.failedExpectations.length)
|
||||||
|
.withContext('Number of failed expectations')
|
||||||
|
.toEqual(1);
|
||||||
|
expect(result.failedExpectations[0].message).toEqual(
|
||||||
|
config.expectedMessage
|
||||||
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -753,76 +755,79 @@ describe('Matchers (Integration)', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('When an async matcher is used with .already()', function() {
|
describe('When an async matcher is used with .already()', function() {
|
||||||
it('propagates the matcher result when the promise is resolved', function(done) {
|
it('propagates the matcher result when the promise is resolved', async function() {
|
||||||
env.it('a spec', function() {
|
env.it('a spec', function() {
|
||||||
return env.expectAsync(Promise.resolve()).already.toBeRejected();
|
return env.expectAsync(Promise.resolve()).already.toBeRejected();
|
||||||
});
|
});
|
||||||
|
|
||||||
const specExpectations = function(result) {
|
const reporter = jasmine.createSpyObj('reporter', ['specDone']);
|
||||||
expect(result.status).toEqual('failed');
|
env.addReporter(reporter);
|
||||||
expect(result.failedExpectations.length)
|
await env.execute();
|
||||||
.withContext('Number of failed expectations')
|
|
||||||
.toEqual(1);
|
|
||||||
expect(result.failedExpectations[0].message).toEqual(
|
|
||||||
'Expected [object Promise] to be rejected.'
|
|
||||||
);
|
|
||||||
expect(result.failedExpectations[0].matcherName)
|
|
||||||
.withContext('Matcher name')
|
|
||||||
.not.toEqual('');
|
|
||||||
};
|
|
||||||
|
|
||||||
env.addReporter({ specDone: specExpectations });
|
expect(reporter.specDone).toHaveBeenCalledTimes(1);
|
||||||
env.execute(null, done);
|
const result = reporter.specDone.calls.argsFor(0)[0];
|
||||||
|
expect(result.status).toEqual('failed');
|
||||||
|
expect(result.failedExpectations.length)
|
||||||
|
.withContext('Number of failed expectations')
|
||||||
|
.toEqual(1);
|
||||||
|
expect(result.failedExpectations[0].message).toEqual(
|
||||||
|
'Expected [object Promise] to be rejected.'
|
||||||
|
);
|
||||||
|
expect(result.failedExpectations[0].matcherName)
|
||||||
|
.withContext('Matcher name')
|
||||||
|
.not.toEqual('');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('propagates the matcher result when the promise is rejected', function(done) {
|
it('propagates the matcher result when the promise is rejected', async function() {
|
||||||
env.it('a spec', function() {
|
env.it('a spec', function() {
|
||||||
return env
|
return env
|
||||||
.expectAsync(Promise.reject(new Error('nope')))
|
.expectAsync(Promise.reject(new Error('nope')))
|
||||||
.already.toBeResolved();
|
.already.toBeResolved();
|
||||||
});
|
});
|
||||||
|
|
||||||
const specExpectations = function(result) {
|
const reporter = jasmine.createSpyObj('reporter', ['specDone']);
|
||||||
expect(result.status).toEqual('failed');
|
env.addReporter(reporter);
|
||||||
expect(result.failedExpectations.length)
|
await env.execute();
|
||||||
.withContext('Number of failed expectations')
|
|
||||||
.toEqual(1);
|
|
||||||
expect(result.failedExpectations[0].message).toEqual(
|
|
||||||
'Expected a promise to be resolved but it was ' +
|
|
||||||
'rejected with Error: nope.'
|
|
||||||
);
|
|
||||||
expect(result.failedExpectations[0].matcherName)
|
|
||||||
.withContext('Matcher name')
|
|
||||||
.not.toEqual('');
|
|
||||||
};
|
|
||||||
|
|
||||||
env.addReporter({ specDone: specExpectations });
|
expect(reporter.specDone).toHaveBeenCalledTimes(1);
|
||||||
env.execute(null, done);
|
const result = reporter.specDone.calls.argsFor(0)[0];
|
||||||
|
expect(result.status).toEqual('failed');
|
||||||
|
expect(result.failedExpectations.length)
|
||||||
|
.withContext('Number of failed expectations')
|
||||||
|
.toEqual(1);
|
||||||
|
expect(result.failedExpectations[0].message).toEqual(
|
||||||
|
'Expected a promise to be resolved but it was ' +
|
||||||
|
'rejected with Error: nope.'
|
||||||
|
);
|
||||||
|
expect(result.failedExpectations[0].matcherName)
|
||||||
|
.withContext('Matcher name')
|
||||||
|
.not.toEqual('');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('fails when the promise is pending', function(done) {
|
it('fails when the promise is pending', async function() {
|
||||||
const promise = new Promise(function() {});
|
const promise = new Promise(function() {});
|
||||||
|
|
||||||
env.it('a spec', function() {
|
env.it('a spec', function() {
|
||||||
return env.expectAsync(promise).already.toBeResolved();
|
return env.expectAsync(promise).already.toBeResolved();
|
||||||
});
|
});
|
||||||
|
|
||||||
const specExpectations = function(result) {
|
const reporter = jasmine.createSpyObj('reporter', ['specDone']);
|
||||||
expect(result.status).toEqual('failed');
|
env.addReporter(reporter);
|
||||||
expect(result.failedExpectations.length)
|
await env.execute();
|
||||||
.withContext('Number of failed expectations')
|
|
||||||
.toEqual(1);
|
|
||||||
expect(result.failedExpectations[0].message).toEqual(
|
|
||||||
'Expected a promise to be settled ' +
|
|
||||||
'(via expectAsync(...).already) but it was pending.'
|
|
||||||
);
|
|
||||||
expect(result.failedExpectations[0].matcherName)
|
|
||||||
.withContext('Matcher name')
|
|
||||||
.not.toEqual('');
|
|
||||||
};
|
|
||||||
|
|
||||||
env.addReporter({ specDone: specExpectations });
|
expect(reporter.specDone).toHaveBeenCalledTimes(1);
|
||||||
env.execute(null, done);
|
const result = reporter.specDone.calls.argsFor(0)[0];
|
||||||
|
expect(result.status).toEqual('failed');
|
||||||
|
expect(result.failedExpectations.length)
|
||||||
|
.withContext('Number of failed expectations')
|
||||||
|
.toEqual(1);
|
||||||
|
expect(result.failedExpectations[0].message).toEqual(
|
||||||
|
'Expected a promise to be settled ' +
|
||||||
|
'(via expectAsync(...).already) but it was pending.'
|
||||||
|
);
|
||||||
|
expect(result.failedExpectations[0].matcherName)
|
||||||
|
.withContext('Matcher name')
|
||||||
|
.not.toEqual('');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ describe('spec running', function() {
|
|||||||
expect(it4.id).toEqual('spec4');
|
expect(it4.id).toEqual('spec4');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('nested suites', function(done) {
|
it('nested suites', async function() {
|
||||||
let foo = 0;
|
let foo = 0;
|
||||||
let bar = 0;
|
let bar = 0;
|
||||||
let baz = 0;
|
let baz = 0;
|
||||||
@@ -61,16 +61,15 @@ describe('spec running', function() {
|
|||||||
expect(baz).toEqual(0);
|
expect(baz).toEqual(0);
|
||||||
expect(quux).toEqual(0);
|
expect(quux).toEqual(0);
|
||||||
|
|
||||||
env.execute(null, function() {
|
await env.execute();
|
||||||
expect(foo).toEqual(1);
|
|
||||||
expect(bar).toEqual(1);
|
expect(foo).toEqual(1);
|
||||||
expect(baz).toEqual(1);
|
expect(bar).toEqual(1);
|
||||||
expect(quux).toEqual(1);
|
expect(baz).toEqual(1);
|
||||||
done();
|
expect(quux).toEqual(1);
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should permit nested describes', function(done) {
|
it('should permit nested describes', async function() {
|
||||||
const actions = [];
|
const actions = [];
|
||||||
|
|
||||||
env.beforeEach(function() {
|
env.beforeEach(function() {
|
||||||
@@ -127,42 +126,41 @@ describe('spec running', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
env.execute(null, function() {
|
await env.execute();
|
||||||
const expected = [
|
|
||||||
'topSuite beforeEach',
|
|
||||||
'outer beforeEach',
|
|
||||||
'outer it 1',
|
|
||||||
'outer afterEach',
|
|
||||||
'topSuite afterEach',
|
|
||||||
|
|
||||||
'topSuite beforeEach',
|
const expected = [
|
||||||
'outer beforeEach',
|
'topSuite beforeEach',
|
||||||
'inner 1 beforeEach',
|
'outer beforeEach',
|
||||||
'inner 1 it',
|
'outer it 1',
|
||||||
'inner 1 afterEach',
|
'outer afterEach',
|
||||||
'outer afterEach',
|
'topSuite afterEach',
|
||||||
'topSuite afterEach',
|
|
||||||
|
|
||||||
'topSuite beforeEach',
|
'topSuite beforeEach',
|
||||||
'outer beforeEach',
|
'outer beforeEach',
|
||||||
'outer it 2',
|
'inner 1 beforeEach',
|
||||||
'outer afterEach',
|
'inner 1 it',
|
||||||
'topSuite afterEach',
|
'inner 1 afterEach',
|
||||||
|
'outer afterEach',
|
||||||
|
'topSuite afterEach',
|
||||||
|
|
||||||
'topSuite beforeEach',
|
'topSuite beforeEach',
|
||||||
'outer beforeEach',
|
'outer beforeEach',
|
||||||
'inner 2 beforeEach',
|
'outer it 2',
|
||||||
'inner 2 it',
|
'outer afterEach',
|
||||||
'inner 2 afterEach',
|
'topSuite afterEach',
|
||||||
'outer afterEach',
|
|
||||||
'topSuite afterEach'
|
'topSuite beforeEach',
|
||||||
];
|
'outer beforeEach',
|
||||||
expect(actions).toEqual(expected);
|
'inner 2 beforeEach',
|
||||||
done();
|
'inner 2 it',
|
||||||
});
|
'inner 2 afterEach',
|
||||||
|
'outer afterEach',
|
||||||
|
'topSuite afterEach'
|
||||||
|
];
|
||||||
|
expect(actions).toEqual(expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should run multiple befores and afters ordered so functions declared later are treated as more specific', function(done) {
|
it('should run multiple befores and afters ordered so functions declared later are treated as more specific', async function() {
|
||||||
const actions = [];
|
const actions = [];
|
||||||
|
|
||||||
env.beforeAll(function() {
|
env.beforeAll(function() {
|
||||||
@@ -219,28 +217,27 @@ describe('spec running', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
env.execute(null, function() {
|
await env.execute();
|
||||||
const expected = [
|
|
||||||
'runner beforeAll1',
|
const expected = [
|
||||||
'runner beforeAll2',
|
'runner beforeAll1',
|
||||||
'runner beforeEach1',
|
'runner beforeAll2',
|
||||||
'runner beforeEach2',
|
'runner beforeEach1',
|
||||||
'beforeEach1',
|
'runner beforeEach2',
|
||||||
'beforeEach2',
|
'beforeEach1',
|
||||||
'outer it 1',
|
'beforeEach2',
|
||||||
'afterEach2',
|
'outer it 1',
|
||||||
'afterEach1',
|
'afterEach2',
|
||||||
'runner afterEach2',
|
'afterEach1',
|
||||||
'runner afterEach1',
|
'runner afterEach2',
|
||||||
'runner afterAll2',
|
'runner afterEach1',
|
||||||
'runner afterAll1'
|
'runner afterAll2',
|
||||||
];
|
'runner afterAll1'
|
||||||
expect(actions).toEqual(expected);
|
];
|
||||||
done();
|
expect(actions).toEqual(expected);
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should run beforeAlls before beforeEachs and afterAlls after afterEachs', function(done) {
|
it('should run beforeAlls before beforeEachs and afterAlls after afterEachs', async function() {
|
||||||
const actions = [];
|
const actions = [];
|
||||||
|
|
||||||
env.beforeAll(function() {
|
env.beforeAll(function() {
|
||||||
@@ -281,24 +278,23 @@ describe('spec running', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
env.execute(null, function() {
|
await env.execute();
|
||||||
const expected = [
|
|
||||||
'runner beforeAll',
|
const expected = [
|
||||||
'inner beforeAll',
|
'runner beforeAll',
|
||||||
'runner beforeEach',
|
'inner beforeAll',
|
||||||
'inner beforeEach',
|
'runner beforeEach',
|
||||||
'it',
|
'inner beforeEach',
|
||||||
'inner afterEach',
|
'it',
|
||||||
'runner afterEach',
|
'inner afterEach',
|
||||||
'inner afterAll',
|
'runner afterEach',
|
||||||
'runner afterAll'
|
'inner afterAll',
|
||||||
];
|
'runner afterAll'
|
||||||
expect(actions).toEqual(expected);
|
];
|
||||||
done();
|
expect(actions).toEqual(expected);
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should run beforeAlls and afterAlls in the order declared when runnablesToRun is provided', function(done) {
|
it('should run beforeAlls and afterAlls in the order declared when runnablesToRun is provided', async function() {
|
||||||
const actions = [];
|
const actions = [];
|
||||||
let spec;
|
let spec;
|
||||||
let spec2;
|
let spec2;
|
||||||
@@ -345,30 +341,29 @@ describe('spec running', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
env.execute([spec2.id, spec.id], function() {
|
await env.execute([spec2.id, spec.id]);
|
||||||
const expected = [
|
|
||||||
'runner beforeAll',
|
|
||||||
'inner beforeAll',
|
|
||||||
'runner beforeEach',
|
|
||||||
'inner beforeEach',
|
|
||||||
'it2',
|
|
||||||
'inner afterEach',
|
|
||||||
'runner afterEach',
|
|
||||||
|
|
||||||
'runner beforeEach',
|
const expected = [
|
||||||
'inner beforeEach',
|
'runner beforeAll',
|
||||||
'it',
|
'inner beforeAll',
|
||||||
'inner afterEach',
|
'runner beforeEach',
|
||||||
'runner afterEach',
|
'inner beforeEach',
|
||||||
'inner afterAll',
|
'it2',
|
||||||
'runner afterAll'
|
'inner afterEach',
|
||||||
];
|
'runner afterEach',
|
||||||
expect(actions).toEqual(expected);
|
|
||||||
done();
|
'runner beforeEach',
|
||||||
});
|
'inner beforeEach',
|
||||||
|
'it',
|
||||||
|
'inner afterEach',
|
||||||
|
'runner afterEach',
|
||||||
|
'inner afterAll',
|
||||||
|
'runner afterAll'
|
||||||
|
];
|
||||||
|
expect(actions).toEqual(expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('only runs *Alls once in a focused suite', function(done) {
|
it('only runs *Alls once in a focused suite', async function() {
|
||||||
const actions = [];
|
const actions = [];
|
||||||
|
|
||||||
env.fdescribe('Suite', function() {
|
env.fdescribe('Suite', function() {
|
||||||
@@ -383,14 +378,13 @@ describe('spec running', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
env.execute(null, function() {
|
await env.execute();
|
||||||
expect(actions).toEqual(['beforeAll', 'spec', 'afterAll']);
|
|
||||||
done();
|
expect(actions).toEqual(['beforeAll', 'spec', 'afterAll']);
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('focused runnables', function() {
|
describe('focused runnables', function() {
|
||||||
it('runs the relevant alls and eachs for each runnable', function(done) {
|
it('runs the relevant alls and eachs for each runnable', async function() {
|
||||||
const actions = [];
|
const actions = [];
|
||||||
env.beforeAll(function() {
|
env.beforeAll(function() {
|
||||||
actions.push('beforeAll');
|
actions.push('beforeAll');
|
||||||
@@ -417,24 +411,23 @@ describe('spec running', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
env.execute(null, function() {
|
await env.execute();
|
||||||
const expected = [
|
|
||||||
'beforeAll',
|
|
||||||
'beforeEach',
|
|
||||||
'spec in fdescribe',
|
|
||||||
'afterEach',
|
|
||||||
|
|
||||||
'beforeEach',
|
const expected = [
|
||||||
'focused spec',
|
'beforeAll',
|
||||||
'afterEach',
|
'beforeEach',
|
||||||
'afterAll'
|
'spec in fdescribe',
|
||||||
];
|
'afterEach',
|
||||||
expect(actions).toEqual(expected);
|
|
||||||
done();
|
'beforeEach',
|
||||||
});
|
'focused spec',
|
||||||
|
'afterEach',
|
||||||
|
'afterAll'
|
||||||
|
];
|
||||||
|
expect(actions).toEqual(expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('focused specs in focused suites cause non-focused siblings to not run', function(done) {
|
it('focused specs in focused suites cause non-focused siblings to not run', async function() {
|
||||||
const actions = [];
|
const actions = [];
|
||||||
|
|
||||||
env.fdescribe('focused suite', function() {
|
env.fdescribe('focused suite', function() {
|
||||||
@@ -446,14 +439,13 @@ describe('spec running', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
env.execute(null, function() {
|
await env.execute();
|
||||||
const expected = ['focused spec'];
|
|
||||||
expect(actions).toEqual(expected);
|
const expected = ['focused spec'];
|
||||||
done();
|
expect(actions).toEqual(expected);
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('focused suites in focused suites cause non-focused siblings to not run', function(done) {
|
it('focused suites in focused suites cause non-focused siblings to not run', async function() {
|
||||||
const actions = [];
|
const actions = [];
|
||||||
|
|
||||||
env.fdescribe('focused suite', function() {
|
env.fdescribe('focused suite', function() {
|
||||||
@@ -467,14 +459,13 @@ describe('spec running', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
env.execute(null, function() {
|
await env.execute();
|
||||||
const expected = ['inner spec'];
|
|
||||||
expect(actions).toEqual(expected);
|
const expected = ['inner spec'];
|
||||||
done();
|
expect(actions).toEqual(expected);
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('focused runnables unfocus ancestor focused suites', function(done) {
|
it('focused runnables unfocus ancestor focused suites', async function() {
|
||||||
const actions = [];
|
const actions = [];
|
||||||
|
|
||||||
env.fdescribe('focused suite', function() {
|
env.fdescribe('focused suite', function() {
|
||||||
@@ -488,15 +479,14 @@ describe('spec running', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
env.execute(null, function() {
|
await env.execute();
|
||||||
const expected = ['focused spec'];
|
|
||||||
expect(actions).toEqual(expected);
|
const expected = ['focused spec'];
|
||||||
done();
|
expect(actions).toEqual(expected);
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("shouldn't run disabled suites", function(done) {
|
it("shouldn't run disabled suites", async function() {
|
||||||
const specInADisabledSuite = jasmine.createSpy('specInADisabledSuite');
|
const specInADisabledSuite = jasmine.createSpy('specInADisabledSuite');
|
||||||
env.describe('A Suite', function() {
|
env.describe('A Suite', function() {
|
||||||
env.xdescribe('with a disabled suite', function() {
|
env.xdescribe('with a disabled suite', function() {
|
||||||
@@ -504,13 +494,12 @@ describe('spec running', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
env.execute(null, function() {
|
await env.execute();
|
||||||
expect(specInADisabledSuite).not.toHaveBeenCalled();
|
|
||||||
done();
|
expect(specInADisabledSuite).not.toHaveBeenCalled();
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("shouldn't run before/after functions in disabled suites", function(done) {
|
it("shouldn't run before/after functions in disabled suites", async function() {
|
||||||
const shouldNotRun = jasmine.createSpy('shouldNotRun');
|
const shouldNotRun = jasmine.createSpy('shouldNotRun');
|
||||||
env.xdescribe('A disabled Suite', function() {
|
env.xdescribe('A disabled Suite', function() {
|
||||||
// None of the before/after functions should run.
|
// None of the before/after functions should run.
|
||||||
@@ -522,13 +511,12 @@ describe('spec running', function() {
|
|||||||
env.it('spec inside a disabled suite', shouldNotRun);
|
env.it('spec inside a disabled suite', shouldNotRun);
|
||||||
});
|
});
|
||||||
|
|
||||||
env.execute(null, function() {
|
await env.execute();
|
||||||
expect(shouldNotRun).not.toHaveBeenCalled();
|
|
||||||
done();
|
expect(shouldNotRun).not.toHaveBeenCalled();
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should allow top level suites to be disabled', function(done) {
|
it('should allow top level suites to be disabled', async function() {
|
||||||
const specInADisabledSuite = jasmine.createSpy('specInADisabledSuite'),
|
const specInADisabledSuite = jasmine.createSpy('specInADisabledSuite'),
|
||||||
otherSpec = jasmine.createSpy('otherSpec');
|
otherSpec = jasmine.createSpy('otherSpec');
|
||||||
|
|
||||||
@@ -539,14 +527,13 @@ describe('spec running', function() {
|
|||||||
env.it('another spec', otherSpec);
|
env.it('another spec', otherSpec);
|
||||||
});
|
});
|
||||||
|
|
||||||
env.execute(null, function() {
|
await env.execute();
|
||||||
expect(specInADisabledSuite).not.toHaveBeenCalled();
|
|
||||||
expect(otherSpec).toHaveBeenCalled();
|
expect(specInADisabledSuite).not.toHaveBeenCalled();
|
||||||
done();
|
expect(otherSpec).toHaveBeenCalled();
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should set all pending specs to pending when a suite is run', function(done) {
|
it('should set all pending specs to pending when a suite is run', async function() {
|
||||||
env.describe('default current suite', function() {
|
env.describe('default current suite', function() {
|
||||||
env.it('I am a pending spec');
|
env.it('I am a pending spec');
|
||||||
});
|
});
|
||||||
@@ -554,17 +541,16 @@ describe('spec running', function() {
|
|||||||
|
|
||||||
env.addReporter(reporter);
|
env.addReporter(reporter);
|
||||||
|
|
||||||
env.execute(null, function() {
|
await env.execute();
|
||||||
expect(reporter.specDone).toHaveBeenCalledWith(
|
|
||||||
jasmine.objectContaining({
|
expect(reporter.specDone).toHaveBeenCalledWith(
|
||||||
status: 'pending'
|
jasmine.objectContaining({
|
||||||
})
|
status: 'pending'
|
||||||
);
|
})
|
||||||
done();
|
);
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should recover gracefully when there are errors in describe functions', function(done) {
|
it('should recover gracefully when there are errors in describe functions', async function() {
|
||||||
const specs = [],
|
const specs = [],
|
||||||
reporter = jasmine.createSpyObj(['specDone', 'suiteDone']);
|
reporter = jasmine.createSpyObj(['specDone', 'suiteDone']);
|
||||||
|
|
||||||
@@ -599,24 +585,23 @@ describe('spec running', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
env.addReporter(reporter);
|
env.addReporter(reporter);
|
||||||
env.execute(null, function() {
|
await env.execute();
|
||||||
expect(specs).toEqual([
|
|
||||||
'outer1 inner1 should thingy',
|
expect(specs).toEqual([
|
||||||
'outer1 inner2 should other thingy',
|
'outer1 inner1 should thingy',
|
||||||
'outer2 should xxx'
|
'outer1 inner2 should other thingy',
|
||||||
]);
|
'outer2 should xxx'
|
||||||
expect(reporter.suiteDone).toHaveFailedExpectationsForRunnable(
|
]);
|
||||||
'outer1 inner1',
|
expect(reporter.suiteDone).toHaveFailedExpectationsForRunnable(
|
||||||
[/inner error/]
|
'outer1 inner1',
|
||||||
);
|
[/inner error/]
|
||||||
expect(reporter.suiteDone).toHaveFailedExpectationsForRunnable('outer1', [
|
);
|
||||||
/outer error/
|
expect(reporter.suiteDone).toHaveFailedExpectationsForRunnable('outer1', [
|
||||||
]);
|
/outer error/
|
||||||
done();
|
]);
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('re-enters suites that have no *Alls', function(done) {
|
it('re-enters suites that have no *Alls', async function() {
|
||||||
const actions = [];
|
const actions = [];
|
||||||
let spec1;
|
let spec1;
|
||||||
let spec2;
|
let spec2;
|
||||||
@@ -636,10 +621,9 @@ describe('spec running', function() {
|
|||||||
actions.push('spec3');
|
actions.push('spec3');
|
||||||
});
|
});
|
||||||
|
|
||||||
env.execute([spec2.id, spec3.id, spec1.id], function() {
|
await env.execute([spec2.id, spec3.id, spec1.id]);
|
||||||
expect(actions).toEqual(['spec2', 'spec3', 'spec1']);
|
|
||||||
done();
|
expect(actions).toEqual(['spec2', 'spec3', 'spec1']);
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('refuses to re-enter suites with a beforeAll', function() {
|
it('refuses to re-enter suites with a beforeAll', function() {
|
||||||
@@ -698,7 +682,7 @@ describe('spec running', function() {
|
|||||||
expect(actions).toEqual([]);
|
expect(actions).toEqual([]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should run the tests in a consistent order when a seed is supplied', function(done) {
|
it('should run the tests in a consistent order when a seed is supplied', async function() {
|
||||||
const actions = [];
|
const actions = [];
|
||||||
env.configure({ random: true, seed: '123456' });
|
env.configure({ random: true, seed: '123456' });
|
||||||
|
|
||||||
@@ -756,39 +740,38 @@ describe('spec running', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
env.execute(null, function() {
|
await env.execute();
|
||||||
const expected = [
|
|
||||||
'topSuite beforeEach',
|
|
||||||
'outer beforeEach',
|
|
||||||
'outer it 2',
|
|
||||||
'outer afterEach',
|
|
||||||
'topSuite afterEach',
|
|
||||||
|
|
||||||
'topSuite beforeEach',
|
const expected = [
|
||||||
'outer beforeEach',
|
'topSuite beforeEach',
|
||||||
'inner 2 beforeEach',
|
'outer beforeEach',
|
||||||
'inner 2 it',
|
'outer it 2',
|
||||||
'inner 2 afterEach',
|
'outer afterEach',
|
||||||
'outer afterEach',
|
'topSuite afterEach',
|
||||||
'topSuite afterEach',
|
|
||||||
|
|
||||||
'topSuite beforeEach',
|
'topSuite beforeEach',
|
||||||
'outer beforeEach',
|
'outer beforeEach',
|
||||||
'inner 1 beforeEach',
|
'inner 2 beforeEach',
|
||||||
'inner 1 it',
|
'inner 2 it',
|
||||||
'inner 1 afterEach',
|
'inner 2 afterEach',
|
||||||
'outer afterEach',
|
'outer afterEach',
|
||||||
'topSuite afterEach',
|
'topSuite afterEach',
|
||||||
|
|
||||||
'topSuite beforeEach',
|
'topSuite beforeEach',
|
||||||
'outer beforeEach',
|
'outer beforeEach',
|
||||||
'outer it 1',
|
'inner 1 beforeEach',
|
||||||
'outer afterEach',
|
'inner 1 it',
|
||||||
'topSuite afterEach'
|
'inner 1 afterEach',
|
||||||
];
|
'outer afterEach',
|
||||||
expect(actions).toEqual(expected);
|
'topSuite afterEach',
|
||||||
done();
|
|
||||||
});
|
'topSuite beforeEach',
|
||||||
|
'outer beforeEach',
|
||||||
|
'outer it 1',
|
||||||
|
'outer afterEach',
|
||||||
|
'topSuite afterEach'
|
||||||
|
];
|
||||||
|
expect(actions).toEqual(expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
function hasStandardErrorHandlingBehavior() {
|
function hasStandardErrorHandlingBehavior() {
|
||||||
@@ -1298,7 +1281,7 @@ describe('spec running', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('when stopOnSpecFailure is on', function() {
|
describe('when stopOnSpecFailure is on', function() {
|
||||||
it('does not run further specs when one fails', function(done) {
|
it('does not run further specs when one fails', async function() {
|
||||||
const actions = [];
|
const actions = [];
|
||||||
|
|
||||||
env.describe('wrapper', function() {
|
env.describe('wrapper', function() {
|
||||||
@@ -1317,10 +1300,9 @@ describe('spec running', function() {
|
|||||||
env.configure({ random: false });
|
env.configure({ random: false });
|
||||||
env.configure({ stopOnSpecFailure: true });
|
env.configure({ stopOnSpecFailure: true });
|
||||||
|
|
||||||
env.execute(null, function() {
|
await env.execute();
|
||||||
expect(actions).toEqual(['fails']);
|
|
||||||
done();
|
expect(actions).toEqual(['fails']);
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('runs afterAll functions', async function() {
|
it('runs afterAll functions', async function() {
|
||||||
@@ -1364,7 +1346,7 @@ describe('spec running', function() {
|
|||||||
env.configure({ autoCleanClosures: false, random: false });
|
env.configure({ autoCleanClosures: false, random: false });
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should be able to run multiple times', function(done) {
|
it('should be able to run multiple times', async function() {
|
||||||
const actions = [];
|
const actions = [];
|
||||||
|
|
||||||
env.describe('Suite', function() {
|
env.describe('Suite', function() {
|
||||||
@@ -1378,16 +1360,14 @@ describe('spec running', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
env.execute(null, function() {
|
await env.execute();
|
||||||
expect(actions).toEqual(['spec1', 'spec2']);
|
expect(actions).toEqual(['spec1', 'spec2']);
|
||||||
env.execute(null, function() {
|
|
||||||
expect(actions).toEqual(['spec1', 'spec2', 'spec1', 'spec2']);
|
await env.execute();
|
||||||
done();
|
expect(actions).toEqual(['spec1', 'spec2', 'spec1', 'spec2']);
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should reset results between runs', function(done) {
|
it('should reset results between runs', async function() {
|
||||||
const specResults = {};
|
const specResults = {};
|
||||||
const suiteResults = {};
|
const suiteResults = {};
|
||||||
let firstExecution = true;
|
let firstExecution = true;
|
||||||
@@ -1440,48 +1420,46 @@ describe('spec running', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
env.execute(null, function() {
|
await env.execute();
|
||||||
expect(specResults).toEqual({
|
expect(specResults).toEqual({
|
||||||
spec1: 'failed',
|
spec1: 'failed',
|
||||||
spec2: 'pending',
|
spec2: 'pending',
|
||||||
spec3: 'pending',
|
spec3: 'pending',
|
||||||
spec4: 'failed',
|
spec4: 'failed',
|
||||||
spec5: 'failed',
|
spec5: 'failed',
|
||||||
spec6: 'pending',
|
spec6: 'pending',
|
||||||
spec7: 'pending'
|
spec7: 'pending'
|
||||||
});
|
});
|
||||||
expect(suiteResults).toEqual({
|
expect(suiteResults).toEqual({
|
||||||
suite0: 'passed',
|
suite0: 'passed',
|
||||||
suite1: 'passed',
|
suite1: 'passed',
|
||||||
suite2: 'passed',
|
suite2: 'passed',
|
||||||
suite3: 'passed',
|
suite3: 'passed',
|
||||||
suite4: 'pending',
|
suite4: 'pending',
|
||||||
suite5: 'passed'
|
suite5: 'passed'
|
||||||
});
|
});
|
||||||
env.execute(null, function() {
|
|
||||||
expect(specResults).toEqual({
|
await env.execute();
|
||||||
spec1: 'passed',
|
expect(specResults).toEqual({
|
||||||
spec2: 'passed',
|
spec1: 'passed',
|
||||||
spec3: 'pending',
|
spec2: 'passed',
|
||||||
spec4: 'passed',
|
spec3: 'pending',
|
||||||
spec5: 'failed',
|
spec4: 'passed',
|
||||||
spec6: 'pending',
|
spec5: 'failed',
|
||||||
spec7: 'pending'
|
spec6: 'pending',
|
||||||
});
|
spec7: 'pending'
|
||||||
expect(suiteResults).toEqual({
|
});
|
||||||
suite0: 'passed',
|
expect(suiteResults).toEqual({
|
||||||
suite1: 'passed',
|
suite0: 'passed',
|
||||||
suite2: 'passed',
|
suite1: 'passed',
|
||||||
suite3: 'passed',
|
suite2: 'passed',
|
||||||
suite4: 'pending',
|
suite3: 'passed',
|
||||||
suite5: 'passed'
|
suite4: 'pending',
|
||||||
});
|
suite5: 'passed'
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should execute before and after hooks per run', function(done) {
|
it('should execute before and after hooks per run', async function() {
|
||||||
let timeline = [];
|
let timeline = [];
|
||||||
const timelineFn = function(hookName) {
|
const timelineFn = function(hookName) {
|
||||||
return function() {
|
return function() {
|
||||||
@@ -1507,17 +1485,15 @@ describe('spec running', function() {
|
|||||||
env.it('spec1', timelineFn('spec1'));
|
env.it('spec1', timelineFn('spec1'));
|
||||||
env.it('spec2', timelineFn('spec2'));
|
env.it('spec2', timelineFn('spec2'));
|
||||||
});
|
});
|
||||||
env.execute(null, function() {
|
await env.execute();
|
||||||
expect(timeline).toEqual(expectedTimeLine);
|
expect(timeline).toEqual(expectedTimeLine);
|
||||||
timeline = [];
|
|
||||||
env.execute(null, function() {
|
timeline = [];
|
||||||
expect(timeline).toEqual(expectedTimeLine);
|
await env.execute();
|
||||||
done();
|
expect(timeline).toEqual(expectedTimeLine);
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should be able to filter out different tests in subsequent runs', function(done) {
|
it('should be able to filter out different tests in subsequent runs', async function() {
|
||||||
const specResults = {};
|
const specResults = {};
|
||||||
let focussedSpec = 'spec1';
|
let focussedSpec = 'spec1';
|
||||||
|
|
||||||
@@ -1539,29 +1515,27 @@ describe('spec running', function() {
|
|||||||
env.it('spec3', function() {});
|
env.it('spec3', function() {});
|
||||||
});
|
});
|
||||||
|
|
||||||
env.execute(null, function() {
|
await env.execute();
|
||||||
expect(specResults).toEqual({
|
expect(specResults).toEqual({
|
||||||
spec1: 'passed',
|
spec1: 'passed',
|
||||||
spec2: 'excluded',
|
spec2: 'excluded',
|
||||||
spec3: 'excluded'
|
spec3: 'excluded'
|
||||||
});
|
});
|
||||||
focussedSpec = 'spec2';
|
|
||||||
env.execute(null, function() {
|
focussedSpec = 'spec2';
|
||||||
expect(specResults).toEqual({
|
await env.execute();
|
||||||
spec1: 'excluded',
|
expect(specResults).toEqual({
|
||||||
spec2: 'passed',
|
spec1: 'excluded',
|
||||||
spec3: 'excluded'
|
spec2: 'passed',
|
||||||
});
|
spec3: 'excluded'
|
||||||
focussedSpec = 'spec3';
|
});
|
||||||
env.execute(null, function() {
|
|
||||||
expect(specResults).toEqual({
|
focussedSpec = 'spec3';
|
||||||
spec1: 'excluded',
|
await env.execute();
|
||||||
spec2: 'excluded',
|
expect(specResults).toEqual({
|
||||||
spec3: 'passed'
|
spec1: 'excluded',
|
||||||
});
|
spec2: 'excluded',
|
||||||
done();
|
spec3: 'passed'
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
describe('DiffBuilder', function() {
|
describe('DiffBuilder', function() {
|
||||||
it('records the actual and expected objects', function() {
|
it('records the actual and expected objects', function() {
|
||||||
const diffBuilder = jasmineUnderTest.DiffBuilder();
|
const diffBuilder = new jasmineUnderTest.DiffBuilder();
|
||||||
diffBuilder.setRoots({ x: 'actual' }, { x: 'expected' });
|
diffBuilder.setRoots({ x: 'actual' }, { x: 'expected' });
|
||||||
diffBuilder.recordMismatch();
|
diffBuilder.recordMismatch();
|
||||||
|
|
||||||
@@ -10,7 +10,7 @@ describe('DiffBuilder', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('prints the path at which the difference was found', function() {
|
it('prints the path at which the difference was found', function() {
|
||||||
const diffBuilder = jasmineUnderTest.DiffBuilder();
|
const diffBuilder = new jasmineUnderTest.DiffBuilder();
|
||||||
diffBuilder.setRoots({ foo: { x: 'actual' } }, { foo: { x: 'expected' } });
|
diffBuilder.setRoots({ foo: { x: 'actual' } }, { foo: { x: 'expected' } });
|
||||||
|
|
||||||
diffBuilder.withPath('foo', function() {
|
diffBuilder.withPath('foo', function() {
|
||||||
@@ -23,7 +23,7 @@ describe('DiffBuilder', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('prints multiple messages, separated by newlines', function() {
|
it('prints multiple messages, separated by newlines', function() {
|
||||||
const diffBuilder = jasmineUnderTest.DiffBuilder();
|
const diffBuilder = new jasmineUnderTest.DiffBuilder();
|
||||||
diffBuilder.setRoots({ foo: 1, bar: 3 }, { foo: 2, bar: 4 });
|
diffBuilder.setRoots({ foo: 1, bar: 3 }, { foo: 2, bar: 4 });
|
||||||
|
|
||||||
diffBuilder.withPath('foo', function() {
|
diffBuilder.withPath('foo', function() {
|
||||||
@@ -40,7 +40,7 @@ describe('DiffBuilder', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('allows customization of the message', function() {
|
it('allows customization of the message', function() {
|
||||||
const diffBuilder = jasmineUnderTest.DiffBuilder();
|
const diffBuilder = new jasmineUnderTest.DiffBuilder();
|
||||||
diffBuilder.setRoots({ x: 'bar' }, { x: 'foo' });
|
diffBuilder.setRoots({ x: 'bar' }, { x: 'foo' });
|
||||||
|
|
||||||
function darthVaderFormatter(actual, expected, path) {
|
function darthVaderFormatter(actual, expected, path) {
|
||||||
@@ -68,7 +68,7 @@ describe('DiffBuilder', function() {
|
|||||||
const prettyPrinter = function(val) {
|
const prettyPrinter = function(val) {
|
||||||
return '|' + val + '|';
|
return '|' + val + '|';
|
||||||
},
|
},
|
||||||
diffBuilder = jasmineUnderTest.DiffBuilder({
|
diffBuilder = new jasmineUnderTest.DiffBuilder({
|
||||||
prettyPrinter: prettyPrinter
|
prettyPrinter: prettyPrinter
|
||||||
});
|
});
|
||||||
prettyPrinter.customFormat_ = function() {};
|
prettyPrinter.customFormat_ = function() {};
|
||||||
@@ -86,7 +86,7 @@ describe('DiffBuilder', function() {
|
|||||||
it('passes the injected pretty-printer to the diff formatter', function() {
|
it('passes the injected pretty-printer to the diff formatter', function() {
|
||||||
const diffFormatter = jasmine.createSpy('diffFormatter'),
|
const diffFormatter = jasmine.createSpy('diffFormatter'),
|
||||||
prettyPrinter = function() {},
|
prettyPrinter = function() {},
|
||||||
diffBuilder = jasmineUnderTest.DiffBuilder({
|
diffBuilder = new jasmineUnderTest.DiffBuilder({
|
||||||
prettyPrinter: prettyPrinter
|
prettyPrinter: prettyPrinter
|
||||||
});
|
});
|
||||||
prettyPrinter.customFormat_ = function() {};
|
prettyPrinter.customFormat_ = function() {};
|
||||||
|
|||||||
@@ -104,7 +104,9 @@ describe('toBeInstanceOf', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('passes for an async function', function() {
|
it('passes for an async function', function() {
|
||||||
const fn = eval("(async function fn() { return 'foo'; })");
|
async function fn() {
|
||||||
|
return 'foo';
|
||||||
|
}
|
||||||
|
|
||||||
const matcher = jasmineUnderTest.matchers.toBeInstanceOf();
|
const matcher = jasmineUnderTest.matchers.toBeInstanceOf();
|
||||||
const result = matcher.compare(fn, Function);
|
const result = matcher.compare(fn, Function);
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ const path = require('path'),
|
|||||||
jasmineBrowser = require('jasmine-browser-runner'),
|
jasmineBrowser = require('jasmine-browser-runner'),
|
||||||
jasmineCore = require('../../lib/jasmine-core');
|
jasmineCore = require('../../lib/jasmine-core');
|
||||||
|
|
||||||
var config = require(path.resolve('spec/support/jasmine-browser.js'));
|
const config = require(path.resolve('spec/support/jasmine-browser.js'));
|
||||||
config.clearReporters = true;
|
config.clearReporters = true;
|
||||||
config.jasmineCore = jasmineCore;
|
config.jasmineCore = jasmineCore;
|
||||||
|
|
||||||
|
|||||||
@@ -5,14 +5,14 @@
|
|||||||
source files or spec files are loaded.
|
source files or spec files are loaded.
|
||||||
*/
|
*/
|
||||||
(function() {
|
(function() {
|
||||||
var jasmineRequire = window.jasmineRequire || require('./jasmine.js');
|
const jasmineRequire = window.jasmineRequire || require('./jasmine.js');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ## Require & Instantiate
|
* ## Require & Instantiate
|
||||||
*
|
*
|
||||||
* Require Jasmine's core files. Specifically, this requires and attaches all of Jasmine's code to the `jasmine` reference.
|
* Require Jasmine's core files. Specifically, this requires and attaches all of Jasmine's code to the `jasmine` reference.
|
||||||
*/
|
*/
|
||||||
var jasmine = jasmineRequire.core(jasmineRequire),
|
const jasmine = jasmineRequire.core(jasmineRequire),
|
||||||
global = jasmine.getGlobal();
|
global = jasmine.getGlobal();
|
||||||
global.jasmine = jasmine;
|
global.jasmine = jasmine;
|
||||||
|
|
||||||
@@ -24,19 +24,19 @@
|
|||||||
/**
|
/**
|
||||||
* Create the Jasmine environment. This is used to run all specs in a project.
|
* Create the Jasmine environment. This is used to run all specs in a project.
|
||||||
*/
|
*/
|
||||||
var env = jasmine.getEnv();
|
const env = jasmine.getEnv();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ## The Global Interface
|
* ## The Global Interface
|
||||||
*
|
*
|
||||||
* Build up the functions that will be exposed as the Jasmine public interface. A project can customize, rename or alias any of these functions as desired, provided the implementation remains unchanged.
|
* Build up the functions that will be exposed as the Jasmine public interface. A project can customize, rename or alias any of these functions as desired, provided the implementation remains unchanged.
|
||||||
*/
|
*/
|
||||||
var jasmineInterface = jasmineRequire.interface(jasmine, env);
|
const jasmineInterface = jasmineRequire.interface(jasmine, env);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add all of the Jasmine global/public interface to the global scope, so a project can use the public interface directly. For example, calling `describe` in specs instead of `jasmine.getEnv().describe`.
|
* Add all of the Jasmine global/public interface to the global scope, so a project can use the public interface directly. For example, calling `describe` in specs instead of `jasmine.getEnv().describe`.
|
||||||
*/
|
*/
|
||||||
for (var property in jasmineInterface) {
|
for (const property in jasmineInterface) {
|
||||||
global[property] = jasmineInterface[property];
|
global[property] = jasmineInterface[property];
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
var env = jasmine.getEnv();
|
const env = jasmine.getEnv();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ## Runner Parameters
|
* ## Runner Parameters
|
||||||
@@ -20,15 +20,15 @@
|
|||||||
* More browser specific code - wrap the query string in an object and to allow for getting/setting parameters from the runner user interface.
|
* More browser specific code - wrap the query string in an object and to allow for getting/setting parameters from the runner user interface.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var queryString = new jasmine.QueryString({
|
const queryString = new jasmine.QueryString({
|
||||||
getWindowLocation: function() {
|
getWindowLocation: function() {
|
||||||
return window.location;
|
return window.location;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
var filterSpecs = !!queryString.getParam('spec');
|
const filterSpecs = !!queryString.getParam('spec');
|
||||||
|
|
||||||
var config = {
|
const config = {
|
||||||
stopOnSpecFailure: queryString.getParam('stopOnSpecFailure'),
|
stopOnSpecFailure: queryString.getParam('stopOnSpecFailure'),
|
||||||
stopSpecOnExpectationFailure: queryString.getParam(
|
stopSpecOnExpectationFailure: queryString.getParam(
|
||||||
'stopSpecOnExpectationFailure'
|
'stopSpecOnExpectationFailure'
|
||||||
@@ -36,13 +36,13 @@
|
|||||||
hideDisabled: queryString.getParam('hideDisabled')
|
hideDisabled: queryString.getParam('hideDisabled')
|
||||||
};
|
};
|
||||||
|
|
||||||
var random = queryString.getParam('random');
|
const random = queryString.getParam('random');
|
||||||
|
|
||||||
if (random !== undefined && random !== '') {
|
if (random !== undefined && random !== '') {
|
||||||
config.random = random;
|
config.random = random;
|
||||||
}
|
}
|
||||||
|
|
||||||
var seed = queryString.getParam('seed');
|
const seed = queryString.getParam('seed');
|
||||||
if (seed) {
|
if (seed) {
|
||||||
config.seed = seed;
|
config.seed = seed;
|
||||||
}
|
}
|
||||||
@@ -51,7 +51,7 @@
|
|||||||
* ## Reporters
|
* ## Reporters
|
||||||
* The `HtmlReporter` builds all of the HTML UI for the runner page. This reporter paints the dots, stars, and x's for specs, as well as all spec names and all failures (if any).
|
* The `HtmlReporter` builds all of the HTML UI for the runner page. This reporter paints the dots, stars, and x's for specs, as well as all spec names and all failures (if any).
|
||||||
*/
|
*/
|
||||||
var htmlReporter = new jasmine.HtmlReporter({
|
const htmlReporter = new jasmine.HtmlReporter({
|
||||||
env: env,
|
env: env,
|
||||||
navigateWithNewParam: function(key, value) {
|
navigateWithNewParam: function(key, value) {
|
||||||
return queryString.navigateWithNewParam(key, value);
|
return queryString.navigateWithNewParam(key, value);
|
||||||
@@ -81,7 +81,7 @@
|
|||||||
/**
|
/**
|
||||||
* Filter which specs will be run by matching the start of the full name against the `spec` query param.
|
* Filter which specs will be run by matching the start of the full name against the `spec` query param.
|
||||||
*/
|
*/
|
||||||
var specFilter = new jasmine.HtmlSpecFilter({
|
const specFilter = new jasmine.HtmlSpecFilter({
|
||||||
filterString: function() {
|
filterString: function() {
|
||||||
return queryString.getParam('spec');
|
return queryString.getParam('spec');
|
||||||
}
|
}
|
||||||
@@ -98,7 +98,7 @@
|
|||||||
*
|
*
|
||||||
* Replace the browser window's `onload`, ensure it's called, and then run all of the loaded specs. This includes initializing the `HtmlReporter` instance and then executing the loaded Jasmine environment. All of this will happen after all of the specs are loaded.
|
* Replace the browser window's `onload`, ensure it's called, and then run all of the loaded specs. This includes initializing the `HtmlReporter` instance and then executing the loaded Jasmine environment. All of this will happen after all of the specs are loaded.
|
||||||
*/
|
*/
|
||||||
var currentWindowOnload = window.onload;
|
const currentWindowOnload = window.onload;
|
||||||
|
|
||||||
window.onload = function() {
|
window.onload = function() {
|
||||||
if (currentWindowOnload) {
|
if (currentWindowOnload) {
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
module.exports = function(jasmineRequire) {
|
module.exports = function(jasmineRequire) {
|
||||||
var jasmine = jasmineRequire.core(jasmineRequire);
|
const jasmine = jasmineRequire.core(jasmineRequire);
|
||||||
|
|
||||||
var env = jasmine.getEnv({ suppressLoadErrors: true });
|
const env = jasmine.getEnv({ suppressLoadErrors: true });
|
||||||
|
|
||||||
var jasmineInterface = jasmineRequire.interface(jasmine, env);
|
const jasmineInterface = jasmineRequire.interface(jasmine, env);
|
||||||
|
|
||||||
extend(global, jasmineInterface);
|
extend(global, jasmineInterface);
|
||||||
|
|
||||||
function extend(destination, source) {
|
function extend(destination, source) {
|
||||||
for (var property in source) destination[property] = source[property];
|
for (const property in source) destination[property] = source[property];
|
||||||
return destination;
|
return destination;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ getJasmineRequireObj().CallTracker = function(j$) {
|
|||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
function CallTracker() {
|
function CallTracker() {
|
||||||
var calls = [];
|
let calls = [];
|
||||||
var opts = {};
|
const opts = {};
|
||||||
|
|
||||||
this.track = function(context) {
|
this.track = function(context) {
|
||||||
if (opts.cloneArgs) {
|
if (opts.cloneArgs) {
|
||||||
@@ -45,7 +45,7 @@ getJasmineRequireObj().CallTracker = function(j$) {
|
|||||||
* @return {Array}
|
* @return {Array}
|
||||||
*/
|
*/
|
||||||
this.argsFor = function(index) {
|
this.argsFor = function(index) {
|
||||||
var call = calls[index];
|
const call = calls[index];
|
||||||
return call ? call.args : [];
|
return call ? call.args : [];
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -58,7 +58,7 @@ getJasmineRequireObj().CallTracker = function(j$) {
|
|||||||
* @return {Object?}
|
* @return {Object?}
|
||||||
*/
|
*/
|
||||||
this.thisFor = function(index) {
|
this.thisFor = function(index) {
|
||||||
var call = calls[index];
|
const call = calls[index];
|
||||||
return call ? call.object : undefined;
|
return call ? call.object : undefined;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -81,12 +81,7 @@ getJasmineRequireObj().CallTracker = function(j$) {
|
|||||||
* @return {Array}
|
* @return {Array}
|
||||||
*/
|
*/
|
||||||
this.allArgs = function() {
|
this.allArgs = function() {
|
||||||
var callArgs = [];
|
return calls.map(c => c.args);
|
||||||
for (var i = 0; i < calls.length; i++) {
|
|
||||||
callArgs.push(calls[i].args);
|
|
||||||
}
|
|
||||||
|
|
||||||
return callArgs;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
getJasmineRequireObj().clearStack = function(j$) {
|
getJasmineRequireObj().clearStack = function(j$) {
|
||||||
var maxInlineCallCount = 10;
|
const maxInlineCallCount = 10;
|
||||||
|
|
||||||
function messageChannelImpl(global, setTimeout) {
|
function messageChannelImpl(global, setTimeout) {
|
||||||
var channel = new global.MessageChannel(),
|
const channel = new global.MessageChannel();
|
||||||
head = {},
|
let head = {};
|
||||||
tail = head;
|
let tail = head;
|
||||||
|
|
||||||
var taskRunning = false;
|
let taskRunning = false;
|
||||||
channel.port1.onmessage = function() {
|
channel.port1.onmessage = function() {
|
||||||
head = head.next;
|
head = head.next;
|
||||||
var task = head.task;
|
const task = head.task;
|
||||||
delete head.task;
|
delete head.task;
|
||||||
|
|
||||||
if (taskRunning) {
|
if (taskRunning) {
|
||||||
@@ -24,7 +24,7 @@ getJasmineRequireObj().clearStack = function(j$) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var currentCallCount = 0;
|
let currentCallCount = 0;
|
||||||
return function clearStack(fn) {
|
return function clearStack(fn) {
|
||||||
currentCallCount++;
|
currentCallCount++;
|
||||||
|
|
||||||
@@ -39,14 +39,14 @@ getJasmineRequireObj().clearStack = function(j$) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getClearStack(global) {
|
function getClearStack(global) {
|
||||||
var currentCallCount = 0;
|
let currentCallCount = 0;
|
||||||
var realSetTimeout = global.setTimeout;
|
const realSetTimeout = global.setTimeout;
|
||||||
var setTimeoutImpl = function clearStack(fn) {
|
const setTimeoutImpl = function clearStack(fn) {
|
||||||
Function.prototype.apply.apply(realSetTimeout, [global, [fn, 0]]);
|
Function.prototype.apply.apply(realSetTimeout, [global, [fn, 0]]);
|
||||||
};
|
};
|
||||||
|
|
||||||
if (j$.isFunction_(global.setImmediate)) {
|
if (j$.isFunction_(global.setImmediate)) {
|
||||||
var realSetImmediate = global.setImmediate;
|
const realSetImmediate = global.setImmediate;
|
||||||
return function(fn) {
|
return function(fn) {
|
||||||
currentCallCount++;
|
currentCallCount++;
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
getJasmineRequireObj().Clock = function() {
|
getJasmineRequireObj().Clock = function() {
|
||||||
/* global process */
|
/* global process */
|
||||||
var NODE_JS =
|
const NODE_JS =
|
||||||
typeof process !== 'undefined' &&
|
typeof process !== 'undefined' &&
|
||||||
process.versions &&
|
process.versions &&
|
||||||
typeof process.versions.node === 'string';
|
typeof process.versions.node === 'string';
|
||||||
@@ -14,24 +14,23 @@ getJasmineRequireObj().Clock = function() {
|
|||||||
* @hideconstructor
|
* @hideconstructor
|
||||||
*/
|
*/
|
||||||
function Clock(global, delayedFunctionSchedulerFactory, mockDate) {
|
function Clock(global, delayedFunctionSchedulerFactory, mockDate) {
|
||||||
var self = this,
|
const realTimingFunctions = {
|
||||||
realTimingFunctions = {
|
setTimeout: global.setTimeout,
|
||||||
setTimeout: global.setTimeout,
|
clearTimeout: global.clearTimeout,
|
||||||
clearTimeout: global.clearTimeout,
|
setInterval: global.setInterval,
|
||||||
setInterval: global.setInterval,
|
clearInterval: global.clearInterval
|
||||||
clearInterval: global.clearInterval
|
};
|
||||||
},
|
const fakeTimingFunctions = {
|
||||||
fakeTimingFunctions = {
|
setTimeout: setTimeout,
|
||||||
setTimeout: setTimeout,
|
clearTimeout: clearTimeout,
|
||||||
clearTimeout: clearTimeout,
|
setInterval: setInterval,
|
||||||
setInterval: setInterval,
|
clearInterval: clearInterval
|
||||||
clearInterval: clearInterval
|
};
|
||||||
},
|
let installed = false;
|
||||||
installed = false,
|
let delayedFunctionScheduler;
|
||||||
delayedFunctionScheduler,
|
let timer;
|
||||||
timer;
|
|
||||||
|
|
||||||
self.FakeTimeout = FakeTimeout;
|
this.FakeTimeout = FakeTimeout;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Install the mock clock over the built-in methods.
|
* Install the mock clock over the built-in methods.
|
||||||
@@ -40,7 +39,7 @@ getJasmineRequireObj().Clock = function() {
|
|||||||
* @function
|
* @function
|
||||||
* @return {Clock}
|
* @return {Clock}
|
||||||
*/
|
*/
|
||||||
self.install = function() {
|
this.install = function() {
|
||||||
if (!originalTimingFunctionsIntact()) {
|
if (!originalTimingFunctionsIntact()) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
'Jasmine Clock was unable to install over custom global timer functions. Is the clock already installed?'
|
'Jasmine Clock was unable to install over custom global timer functions. Is the clock already installed?'
|
||||||
@@ -51,7 +50,7 @@ getJasmineRequireObj().Clock = function() {
|
|||||||
delayedFunctionScheduler = delayedFunctionSchedulerFactory();
|
delayedFunctionScheduler = delayedFunctionSchedulerFactory();
|
||||||
installed = true;
|
installed = true;
|
||||||
|
|
||||||
return self;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -60,7 +59,7 @@ getJasmineRequireObj().Clock = function() {
|
|||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
* @function
|
* @function
|
||||||
*/
|
*/
|
||||||
self.uninstall = function() {
|
this.uninstall = function() {
|
||||||
delayedFunctionScheduler = null;
|
delayedFunctionScheduler = null;
|
||||||
mockDate.uninstall();
|
mockDate.uninstall();
|
||||||
replace(global, realTimingFunctions);
|
replace(global, realTimingFunctions);
|
||||||
@@ -78,7 +77,7 @@ getJasmineRequireObj().Clock = function() {
|
|||||||
* @function
|
* @function
|
||||||
* @param {Function} closure The function to be called.
|
* @param {Function} closure The function to be called.
|
||||||
*/
|
*/
|
||||||
self.withMock = function(closure) {
|
this.withMock = function(closure) {
|
||||||
this.install();
|
this.install();
|
||||||
try {
|
try {
|
||||||
closure();
|
closure();
|
||||||
@@ -94,29 +93,29 @@ getJasmineRequireObj().Clock = function() {
|
|||||||
* @function
|
* @function
|
||||||
* @param {Date} [initialDate=now] The `Date` to provide.
|
* @param {Date} [initialDate=now] The `Date` to provide.
|
||||||
*/
|
*/
|
||||||
self.mockDate = function(initialDate) {
|
this.mockDate = function(initialDate) {
|
||||||
mockDate.install(initialDate);
|
mockDate.install(initialDate);
|
||||||
};
|
};
|
||||||
|
|
||||||
self.setTimeout = function(fn, delay, params) {
|
this.setTimeout = function(fn, delay, params) {
|
||||||
return Function.prototype.apply.apply(timer.setTimeout, [
|
return Function.prototype.apply.apply(timer.setTimeout, [
|
||||||
global,
|
global,
|
||||||
arguments
|
arguments
|
||||||
]);
|
]);
|
||||||
};
|
};
|
||||||
|
|
||||||
self.setInterval = function(fn, delay, params) {
|
this.setInterval = function(fn, delay, params) {
|
||||||
return Function.prototype.apply.apply(timer.setInterval, [
|
return Function.prototype.apply.apply(timer.setInterval, [
|
||||||
global,
|
global,
|
||||||
arguments
|
arguments
|
||||||
]);
|
]);
|
||||||
};
|
};
|
||||||
|
|
||||||
self.clearTimeout = function(id) {
|
this.clearTimeout = function(id) {
|
||||||
return Function.prototype.call.apply(timer.clearTimeout, [global, id]);
|
return Function.prototype.call.apply(timer.clearTimeout, [global, id]);
|
||||||
};
|
};
|
||||||
|
|
||||||
self.clearInterval = function(id) {
|
this.clearInterval = function(id) {
|
||||||
return Function.prototype.call.apply(timer.clearInterval, [global, id]);
|
return Function.prototype.call.apply(timer.clearInterval, [global, id]);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -127,7 +126,7 @@ getJasmineRequireObj().Clock = function() {
|
|||||||
* @function
|
* @function
|
||||||
* @param {int} millis The number of milliseconds to tick.
|
* @param {int} millis The number of milliseconds to tick.
|
||||||
*/
|
*/
|
||||||
self.tick = function(millis) {
|
this.tick = function(millis) {
|
||||||
if (installed) {
|
if (installed) {
|
||||||
delayedFunctionScheduler.tick(millis, function(millis) {
|
delayedFunctionScheduler.tick(millis, function(millis) {
|
||||||
mockDate.tick(millis);
|
mockDate.tick(millis);
|
||||||
@@ -139,7 +138,7 @@ getJasmineRequireObj().Clock = function() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return self;
|
return this;
|
||||||
|
|
||||||
function originalTimingFunctionsIntact() {
|
function originalTimingFunctionsIntact() {
|
||||||
return (
|
return (
|
||||||
@@ -151,7 +150,7 @@ getJasmineRequireObj().Clock = function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function replace(dest, source) {
|
function replace(dest, source) {
|
||||||
for (var prop in source) {
|
for (const prop in source) {
|
||||||
dest[prop] = source[prop];
|
dest[prop] = source[prop];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -165,7 +164,7 @@ getJasmineRequireObj().Clock = function() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
var timeout = new FakeTimeout();
|
const timeout = new FakeTimeout();
|
||||||
|
|
||||||
delayedFunctionScheduler.scheduleFunction(
|
delayedFunctionScheduler.scheduleFunction(
|
||||||
fn,
|
fn,
|
||||||
@@ -192,7 +191,7 @@ getJasmineRequireObj().Clock = function() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
var timeout = new FakeTimeout();
|
const timeout = new FakeTimeout();
|
||||||
|
|
||||||
delayedFunctionScheduler.scheduleFunction(
|
delayedFunctionScheduler.scheduleFunction(
|
||||||
fn,
|
fn,
|
||||||
|
|||||||
@@ -1,20 +1,19 @@
|
|||||||
getJasmineRequireObj().DelayedFunctionScheduler = function(j$) {
|
getJasmineRequireObj().DelayedFunctionScheduler = function(j$) {
|
||||||
function DelayedFunctionScheduler() {
|
function DelayedFunctionScheduler() {
|
||||||
var self = this;
|
this.scheduledLookup_ = [];
|
||||||
var scheduledLookup = [];
|
this.scheduledFunctions_ = {};
|
||||||
var scheduledFunctions = {};
|
this.currentTime_ = 0;
|
||||||
var currentTime = 0;
|
this.delayedFnCount_ = 0;
|
||||||
var delayedFnCount = 0;
|
this.deletedKeys_ = [];
|
||||||
var deletedKeys = [];
|
|
||||||
|
|
||||||
self.tick = function(millis, tickDate) {
|
this.tick = function(millis, tickDate) {
|
||||||
millis = millis || 0;
|
millis = millis || 0;
|
||||||
var endTime = currentTime + millis;
|
const endTime = this.currentTime_ + millis;
|
||||||
|
|
||||||
runScheduledFunctions(endTime, tickDate);
|
this.runScheduledFunctions_(endTime, tickDate);
|
||||||
};
|
};
|
||||||
|
|
||||||
self.scheduleFunction = function(
|
this.scheduleFunction = function(
|
||||||
funcToCall,
|
funcToCall,
|
||||||
millis,
|
millis,
|
||||||
params,
|
params,
|
||||||
@@ -22,22 +21,21 @@ getJasmineRequireObj().DelayedFunctionScheduler = function(j$) {
|
|||||||
timeoutKey,
|
timeoutKey,
|
||||||
runAtMillis
|
runAtMillis
|
||||||
) {
|
) {
|
||||||
var f;
|
let f;
|
||||||
if (typeof funcToCall === 'string') {
|
if (typeof funcToCall === 'string') {
|
||||||
/* jshint evil: true */
|
|
||||||
f = function() {
|
f = function() {
|
||||||
|
// eslint-disable-next-line no-eval
|
||||||
return eval(funcToCall);
|
return eval(funcToCall);
|
||||||
};
|
};
|
||||||
/* jshint evil: false */
|
|
||||||
} else {
|
} else {
|
||||||
f = funcToCall;
|
f = funcToCall;
|
||||||
}
|
}
|
||||||
|
|
||||||
millis = millis || 0;
|
millis = millis || 0;
|
||||||
timeoutKey = timeoutKey || ++delayedFnCount;
|
timeoutKey = timeoutKey || ++this.delayedFnCount_;
|
||||||
runAtMillis = runAtMillis || currentTime + millis;
|
runAtMillis = runAtMillis || this.currentTime_ + millis;
|
||||||
|
|
||||||
var funcToSchedule = {
|
const funcToSchedule = {
|
||||||
runAtMillis: runAtMillis,
|
runAtMillis: runAtMillis,
|
||||||
funcToCall: f,
|
funcToCall: f,
|
||||||
recurring: recurring,
|
recurring: recurring,
|
||||||
@@ -46,12 +44,12 @@ getJasmineRequireObj().DelayedFunctionScheduler = function(j$) {
|
|||||||
millis: millis
|
millis: millis
|
||||||
};
|
};
|
||||||
|
|
||||||
if (runAtMillis in scheduledFunctions) {
|
if (runAtMillis in this.scheduledFunctions_) {
|
||||||
scheduledFunctions[runAtMillis].push(funcToSchedule);
|
this.scheduledFunctions_[runAtMillis].push(funcToSchedule);
|
||||||
} else {
|
} else {
|
||||||
scheduledFunctions[runAtMillis] = [funcToSchedule];
|
this.scheduledFunctions_[runAtMillis] = [funcToSchedule];
|
||||||
scheduledLookup.push(runAtMillis);
|
this.scheduledLookup_.push(runAtMillis);
|
||||||
scheduledLookup.sort(function(a, b) {
|
this.scheduledLookup_.sort(function(a, b) {
|
||||||
return a - b;
|
return a - b;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -59,19 +57,19 @@ getJasmineRequireObj().DelayedFunctionScheduler = function(j$) {
|
|||||||
return timeoutKey;
|
return timeoutKey;
|
||||||
};
|
};
|
||||||
|
|
||||||
self.removeFunctionWithId = function(timeoutKey) {
|
this.removeFunctionWithId = function(timeoutKey) {
|
||||||
deletedKeys.push(timeoutKey);
|
this.deletedKeys_.push(timeoutKey);
|
||||||
|
|
||||||
for (var runAtMillis in scheduledFunctions) {
|
for (const runAtMillis in this.scheduledFunctions_) {
|
||||||
var funcs = scheduledFunctions[runAtMillis];
|
const funcs = this.scheduledFunctions_[runAtMillis];
|
||||||
var i = indexOfFirstToPass(funcs, function(func) {
|
const i = indexOfFirstToPass(funcs, function(func) {
|
||||||
return func.timeoutKey === timeoutKey;
|
return func.timeoutKey === timeoutKey;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (i > -1) {
|
if (i > -1) {
|
||||||
if (funcs.length === 1) {
|
if (funcs.length === 1) {
|
||||||
delete scheduledFunctions[runAtMillis];
|
delete this.scheduledFunctions_[runAtMillis];
|
||||||
deleteFromLookup(runAtMillis);
|
this.deleteFromLookup_(runAtMillis);
|
||||||
} else {
|
} else {
|
||||||
funcs.splice(i, 1);
|
funcs.splice(i, 1);
|
||||||
}
|
}
|
||||||
@@ -83,99 +81,99 @@ getJasmineRequireObj().DelayedFunctionScheduler = function(j$) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return self;
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
function indexOfFirstToPass(array, testFn) {
|
DelayedFunctionScheduler.prototype.runScheduledFunctions_ = function(
|
||||||
var index = -1;
|
endTime,
|
||||||
|
tickDate
|
||||||
|
) {
|
||||||
|
tickDate = tickDate || function() {};
|
||||||
|
if (
|
||||||
|
this.scheduledLookup_.length === 0 ||
|
||||||
|
this.scheduledLookup_[0] > endTime
|
||||||
|
) {
|
||||||
|
if (endTime >= this.currentTime_) {
|
||||||
|
tickDate(endTime - this.currentTime_);
|
||||||
|
this.currentTime_ = endTime;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
for (var i = 0; i < array.length; ++i) {
|
do {
|
||||||
if (testFn(array[i])) {
|
this.deletedKeys_ = [];
|
||||||
index = i;
|
const newCurrentTime = this.scheduledLookup_.shift();
|
||||||
break;
|
if (newCurrentTime >= this.currentTime_) {
|
||||||
|
tickDate(newCurrentTime - this.currentTime_);
|
||||||
|
this.currentTime_ = newCurrentTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
const funcsToRun = this.scheduledFunctions_[this.currentTime_];
|
||||||
|
|
||||||
|
delete this.scheduledFunctions_[this.currentTime_];
|
||||||
|
|
||||||
|
for (const fn of funcsToRun) {
|
||||||
|
if (fn.recurring) {
|
||||||
|
this.reschedule_(fn);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return index;
|
for (const fn of funcsToRun) {
|
||||||
}
|
if (this.deletedKeys_.includes(fn.timeoutKey)) {
|
||||||
|
// skip a timeoutKey deleted whilst we were running
|
||||||
function deleteFromLookup(key) {
|
return;
|
||||||
var value = Number(key);
|
|
||||||
var i = indexOfFirstToPass(scheduledLookup, function(millis) {
|
|
||||||
return millis === value;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (i > -1) {
|
|
||||||
scheduledLookup.splice(i, 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function reschedule(scheduledFn) {
|
|
||||||
self.scheduleFunction(
|
|
||||||
scheduledFn.funcToCall,
|
|
||||||
scheduledFn.millis,
|
|
||||||
scheduledFn.params,
|
|
||||||
true,
|
|
||||||
scheduledFn.timeoutKey,
|
|
||||||
scheduledFn.runAtMillis + scheduledFn.millis
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function forEachFunction(funcsToRun, callback) {
|
|
||||||
for (var i = 0; i < funcsToRun.length; ++i) {
|
|
||||||
callback(funcsToRun[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function runScheduledFunctions(endTime, tickDate) {
|
|
||||||
tickDate = tickDate || function() {};
|
|
||||||
if (scheduledLookup.length === 0 || scheduledLookup[0] > endTime) {
|
|
||||||
if (endTime >= currentTime) {
|
|
||||||
tickDate(endTime - currentTime);
|
|
||||||
currentTime = endTime;
|
|
||||||
}
|
}
|
||||||
return;
|
fn.funcToCall.apply(null, fn.params || []);
|
||||||
}
|
}
|
||||||
|
this.deletedKeys_ = [];
|
||||||
|
} while (
|
||||||
|
this.scheduledLookup_.length > 0 &&
|
||||||
|
// checking first if we're out of time prevents setTimeout(0)
|
||||||
|
// scheduled in a funcToRun from forcing an extra iteration
|
||||||
|
this.currentTime_ !== endTime &&
|
||||||
|
this.scheduledLookup_[0] <= endTime
|
||||||
|
);
|
||||||
|
|
||||||
do {
|
// ran out of functions to call, but still time left on the clock
|
||||||
deletedKeys = [];
|
if (endTime >= this.currentTime_) {
|
||||||
var newCurrentTime = scheduledLookup.shift();
|
tickDate(endTime - this.currentTime_);
|
||||||
if (newCurrentTime >= currentTime) {
|
this.currentTime_ = endTime;
|
||||||
tickDate(newCurrentTime - currentTime);
|
}
|
||||||
currentTime = newCurrentTime;
|
};
|
||||||
}
|
|
||||||
|
|
||||||
var funcsToRun = scheduledFunctions[currentTime];
|
DelayedFunctionScheduler.prototype.reschedule_ = function(scheduledFn) {
|
||||||
|
this.scheduleFunction(
|
||||||
|
scheduledFn.funcToCall,
|
||||||
|
scheduledFn.millis,
|
||||||
|
scheduledFn.params,
|
||||||
|
true,
|
||||||
|
scheduledFn.timeoutKey,
|
||||||
|
scheduledFn.runAtMillis + scheduledFn.millis
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
delete scheduledFunctions[currentTime];
|
DelayedFunctionScheduler.prototype.deleteFromLookup_ = function(key) {
|
||||||
|
const value = Number(key);
|
||||||
|
const i = indexOfFirstToPass(this.scheduledLookup_, function(millis) {
|
||||||
|
return millis === value;
|
||||||
|
});
|
||||||
|
|
||||||
forEachFunction(funcsToRun, function(funcToRun) {
|
if (i > -1) {
|
||||||
if (funcToRun.recurring) {
|
this.scheduledLookup_.splice(i, 1);
|
||||||
reschedule(funcToRun);
|
}
|
||||||
}
|
};
|
||||||
});
|
|
||||||
|
|
||||||
forEachFunction(funcsToRun, function(funcToRun) {
|
function indexOfFirstToPass(array, testFn) {
|
||||||
if (j$.util.arrayContains(deletedKeys, funcToRun.timeoutKey)) {
|
let index = -1;
|
||||||
// skip a timeoutKey deleted whilst we were running
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
funcToRun.funcToCall.apply(null, funcToRun.params || []);
|
|
||||||
});
|
|
||||||
deletedKeys = [];
|
|
||||||
} while (
|
|
||||||
scheduledLookup.length > 0 &&
|
|
||||||
// checking first if we're out of time prevents setTimeout(0)
|
|
||||||
// scheduled in a funcToRun from forcing an extra iteration
|
|
||||||
currentTime !== endTime &&
|
|
||||||
scheduledLookup[0] <= endTime
|
|
||||||
);
|
|
||||||
|
|
||||||
// ran out of functions to call, but still time left on the clock
|
for (let i = 0; i < array.length; ++i) {
|
||||||
if (endTime >= currentTime) {
|
if (testFn(array[i])) {
|
||||||
tickDate(endTime - currentTime);
|
index = i;
|
||||||
currentTime = endTime;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
return DelayedFunctionScheduler;
|
return DelayedFunctionScheduler;
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ getJasmineRequireObj().Deprecator = function(j$) {
|
|||||||
this.toSuppress_ = [];
|
this.toSuppress_ = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
var verboseNote =
|
const verboseNote =
|
||||||
'Note: This message will be shown only once. Set the verboseDeprecations ' +
|
'Note: This message will be shown only once. Set the verboseDeprecations ' +
|
||||||
'config property to true to see every occurrence.';
|
'config property to true to see every occurrence.';
|
||||||
|
|
||||||
@@ -35,13 +35,13 @@ getJasmineRequireObj().Deprecator = function(j$) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Deprecator.prototype.log_ = function(runnable, deprecation, options) {
|
Deprecator.prototype.log_ = function(runnable, deprecation, options) {
|
||||||
var context;
|
|
||||||
|
|
||||||
if (j$.isError_(deprecation)) {
|
if (j$.isError_(deprecation)) {
|
||||||
console.error(deprecation);
|
console.error(deprecation);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let context;
|
||||||
|
|
||||||
if (runnable === this.topSuite_ || options.ignoreRunnable) {
|
if (runnable === this.topSuite_ || options.ignoreRunnable) {
|
||||||
context = '';
|
context = '';
|
||||||
} else if (runnable.children) {
|
} else if (runnable.children) {
|
||||||
@@ -62,7 +62,7 @@ getJasmineRequireObj().Deprecator = function(j$) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Deprecator.prototype.stackTrace_ = function() {
|
Deprecator.prototype.stackTrace_ = function() {
|
||||||
var formatter = new j$.ExceptionFormatter();
|
const formatter = new j$.ExceptionFormatter();
|
||||||
return formatter.stack(j$.util.errorWithStack()).replace(/^Error\n/m, '');
|
return formatter.stack(j$.util.errorWithStack()).replace(/^Error\n/m, '');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
950
src/core/Env.js
950
src/core/Env.js
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,5 @@
|
|||||||
getJasmineRequireObj().ExceptionFormatter = function(j$) {
|
getJasmineRequireObj().ExceptionFormatter = function(j$) {
|
||||||
var ignoredProperties = [
|
const ignoredProperties = [
|
||||||
'name',
|
'name',
|
||||||
'message',
|
'message',
|
||||||
'stack',
|
'stack',
|
||||||
@@ -13,9 +13,10 @@ getJasmineRequireObj().ExceptionFormatter = function(j$) {
|
|||||||
];
|
];
|
||||||
|
|
||||||
function ExceptionFormatter(options) {
|
function ExceptionFormatter(options) {
|
||||||
var jasmineFile = (options && options.jasmineFile) || j$.util.jasmineFile();
|
const jasmineFile =
|
||||||
|
(options && options.jasmineFile) || j$.util.jasmineFile();
|
||||||
this.message = function(error) {
|
this.message = function(error) {
|
||||||
var message = '';
|
let message = '';
|
||||||
|
|
||||||
if (error.jasmineMessage) {
|
if (error.jasmineMessage) {
|
||||||
message += error.jasmineMessage;
|
message += error.jasmineMessage;
|
||||||
@@ -43,9 +44,9 @@ getJasmineRequireObj().ExceptionFormatter = function(j$) {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
var stackTrace = new j$.StackTrace(error);
|
const stackTrace = new j$.StackTrace(error);
|
||||||
var lines = filterJasmine(stackTrace);
|
const lines = filterJasmine(stackTrace);
|
||||||
var result = '';
|
let result = '';
|
||||||
|
|
||||||
if (stackTrace.message && !omitMessage) {
|
if (stackTrace.message && !omitMessage) {
|
||||||
lines.unshift(stackTrace.message);
|
lines.unshift(stackTrace.message);
|
||||||
@@ -58,9 +59,9 @@ getJasmineRequireObj().ExceptionFormatter = function(j$) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function filterJasmine(stackTrace) {
|
function filterJasmine(stackTrace) {
|
||||||
var result = [],
|
const result = [];
|
||||||
jasmineMarker =
|
const jasmineMarker =
|
||||||
stackTrace.style === 'webkit' ? '<Jasmine>' : ' at <Jasmine>';
|
stackTrace.style === 'webkit' ? '<Jasmine>' : ' at <Jasmine>';
|
||||||
|
|
||||||
stackTrace.frames.forEach(function(frame) {
|
stackTrace.frames.forEach(function(frame) {
|
||||||
if (frame.file !== jasmineFile) {
|
if (frame.file !== jasmineFile) {
|
||||||
@@ -78,11 +79,11 @@ getJasmineRequireObj().ExceptionFormatter = function(j$) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var result = {};
|
const result = {};
|
||||||
var empty = true;
|
let empty = true;
|
||||||
|
|
||||||
for (var prop in error) {
|
for (const prop in error) {
|
||||||
if (j$.util.arrayContains(ignoredProperties, prop)) {
|
if (ignoredProperties.includes(prop)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
result[prop] = error[prop];
|
result[prop] = error[prop];
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ getJasmineRequireObj().Expectation = function(j$) {
|
|||||||
function Expectation(options) {
|
function Expectation(options) {
|
||||||
this.expector = new j$.Expector(options);
|
this.expector = new j$.Expector(options);
|
||||||
|
|
||||||
var customMatchers = options.customMatchers || {};
|
const customMatchers = options.customMatchers || {};
|
||||||
for (var matcherName in customMatchers) {
|
for (const matcherName in customMatchers) {
|
||||||
this[matcherName] = wrapSyncCompare(
|
this[matcherName] = wrapSyncCompare(
|
||||||
matcherName,
|
matcherName,
|
||||||
customMatchers[matcherName]
|
customMatchers[matcherName]
|
||||||
@@ -77,8 +77,8 @@ getJasmineRequireObj().Expectation = function(j$) {
|
|||||||
function AsyncExpectation(options) {
|
function AsyncExpectation(options) {
|
||||||
this.expector = new j$.Expector(options);
|
this.expector = new j$.Expector(options);
|
||||||
|
|
||||||
var customAsyncMatchers = options.customAsyncMatchers || {};
|
const customAsyncMatchers = options.customAsyncMatchers || {};
|
||||||
for (var matcherName in customAsyncMatchers) {
|
for (const matcherName in customAsyncMatchers) {
|
||||||
this[matcherName] = wrapAsyncCompare(
|
this[matcherName] = wrapAsyncCompare(
|
||||||
matcherName,
|
matcherName,
|
||||||
customAsyncMatchers[matcherName]
|
customAsyncMatchers[matcherName]
|
||||||
@@ -134,36 +134,34 @@ getJasmineRequireObj().Expectation = function(j$) {
|
|||||||
|
|
||||||
function wrapSyncCompare(name, matcherFactory) {
|
function wrapSyncCompare(name, matcherFactory) {
|
||||||
return function() {
|
return function() {
|
||||||
var result = this.expector.compare(name, matcherFactory, arguments);
|
const result = this.expector.compare(name, matcherFactory, arguments);
|
||||||
this.expector.processResult(result);
|
this.expector.processResult(result);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function wrapAsyncCompare(name, matcherFactory) {
|
function wrapAsyncCompare(name, matcherFactory) {
|
||||||
return function() {
|
return function() {
|
||||||
var self = this;
|
|
||||||
|
|
||||||
// Capture the call stack here, before we go async, so that it will contain
|
// Capture the call stack here, before we go async, so that it will contain
|
||||||
// frames that are relevant to the user instead of just parts of Jasmine.
|
// frames that are relevant to the user instead of just parts of Jasmine.
|
||||||
var errorForStack = j$.util.errorWithStack();
|
const errorForStack = j$.util.errorWithStack();
|
||||||
|
|
||||||
return this.expector
|
return this.expector
|
||||||
.compare(name, matcherFactory, arguments)
|
.compare(name, matcherFactory, arguments)
|
||||||
.then(function(result) {
|
.then(result => {
|
||||||
self.expector.processResult(result, errorForStack);
|
this.expector.processResult(result, errorForStack);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function addCoreMatchers(prototype, matchers, wrapper) {
|
function addCoreMatchers(prototype, matchers, wrapper) {
|
||||||
for (var matcherName in matchers) {
|
for (const matcherName in matchers) {
|
||||||
var matcher = matchers[matcherName];
|
const matcher = matchers[matcherName];
|
||||||
prototype[matcherName] = wrapper(matcherName, matcher);
|
prototype[matcherName] = wrapper(matcherName, matcher);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function addFilter(source, filter) {
|
function addFilter(source, filter) {
|
||||||
var result = Object.create(source);
|
const result = Object.create(source);
|
||||||
result.expector = source.expector.addFilter(filter);
|
result.expector = source.expector.addFilter(filter);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -188,7 +186,7 @@ getJasmineRequireObj().Expectation = function(j$) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
var syncNegatingFilter = {
|
const syncNegatingFilter = {
|
||||||
selectComparisonFunc: function(matcher) {
|
selectComparisonFunc: function(matcher) {
|
||||||
function defaultNegativeCompare() {
|
function defaultNegativeCompare() {
|
||||||
return negate(matcher.compare.apply(null, arguments));
|
return negate(matcher.compare.apply(null, arguments));
|
||||||
@@ -199,7 +197,7 @@ getJasmineRequireObj().Expectation = function(j$) {
|
|||||||
buildFailureMessage: negatedFailureMessage
|
buildFailureMessage: negatedFailureMessage
|
||||||
};
|
};
|
||||||
|
|
||||||
var asyncNegatingFilter = {
|
const asyncNegatingFilter = {
|
||||||
selectComparisonFunc: function(matcher) {
|
selectComparisonFunc: function(matcher) {
|
||||||
function defaultNegativeCompare() {
|
function defaultNegativeCompare() {
|
||||||
return matcher.compare.apply(this, arguments).then(negate);
|
return matcher.compare.apply(this, arguments).then(negate);
|
||||||
@@ -210,10 +208,10 @@ getJasmineRequireObj().Expectation = function(j$) {
|
|||||||
buildFailureMessage: negatedFailureMessage
|
buildFailureMessage: negatedFailureMessage
|
||||||
};
|
};
|
||||||
|
|
||||||
var expectSettledPromiseFilter = {
|
const expectSettledPromiseFilter = {
|
||||||
selectComparisonFunc: function(matcher) {
|
selectComparisonFunc: function(matcher) {
|
||||||
return function(actual) {
|
return function(actual) {
|
||||||
var matcherArgs = arguments;
|
const matcherArgs = arguments;
|
||||||
|
|
||||||
return j$.isPending_(actual).then(function(isPending) {
|
return j$.isPending_(actual).then(function(isPending) {
|
||||||
if (isPending) {
|
if (isPending) {
|
||||||
@@ -236,9 +234,7 @@ getJasmineRequireObj().Expectation = function(j$) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ContextAddingFilter.prototype.modifyFailureMessage = function(msg) {
|
ContextAddingFilter.prototype.modifyFailureMessage = function(msg) {
|
||||||
var nl = msg.indexOf('\n');
|
if (msg.indexOf('\n') === -1) {
|
||||||
|
|
||||||
if (nl === -1) {
|
|
||||||
return this.message + ': ' + msg;
|
return this.message + ': ' + msg;
|
||||||
} else {
|
} else {
|
||||||
return this.message + ':\n' + indent(msg);
|
return this.message + ':\n' + indent(msg);
|
||||||
|
|||||||
@@ -22,15 +22,13 @@ getJasmineRequireObj().ExpectationFilterChain = function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
ExpectationFilterChain.prototype.modifyFailureMessage = function(msg) {
|
ExpectationFilterChain.prototype.modifyFailureMessage = function(msg) {
|
||||||
var result = this.callFirst_('modifyFailureMessage', arguments).result;
|
const result = this.callFirst_('modifyFailureMessage', arguments).result;
|
||||||
return result || msg;
|
return result || msg;
|
||||||
};
|
};
|
||||||
|
|
||||||
ExpectationFilterChain.prototype.callFirst_ = function(fname, args) {
|
ExpectationFilterChain.prototype.callFirst_ = function(fname, args) {
|
||||||
var prevResult;
|
|
||||||
|
|
||||||
if (this.prev_) {
|
if (this.prev_) {
|
||||||
prevResult = this.prev_.callFirst_(fname, args);
|
const prevResult = this.prev_.callFirst_(fname, args);
|
||||||
|
|
||||||
if (prevResult.found) {
|
if (prevResult.found) {
|
||||||
return prevResult;
|
return prevResult;
|
||||||
|
|||||||
@@ -19,35 +19,24 @@ getJasmineRequireObj().Expector = function(j$) {
|
|||||||
|
|
||||||
this.args.unshift(this.actual);
|
this.args.unshift(this.actual);
|
||||||
|
|
||||||
var matcher = matcherFactory(this.matchersUtil);
|
const matcher = matcherFactory(this.matchersUtil);
|
||||||
|
|
||||||
var comparisonFunc = this.filters.selectComparisonFunc(matcher);
|
const comparisonFunc = this.filters.selectComparisonFunc(matcher);
|
||||||
return comparisonFunc || matcher.compare;
|
return comparisonFunc || matcher.compare;
|
||||||
};
|
};
|
||||||
|
|
||||||
Expector.prototype.buildMessage = function(result) {
|
Expector.prototype.buildMessage = function(result) {
|
||||||
var self = this;
|
|
||||||
|
|
||||||
if (result.pass) {
|
if (result.pass) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
var msg = this.filters.buildFailureMessage(
|
const defaultMessage = () => {
|
||||||
result,
|
|
||||||
this.matcherName,
|
|
||||||
this.args,
|
|
||||||
this.matchersUtil,
|
|
||||||
defaultMessage
|
|
||||||
);
|
|
||||||
return this.filters.modifyFailureMessage(msg || defaultMessage());
|
|
||||||
|
|
||||||
function defaultMessage() {
|
|
||||||
if (!result.message) {
|
if (!result.message) {
|
||||||
var args = self.args.slice();
|
const args = this.args.slice();
|
||||||
args.unshift(false);
|
args.unshift(false);
|
||||||
args.unshift(self.matcherName);
|
args.unshift(this.matcherName);
|
||||||
return self.matchersUtil.buildFailureMessage.apply(
|
return this.matchersUtil.buildFailureMessage.apply(
|
||||||
self.matchersUtil,
|
this.matchersUtil,
|
||||||
args
|
args
|
||||||
);
|
);
|
||||||
} else if (j$.isFunction_(result.message)) {
|
} else if (j$.isFunction_(result.message)) {
|
||||||
@@ -55,11 +44,20 @@ getJasmineRequireObj().Expector = function(j$) {
|
|||||||
} else {
|
} else {
|
||||||
return result.message;
|
return result.message;
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
|
const msg = this.filters.buildFailureMessage(
|
||||||
|
result,
|
||||||
|
this.matcherName,
|
||||||
|
this.args,
|
||||||
|
this.matchersUtil,
|
||||||
|
defaultMessage
|
||||||
|
);
|
||||||
|
return this.filters.modifyFailureMessage(msg || defaultMessage());
|
||||||
};
|
};
|
||||||
|
|
||||||
Expector.prototype.compare = function(matcherName, matcherFactory, args) {
|
Expector.prototype.compare = function(matcherName, matcherFactory, args) {
|
||||||
var matcherCompare = this.instantiateMatcher(
|
const matcherCompare = this.instantiateMatcher(
|
||||||
matcherName,
|
matcherName,
|
||||||
matcherFactory,
|
matcherFactory,
|
||||||
args
|
args
|
||||||
@@ -68,13 +66,13 @@ getJasmineRequireObj().Expector = function(j$) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Expector.prototype.addFilter = function(filter) {
|
Expector.prototype.addFilter = function(filter) {
|
||||||
var result = Object.create(this);
|
const result = Object.create(this);
|
||||||
result.filters = this.filters.addFilter(filter);
|
result.filters = this.filters.addFilter(filter);
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
Expector.prototype.processResult = function(result, errorForStack) {
|
Expector.prototype.processResult = function(result, errorForStack) {
|
||||||
var message = this.buildMessage(result);
|
const message = this.buildMessage(result);
|
||||||
|
|
||||||
if (this.expected.length === 1) {
|
if (this.expected.length === 1) {
|
||||||
this.expected = this.expected[0];
|
this.expected = this.expected[0];
|
||||||
|
|||||||
@@ -1,27 +1,35 @@
|
|||||||
getJasmineRequireObj().GlobalErrors = function(j$) {
|
getJasmineRequireObj().GlobalErrors = function(j$) {
|
||||||
function GlobalErrors(global) {
|
function GlobalErrors(global) {
|
||||||
var handlers = [];
|
|
||||||
global = global || j$.getGlobal();
|
global = global || j$.getGlobal();
|
||||||
|
|
||||||
var onerror = function onerror() {
|
const handlers = [];
|
||||||
var handler = handlers[handlers.length - 1];
|
let overrideHandler = null,
|
||||||
|
onRemoveOverrideHandler = null;
|
||||||
|
|
||||||
|
function onerror(message, source, lineno, colno, error) {
|
||||||
|
if (overrideHandler) {
|
||||||
|
overrideHandler(error || message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const handler = handlers[handlers.length - 1];
|
||||||
|
|
||||||
if (handler) {
|
if (handler) {
|
||||||
handler.apply(null, Array.prototype.slice.call(arguments, 0));
|
handler.apply(null, Array.prototype.slice.call(arguments, 0));
|
||||||
} else {
|
} else {
|
||||||
throw arguments[0];
|
throw arguments[0];
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
this.originalHandlers = {};
|
this.originalHandlers = {};
|
||||||
this.jasmineHandlers = {};
|
this.jasmineHandlers = {};
|
||||||
this.installOne_ = function installOne_(errorType, jasmineMessage) {
|
this.installOne_ = function installOne_(errorType, jasmineMessage) {
|
||||||
function taggedOnError(error) {
|
function taggedOnError(error) {
|
||||||
var substituteMsg;
|
|
||||||
|
|
||||||
if (j$.isError_(error)) {
|
if (j$.isError_(error)) {
|
||||||
error.jasmineMessage = jasmineMessage + ': ' + error;
|
error.jasmineMessage = jasmineMessage + ': ' + error;
|
||||||
} else {
|
} else {
|
||||||
|
let substituteMsg;
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
substituteMsg = jasmineMessage + ': ' + error;
|
substituteMsg = jasmineMessage + ': ' + error;
|
||||||
} else {
|
} else {
|
||||||
@@ -40,7 +48,12 @@ getJasmineRequireObj().GlobalErrors = function(j$) {
|
|||||||
error = new Error(substituteMsg);
|
error = new Error(substituteMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
var handler = handlers[handlers.length - 1];
|
const handler = handlers[handlers.length - 1];
|
||||||
|
|
||||||
|
if (overrideHandler) {
|
||||||
|
overrideHandler(error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (handler) {
|
if (handler) {
|
||||||
handler(error);
|
handler(error);
|
||||||
@@ -56,14 +69,14 @@ getJasmineRequireObj().GlobalErrors = function(j$) {
|
|||||||
global.process.on(errorType, taggedOnError);
|
global.process.on(errorType, taggedOnError);
|
||||||
|
|
||||||
this.uninstall = function uninstall() {
|
this.uninstall = function uninstall() {
|
||||||
var errorTypes = Object.keys(this.originalHandlers);
|
const errorTypes = Object.keys(this.originalHandlers);
|
||||||
for (var iType = 0; iType < errorTypes.length; iType++) {
|
for (const errorType of errorTypes) {
|
||||||
var errorType = errorTypes[iType];
|
|
||||||
global.process.removeListener(
|
global.process.removeListener(
|
||||||
errorType,
|
errorType,
|
||||||
this.jasmineHandlers[errorType]
|
this.jasmineHandlers[errorType]
|
||||||
);
|
);
|
||||||
for (var i = 0; i < this.originalHandlers[errorType].length; i++) {
|
|
||||||
|
for (let i = 0; i < this.originalHandlers[errorType].length; i++) {
|
||||||
global.process.on(errorType, this.originalHandlers[errorType][i]);
|
global.process.on(errorType, this.originalHandlers[errorType][i]);
|
||||||
}
|
}
|
||||||
delete this.originalHandlers[errorType];
|
delete this.originalHandlers[errorType];
|
||||||
@@ -81,10 +94,12 @@ getJasmineRequireObj().GlobalErrors = function(j$) {
|
|||||||
this.installOne_('uncaughtException', 'Uncaught exception');
|
this.installOne_('uncaughtException', 'Uncaught exception');
|
||||||
this.installOne_('unhandledRejection', 'Unhandled promise rejection');
|
this.installOne_('unhandledRejection', 'Unhandled promise rejection');
|
||||||
} else {
|
} else {
|
||||||
var originalHandler = global.onerror;
|
const originalHandler = global.onerror;
|
||||||
global.onerror = onerror;
|
global.onerror = onerror;
|
||||||
|
|
||||||
var browserRejectionHandler = function browserRejectionHandler(event) {
|
const browserRejectionHandler = function browserRejectionHandler(
|
||||||
|
event
|
||||||
|
) {
|
||||||
if (j$.isError_(event.reason)) {
|
if (j$.isError_(event.reason)) {
|
||||||
event.reason.jasmineMessage =
|
event.reason.jasmineMessage =
|
||||||
'Unhandled promise rejection: ' + event.reason;
|
'Unhandled promise rejection: ' + event.reason;
|
||||||
@@ -124,6 +139,24 @@ getJasmineRequireObj().GlobalErrors = function(j$) {
|
|||||||
|
|
||||||
handlers.pop();
|
handlers.pop();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.setOverrideListener = function(listener, onRemove) {
|
||||||
|
if (overrideHandler) {
|
||||||
|
throw new Error("Can't set more than one override listener at a time");
|
||||||
|
}
|
||||||
|
|
||||||
|
overrideHandler = listener;
|
||||||
|
onRemoveOverrideHandler = onRemove;
|
||||||
|
};
|
||||||
|
|
||||||
|
this.removeOverrideListener = function() {
|
||||||
|
if (onRemoveOverrideHandler) {
|
||||||
|
onRemoveOverrideHandler();
|
||||||
|
}
|
||||||
|
|
||||||
|
overrideHandler = null;
|
||||||
|
onRemoveOverrideHandler = null;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
return GlobalErrors;
|
return GlobalErrors;
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ getJasmineRequireObj().JsApiReporter = function(j$) {
|
|||||||
* @hideconstructor
|
* @hideconstructor
|
||||||
*/
|
*/
|
||||||
function JsApiReporter(options) {
|
function JsApiReporter(options) {
|
||||||
var timer = options.timer || new j$.Timer(),
|
const timer = options.timer || new j$.Timer();
|
||||||
status = 'loaded';
|
let status = 'loaded';
|
||||||
|
|
||||||
this.started = false;
|
this.started = false;
|
||||||
this.finished = false;
|
this.finished = false;
|
||||||
@@ -19,7 +19,7 @@ getJasmineRequireObj().JsApiReporter = function(j$) {
|
|||||||
timer.start();
|
timer.start();
|
||||||
};
|
};
|
||||||
|
|
||||||
var executionTime;
|
let executionTime;
|
||||||
|
|
||||||
this.jasmineDone = function(runDetails) {
|
this.jasmineDone = function(runDetails) {
|
||||||
this.finished = true;
|
this.finished = true;
|
||||||
@@ -39,7 +39,7 @@ getJasmineRequireObj().JsApiReporter = function(j$) {
|
|||||||
return status;
|
return status;
|
||||||
};
|
};
|
||||||
|
|
||||||
var suites = [],
|
const suites = [],
|
||||||
suites_hash = {};
|
suites_hash = {};
|
||||||
|
|
||||||
this.suiteStarted = function(result) {
|
this.suiteStarted = function(result) {
|
||||||
@@ -81,7 +81,7 @@ getJasmineRequireObj().JsApiReporter = function(j$) {
|
|||||||
return suites_hash;
|
return suites_hash;
|
||||||
};
|
};
|
||||||
|
|
||||||
var specs = [];
|
const specs = [];
|
||||||
|
|
||||||
this.specDone = function(result) {
|
this.specDone = function(result) {
|
||||||
specs.push(result);
|
specs.push(result);
|
||||||
|
|||||||
@@ -1,18 +1,17 @@
|
|||||||
getJasmineRequireObj().MockDate = function(j$) {
|
getJasmineRequireObj().MockDate = function(j$) {
|
||||||
function MockDate(global) {
|
function MockDate(global) {
|
||||||
var self = this;
|
let currentTime = 0;
|
||||||
var currentTime = 0;
|
|
||||||
|
|
||||||
if (!global || !global.Date) {
|
if (!global || !global.Date) {
|
||||||
self.install = function() {};
|
this.install = function() {};
|
||||||
self.tick = function() {};
|
this.tick = function() {};
|
||||||
self.uninstall = function() {};
|
this.uninstall = function() {};
|
||||||
return self;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
var GlobalDate = global.Date;
|
const GlobalDate = global.Date;
|
||||||
|
|
||||||
self.install = function(mockDate) {
|
this.install = function(mockDate) {
|
||||||
if (mockDate instanceof GlobalDate) {
|
if (mockDate instanceof GlobalDate) {
|
||||||
currentTime = mockDate.getTime();
|
currentTime = mockDate.getTime();
|
||||||
} else {
|
} else {
|
||||||
@@ -29,19 +28,19 @@ getJasmineRequireObj().MockDate = function(j$) {
|
|||||||
global.Date = FakeDate;
|
global.Date = FakeDate;
|
||||||
};
|
};
|
||||||
|
|
||||||
self.tick = function(millis) {
|
this.tick = function(millis) {
|
||||||
millis = millis || 0;
|
millis = millis || 0;
|
||||||
currentTime = currentTime + millis;
|
currentTime = currentTime + millis;
|
||||||
};
|
};
|
||||||
|
|
||||||
self.uninstall = function() {
|
this.uninstall = function() {
|
||||||
currentTime = 0;
|
currentTime = 0;
|
||||||
global.Date = GlobalDate;
|
global.Date = GlobalDate;
|
||||||
};
|
};
|
||||||
|
|
||||||
createDateProperties();
|
createDateProperties();
|
||||||
|
|
||||||
return self;
|
return this;
|
||||||
|
|
||||||
function FakeDate() {
|
function FakeDate() {
|
||||||
switch (arguments.length) {
|
switch (arguments.length) {
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
/*jshint bitwise: false*/
|
|
||||||
|
|
||||||
getJasmineRequireObj().Order = function() {
|
getJasmineRequireObj().Order = function() {
|
||||||
function Order(options) {
|
function Order(options) {
|
||||||
this.random = 'random' in options ? options.random : true;
|
this.random = 'random' in options ? options.random : true;
|
||||||
var seed = (this.seed = options.seed || generateSeed());
|
const seed = (this.seed = options.seed || generateSeed());
|
||||||
this.sort = this.random ? randomOrder : naturalOrder;
|
this.sort = this.random ? randomOrder : naturalOrder;
|
||||||
|
|
||||||
function naturalOrder(items) {
|
function naturalOrder(items) {
|
||||||
@@ -11,7 +9,7 @@ getJasmineRequireObj().Order = function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function randomOrder(items) {
|
function randomOrder(items) {
|
||||||
var copy = items.slice();
|
const copy = items.slice();
|
||||||
copy.sort(function(a, b) {
|
copy.sort(function(a, b) {
|
||||||
return jenkinsHash(seed + a.id) - jenkinsHash(seed + b.id);
|
return jenkinsHash(seed + a.id) - jenkinsHash(seed + b.id);
|
||||||
});
|
});
|
||||||
@@ -28,7 +26,7 @@ getJasmineRequireObj().Order = function() {
|
|||||||
// used in conjunction with a seed
|
// used in conjunction with a seed
|
||||||
|
|
||||||
function jenkinsHash(key) {
|
function jenkinsHash(key) {
|
||||||
var hash, i;
|
let hash, i;
|
||||||
for (hash = i = 0; i < key.length; ++i) {
|
for (hash = i = 0; i < key.length; ++i) {
|
||||||
hash += key.charCodeAt(i);
|
hash += key.charCodeAt(i);
|
||||||
hash += hash << 10;
|
hash += hash << 10;
|
||||||
|
|||||||
@@ -1,11 +1,298 @@
|
|||||||
getJasmineRequireObj().makePrettyPrinter = function(j$) {
|
getJasmineRequireObj().makePrettyPrinter = function(j$) {
|
||||||
function SinglePrettyPrintRun(customObjectFormatters, pp) {
|
class SinglePrettyPrintRun {
|
||||||
this.customObjectFormatters_ = customObjectFormatters;
|
constructor(customObjectFormatters, pp) {
|
||||||
this.ppNestLevel_ = 0;
|
this.customObjectFormatters_ = customObjectFormatters;
|
||||||
this.seen = [];
|
this.ppNestLevel_ = 0;
|
||||||
this.length = 0;
|
this.seen = [];
|
||||||
this.stringParts = [];
|
this.length = 0;
|
||||||
this.pp_ = pp;
|
this.stringParts = [];
|
||||||
|
this.pp_ = pp;
|
||||||
|
}
|
||||||
|
|
||||||
|
format(value) {
|
||||||
|
this.ppNestLevel_++;
|
||||||
|
try {
|
||||||
|
const customFormatResult = this.applyCustomFormatters_(value);
|
||||||
|
|
||||||
|
if (customFormatResult) {
|
||||||
|
this.emitScalar(customFormatResult);
|
||||||
|
} else if (j$.util.isUndefined(value)) {
|
||||||
|
this.emitScalar('undefined');
|
||||||
|
} else if (value === null) {
|
||||||
|
this.emitScalar('null');
|
||||||
|
} else if (value === 0 && 1 / value === -Infinity) {
|
||||||
|
this.emitScalar('-0');
|
||||||
|
} else if (value === j$.getGlobal()) {
|
||||||
|
this.emitScalar('<global>');
|
||||||
|
} else if (value.jasmineToString) {
|
||||||
|
this.emitScalar(value.jasmineToString(this.pp_));
|
||||||
|
} else if (j$.isString_(value)) {
|
||||||
|
this.emitString(value);
|
||||||
|
} else if (j$.isSpy(value)) {
|
||||||
|
this.emitScalar('spy on ' + value.and.identity);
|
||||||
|
} else if (j$.isSpy(value.toString)) {
|
||||||
|
this.emitScalar('spy on ' + value.toString.and.identity);
|
||||||
|
} else if (value instanceof RegExp) {
|
||||||
|
this.emitScalar(value.toString());
|
||||||
|
} else if (typeof value === 'function') {
|
||||||
|
this.emitScalar('Function');
|
||||||
|
} else if (j$.isDomNode(value)) {
|
||||||
|
if (value.tagName) {
|
||||||
|
this.emitDomElement(value);
|
||||||
|
} else {
|
||||||
|
this.emitScalar('HTMLNode');
|
||||||
|
}
|
||||||
|
} else if (value instanceof Date) {
|
||||||
|
this.emitScalar('Date(' + value + ')');
|
||||||
|
} else if (j$.isSet(value)) {
|
||||||
|
this.emitSet(value);
|
||||||
|
} else if (j$.isMap(value)) {
|
||||||
|
this.emitMap(value);
|
||||||
|
} else if (j$.isTypedArray_(value)) {
|
||||||
|
this.emitTypedArray(value);
|
||||||
|
} else if (
|
||||||
|
value.toString &&
|
||||||
|
typeof value === 'object' &&
|
||||||
|
!j$.isArray_(value) &&
|
||||||
|
hasCustomToString(value)
|
||||||
|
) {
|
||||||
|
try {
|
||||||
|
this.emitScalar(value.toString());
|
||||||
|
} catch (e) {
|
||||||
|
this.emitScalar('has-invalid-toString-method');
|
||||||
|
}
|
||||||
|
} else if (this.seen.includes(value)) {
|
||||||
|
this.emitScalar(
|
||||||
|
'<circular reference: ' +
|
||||||
|
(j$.isArray_(value) ? 'Array' : 'Object') +
|
||||||
|
'>'
|
||||||
|
);
|
||||||
|
} else if (j$.isArray_(value) || j$.isA_('Object', value)) {
|
||||||
|
this.seen.push(value);
|
||||||
|
if (j$.isArray_(value)) {
|
||||||
|
this.emitArray(value);
|
||||||
|
} else {
|
||||||
|
this.emitObject(value);
|
||||||
|
}
|
||||||
|
this.seen.pop();
|
||||||
|
} else {
|
||||||
|
this.emitScalar(value.toString());
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
if (this.ppNestLevel_ > 1 || !(e instanceof MaxCharsReachedError)) {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
this.ppNestLevel_--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
applyCustomFormatters_(value) {
|
||||||
|
return customFormat(value, this.customObjectFormatters_);
|
||||||
|
}
|
||||||
|
|
||||||
|
iterateObject(obj, fn) {
|
||||||
|
const objKeys = j$.MatchersUtil.keys(obj, j$.isArray_(obj));
|
||||||
|
const length = Math.min(objKeys.length, j$.MAX_PRETTY_PRINT_ARRAY_LENGTH);
|
||||||
|
|
||||||
|
for (let i = 0; i < length; i++) {
|
||||||
|
fn(objKeys[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return objKeys.length > length;
|
||||||
|
}
|
||||||
|
|
||||||
|
emitScalar(value) {
|
||||||
|
this.append(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
emitString(value) {
|
||||||
|
this.append("'" + value + "'");
|
||||||
|
}
|
||||||
|
|
||||||
|
emitArray(array) {
|
||||||
|
if (this.ppNestLevel_ > j$.MAX_PRETTY_PRINT_DEPTH) {
|
||||||
|
this.append('Array');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const length = Math.min(array.length, j$.MAX_PRETTY_PRINT_ARRAY_LENGTH);
|
||||||
|
this.append('[ ');
|
||||||
|
|
||||||
|
for (let i = 0; i < length; i++) {
|
||||||
|
if (i > 0) {
|
||||||
|
this.append(', ');
|
||||||
|
}
|
||||||
|
this.format(array[i]);
|
||||||
|
}
|
||||||
|
if (array.length > length) {
|
||||||
|
this.append(', ...');
|
||||||
|
}
|
||||||
|
|
||||||
|
let first = array.length === 0;
|
||||||
|
const wasTruncated = this.iterateObject(array, property => {
|
||||||
|
if (first) {
|
||||||
|
first = false;
|
||||||
|
} else {
|
||||||
|
this.append(', ');
|
||||||
|
}
|
||||||
|
|
||||||
|
this.formatProperty(array, property);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (wasTruncated) {
|
||||||
|
this.append(', ...');
|
||||||
|
}
|
||||||
|
|
||||||
|
this.append(' ]');
|
||||||
|
}
|
||||||
|
|
||||||
|
emitSet(set) {
|
||||||
|
if (this.ppNestLevel_ > j$.MAX_PRETTY_PRINT_DEPTH) {
|
||||||
|
this.append('Set');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.append('Set( ');
|
||||||
|
const size = Math.min(set.size, j$.MAX_PRETTY_PRINT_ARRAY_LENGTH);
|
||||||
|
let i = 0;
|
||||||
|
set.forEach(function(value, key) {
|
||||||
|
if (i >= size) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (i > 0) {
|
||||||
|
this.append(', ');
|
||||||
|
}
|
||||||
|
this.format(value);
|
||||||
|
|
||||||
|
i++;
|
||||||
|
}, this);
|
||||||
|
if (set.size > size) {
|
||||||
|
this.append(', ...');
|
||||||
|
}
|
||||||
|
this.append(' )');
|
||||||
|
}
|
||||||
|
|
||||||
|
emitMap(map) {
|
||||||
|
if (this.ppNestLevel_ > j$.MAX_PRETTY_PRINT_DEPTH) {
|
||||||
|
this.append('Map');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.append('Map( ');
|
||||||
|
const size = Math.min(map.size, j$.MAX_PRETTY_PRINT_ARRAY_LENGTH);
|
||||||
|
let i = 0;
|
||||||
|
map.forEach(function(value, key) {
|
||||||
|
if (i >= size) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (i > 0) {
|
||||||
|
this.append(', ');
|
||||||
|
}
|
||||||
|
this.format([key, value]);
|
||||||
|
|
||||||
|
i++;
|
||||||
|
}, this);
|
||||||
|
if (map.size > size) {
|
||||||
|
this.append(', ...');
|
||||||
|
}
|
||||||
|
this.append(' )');
|
||||||
|
}
|
||||||
|
|
||||||
|
emitObject(obj) {
|
||||||
|
const ctor = obj.constructor;
|
||||||
|
const constructorName =
|
||||||
|
typeof ctor === 'function' && obj instanceof ctor
|
||||||
|
? j$.fnNameFor(obj.constructor)
|
||||||
|
: 'null';
|
||||||
|
|
||||||
|
this.append(constructorName);
|
||||||
|
|
||||||
|
if (this.ppNestLevel_ > j$.MAX_PRETTY_PRINT_DEPTH) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.append('({ ');
|
||||||
|
let first = true;
|
||||||
|
|
||||||
|
const wasTruncated = this.iterateObject(obj, property => {
|
||||||
|
if (first) {
|
||||||
|
first = false;
|
||||||
|
} else {
|
||||||
|
this.append(', ');
|
||||||
|
}
|
||||||
|
|
||||||
|
this.formatProperty(obj, property);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (wasTruncated) {
|
||||||
|
this.append(', ...');
|
||||||
|
}
|
||||||
|
|
||||||
|
this.append(' })');
|
||||||
|
}
|
||||||
|
|
||||||
|
emitTypedArray(arr) {
|
||||||
|
const constructorName = j$.fnNameFor(arr.constructor);
|
||||||
|
const limitedArray = Array.prototype.slice.call(
|
||||||
|
arr,
|
||||||
|
0,
|
||||||
|
j$.MAX_PRETTY_PRINT_ARRAY_LENGTH
|
||||||
|
);
|
||||||
|
let itemsString = Array.prototype.join.call(limitedArray, ', ');
|
||||||
|
|
||||||
|
if (limitedArray.length !== arr.length) {
|
||||||
|
itemsString += ', ...';
|
||||||
|
}
|
||||||
|
|
||||||
|
this.append(constructorName + ' [ ' + itemsString + ' ]');
|
||||||
|
}
|
||||||
|
|
||||||
|
emitDomElement(el) {
|
||||||
|
const tagName = el.tagName.toLowerCase();
|
||||||
|
let out = '<' + tagName;
|
||||||
|
|
||||||
|
for (const attr of el.attributes) {
|
||||||
|
out += ' ' + attr.name;
|
||||||
|
|
||||||
|
if (attr.value !== '') {
|
||||||
|
out += '="' + attr.value + '"';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
out += '>';
|
||||||
|
|
||||||
|
if (el.childElementCount !== 0 || el.textContent !== '') {
|
||||||
|
out += '...</' + tagName + '>';
|
||||||
|
}
|
||||||
|
|
||||||
|
this.append(out);
|
||||||
|
}
|
||||||
|
|
||||||
|
formatProperty(obj, property) {
|
||||||
|
if (typeof property === 'symbol') {
|
||||||
|
this.append(property.toString());
|
||||||
|
} else {
|
||||||
|
this.append(property);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.append(': ');
|
||||||
|
this.format(obj[property]);
|
||||||
|
}
|
||||||
|
|
||||||
|
append(value) {
|
||||||
|
// This check protects us from the rare case where an object has overriden
|
||||||
|
// `toString()` with an invalid implementation (returning a non-string).
|
||||||
|
if (typeof value !== 'string') {
|
||||||
|
value = Object.prototype.toString.call(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = truncate(value, j$.MAX_PRETTY_PRINT_CHARS - this.length);
|
||||||
|
this.length += result.value.length;
|
||||||
|
this.stringParts.push(result.value);
|
||||||
|
|
||||||
|
if (result.truncated) {
|
||||||
|
throw new MaxCharsReachedError();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function hasCustomToString(value) {
|
function hasCustomToString(value) {
|
||||||
@@ -23,315 +310,6 @@ getJasmineRequireObj().makePrettyPrinter = function(j$) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SinglePrettyPrintRun.prototype.format = function(value) {
|
|
||||||
this.ppNestLevel_++;
|
|
||||||
try {
|
|
||||||
var customFormatResult = this.applyCustomFormatters_(value);
|
|
||||||
|
|
||||||
if (customFormatResult) {
|
|
||||||
this.emitScalar(customFormatResult);
|
|
||||||
} else if (j$.util.isUndefined(value)) {
|
|
||||||
this.emitScalar('undefined');
|
|
||||||
} else if (value === null) {
|
|
||||||
this.emitScalar('null');
|
|
||||||
} else if (value === 0 && 1 / value === -Infinity) {
|
|
||||||
this.emitScalar('-0');
|
|
||||||
} else if (value === j$.getGlobal()) {
|
|
||||||
this.emitScalar('<global>');
|
|
||||||
} else if (value.jasmineToString) {
|
|
||||||
this.emitScalar(value.jasmineToString(this.pp_));
|
|
||||||
} else if (j$.isString_(value)) {
|
|
||||||
this.emitString(value);
|
|
||||||
} else if (j$.isSpy(value)) {
|
|
||||||
this.emitScalar('spy on ' + value.and.identity);
|
|
||||||
} else if (j$.isSpy(value.toString)) {
|
|
||||||
this.emitScalar('spy on ' + value.toString.and.identity);
|
|
||||||
} else if (value instanceof RegExp) {
|
|
||||||
this.emitScalar(value.toString());
|
|
||||||
} else if (typeof value === 'function') {
|
|
||||||
this.emitScalar('Function');
|
|
||||||
} else if (j$.isDomNode(value)) {
|
|
||||||
if (value.tagName) {
|
|
||||||
this.emitDomElement(value);
|
|
||||||
} else {
|
|
||||||
this.emitScalar('HTMLNode');
|
|
||||||
}
|
|
||||||
} else if (value instanceof Date) {
|
|
||||||
this.emitScalar('Date(' + value + ')');
|
|
||||||
} else if (j$.isSet(value)) {
|
|
||||||
this.emitSet(value);
|
|
||||||
} else if (j$.isMap(value)) {
|
|
||||||
this.emitMap(value);
|
|
||||||
} else if (j$.isTypedArray_(value)) {
|
|
||||||
this.emitTypedArray(value);
|
|
||||||
} else if (
|
|
||||||
value.toString &&
|
|
||||||
typeof value === 'object' &&
|
|
||||||
!j$.isArray_(value) &&
|
|
||||||
hasCustomToString(value)
|
|
||||||
) {
|
|
||||||
try {
|
|
||||||
this.emitScalar(value.toString());
|
|
||||||
} catch (e) {
|
|
||||||
this.emitScalar('has-invalid-toString-method');
|
|
||||||
}
|
|
||||||
} else if (j$.util.arrayContains(this.seen, value)) {
|
|
||||||
this.emitScalar(
|
|
||||||
'<circular reference: ' +
|
|
||||||
(j$.isArray_(value) ? 'Array' : 'Object') +
|
|
||||||
'>'
|
|
||||||
);
|
|
||||||
} else if (j$.isArray_(value) || j$.isA_('Object', value)) {
|
|
||||||
this.seen.push(value);
|
|
||||||
if (j$.isArray_(value)) {
|
|
||||||
this.emitArray(value);
|
|
||||||
} else {
|
|
||||||
this.emitObject(value);
|
|
||||||
}
|
|
||||||
this.seen.pop();
|
|
||||||
} else {
|
|
||||||
this.emitScalar(value.toString());
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
if (this.ppNestLevel_ > 1 || !(e instanceof MaxCharsReachedError)) {
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
this.ppNestLevel_--;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
SinglePrettyPrintRun.prototype.applyCustomFormatters_ = function(value) {
|
|
||||||
return customFormat(value, this.customObjectFormatters_);
|
|
||||||
};
|
|
||||||
|
|
||||||
SinglePrettyPrintRun.prototype.iterateObject = function(obj, fn) {
|
|
||||||
var objKeys = j$.MatchersUtil.keys(obj, j$.isArray_(obj));
|
|
||||||
var isGetter = function isGetter(prop) {};
|
|
||||||
|
|
||||||
if (obj.__lookupGetter__) {
|
|
||||||
isGetter = function isGetter(prop) {
|
|
||||||
var getter = obj.__lookupGetter__(prop);
|
|
||||||
return !j$.util.isUndefined(getter) && getter !== null;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
var length = Math.min(objKeys.length, j$.MAX_PRETTY_PRINT_ARRAY_LENGTH);
|
|
||||||
for (var i = 0; i < length; i++) {
|
|
||||||
var property = objKeys[i];
|
|
||||||
fn(property, isGetter(property));
|
|
||||||
}
|
|
||||||
|
|
||||||
return objKeys.length > length;
|
|
||||||
};
|
|
||||||
|
|
||||||
SinglePrettyPrintRun.prototype.emitScalar = function(value) {
|
|
||||||
this.append(value);
|
|
||||||
};
|
|
||||||
|
|
||||||
SinglePrettyPrintRun.prototype.emitString = function(value) {
|
|
||||||
this.append("'" + value + "'");
|
|
||||||
};
|
|
||||||
|
|
||||||
SinglePrettyPrintRun.prototype.emitArray = function(array) {
|
|
||||||
if (this.ppNestLevel_ > j$.MAX_PRETTY_PRINT_DEPTH) {
|
|
||||||
this.append('Array');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
var length = Math.min(array.length, j$.MAX_PRETTY_PRINT_ARRAY_LENGTH);
|
|
||||||
this.append('[ ');
|
|
||||||
for (var i = 0; i < length; i++) {
|
|
||||||
if (i > 0) {
|
|
||||||
this.append(', ');
|
|
||||||
}
|
|
||||||
this.format(array[i]);
|
|
||||||
}
|
|
||||||
if (array.length > length) {
|
|
||||||
this.append(', ...');
|
|
||||||
}
|
|
||||||
|
|
||||||
var self = this;
|
|
||||||
var first = array.length === 0;
|
|
||||||
var truncated = this.iterateObject(array, function(property, isGetter) {
|
|
||||||
if (first) {
|
|
||||||
first = false;
|
|
||||||
} else {
|
|
||||||
self.append(', ');
|
|
||||||
}
|
|
||||||
|
|
||||||
self.formatProperty(array, property, isGetter);
|
|
||||||
});
|
|
||||||
|
|
||||||
if (truncated) {
|
|
||||||
this.append(', ...');
|
|
||||||
}
|
|
||||||
|
|
||||||
this.append(' ]');
|
|
||||||
};
|
|
||||||
|
|
||||||
SinglePrettyPrintRun.prototype.emitSet = function(set) {
|
|
||||||
if (this.ppNestLevel_ > j$.MAX_PRETTY_PRINT_DEPTH) {
|
|
||||||
this.append('Set');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.append('Set( ');
|
|
||||||
var size = Math.min(set.size, j$.MAX_PRETTY_PRINT_ARRAY_LENGTH);
|
|
||||||
var i = 0;
|
|
||||||
set.forEach(function(value, key) {
|
|
||||||
if (i >= size) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (i > 0) {
|
|
||||||
this.append(', ');
|
|
||||||
}
|
|
||||||
this.format(value);
|
|
||||||
|
|
||||||
i++;
|
|
||||||
}, this);
|
|
||||||
if (set.size > size) {
|
|
||||||
this.append(', ...');
|
|
||||||
}
|
|
||||||
this.append(' )');
|
|
||||||
};
|
|
||||||
|
|
||||||
SinglePrettyPrintRun.prototype.emitMap = function(map) {
|
|
||||||
if (this.ppNestLevel_ > j$.MAX_PRETTY_PRINT_DEPTH) {
|
|
||||||
this.append('Map');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.append('Map( ');
|
|
||||||
var size = Math.min(map.size, j$.MAX_PRETTY_PRINT_ARRAY_LENGTH);
|
|
||||||
var i = 0;
|
|
||||||
map.forEach(function(value, key) {
|
|
||||||
if (i >= size) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (i > 0) {
|
|
||||||
this.append(', ');
|
|
||||||
}
|
|
||||||
this.format([key, value]);
|
|
||||||
|
|
||||||
i++;
|
|
||||||
}, this);
|
|
||||||
if (map.size > size) {
|
|
||||||
this.append(', ...');
|
|
||||||
}
|
|
||||||
this.append(' )');
|
|
||||||
};
|
|
||||||
|
|
||||||
SinglePrettyPrintRun.prototype.emitObject = function(obj) {
|
|
||||||
var ctor = obj.constructor,
|
|
||||||
constructorName;
|
|
||||||
|
|
||||||
constructorName =
|
|
||||||
typeof ctor === 'function' && obj instanceof ctor
|
|
||||||
? j$.fnNameFor(obj.constructor)
|
|
||||||
: 'null';
|
|
||||||
|
|
||||||
this.append(constructorName);
|
|
||||||
|
|
||||||
if (this.ppNestLevel_ > j$.MAX_PRETTY_PRINT_DEPTH) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var self = this;
|
|
||||||
this.append('({ ');
|
|
||||||
var first = true;
|
|
||||||
|
|
||||||
var truncated = this.iterateObject(obj, function(property, isGetter) {
|
|
||||||
if (first) {
|
|
||||||
first = false;
|
|
||||||
} else {
|
|
||||||
self.append(', ');
|
|
||||||
}
|
|
||||||
|
|
||||||
self.formatProperty(obj, property, isGetter);
|
|
||||||
});
|
|
||||||
|
|
||||||
if (truncated) {
|
|
||||||
this.append(', ...');
|
|
||||||
}
|
|
||||||
|
|
||||||
this.append(' })');
|
|
||||||
};
|
|
||||||
|
|
||||||
SinglePrettyPrintRun.prototype.emitTypedArray = function(arr) {
|
|
||||||
var constructorName = j$.fnNameFor(arr.constructor),
|
|
||||||
limitedArray = Array.prototype.slice.call(
|
|
||||||
arr,
|
|
||||||
0,
|
|
||||||
j$.MAX_PRETTY_PRINT_ARRAY_LENGTH
|
|
||||||
),
|
|
||||||
itemsString = Array.prototype.join.call(limitedArray, ', ');
|
|
||||||
|
|
||||||
if (limitedArray.length !== arr.length) {
|
|
||||||
itemsString += ', ...';
|
|
||||||
}
|
|
||||||
|
|
||||||
this.append(constructorName + ' [ ' + itemsString + ' ]');
|
|
||||||
};
|
|
||||||
|
|
||||||
SinglePrettyPrintRun.prototype.emitDomElement = function(el) {
|
|
||||||
var tagName = el.tagName.toLowerCase(),
|
|
||||||
attrs = el.attributes,
|
|
||||||
i,
|
|
||||||
len = attrs.length,
|
|
||||||
out = '<' + tagName,
|
|
||||||
attr;
|
|
||||||
|
|
||||||
for (i = 0; i < len; i++) {
|
|
||||||
attr = attrs[i];
|
|
||||||
out += ' ' + attr.name;
|
|
||||||
|
|
||||||
if (attr.value !== '') {
|
|
||||||
out += '="' + attr.value + '"';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
out += '>';
|
|
||||||
|
|
||||||
if (el.childElementCount !== 0 || el.textContent !== '') {
|
|
||||||
out += '...</' + tagName + '>';
|
|
||||||
}
|
|
||||||
|
|
||||||
this.append(out);
|
|
||||||
};
|
|
||||||
|
|
||||||
SinglePrettyPrintRun.prototype.formatProperty = function(
|
|
||||||
obj,
|
|
||||||
property,
|
|
||||||
isGetter
|
|
||||||
) {
|
|
||||||
if (typeof property === 'symbol') {
|
|
||||||
this.append(property.toString());
|
|
||||||
} else {
|
|
||||||
this.append(property);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.append(': ');
|
|
||||||
|
|
||||||
if (isGetter) {
|
|
||||||
this.append('<getter>');
|
|
||||||
} else {
|
|
||||||
this.format(obj[property]);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
SinglePrettyPrintRun.prototype.append = function(value) {
|
|
||||||
// This check protects us from the rare case where an object has overriden
|
|
||||||
// `toString()` with an invalid implementation (returning a non-string).
|
|
||||||
if (typeof value !== 'string') {
|
|
||||||
value = Object.prototype.toString.call(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
var result = truncate(value, j$.MAX_PRETTY_PRINT_CHARS - this.length);
|
|
||||||
this.length += result.value.length;
|
|
||||||
this.stringParts.push(result.value);
|
|
||||||
|
|
||||||
if (result.truncated) {
|
|
||||||
throw new MaxCharsReachedError();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
function truncate(s, maxlen) {
|
function truncate(s, maxlen) {
|
||||||
if (s.length <= maxlen) {
|
if (s.length <= maxlen) {
|
||||||
return { value: s, truncated: false };
|
return { value: s, truncated: false };
|
||||||
@@ -351,10 +329,8 @@ getJasmineRequireObj().makePrettyPrinter = function(j$) {
|
|||||||
MaxCharsReachedError.prototype = new Error();
|
MaxCharsReachedError.prototype = new Error();
|
||||||
|
|
||||||
function customFormat(value, customObjectFormatters) {
|
function customFormat(value, customObjectFormatters) {
|
||||||
var i, result;
|
for (const formatter of customObjectFormatters) {
|
||||||
|
const result = formatter(value);
|
||||||
for (i = 0; i < customObjectFormatters.length; i++) {
|
|
||||||
result = customObjectFormatters[i](value);
|
|
||||||
|
|
||||||
if (result !== undefined) {
|
if (result !== undefined) {
|
||||||
return result;
|
return result;
|
||||||
@@ -365,8 +341,11 @@ getJasmineRequireObj().makePrettyPrinter = function(j$) {
|
|||||||
return function(customObjectFormatters) {
|
return function(customObjectFormatters) {
|
||||||
customObjectFormatters = customObjectFormatters || [];
|
customObjectFormatters = customObjectFormatters || [];
|
||||||
|
|
||||||
var pp = function(value) {
|
const pp = function(value) {
|
||||||
var prettyPrinter = new SinglePrettyPrintRun(customObjectFormatters, pp);
|
const prettyPrinter = new SinglePrettyPrintRun(
|
||||||
|
customObjectFormatters,
|
||||||
|
pp
|
||||||
|
);
|
||||||
prettyPrinter.format(value);
|
prettyPrinter.format(value);
|
||||||
return prettyPrinter.stringParts.join('');
|
return prettyPrinter.stringParts.join('');
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
getJasmineRequireObj().QueueRunner = function(j$) {
|
getJasmineRequireObj().QueueRunner = function(j$) {
|
||||||
var nextid = 1;
|
let nextid = 1;
|
||||||
|
|
||||||
function StopExecutionError() {}
|
function StopExecutionError() {}
|
||||||
StopExecutionError.prototype = new Error();
|
StopExecutionError.prototype = new Error();
|
||||||
j$.StopExecutionError = StopExecutionError;
|
j$.StopExecutionError = StopExecutionError;
|
||||||
|
|
||||||
function once(fn, onTwice) {
|
function once(fn, onTwice) {
|
||||||
var called = false;
|
let called = false;
|
||||||
return function(arg) {
|
return function(arg) {
|
||||||
if (called) {
|
if (called) {
|
||||||
if (onTwice) {
|
if (onTwice) {
|
||||||
@@ -66,12 +66,11 @@ getJasmineRequireObj().QueueRunner = function(j$) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
QueueRunner.prototype.execute = function() {
|
QueueRunner.prototype.execute = function() {
|
||||||
var self = this;
|
this.handleFinalError = (message, source, lineno, colno, error) => {
|
||||||
this.handleFinalError = function(message, source, lineno, colno, error) {
|
|
||||||
// Older browsers would send the error as the first parameter. HTML5
|
// Older browsers would send the error as the first parameter. HTML5
|
||||||
// specifies the the five parameters above. The error instance should
|
// specifies the the five parameters above. The error instance should
|
||||||
// be preffered, otherwise the call stack would get lost.
|
// be preffered, otherwise the call stack would get lost.
|
||||||
self.onException(error || message);
|
this.onException(error || message);
|
||||||
};
|
};
|
||||||
this.globalErrors.pushListener(this.handleFinalError);
|
this.globalErrors.pushListener(this.handleFinalError);
|
||||||
this.run(0);
|
this.run(0);
|
||||||
@@ -92,71 +91,77 @@ getJasmineRequireObj().QueueRunner = function(j$) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
QueueRunner.prototype.attempt = function attempt(iterativeIndex) {
|
QueueRunner.prototype.attempt = function attempt(iterativeIndex) {
|
||||||
var self = this,
|
let timeoutId;
|
||||||
completedSynchronously = true,
|
let timedOut;
|
||||||
handleError = function handleError(error) {
|
let completedSynchronously = true;
|
||||||
// TODO probably shouldn't next() right away here.
|
|
||||||
// That makes debugging async failures much more confusing.
|
|
||||||
onException(error);
|
|
||||||
},
|
|
||||||
cleanup = once(function cleanup() {
|
|
||||||
if (timeoutId !== void 0) {
|
|
||||||
self.clearTimeout(timeoutId);
|
|
||||||
}
|
|
||||||
self.globalErrors.popListener(handleError);
|
|
||||||
}),
|
|
||||||
next = once(
|
|
||||||
function next(err) {
|
|
||||||
cleanup();
|
|
||||||
|
|
||||||
if (typeof err !== 'undefined') {
|
const onException = e => {
|
||||||
if (!(err instanceof StopExecutionError) && !err.jasmineMessage) {
|
this.onException(e);
|
||||||
self.fail(err);
|
this.recordError_(iterativeIndex);
|
||||||
}
|
|
||||||
self.recordError_(iterativeIndex);
|
|
||||||
}
|
|
||||||
|
|
||||||
function runNext() {
|
|
||||||
self.run(self.nextFnIx_(iterativeIndex));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (completedSynchronously) {
|
|
||||||
self.setTimeout(runNext);
|
|
||||||
} else {
|
|
||||||
runNext();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
function() {
|
|
||||||
try {
|
|
||||||
if (!timedOut) {
|
|
||||||
self.onMultipleDone();
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
// Any error we catch here is probably due to a bug in Jasmine,
|
|
||||||
// and it's not likely to end up anywhere useful if we let it
|
|
||||||
// propagate. Log it so it can at least show up when debugging.
|
|
||||||
console.error(error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
),
|
|
||||||
timedOut = false,
|
|
||||||
queueableFn = self.queueableFns[iterativeIndex],
|
|
||||||
timeoutId,
|
|
||||||
maybeThenable;
|
|
||||||
|
|
||||||
next.fail = function nextFail() {
|
|
||||||
self.fail.apply(null, arguments);
|
|
||||||
self.recordError_(iterativeIndex);
|
|
||||||
next();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
self.globalErrors.pushListener(handleError);
|
function handleError(error) {
|
||||||
|
// TODO probably shouldn't next() right away here.
|
||||||
|
// That makes debugging async failures much more confusing.
|
||||||
|
onException(error);
|
||||||
|
}
|
||||||
|
const cleanup = once(() => {
|
||||||
|
if (timeoutId !== void 0) {
|
||||||
|
this.clearTimeout(timeoutId);
|
||||||
|
}
|
||||||
|
this.globalErrors.popListener(handleError);
|
||||||
|
});
|
||||||
|
const next = once(
|
||||||
|
err => {
|
||||||
|
cleanup();
|
||||||
|
|
||||||
|
if (typeof err !== 'undefined') {
|
||||||
|
if (!(err instanceof StopExecutionError) && !err.jasmineMessage) {
|
||||||
|
this.fail(err);
|
||||||
|
}
|
||||||
|
this.recordError_(iterativeIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
const runNext = () => {
|
||||||
|
this.run(this.nextFnIx_(iterativeIndex));
|
||||||
|
};
|
||||||
|
|
||||||
|
if (completedSynchronously) {
|
||||||
|
this.setTimeout(runNext);
|
||||||
|
} else {
|
||||||
|
runNext();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
() => {
|
||||||
|
try {
|
||||||
|
if (!timedOut) {
|
||||||
|
this.onMultipleDone();
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
// Any error we catch here is probably due to a bug in Jasmine,
|
||||||
|
// and it's not likely to end up anywhere useful if we let it
|
||||||
|
// propagate. Log it so it can at least show up when debugging.
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
timedOut = false;
|
||||||
|
const queueableFn = this.queueableFns[iterativeIndex];
|
||||||
|
|
||||||
|
next.fail = function nextFail() {
|
||||||
|
this.fail.apply(null, arguments);
|
||||||
|
this.recordError_(iterativeIndex);
|
||||||
|
next();
|
||||||
|
}.bind(this);
|
||||||
|
|
||||||
|
this.globalErrors.pushListener(handleError);
|
||||||
|
|
||||||
if (queueableFn.timeout !== undefined) {
|
if (queueableFn.timeout !== undefined) {
|
||||||
var timeoutInterval = queueableFn.timeout || j$.DEFAULT_TIMEOUT_INTERVAL;
|
const timeoutInterval =
|
||||||
timeoutId = self.setTimeout(function() {
|
queueableFn.timeout || j$.DEFAULT_TIMEOUT_INTERVAL;
|
||||||
|
timeoutId = this.setTimeout(function() {
|
||||||
timedOut = true;
|
timedOut = true;
|
||||||
var error = new Error(
|
const error = new Error(
|
||||||
'Timeout - Async function did not complete within ' +
|
'Timeout - Async function did not complete within ' +
|
||||||
timeoutInterval +
|
timeoutInterval +
|
||||||
'ms ' +
|
'ms ' +
|
||||||
@@ -173,8 +178,10 @@ getJasmineRequireObj().QueueRunner = function(j$) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
let maybeThenable;
|
||||||
|
|
||||||
if (queueableFn.fn.length === 0) {
|
if (queueableFn.fn.length === 0) {
|
||||||
maybeThenable = queueableFn.fn.call(self.userContext);
|
maybeThenable = queueableFn.fn.call(this.userContext);
|
||||||
|
|
||||||
if (maybeThenable && j$.isFunction_(maybeThenable.then)) {
|
if (maybeThenable && j$.isFunction_(maybeThenable.then)) {
|
||||||
maybeThenable.then(
|
maybeThenable.then(
|
||||||
@@ -185,24 +192,19 @@ getJasmineRequireObj().QueueRunner = function(j$) {
|
|||||||
return { completedSynchronously: false };
|
return { completedSynchronously: false };
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
maybeThenable = queueableFn.fn.call(self.userContext, next);
|
maybeThenable = queueableFn.fn.call(this.userContext, next);
|
||||||
this.diagnoseConflictingAsync_(queueableFn.fn, maybeThenable);
|
this.diagnoseConflictingAsync_(queueableFn.fn, maybeThenable);
|
||||||
completedSynchronously = false;
|
completedSynchronously = false;
|
||||||
return { completedSynchronously: false };
|
return { completedSynchronously: false };
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
onException(e);
|
onException(e);
|
||||||
self.recordError_(iterativeIndex);
|
this.recordError_(iterativeIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
cleanup();
|
cleanup();
|
||||||
return { completedSynchronously: true };
|
return { completedSynchronously: true };
|
||||||
|
|
||||||
function onException(e) {
|
|
||||||
self.onException(e);
|
|
||||||
self.recordError_(iterativeIndex);
|
|
||||||
}
|
|
||||||
|
|
||||||
function onPromiseRejection(e) {
|
function onPromiseRejection(e) {
|
||||||
onException(e);
|
onException(e);
|
||||||
next();
|
next();
|
||||||
@@ -210,29 +212,27 @@ getJasmineRequireObj().QueueRunner = function(j$) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
QueueRunner.prototype.run = function(recursiveIndex) {
|
QueueRunner.prototype.run = function(recursiveIndex) {
|
||||||
var length = this.queueableFns.length,
|
const length = this.queueableFns.length;
|
||||||
self = this,
|
|
||||||
iterativeIndex;
|
|
||||||
|
|
||||||
for (
|
for (
|
||||||
iterativeIndex = recursiveIndex;
|
let iterativeIndex = recursiveIndex;
|
||||||
iterativeIndex < length;
|
iterativeIndex < length;
|
||||||
iterativeIndex = this.nextFnIx_(iterativeIndex)
|
iterativeIndex = this.nextFnIx_(iterativeIndex)
|
||||||
) {
|
) {
|
||||||
var result = this.attempt(iterativeIndex);
|
const result = this.attempt(iterativeIndex);
|
||||||
|
|
||||||
if (!result.completedSynchronously) {
|
if (!result.completedSynchronously) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.clearStack(function() {
|
this.clearStack(() => {
|
||||||
self.globalErrors.popListener(self.handleFinalError);
|
this.globalErrors.popListener(this.handleFinalError);
|
||||||
|
|
||||||
if (self.errored_) {
|
if (this.errored_) {
|
||||||
self.onComplete(new StopExecutionError());
|
this.onComplete(new StopExecutionError());
|
||||||
} else {
|
} else {
|
||||||
self.onComplete();
|
this.onComplete();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -253,8 +253,6 @@ getJasmineRequireObj().QueueRunner = function(j$) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
QueueRunner.prototype.diagnoseConflictingAsync_ = function(fn, retval) {
|
QueueRunner.prototype.diagnoseConflictingAsync_ = function(fn, retval) {
|
||||||
var msg;
|
|
||||||
|
|
||||||
if (retval && j$.isFunction_(retval.then)) {
|
if (retval && j$.isFunction_(retval.then)) {
|
||||||
// Issue a warning that matches the user's code.
|
// Issue a warning that matches the user's code.
|
||||||
// Omit the stack trace because there's almost certainly no user code
|
// Omit the stack trace because there's almost certainly no user code
|
||||||
@@ -274,8 +272,6 @@ getJasmineRequireObj().QueueRunner = function(j$) {
|
|||||||
'function to not return a promise.'
|
'function to not return a promise.'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.deprecated(msg, { omitStackTrace: true });
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
getJasmineRequireObj().ReportDispatcher = function(j$) {
|
getJasmineRequireObj().ReportDispatcher = function(j$) {
|
||||||
function ReportDispatcher(methods, queueRunnerFactory, onLateError) {
|
function ReportDispatcher(methods, queueRunnerFactory, onLateError) {
|
||||||
var dispatchedMethods = methods || [];
|
const dispatchedMethods = methods || [];
|
||||||
|
|
||||||
for (var i = 0; i < dispatchedMethods.length; i++) {
|
for (const method of dispatchedMethods) {
|
||||||
var method = dispatchedMethods[i];
|
|
||||||
this[method] = (function(m) {
|
this[method] = (function(m) {
|
||||||
return function() {
|
return function() {
|
||||||
dispatch(m, arguments);
|
dispatch(m, arguments);
|
||||||
@@ -11,8 +10,8 @@ getJasmineRequireObj().ReportDispatcher = function(j$) {
|
|||||||
})(method);
|
})(method);
|
||||||
}
|
}
|
||||||
|
|
||||||
var reporters = [];
|
let reporters = [];
|
||||||
var fallbackReporter = null;
|
let fallbackReporter = null;
|
||||||
|
|
||||||
this.addReporter = function(reporter) {
|
this.addReporter = function(reporter) {
|
||||||
reporters.push(reporter);
|
reporters.push(reporter);
|
||||||
@@ -32,11 +31,10 @@ getJasmineRequireObj().ReportDispatcher = function(j$) {
|
|||||||
if (reporters.length === 0 && fallbackReporter !== null) {
|
if (reporters.length === 0 && fallbackReporter !== null) {
|
||||||
reporters.push(fallbackReporter);
|
reporters.push(fallbackReporter);
|
||||||
}
|
}
|
||||||
var onComplete = args[args.length - 1];
|
const onComplete = args[args.length - 1];
|
||||||
args = j$.util.argsToArray(args).splice(0, args.length - 1);
|
args = Array.from(args).splice(0, args.length - 1);
|
||||||
var fns = [];
|
const fns = [];
|
||||||
for (var i = 0; i < reporters.length; i++) {
|
for (const reporter of reporters) {
|
||||||
var reporter = reporters[i];
|
|
||||||
addFn(fns, reporter, method, args);
|
addFn(fns, reporter, method, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,12 +54,12 @@ getJasmineRequireObj().ReportDispatcher = function(j$) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function addFn(fns, reporter, method, args) {
|
function addFn(fns, reporter, method, args) {
|
||||||
var fn = reporter[method];
|
const fn = reporter[method];
|
||||||
if (!fn) {
|
if (!fn) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var thisArgs = j$.util.cloneArgs(args);
|
const thisArgs = j$.util.cloneArgs(args);
|
||||||
if (fn.length <= 1) {
|
if (fn.length <= 1) {
|
||||||
fns.push({
|
fns.push({
|
||||||
fn: function() {
|
fn: function() {
|
||||||
|
|||||||
155
src/core/RunableResources.js
Normal file
155
src/core/RunableResources.js
Normal file
@@ -0,0 +1,155 @@
|
|||||||
|
getJasmineRequireObj().RunableResources = function(j$) {
|
||||||
|
class RunableResources {
|
||||||
|
constructor(options) {
|
||||||
|
this.byRunableId_ = {};
|
||||||
|
this.getCurrentRunableId_ = options.getCurrentRunableId;
|
||||||
|
this.globalErrors_ = options.globalErrors;
|
||||||
|
|
||||||
|
this.spyFactory = new j$.SpyFactory(
|
||||||
|
() => {
|
||||||
|
if (this.getCurrentRunableId_()) {
|
||||||
|
return this.customSpyStrategies();
|
||||||
|
} else {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
},
|
||||||
|
() => this.defaultSpyStrategy(),
|
||||||
|
() => this.makeMatchersUtil()
|
||||||
|
);
|
||||||
|
|
||||||
|
this.spyRegistry = new j$.SpyRegistry({
|
||||||
|
currentSpies: () => this.spies(),
|
||||||
|
createSpy: (name, originalFn) =>
|
||||||
|
this.spyFactory.createSpy(name, originalFn)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
initForRunable(runableId, parentId) {
|
||||||
|
const newRes = (this.byRunableId_[runableId] = {
|
||||||
|
customEqualityTesters: [],
|
||||||
|
customMatchers: {},
|
||||||
|
customAsyncMatchers: {},
|
||||||
|
customSpyStrategies: {},
|
||||||
|
customObjectFormatters: [],
|
||||||
|
defaultSpyStrategy: undefined,
|
||||||
|
spies: []
|
||||||
|
});
|
||||||
|
|
||||||
|
const parentRes = this.byRunableId_[parentId];
|
||||||
|
|
||||||
|
if (parentRes) {
|
||||||
|
newRes.defaultSpyStrategy = parentRes.defaultSpyStrategy;
|
||||||
|
const toClone = [
|
||||||
|
'customEqualityTesters',
|
||||||
|
'customMatchers',
|
||||||
|
'customAsyncMatchers',
|
||||||
|
'customObjectFormatters',
|
||||||
|
'customSpyStrategies'
|
||||||
|
];
|
||||||
|
|
||||||
|
for (const k of toClone) {
|
||||||
|
newRes[k] = j$.util.clone(parentRes[k]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
clearForRunable(runableId) {
|
||||||
|
this.globalErrors_.removeOverrideListener();
|
||||||
|
this.spyRegistry.clearSpies();
|
||||||
|
delete this.byRunableId_[runableId];
|
||||||
|
}
|
||||||
|
|
||||||
|
spies() {
|
||||||
|
return this.forCurrentRunable_(
|
||||||
|
'Spies must be created in a before function or a spec'
|
||||||
|
).spies;
|
||||||
|
}
|
||||||
|
|
||||||
|
defaultSpyStrategy() {
|
||||||
|
if (!this.getCurrentRunableId_()) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.byRunableId_[this.getCurrentRunableId_()].defaultSpyStrategy;
|
||||||
|
}
|
||||||
|
|
||||||
|
setDefaultSpyStrategy(fn) {
|
||||||
|
this.forCurrentRunable_(
|
||||||
|
'Default spy strategy must be set in a before function or a spec'
|
||||||
|
).defaultSpyStrategy = fn;
|
||||||
|
}
|
||||||
|
|
||||||
|
customSpyStrategies() {
|
||||||
|
return this.forCurrentRunable_(
|
||||||
|
'Custom spy strategies must be added in a before function or a spec'
|
||||||
|
).customSpyStrategies;
|
||||||
|
}
|
||||||
|
|
||||||
|
customEqualityTesters() {
|
||||||
|
return this.forCurrentRunable_(
|
||||||
|
'Custom Equalities must be added in a before function or a spec'
|
||||||
|
).customEqualityTesters;
|
||||||
|
}
|
||||||
|
|
||||||
|
customMatchers() {
|
||||||
|
return this.forCurrentRunable_(
|
||||||
|
'Matchers must be added in a before function or a spec'
|
||||||
|
).customMatchers;
|
||||||
|
}
|
||||||
|
|
||||||
|
addCustomMatchers(matchersToAdd) {
|
||||||
|
const matchers = this.customMatchers();
|
||||||
|
|
||||||
|
for (const name in matchersToAdd) {
|
||||||
|
matchers[name] = matchersToAdd[name];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
customAsyncMatchers() {
|
||||||
|
return this.forCurrentRunable_(
|
||||||
|
'Async Matchers must be added in a before function or a spec'
|
||||||
|
).customAsyncMatchers;
|
||||||
|
}
|
||||||
|
|
||||||
|
addCustomAsyncMatchers(matchersToAdd) {
|
||||||
|
const matchers = this.customAsyncMatchers();
|
||||||
|
|
||||||
|
for (const name in matchersToAdd) {
|
||||||
|
matchers[name] = matchersToAdd[name];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
customObjectFormatters() {
|
||||||
|
return this.forCurrentRunable_(
|
||||||
|
'Custom object formatters must be added in a before function or a spec'
|
||||||
|
).customObjectFormatters;
|
||||||
|
}
|
||||||
|
|
||||||
|
makePrettyPrinter() {
|
||||||
|
return j$.makePrettyPrinter(this.customObjectFormatters());
|
||||||
|
}
|
||||||
|
|
||||||
|
makeMatchersUtil() {
|
||||||
|
if (this.getCurrentRunableId_()) {
|
||||||
|
return new j$.MatchersUtil({
|
||||||
|
customTesters: this.customEqualityTesters(),
|
||||||
|
pp: this.makePrettyPrinter()
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
return new j$.MatchersUtil({ pp: j$.basicPrettyPrinter_ });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
forCurrentRunable_(errorMsg) {
|
||||||
|
const resources = this.byRunableId_[this.getCurrentRunableId_()];
|
||||||
|
|
||||||
|
if (!resources && errorMsg) {
|
||||||
|
throw new Error(errorMsg);
|
||||||
|
}
|
||||||
|
|
||||||
|
return resources;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return RunableResources;
|
||||||
|
};
|
||||||
240
src/core/Runner.js
Normal file
240
src/core/Runner.js
Normal file
@@ -0,0 +1,240 @@
|
|||||||
|
getJasmineRequireObj().Runner = function(j$) {
|
||||||
|
class Runner {
|
||||||
|
constructor(options) {
|
||||||
|
this.topSuite_ = options.topSuite;
|
||||||
|
this.totalSpecsDefined_ = options.totalSpecsDefined;
|
||||||
|
this.focusedRunables_ = options.focusedRunables;
|
||||||
|
this.runableResources_ = options.runableResources;
|
||||||
|
this.queueRunnerFactory_ = options.queueRunnerFactory;
|
||||||
|
this.reporter_ = options.reporter;
|
||||||
|
this.getConfig_ = options.getConfig;
|
||||||
|
this.reportSpecDone_ = options.reportSpecDone;
|
||||||
|
this.hasFailures = false;
|
||||||
|
this.executedBefore_ = false;
|
||||||
|
|
||||||
|
this.currentlyExecutingSuites_ = [];
|
||||||
|
this.currentSpec = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
currentRunable() {
|
||||||
|
return this.currentSpec || this.currentSuite();
|
||||||
|
}
|
||||||
|
|
||||||
|
currentSuite() {
|
||||||
|
return this.currentlyExecutingSuites_[
|
||||||
|
this.currentlyExecutingSuites_.length - 1
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Although execute returns a promise, it isn't async for backwards
|
||||||
|
// compatibility: The "Invalid order" exception needs to be propagated
|
||||||
|
// synchronously from Env#execute.
|
||||||
|
// TODO: make this and Env#execute async in the next major release
|
||||||
|
execute(runablesToRun) {
|
||||||
|
if (this.executedBefore_) {
|
||||||
|
this.topSuite_.reset();
|
||||||
|
}
|
||||||
|
this.executedBefore_ = true;
|
||||||
|
|
||||||
|
this.hasFailures = false;
|
||||||
|
const totalSpecsDefined = this.totalSpecsDefined_();
|
||||||
|
const focusedRunables = this.focusedRunables_();
|
||||||
|
const config = this.getConfig_();
|
||||||
|
|
||||||
|
if (!runablesToRun) {
|
||||||
|
if (focusedRunables.length) {
|
||||||
|
runablesToRun = focusedRunables;
|
||||||
|
} else {
|
||||||
|
runablesToRun = [this.topSuite_.id];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const order = new j$.Order({
|
||||||
|
random: config.random,
|
||||||
|
seed: config.seed
|
||||||
|
});
|
||||||
|
|
||||||
|
const processor = new j$.TreeProcessor({
|
||||||
|
tree: this.topSuite_,
|
||||||
|
runnableIds: runablesToRun,
|
||||||
|
queueRunnerFactory: options => {
|
||||||
|
if (options.isLeaf) {
|
||||||
|
// A spec
|
||||||
|
options.SkipPolicy = j$.CompleteOnFirstErrorSkipPolicy;
|
||||||
|
} else {
|
||||||
|
// A suite
|
||||||
|
if (config.stopOnSpecFailure) {
|
||||||
|
options.SkipPolicy = j$.CompleteOnFirstErrorSkipPolicy;
|
||||||
|
} else {
|
||||||
|
options.SkipPolicy = j$.SkipAfterBeforeAllErrorPolicy;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.queueRunnerFactory_(options);
|
||||||
|
},
|
||||||
|
failSpecWithNoExpectations: config.failSpecWithNoExpectations,
|
||||||
|
nodeStart: (suite, next) => {
|
||||||
|
this.currentlyExecutingSuites_.push(suite);
|
||||||
|
this.runableResources_.initForRunable(suite.id, suite.parentSuite.id);
|
||||||
|
this.reporter_.suiteStarted(suite.result, next);
|
||||||
|
suite.startTimer();
|
||||||
|
},
|
||||||
|
nodeComplete: (suite, result, next) => {
|
||||||
|
if (suite !== this.currentSuite()) {
|
||||||
|
throw new Error('Tried to complete the wrong suite');
|
||||||
|
}
|
||||||
|
|
||||||
|
this.runableResources_.clearForRunable(suite.id);
|
||||||
|
this.currentlyExecutingSuites_.pop();
|
||||||
|
|
||||||
|
if (result.status === 'failed') {
|
||||||
|
this.hasFailures = true;
|
||||||
|
}
|
||||||
|
suite.endTimer();
|
||||||
|
|
||||||
|
if (suite.hadBeforeAllFailure) {
|
||||||
|
this.reportChildrenOfBeforeAllFailure_(suite).then(() => {
|
||||||
|
this.reportSuiteDone_(suite, result, next);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
this.reportSuiteDone_(suite, result, next);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
orderChildren: function(node) {
|
||||||
|
return order.sort(node.children);
|
||||||
|
},
|
||||||
|
excludeNode: function(spec) {
|
||||||
|
return !config.specFilter(spec);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!processor.processTree().valid) {
|
||||||
|
throw new Error(
|
||||||
|
'Invalid order: would cause a beforeAll or afterAll to be run multiple times'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.runableResources_.initForRunable(this.topSuite_.id);
|
||||||
|
const jasmineTimer = new j$.Timer();
|
||||||
|
jasmineTimer.start();
|
||||||
|
|
||||||
|
return new Promise(resolve => {
|
||||||
|
/**
|
||||||
|
* Information passed to the {@link Reporter#jasmineStarted} event.
|
||||||
|
* @typedef JasmineStartedInfo
|
||||||
|
* @property {Int} totalSpecsDefined - The total number of specs defined in this suite.
|
||||||
|
* @property {Order} order - Information about the ordering (random or not) of this execution of the suite.
|
||||||
|
* @since 2.0.0
|
||||||
|
*/
|
||||||
|
this.reporter_.jasmineStarted(
|
||||||
|
{
|
||||||
|
totalSpecsDefined,
|
||||||
|
order: order
|
||||||
|
},
|
||||||
|
() => {
|
||||||
|
this.currentlyExecutingSuites_.push(this.topSuite_);
|
||||||
|
|
||||||
|
processor.execute(() => {
|
||||||
|
(async () => {
|
||||||
|
if (this.topSuite_.hadBeforeAllFailure) {
|
||||||
|
await this.reportChildrenOfBeforeAllFailure_(this.topSuite_);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.runableResources_.clearForRunable(this.topSuite_.id);
|
||||||
|
this.currentlyExecutingSuites_.pop();
|
||||||
|
let overallStatus, incompleteReason;
|
||||||
|
|
||||||
|
if (
|
||||||
|
this.hasFailures ||
|
||||||
|
this.topSuite_.result.failedExpectations.length > 0
|
||||||
|
) {
|
||||||
|
overallStatus = 'failed';
|
||||||
|
} else if (focusedRunables.length > 0) {
|
||||||
|
overallStatus = 'incomplete';
|
||||||
|
incompleteReason = 'fit() or fdescribe() was found';
|
||||||
|
} else if (totalSpecsDefined === 0) {
|
||||||
|
overallStatus = 'incomplete';
|
||||||
|
incompleteReason = 'No specs found';
|
||||||
|
} else {
|
||||||
|
overallStatus = 'passed';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Information passed to the {@link Reporter#jasmineDone} event.
|
||||||
|
* @typedef JasmineDoneInfo
|
||||||
|
* @property {OverallStatus} overallStatus - The overall result of the suite: 'passed', 'failed', or 'incomplete'.
|
||||||
|
* @property {Int} totalTime - The total time (in ms) that it took to execute the suite
|
||||||
|
* @property {IncompleteReason} incompleteReason - Explanation of why the suite was incomplete.
|
||||||
|
* @property {Order} order - Information about the ordering (random or not) of this execution of the suite.
|
||||||
|
* @property {Expectation[]} failedExpectations - List of expectations that failed in an {@link afterAll} at the global level.
|
||||||
|
* @property {Expectation[]} deprecationWarnings - List of deprecation warnings that occurred at the global level.
|
||||||
|
* @since 2.4.0
|
||||||
|
*/
|
||||||
|
const jasmineDoneInfo = {
|
||||||
|
overallStatus: overallStatus,
|
||||||
|
totalTime: jasmineTimer.elapsed(),
|
||||||
|
incompleteReason: incompleteReason,
|
||||||
|
order: order,
|
||||||
|
failedExpectations: this.topSuite_.result.failedExpectations,
|
||||||
|
deprecationWarnings: this.topSuite_.result.deprecationWarnings
|
||||||
|
};
|
||||||
|
this.topSuite_.reportedDone = true;
|
||||||
|
this.reporter_.jasmineDone(jasmineDoneInfo, function() {
|
||||||
|
resolve(jasmineDoneInfo);
|
||||||
|
});
|
||||||
|
})();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
reportSuiteDone_(suite, result, next) {
|
||||||
|
suite.reportedDone = true;
|
||||||
|
this.reporter_.suiteDone(result, next);
|
||||||
|
}
|
||||||
|
|
||||||
|
async reportChildrenOfBeforeAllFailure_(suite) {
|
||||||
|
for (const child of suite.children) {
|
||||||
|
if (child instanceof j$.Suite) {
|
||||||
|
await new Promise(resolve => {
|
||||||
|
this.reporter_.suiteStarted(child.result, resolve);
|
||||||
|
});
|
||||||
|
await this.reportChildrenOfBeforeAllFailure_(child);
|
||||||
|
|
||||||
|
// Marking the suite passed is consistent with how suites that
|
||||||
|
// contain failed specs but no suite-level failures are reported.
|
||||||
|
child.result.status = 'passed';
|
||||||
|
|
||||||
|
await new Promise(resolve => {
|
||||||
|
this.reporter_.suiteDone(child.result, resolve);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
/* a spec */
|
||||||
|
await new Promise(resolve => {
|
||||||
|
this.reporter_.specStarted(child.result, resolve);
|
||||||
|
});
|
||||||
|
|
||||||
|
child.addExpectationResult(
|
||||||
|
false,
|
||||||
|
{
|
||||||
|
passed: false,
|
||||||
|
message:
|
||||||
|
'Not run because a beforeAll function failed. The ' +
|
||||||
|
'beforeAll failure will be reported on the suite that ' +
|
||||||
|
'caused it.'
|
||||||
|
},
|
||||||
|
true
|
||||||
|
);
|
||||||
|
child.result.status = 'failed';
|
||||||
|
|
||||||
|
await new Promise(resolve => {
|
||||||
|
this.reportSpecDone_(child, child.result, resolve);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Runner;
|
||||||
|
};
|
||||||
113
src/core/Spec.js
113
src/core/Spec.js
@@ -1,28 +1,9 @@
|
|||||||
getJasmineRequireObj().Spec = function(j$) {
|
getJasmineRequireObj().Spec = function(j$) {
|
||||||
/**
|
|
||||||
* @interface Spec
|
|
||||||
* @see Configuration#specFilter
|
|
||||||
* @since 2.0.0
|
|
||||||
*/
|
|
||||||
function Spec(attrs) {
|
function Spec(attrs) {
|
||||||
this.expectationFactory = attrs.expectationFactory;
|
this.expectationFactory = attrs.expectationFactory;
|
||||||
this.asyncExpectationFactory = attrs.asyncExpectationFactory;
|
this.asyncExpectationFactory = attrs.asyncExpectationFactory;
|
||||||
this.resultCallback = attrs.resultCallback || function() {};
|
this.resultCallback = attrs.resultCallback || function() {};
|
||||||
/**
|
|
||||||
* The unique ID of this spec.
|
|
||||||
* @name Spec#id
|
|
||||||
* @readonly
|
|
||||||
* @type {string}
|
|
||||||
* @since 2.0.0
|
|
||||||
*/
|
|
||||||
this.id = attrs.id;
|
this.id = attrs.id;
|
||||||
/**
|
|
||||||
* The description passed to the {@link it} that created this spec.
|
|
||||||
* @name Spec#description
|
|
||||||
* @readonly
|
|
||||||
* @type {string}
|
|
||||||
* @since 2.0.0
|
|
||||||
*/
|
|
||||||
this.description = attrs.description || '';
|
this.description = attrs.description || '';
|
||||||
this.queueableFn = attrs.queueableFn;
|
this.queueableFn = attrs.queueableFn;
|
||||||
this.beforeAndAfterFns =
|
this.beforeAndAfterFns =
|
||||||
@@ -43,10 +24,7 @@ getJasmineRequireObj().Spec = function(j$) {
|
|||||||
function() {
|
function() {
|
||||||
return '';
|
return '';
|
||||||
};
|
};
|
||||||
this.expectationResultFactory =
|
|
||||||
attrs.expectationResultFactory || function() {};
|
|
||||||
this.onLateError = attrs.onLateError || function() {};
|
this.onLateError = attrs.onLateError || function() {};
|
||||||
this.queueRunnerFactory = attrs.queueRunnerFactory || function() {};
|
|
||||||
this.catchingExceptions =
|
this.catchingExceptions =
|
||||||
attrs.catchingExceptions ||
|
attrs.catchingExceptions ||
|
||||||
function() {
|
function() {
|
||||||
@@ -86,14 +64,26 @@ getJasmineRequireObj().Spec = function(j$) {
|
|||||||
properties: null,
|
properties: null,
|
||||||
debugLogs: null
|
debugLogs: null
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.reportedDone = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Spec.prototype.addExpectationResult = function(passed, data, isError) {
|
Spec.prototype.addExpectationResult = function(passed, data, isError) {
|
||||||
var expectationResult = this.expectationResultFactory(data);
|
const expectationResult = j$.buildExpectationResult(data);
|
||||||
|
|
||||||
if (passed) {
|
if (passed) {
|
||||||
this.result.passedExpectations.push(expectationResult);
|
this.result.passedExpectations.push(expectationResult);
|
||||||
} else {
|
} else {
|
||||||
this.result.failedExpectations.push(expectationResult);
|
if (this.reportedDone) {
|
||||||
|
this.onLateError(expectationResult);
|
||||||
|
} else {
|
||||||
|
this.result.failedExpectations.push(expectationResult);
|
||||||
|
|
||||||
|
// TODO: refactor so that we don't need to override cached status
|
||||||
|
if (this.result.status) {
|
||||||
|
this.result.status = 'failed';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (this.throwOnExpectationFailure && !isError) {
|
if (this.throwOnExpectationFailure && !isError) {
|
||||||
throw new j$.errors.ExpectationFailed();
|
throw new j$.errors.ExpectationFailed();
|
||||||
@@ -114,56 +104,57 @@ getJasmineRequireObj().Spec = function(j$) {
|
|||||||
return this.asyncExpectationFactory(actual, this);
|
return this.asyncExpectationFactory(actual, this);
|
||||||
};
|
};
|
||||||
|
|
||||||
Spec.prototype.execute = function(onComplete, excluded, failSpecWithNoExp) {
|
Spec.prototype.execute = function(
|
||||||
var self = this;
|
queueRunnerFactory,
|
||||||
|
onComplete,
|
||||||
var onStart = {
|
excluded,
|
||||||
fn: function(done) {
|
failSpecWithNoExp
|
||||||
self.timer.start();
|
) {
|
||||||
self.onStart(self, done);
|
const onStart = {
|
||||||
|
fn: done => {
|
||||||
|
this.timer.start();
|
||||||
|
this.onStart(this, done);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var complete = {
|
const complete = {
|
||||||
fn: function(done) {
|
fn: done => {
|
||||||
if (self.autoCleanClosures) {
|
if (this.autoCleanClosures) {
|
||||||
self.queueableFn.fn = null;
|
this.queueableFn.fn = null;
|
||||||
}
|
}
|
||||||
self.result.status = self.status(excluded, failSpecWithNoExp);
|
this.result.status = this.status(excluded, failSpecWithNoExp);
|
||||||
self.result.duration = self.timer.elapsed();
|
this.result.duration = this.timer.elapsed();
|
||||||
|
|
||||||
if (self.result.status !== 'failed') {
|
if (this.result.status !== 'failed') {
|
||||||
self.result.debugLogs = null;
|
this.result.debugLogs = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.resultCallback(self.result, done);
|
this.resultCallback(this.result, done);
|
||||||
},
|
},
|
||||||
type: 'specCleanup'
|
type: 'specCleanup'
|
||||||
};
|
};
|
||||||
|
|
||||||
var fns = this.beforeAndAfterFns();
|
const fns = this.beforeAndAfterFns();
|
||||||
|
|
||||||
var runnerConfig = {
|
const runnerConfig = {
|
||||||
isLeaf: true,
|
isLeaf: true,
|
||||||
queueableFns: [...fns.befores, this.queueableFn, ...fns.afters],
|
queueableFns: [...fns.befores, this.queueableFn, ...fns.afters],
|
||||||
onException: function() {
|
onException: e => this.handleException(e),
|
||||||
self.onException.apply(self, arguments);
|
onMultipleDone: () => {
|
||||||
},
|
|
||||||
onMultipleDone: function() {
|
|
||||||
// Issue a deprecation. Include the context ourselves and pass
|
// Issue a deprecation. Include the context ourselves and pass
|
||||||
// ignoreRunnable: true, since getting here always means that we've already
|
// ignoreRunnable: true, since getting here always means that we've already
|
||||||
// moved on and the current runnable isn't the one that caused the problem.
|
// moved on and the current runnable isn't the one that caused the problem.
|
||||||
self.onLateError(
|
this.onLateError(
|
||||||
new Error(
|
new Error(
|
||||||
'An asynchronous spec, beforeEach, or afterEach function called its ' +
|
'An asynchronous spec, beforeEach, or afterEach function called its ' +
|
||||||
"'done' callback more than once.\n(in spec: " +
|
"'done' callback more than once.\n(in spec: " +
|
||||||
self.getFullName() +
|
this.getFullName() +
|
||||||
')'
|
')'
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
onComplete: function() {
|
onComplete: () => {
|
||||||
if (self.result.status === 'failed') {
|
if (this.result.status === 'failed') {
|
||||||
onComplete(new j$.StopExecutionError('spec failed'));
|
onComplete(new j$.StopExecutionError('spec failed'));
|
||||||
} else {
|
} else {
|
||||||
onComplete();
|
onComplete();
|
||||||
@@ -180,7 +171,7 @@ getJasmineRequireObj().Spec = function(j$) {
|
|||||||
runnerConfig.queueableFns.unshift(onStart);
|
runnerConfig.queueableFns.unshift(onStart);
|
||||||
runnerConfig.queueableFns.push(complete);
|
runnerConfig.queueableFns.push(complete);
|
||||||
|
|
||||||
this.queueRunnerFactory(runnerConfig);
|
queueRunnerFactory(runnerConfig);
|
||||||
};
|
};
|
||||||
|
|
||||||
Spec.prototype.reset = function() {
|
Spec.prototype.reset = function() {
|
||||||
@@ -197,9 +188,10 @@ getJasmineRequireObj().Spec = function(j$) {
|
|||||||
debugLogs: null
|
debugLogs: null
|
||||||
};
|
};
|
||||||
this.markedPending = this.markedExcluding;
|
this.markedPending = this.markedExcluding;
|
||||||
|
this.reportedDone = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
Spec.prototype.onException = function onException(e) {
|
Spec.prototype.handleException = function handleException(e) {
|
||||||
if (Spec.isPendingSpecException(e)) {
|
if (Spec.isPendingSpecException(e)) {
|
||||||
this.pend(extractCustomPendingMessage(e));
|
this.pend(extractCustomPendingMessage(e));
|
||||||
return;
|
return;
|
||||||
@@ -273,13 +265,6 @@ getJasmineRequireObj().Spec = function(j$) {
|
|||||||
return 'passed';
|
return 'passed';
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* The full description including all ancestors of this spec.
|
|
||||||
* @name Spec#getFullName
|
|
||||||
* @function
|
|
||||||
* @returns {string}
|
|
||||||
* @since 2.0.0
|
|
||||||
*/
|
|
||||||
Spec.prototype.getFullName = function() {
|
Spec.prototype.getFullName = function() {
|
||||||
return this.getSpecName(this);
|
return this.getSpecName(this);
|
||||||
};
|
};
|
||||||
@@ -289,7 +274,7 @@ getJasmineRequireObj().Spec = function(j$) {
|
|||||||
deprecation = { message: deprecation };
|
deprecation = { message: deprecation };
|
||||||
}
|
}
|
||||||
this.result.deprecationWarnings.push(
|
this.result.deprecationWarnings.push(
|
||||||
this.expectationResultFactory(deprecation)
|
j$.buildExpectationResult(deprecation)
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -310,8 +295,8 @@ getJasmineRequireObj().Spec = function(j$) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
var extractCustomPendingMessage = function(e) {
|
const extractCustomPendingMessage = function(e) {
|
||||||
var fullMessage = e.toString(),
|
const fullMessage = e.toString(),
|
||||||
boilerplateStart = fullMessage.indexOf(Spec.pendingSpecExceptionMessage),
|
boilerplateStart = fullMessage.indexOf(Spec.pendingSpecExceptionMessage),
|
||||||
boilerplateEnd =
|
boilerplateEnd =
|
||||||
boilerplateStart + Spec.pendingSpecExceptionMessage.length;
|
boilerplateStart + Spec.pendingSpecExceptionMessage.length;
|
||||||
@@ -332,6 +317,7 @@ getJasmineRequireObj().Spec = function(j$) {
|
|||||||
/**
|
/**
|
||||||
* @interface Spec
|
* @interface Spec
|
||||||
* @see Configuration#specFilter
|
* @see Configuration#specFilter
|
||||||
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
Object.defineProperty(Spec.prototype, 'metadata', {
|
Object.defineProperty(Spec.prototype, 'metadata', {
|
||||||
get: function() {
|
get: function() {
|
||||||
@@ -342,6 +328,7 @@ getJasmineRequireObj().Spec = function(j$) {
|
|||||||
* @name Spec#id
|
* @name Spec#id
|
||||||
* @readonly
|
* @readonly
|
||||||
* @type {string}
|
* @type {string}
|
||||||
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
id: this.id,
|
id: this.id,
|
||||||
|
|
||||||
@@ -350,6 +337,7 @@ getJasmineRequireObj().Spec = function(j$) {
|
|||||||
* @name Spec#description
|
* @name Spec#description
|
||||||
* @readonly
|
* @readonly
|
||||||
* @type {string}
|
* @type {string}
|
||||||
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
description: this.description,
|
description: this.description,
|
||||||
|
|
||||||
@@ -358,6 +346,7 @@ getJasmineRequireObj().Spec = function(j$) {
|
|||||||
* @name Spec#getFullName
|
* @name Spec#getFullName
|
||||||
* @function
|
* @function
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
getFullName: this.getFullName.bind(this)
|
getFullName: this.getFullName.bind(this)
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
getJasmineRequireObj().Spy = function(j$) {
|
getJasmineRequireObj().Spy = function(j$) {
|
||||||
var nextOrder = (function() {
|
const nextOrder = (function() {
|
||||||
var order = 0;
|
let order = 0;
|
||||||
|
|
||||||
return function() {
|
return function() {
|
||||||
return order++;
|
return order++;
|
||||||
@@ -15,9 +15,29 @@ getJasmineRequireObj().Spy = function(j$) {
|
|||||||
* @hideconstructor
|
* @hideconstructor
|
||||||
*/
|
*/
|
||||||
function Spy(name, matchersUtil, optionals) {
|
function Spy(name, matchersUtil, optionals) {
|
||||||
|
const spy = function(context, args, invokeNew) {
|
||||||
|
/**
|
||||||
|
* @name Spy.callData
|
||||||
|
* @property {object} object - `this` context for the invocation.
|
||||||
|
* @property {number} invocationOrder - Order of the invocation.
|
||||||
|
* @property {Array} args - The arguments passed for this invocation.
|
||||||
|
* @property returnValue - The value that was returned from this invocation.
|
||||||
|
*/
|
||||||
|
const callData = {
|
||||||
|
object: context,
|
||||||
|
invocationOrder: nextOrder(),
|
||||||
|
args: Array.prototype.slice.apply(args)
|
||||||
|
};
|
||||||
|
|
||||||
|
callTracker.track(callData);
|
||||||
|
const returnValue = strategyDispatcher.exec(context, args, invokeNew);
|
||||||
|
callData.returnValue = returnValue;
|
||||||
|
|
||||||
|
return returnValue;
|
||||||
|
};
|
||||||
const { originalFn, customStrategies, defaultStrategyFn } = optionals || {};
|
const { originalFn, customStrategies, defaultStrategyFn } = optionals || {};
|
||||||
|
|
||||||
var numArgs = typeof originalFn === 'function' ? originalFn.length : 0,
|
const numArgs = typeof originalFn === 'function' ? originalFn.length : 0,
|
||||||
wrapper = makeFunc(numArgs, function(context, args, invokeNew) {
|
wrapper = makeFunc(numArgs, function(context, args, invokeNew) {
|
||||||
return spy(context, args, invokeNew);
|
return spy(context, args, invokeNew);
|
||||||
}),
|
}),
|
||||||
@@ -32,27 +52,7 @@ getJasmineRequireObj().Spy = function(j$) {
|
|||||||
},
|
},
|
||||||
matchersUtil
|
matchersUtil
|
||||||
),
|
),
|
||||||
callTracker = new j$.CallTracker(),
|
callTracker = new j$.CallTracker();
|
||||||
spy = function(context, args, invokeNew) {
|
|
||||||
/**
|
|
||||||
* @name Spy.callData
|
|
||||||
* @property {object} object - `this` context for the invocation.
|
|
||||||
* @property {number} invocationOrder - Order of the invocation.
|
|
||||||
* @property {Array} args - The arguments passed for this invocation.
|
|
||||||
* @property returnValue - The value that was returned from this invocation.
|
|
||||||
*/
|
|
||||||
var callData = {
|
|
||||||
object: context,
|
|
||||||
invocationOrder: nextOrder(),
|
|
||||||
args: Array.prototype.slice.apply(args)
|
|
||||||
};
|
|
||||||
|
|
||||||
callTracker.track(callData);
|
|
||||||
var returnValue = strategyDispatcher.exec(context, args, invokeNew);
|
|
||||||
callData.returnValue = returnValue;
|
|
||||||
|
|
||||||
return returnValue;
|
|
||||||
};
|
|
||||||
|
|
||||||
function makeFunc(length, fn) {
|
function makeFunc(length, fn) {
|
||||||
switch (length) {
|
switch (length) {
|
||||||
@@ -99,7 +99,7 @@ getJasmineRequireObj().Spy = function(j$) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var prop in originalFn) {
|
for (const prop in originalFn) {
|
||||||
if (prop === 'and' || prop === 'calls') {
|
if (prop === 'and' || prop === 'calls') {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
"Jasmine spies would overwrite the 'and' and 'calls' properties on the object being spied upon"
|
"Jasmine spies would overwrite the 'and' and 'calls' properties on the object being spied upon"
|
||||||
@@ -144,15 +144,15 @@ getJasmineRequireObj().Spy = function(j$) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function SpyStrategyDispatcher(strategyArgs, matchersUtil) {
|
function SpyStrategyDispatcher(strategyArgs, matchersUtil) {
|
||||||
var baseStrategy = new j$.SpyStrategy(strategyArgs);
|
const baseStrategy = new j$.SpyStrategy(strategyArgs);
|
||||||
var argsStrategies = new StrategyDict(function() {
|
const argsStrategies = new StrategyDict(function() {
|
||||||
return new j$.SpyStrategy(strategyArgs);
|
return new j$.SpyStrategy(strategyArgs);
|
||||||
}, matchersUtil);
|
}, matchersUtil);
|
||||||
|
|
||||||
this.and = baseStrategy;
|
this.and = baseStrategy;
|
||||||
|
|
||||||
this.exec = function(spy, args, invokeNew) {
|
this.exec = function(spy, args, invokeNew) {
|
||||||
var strategy = argsStrategies.get(args);
|
let strategy = argsStrategies.get(args);
|
||||||
|
|
||||||
if (!strategy) {
|
if (!strategy) {
|
||||||
if (argsStrategies.any() && !baseStrategy.isConfigured()) {
|
if (argsStrategies.any() && !baseStrategy.isConfigured()) {
|
||||||
@@ -187,7 +187,7 @@ getJasmineRequireObj().Spy = function(j$) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
StrategyDict.prototype.getOrCreate = function(args) {
|
StrategyDict.prototype.getOrCreate = function(args) {
|
||||||
var strategy = this.get(args);
|
let strategy = this.get(args);
|
||||||
|
|
||||||
if (!strategy) {
|
if (!strategy) {
|
||||||
strategy = this.strategyFactory();
|
strategy = this.strategyFactory();
|
||||||
@@ -201,9 +201,7 @@ getJasmineRequireObj().Spy = function(j$) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
StrategyDict.prototype.get = function(args) {
|
StrategyDict.prototype.get = function(args) {
|
||||||
var i;
|
for (let i = 0; i < this.strategies.length; i++) {
|
||||||
|
|
||||||
for (i = 0; i < this.strategies.length; i++) {
|
|
||||||
if (this.matchersUtil.equals(args, this.strategies[i].args)) {
|
if (this.matchersUtil.equals(args, this.strategies[i].args)) {
|
||||||
return this.strategies[i].strategy;
|
return this.strategies[i].strategy;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,9 +4,12 @@ getJasmineRequireObj().SpyFactory = function(j$) {
|
|||||||
getDefaultStrategyFn,
|
getDefaultStrategyFn,
|
||||||
getMatchersUtil
|
getMatchersUtil
|
||||||
) {
|
) {
|
||||||
var self = this;
|
|
||||||
|
|
||||||
this.createSpy = function(name, originalFn) {
|
this.createSpy = function(name, originalFn) {
|
||||||
|
if (j$.isFunction_(name) && originalFn === undefined) {
|
||||||
|
originalFn = name;
|
||||||
|
name = originalFn.name;
|
||||||
|
}
|
||||||
|
|
||||||
return j$.Spy(name, getMatchersUtil(), {
|
return j$.Spy(name, getMatchersUtil(), {
|
||||||
originalFn,
|
originalFn,
|
||||||
customStrategies: getCustomStrategies(),
|
customStrategies: getCustomStrategies(),
|
||||||
@@ -15,7 +18,7 @@ getJasmineRequireObj().SpyFactory = function(j$) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.createSpyObj = function(baseName, methodNames, propertyNames) {
|
this.createSpyObj = function(baseName, methodNames, propertyNames) {
|
||||||
var baseNameIsCollection =
|
const baseNameIsCollection =
|
||||||
j$.isObject_(baseName) || j$.isArray_(baseName);
|
j$.isObject_(baseName) || j$.isArray_(baseName);
|
||||||
|
|
||||||
if (baseNameIsCollection) {
|
if (baseNameIsCollection) {
|
||||||
@@ -24,25 +27,24 @@ getJasmineRequireObj().SpyFactory = function(j$) {
|
|||||||
baseName = 'unknown';
|
baseName = 'unknown';
|
||||||
}
|
}
|
||||||
|
|
||||||
var obj = {};
|
const obj = {};
|
||||||
var spy, descriptor;
|
|
||||||
|
|
||||||
var methods = normalizeKeyValues(methodNames);
|
const methods = normalizeKeyValues(methodNames);
|
||||||
for (var i = 0; i < methods.length; i++) {
|
for (let i = 0; i < methods.length; i++) {
|
||||||
spy = obj[methods[i][0]] = self.createSpy(
|
const spy = (obj[methods[i][0]] = this.createSpy(
|
||||||
baseName + '.' + methods[i][0]
|
baseName + '.' + methods[i][0]
|
||||||
);
|
));
|
||||||
if (methods[i].length > 1) {
|
if (methods[i].length > 1) {
|
||||||
spy.and.returnValue(methods[i][1]);
|
spy.and.returnValue(methods[i][1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var properties = normalizeKeyValues(propertyNames);
|
const properties = normalizeKeyValues(propertyNames);
|
||||||
for (var i = 0; i < properties.length; i++) {
|
for (let i = 0; i < properties.length; i++) {
|
||||||
descriptor = {
|
const descriptor = {
|
||||||
enumerable: true,
|
enumerable: true,
|
||||||
get: self.createSpy(baseName + '.' + properties[i][0] + '.get'),
|
get: this.createSpy(baseName + '.' + properties[i][0] + '.get'),
|
||||||
set: self.createSpy(baseName + '.' + properties[i][0] + '.set')
|
set: this.createSpy(baseName + '.' + properties[i][0] + '.set')
|
||||||
};
|
};
|
||||||
if (properties[i].length > 1) {
|
if (properties[i].length > 1) {
|
||||||
descriptor.get.and.returnValue(properties[i][1]);
|
descriptor.get.and.returnValue(properties[i][1]);
|
||||||
@@ -60,13 +62,13 @@ getJasmineRequireObj().SpyFactory = function(j$) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function normalizeKeyValues(object) {
|
function normalizeKeyValues(object) {
|
||||||
var result = [];
|
const result = [];
|
||||||
if (j$.isArray_(object)) {
|
if (j$.isArray_(object)) {
|
||||||
for (var i = 0; i < object.length; i++) {
|
for (let i = 0; i < object.length; i++) {
|
||||||
result.push([object[i]]);
|
result.push([object[i]]);
|
||||||
}
|
}
|
||||||
} else if (j$.isObject_(object)) {
|
} else if (j$.isObject_(object)) {
|
||||||
for (var key in object) {
|
for (const key in object) {
|
||||||
if (object.hasOwnProperty(key)) {
|
if (object.hasOwnProperty(key)) {
|
||||||
result.push([key, object[key]]);
|
result.push([key, object[key]]);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,18 @@
|
|||||||
getJasmineRequireObj().SpyRegistry = function(j$) {
|
getJasmineRequireObj().SpyRegistry = function(j$) {
|
||||||
var spyOnMsg = j$.formatErrorMsg('<spyOn>', 'spyOn(<object>, <methodName>)');
|
const spyOnMsg = j$.formatErrorMsg(
|
||||||
var spyOnPropertyMsg = j$.formatErrorMsg(
|
'<spyOn>',
|
||||||
|
'spyOn(<object>, <methodName>)'
|
||||||
|
);
|
||||||
|
const spyOnPropertyMsg = j$.formatErrorMsg(
|
||||||
'<spyOnProperty>',
|
'<spyOnProperty>',
|
||||||
'spyOnProperty(<object>, <propName>, [accessType])'
|
'spyOnProperty(<object>, <propName>, [accessType])'
|
||||||
);
|
);
|
||||||
|
|
||||||
function SpyRegistry(options) {
|
function SpyRegistry(options) {
|
||||||
options = options || {};
|
options = options || {};
|
||||||
var global = options.global || j$.getGlobal();
|
const global = options.global || j$.getGlobal();
|
||||||
var createSpy = options.createSpy;
|
const createSpy = options.createSpy;
|
||||||
var currentSpies =
|
const currentSpies =
|
||||||
options.currentSpies ||
|
options.currentSpies ||
|
||||||
function() {
|
function() {
|
||||||
return [];
|
return [];
|
||||||
@@ -20,7 +23,7 @@ getJasmineRequireObj().SpyRegistry = function(j$) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.spyOn = function(obj, methodName) {
|
this.spyOn = function(obj, methodName) {
|
||||||
var getErrorMsg = spyOnMsg;
|
const getErrorMsg = spyOnMsg;
|
||||||
|
|
||||||
if (j$.util.isUndefined(obj) || obj === null) {
|
if (j$.util.isUndefined(obj) || obj === null) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
@@ -48,7 +51,7 @@ getJasmineRequireObj().SpyRegistry = function(j$) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var descriptor = Object.getOwnPropertyDescriptor(obj, methodName);
|
const descriptor = Object.getOwnPropertyDescriptor(obj, methodName);
|
||||||
|
|
||||||
if (descriptor && !(descriptor.writable || descriptor.set)) {
|
if (descriptor && !(descriptor.writable || descriptor.set)) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
@@ -56,9 +59,9 @@ getJasmineRequireObj().SpyRegistry = function(j$) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
var originalMethod = obj[methodName],
|
const originalMethod = obj[methodName];
|
||||||
spiedMethod = createSpy(methodName, originalMethod),
|
const spiedMethod = createSpy(methodName, originalMethod);
|
||||||
restoreStrategy;
|
let restoreStrategy;
|
||||||
|
|
||||||
if (
|
if (
|
||||||
Object.prototype.hasOwnProperty.call(obj, methodName) ||
|
Object.prototype.hasOwnProperty.call(obj, methodName) ||
|
||||||
@@ -85,7 +88,7 @@ getJasmineRequireObj().SpyRegistry = function(j$) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.spyOnProperty = function(obj, propertyName, accessType) {
|
this.spyOnProperty = function(obj, propertyName, accessType) {
|
||||||
var getErrorMsg = spyOnPropertyMsg;
|
const getErrorMsg = spyOnPropertyMsg;
|
||||||
|
|
||||||
accessType = accessType || 'get';
|
accessType = accessType || 'get';
|
||||||
|
|
||||||
@@ -103,7 +106,7 @@ getJasmineRequireObj().SpyRegistry = function(j$) {
|
|||||||
throw new Error(getErrorMsg('No property name supplied'));
|
throw new Error(getErrorMsg('No property name supplied'));
|
||||||
}
|
}
|
||||||
|
|
||||||
var descriptor = j$.util.getPropertyDescriptor(obj, propertyName);
|
const descriptor = j$.util.getPropertyDescriptor(obj, propertyName);
|
||||||
|
|
||||||
if (!descriptor) {
|
if (!descriptor) {
|
||||||
throw new Error(getErrorMsg(propertyName + ' property does not exist'));
|
throw new Error(getErrorMsg(propertyName + ' property does not exist'));
|
||||||
@@ -138,9 +141,9 @@ getJasmineRequireObj().SpyRegistry = function(j$) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var originalDescriptor = j$.util.clone(descriptor),
|
const originalDescriptor = j$.util.clone(descriptor);
|
||||||
spy = createSpy(propertyName, descriptor[accessType]),
|
const spy = createSpy(propertyName, descriptor[accessType]);
|
||||||
restoreStrategy;
|
let restoreStrategy;
|
||||||
|
|
||||||
if (Object.prototype.hasOwnProperty.call(obj, propertyName)) {
|
if (Object.prototype.hasOwnProperty.call(obj, propertyName)) {
|
||||||
restoreStrategy = function() {
|
restoreStrategy = function() {
|
||||||
@@ -170,7 +173,7 @@ getJasmineRequireObj().SpyRegistry = function(j$) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
var pointer = obj,
|
let pointer = obj,
|
||||||
propsToSpyOn = [],
|
propsToSpyOn = [],
|
||||||
properties,
|
properties,
|
||||||
propertiesToSkip = [];
|
propertiesToSkip = [];
|
||||||
@@ -190,24 +193,24 @@ getJasmineRequireObj().SpyRegistry = function(j$) {
|
|||||||
pointer = Object.getPrototypeOf(pointer);
|
pointer = Object.getPrototypeOf(pointer);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var i = 0; i < propsToSpyOn.length; i++) {
|
for (const prop of propsToSpyOn) {
|
||||||
this.spyOn(obj, propsToSpyOn[i]);
|
this.spyOn(obj, prop);
|
||||||
}
|
}
|
||||||
|
|
||||||
return obj;
|
return obj;
|
||||||
};
|
};
|
||||||
|
|
||||||
this.clearSpies = function() {
|
this.clearSpies = function() {
|
||||||
var spies = currentSpies();
|
const spies = currentSpies();
|
||||||
for (var i = spies.length - 1; i >= 0; i--) {
|
for (let i = spies.length - 1; i >= 0; i--) {
|
||||||
var spyEntry = spies[i];
|
const spyEntry = spies[i];
|
||||||
spyEntry.restoreObjectToOriginalState();
|
spyEntry.restoreObjectToOriginalState();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function getProps(obj, includeNonEnumerable) {
|
function getProps(obj, includeNonEnumerable) {
|
||||||
var enumerableProperties = Object.keys(obj);
|
const enumerableProperties = Object.keys(obj);
|
||||||
|
|
||||||
if (!includeNonEnumerable) {
|
if (!includeNonEnumerable) {
|
||||||
return enumerableProperties;
|
return enumerableProperties;
|
||||||
@@ -222,10 +225,9 @@ getJasmineRequireObj().SpyRegistry = function(j$) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getSpyableFunctionProps(obj, propertiesToCheck) {
|
function getSpyableFunctionProps(obj, propertiesToCheck) {
|
||||||
var props = [],
|
const props = [];
|
||||||
prop;
|
|
||||||
for (var i = 0; i < propertiesToCheck.length; i++) {
|
for (const prop of propertiesToCheck) {
|
||||||
prop = propertiesToCheck[i];
|
|
||||||
if (
|
if (
|
||||||
Object.prototype.hasOwnProperty.call(obj, prop) &&
|
Object.prototype.hasOwnProperty.call(obj, prop) &&
|
||||||
isSpyableProp(obj, prop)
|
isSpyableProp(obj, prop)
|
||||||
@@ -237,14 +239,15 @@ getJasmineRequireObj().SpyRegistry = function(j$) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function isSpyableProp(obj, prop) {
|
function isSpyableProp(obj, prop) {
|
||||||
var value, descriptor;
|
let value;
|
||||||
try {
|
try {
|
||||||
value = obj[prop];
|
value = obj[prop];
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (value instanceof Function) {
|
if (value instanceof Function) {
|
||||||
descriptor = Object.getOwnPropertyDescriptor(obj, prop);
|
const descriptor = Object.getOwnPropertyDescriptor(obj, prop);
|
||||||
return (descriptor.writable || descriptor.set) && descriptor.configurable;
|
return (descriptor.writable || descriptor.set) && descriptor.configurable;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -5,8 +5,6 @@ getJasmineRequireObj().SpyStrategy = function(j$) {
|
|||||||
function SpyStrategy(options) {
|
function SpyStrategy(options) {
|
||||||
options = options || {};
|
options = options || {};
|
||||||
|
|
||||||
var self = this;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the identifying information for the spy.
|
* Get the identifying information for the spy.
|
||||||
* @name SpyStrategy#identity
|
* @name SpyStrategy#identity
|
||||||
@@ -19,9 +17,8 @@ getJasmineRequireObj().SpyStrategy = function(j$) {
|
|||||||
this.getSpy = options.getSpy || function() {};
|
this.getSpy = options.getSpy || function() {};
|
||||||
this.plan = this._defaultPlan = function() {};
|
this.plan = this._defaultPlan = function() {};
|
||||||
|
|
||||||
var k,
|
const cs = options.customStrategies || {};
|
||||||
cs = options.customStrategies || {};
|
for (const k in cs) {
|
||||||
for (k in cs) {
|
|
||||||
if (j$.util.has(cs, k) && !this[k]) {
|
if (j$.util.has(cs, k) && !this[k]) {
|
||||||
this[k] = createCustomPlan(cs[k]);
|
this[k] = createCustomPlan(cs[k]);
|
||||||
}
|
}
|
||||||
@@ -35,10 +32,10 @@ getJasmineRequireObj().SpyStrategy = function(j$) {
|
|||||||
* @param {*} value The value to return.
|
* @param {*} value The value to return.
|
||||||
*/
|
*/
|
||||||
this.resolveTo = function(value) {
|
this.resolveTo = function(value) {
|
||||||
self.plan = function() {
|
this.plan = function() {
|
||||||
return Promise.resolve(value);
|
return Promise.resolve(value);
|
||||||
};
|
};
|
||||||
return self.getSpy();
|
return this.getSpy();
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -49,16 +46,16 @@ getJasmineRequireObj().SpyStrategy = function(j$) {
|
|||||||
* @param {*} value The value to return.
|
* @param {*} value The value to return.
|
||||||
*/
|
*/
|
||||||
this.rejectWith = function(value) {
|
this.rejectWith = function(value) {
|
||||||
self.plan = function() {
|
this.plan = function() {
|
||||||
return Promise.reject(value);
|
return Promise.reject(value);
|
||||||
};
|
};
|
||||||
return self.getSpy();
|
return this.getSpy();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function createCustomPlan(factory) {
|
function createCustomPlan(factory) {
|
||||||
return function() {
|
return function() {
|
||||||
var plan = factory.apply(null, arguments);
|
const plan = factory.apply(null, arguments);
|
||||||
|
|
||||||
if (!j$.isFunction_(plan)) {
|
if (!j$.isFunction_(plan)) {
|
||||||
throw new Error('Spy strategy must return a function');
|
throw new Error('Spy strategy must return a function');
|
||||||
@@ -76,10 +73,10 @@ getJasmineRequireObj().SpyStrategy = function(j$) {
|
|||||||
* @function
|
* @function
|
||||||
*/
|
*/
|
||||||
SpyStrategy.prototype.exec = function(context, args, invokeNew) {
|
SpyStrategy.prototype.exec = function(context, args, invokeNew) {
|
||||||
var contextArgs = [context].concat(
|
const contextArgs = [context].concat(
|
||||||
args ? Array.prototype.slice.call(args) : []
|
args ? Array.prototype.slice.call(args) : []
|
||||||
);
|
);
|
||||||
var target = this.plan.bind.apply(this.plan, contextArgs);
|
const target = this.plan.bind.apply(this.plan, contextArgs);
|
||||||
|
|
||||||
return invokeNew ? new target() : target();
|
return invokeNew ? new target() : target();
|
||||||
};
|
};
|
||||||
@@ -117,7 +114,7 @@ getJasmineRequireObj().SpyStrategy = function(j$) {
|
|||||||
* @param {...*} values - Values to be returned on subsequent calls to the spy.
|
* @param {...*} values - Values to be returned on subsequent calls to the spy.
|
||||||
*/
|
*/
|
||||||
SpyStrategy.prototype.returnValues = function() {
|
SpyStrategy.prototype.returnValues = function() {
|
||||||
var values = Array.prototype.slice.call(arguments);
|
const values = Array.prototype.slice.call(arguments);
|
||||||
this.plan = function() {
|
this.plan = function() {
|
||||||
return values.shift();
|
return values.shift();
|
||||||
};
|
};
|
||||||
@@ -132,7 +129,7 @@ getJasmineRequireObj().SpyStrategy = function(j$) {
|
|||||||
* @param {Error|Object|String} something Thing to throw
|
* @param {Error|Object|String} something Thing to throw
|
||||||
*/
|
*/
|
||||||
SpyStrategy.prototype.throwError = function(something) {
|
SpyStrategy.prototype.throwError = function(something) {
|
||||||
var error = j$.isString_(something) ? new Error(something) : something;
|
const error = j$.isString_(something) ? new Error(something) : something;
|
||||||
this.plan = function() {
|
this.plan = function() {
|
||||||
throw error;
|
throw error;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,22 +1,22 @@
|
|||||||
getJasmineRequireObj().StackTrace = function(j$) {
|
getJasmineRequireObj().StackTrace = function(j$) {
|
||||||
function StackTrace(error) {
|
function StackTrace(error) {
|
||||||
var lines = error.stack.split('\n').filter(function(line) {
|
let lines = error.stack.split('\n').filter(function(line) {
|
||||||
return line !== '';
|
return line !== '';
|
||||||
});
|
});
|
||||||
|
|
||||||
var extractResult = extractMessage(error.message, lines);
|
const extractResult = extractMessage(error.message, lines);
|
||||||
|
|
||||||
if (extractResult) {
|
if (extractResult) {
|
||||||
this.message = extractResult.message;
|
this.message = extractResult.message;
|
||||||
lines = extractResult.remainder;
|
lines = extractResult.remainder;
|
||||||
}
|
}
|
||||||
|
|
||||||
var parseResult = tryParseFrames(lines);
|
const parseResult = tryParseFrames(lines);
|
||||||
this.frames = parseResult.frames;
|
this.frames = parseResult.frames;
|
||||||
this.style = parseResult.style;
|
this.style = parseResult.style;
|
||||||
}
|
}
|
||||||
|
|
||||||
var framePatterns = [
|
const framePatterns = [
|
||||||
// Node, Chrome, Edge
|
// Node, Chrome, Edge
|
||||||
// e.g. " at QueueRunner.run (http://localhost:8888/__jasmine__/jasmine.js:4320:20)"
|
// e.g. " at QueueRunner.run (http://localhost:8888/__jasmine__/jasmine.js:4320:20)"
|
||||||
// Note that the "function name" can include a surprisingly large set of
|
// Note that the "function name" can include a surprisingly large set of
|
||||||
@@ -46,16 +46,15 @@ getJasmineRequireObj().StackTrace = function(j$) {
|
|||||||
// regexes should capture the function name (if any) as group 1
|
// regexes should capture the function name (if any) as group 1
|
||||||
// and the file, line, and column as group 2.
|
// and the file, line, and column as group 2.
|
||||||
function tryParseFrames(lines) {
|
function tryParseFrames(lines) {
|
||||||
var style = null;
|
let style = null;
|
||||||
var frames = lines.map(function(line) {
|
const frames = lines.map(function(line) {
|
||||||
var convertedLine = first(framePatterns, function(pattern) {
|
const convertedLine = first(framePatterns, function(pattern) {
|
||||||
var overallMatch = line.match(pattern.re),
|
const overallMatch = line.match(pattern.re);
|
||||||
fileLineColMatch;
|
|
||||||
if (!overallMatch) {
|
if (!overallMatch) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
fileLineColMatch = overallMatch[pattern.fileLineColIx].match(
|
const fileLineColMatch = overallMatch[pattern.fileLineColIx].match(
|
||||||
/^(.*):(\d+):\d+$/
|
/^(.*):(\d+):\d+$/
|
||||||
);
|
);
|
||||||
if (!fileLineColMatch) {
|
if (!fileLineColMatch) {
|
||||||
@@ -81,10 +80,8 @@ getJasmineRequireObj().StackTrace = function(j$) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function first(items, fn) {
|
function first(items, fn) {
|
||||||
var i, result;
|
for (const item of items) {
|
||||||
|
const result = fn(item);
|
||||||
for (i = 0; i < items.length; i++) {
|
|
||||||
result = fn(items[i]);
|
|
||||||
|
|
||||||
if (result) {
|
if (result) {
|
||||||
return result;
|
return result;
|
||||||
@@ -93,7 +90,7 @@ getJasmineRequireObj().StackTrace = function(j$) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function extractMessage(message, stackLines) {
|
function extractMessage(message, stackLines) {
|
||||||
var len = messagePrefixLength(message, stackLines);
|
const len = messagePrefixLength(message, stackLines);
|
||||||
|
|
||||||
if (len > 0) {
|
if (len > 0) {
|
||||||
return {
|
return {
|
||||||
@@ -108,10 +105,9 @@ getJasmineRequireObj().StackTrace = function(j$) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
var messageLines = message.split('\n');
|
const messageLines = message.split('\n');
|
||||||
var i;
|
|
||||||
|
|
||||||
for (i = 1; i < messageLines.length; i++) {
|
for (let i = 1; i < messageLines.length; i++) {
|
||||||
if (messageLines[i] !== stackLines[i]) {
|
if (messageLines[i] !== stackLines[i]) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,48 +1,21 @@
|
|||||||
getJasmineRequireObj().Suite = function(j$) {
|
getJasmineRequireObj().Suite = function(j$) {
|
||||||
/**
|
|
||||||
* @interface Suite
|
|
||||||
* @see Env#topSuite
|
|
||||||
* @since 2.0.0
|
|
||||||
*/
|
|
||||||
function Suite(attrs) {
|
function Suite(attrs) {
|
||||||
this.env = attrs.env;
|
this.env = attrs.env;
|
||||||
/**
|
|
||||||
* The unique ID of this suite.
|
|
||||||
* @name Suite#id
|
|
||||||
* @readonly
|
|
||||||
* @type {string}
|
|
||||||
* @since 2.0.0
|
|
||||||
*/
|
|
||||||
this.id = attrs.id;
|
this.id = attrs.id;
|
||||||
this.parentSuite = attrs.parentSuite;
|
this.parentSuite = attrs.parentSuite;
|
||||||
/**
|
|
||||||
* The description passed to the {@link describe} that created this suite.
|
|
||||||
* @name Suite#description
|
|
||||||
* @readonly
|
|
||||||
* @type {string}
|
|
||||||
* @since 2.0.0
|
|
||||||
*/
|
|
||||||
this.description = attrs.description;
|
this.description = attrs.description;
|
||||||
this.expectationFactory = attrs.expectationFactory;
|
this.expectationFactory = attrs.expectationFactory;
|
||||||
this.asyncExpectationFactory = attrs.asyncExpectationFactory;
|
this.asyncExpectationFactory = attrs.asyncExpectationFactory;
|
||||||
this.expectationResultFactory = attrs.expectationResultFactory;
|
|
||||||
this.throwOnExpectationFailure = !!attrs.throwOnExpectationFailure;
|
this.throwOnExpectationFailure = !!attrs.throwOnExpectationFailure;
|
||||||
this.autoCleanClosures =
|
this.autoCleanClosures =
|
||||||
attrs.autoCleanClosures === undefined ? true : !!attrs.autoCleanClosures;
|
attrs.autoCleanClosures === undefined ? true : !!attrs.autoCleanClosures;
|
||||||
this.onLateError = attrs.onLateError;
|
this.onLateError = attrs.onLateError || function() {};
|
||||||
|
|
||||||
this.beforeFns = [];
|
this.beforeFns = [];
|
||||||
this.afterFns = [];
|
this.afterFns = [];
|
||||||
this.beforeAllFns = [];
|
this.beforeAllFns = [];
|
||||||
this.afterAllFns = [];
|
this.afterAllFns = [];
|
||||||
this.timer = attrs.timer || new j$.Timer();
|
this.timer = attrs.timer || new j$.Timer();
|
||||||
|
|
||||||
/**
|
|
||||||
* The suite's children.
|
|
||||||
* @name Suite#children
|
|
||||||
* @type {Array.<(Spec|Suite)>}
|
|
||||||
* @since 2.0.0
|
|
||||||
*/
|
|
||||||
this.children = [];
|
this.children = [];
|
||||||
|
|
||||||
this.reset();
|
this.reset();
|
||||||
@@ -61,17 +34,10 @@ getJasmineRequireObj().Suite = function(j$) {
|
|||||||
return this.asyncExpectationFactory(actual, this);
|
return this.asyncExpectationFactory(actual, this);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* The full description including all ancestors of this suite.
|
|
||||||
* @name Suite#getFullName
|
|
||||||
* @function
|
|
||||||
* @returns {string}
|
|
||||||
* @since 2.0.0
|
|
||||||
*/
|
|
||||||
Suite.prototype.getFullName = function() {
|
Suite.prototype.getFullName = function() {
|
||||||
var fullName = [];
|
const fullName = [];
|
||||||
for (
|
for (
|
||||||
var parentSuite = this;
|
let parentSuite = this;
|
||||||
parentSuite;
|
parentSuite;
|
||||||
parentSuite = parentSuite.parentSuite
|
parentSuite = parentSuite.parentSuite
|
||||||
) {
|
) {
|
||||||
@@ -123,8 +89,8 @@ getJasmineRequireObj().Suite = function(j$) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function removeFns(queueableFns) {
|
function removeFns(queueableFns) {
|
||||||
for (var i = 0; i < queueableFns.length; i++) {
|
for (const qf of queueableFns) {
|
||||||
queueableFns[i].fn = null;
|
qf.fn = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -163,6 +129,7 @@ getJasmineRequireObj().Suite = function(j$) {
|
|||||||
this.children.forEach(function(child) {
|
this.children.forEach(function(child) {
|
||||||
child.reset();
|
child.reset();
|
||||||
});
|
});
|
||||||
|
this.reportedDone = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
Suite.prototype.addChild = function(child) {
|
Suite.prototype.addChild = function(child) {
|
||||||
@@ -204,25 +171,29 @@ getJasmineRequireObj().Suite = function(j$) {
|
|||||||
return j$.UserContext.fromExisting(this.sharedUserContext());
|
return j$.UserContext.fromExisting(this.sharedUserContext());
|
||||||
};
|
};
|
||||||
|
|
||||||
Suite.prototype.onException = function() {
|
Suite.prototype.handleException = function() {
|
||||||
if (arguments[0] instanceof j$.errors.ExpectationFailed) {
|
if (arguments[0] instanceof j$.errors.ExpectationFailed) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var data = {
|
const data = {
|
||||||
matcherName: '',
|
matcherName: '',
|
||||||
passed: false,
|
passed: false,
|
||||||
expected: '',
|
expected: '',
|
||||||
actual: '',
|
actual: '',
|
||||||
error: arguments[0]
|
error: arguments[0]
|
||||||
};
|
};
|
||||||
var failedExpectation = this.expectationResultFactory(data);
|
const failedExpectation = j$.buildExpectationResult(data);
|
||||||
|
|
||||||
if (!this.parentSuite) {
|
if (!this.parentSuite) {
|
||||||
failedExpectation.globalErrorType = 'afterAll';
|
failedExpectation.globalErrorType = 'afterAll';
|
||||||
}
|
}
|
||||||
|
|
||||||
this.result.failedExpectations.push(failedExpectation);
|
if (this.reportedDone) {
|
||||||
|
this.onLateError(failedExpectation);
|
||||||
|
} else {
|
||||||
|
this.result.failedExpectations.push(failedExpectation);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Suite.prototype.onMultipleDone = function() {
|
Suite.prototype.onMultipleDone = function() {
|
||||||
@@ -249,8 +220,20 @@ getJasmineRequireObj().Suite = function(j$) {
|
|||||||
|
|
||||||
Suite.prototype.addExpectationResult = function() {
|
Suite.prototype.addExpectationResult = function() {
|
||||||
if (isFailure(arguments)) {
|
if (isFailure(arguments)) {
|
||||||
var data = arguments[1];
|
const data = arguments[1];
|
||||||
this.result.failedExpectations.push(this.expectationResultFactory(data));
|
const expectationResult = j$.buildExpectationResult(data);
|
||||||
|
|
||||||
|
if (this.reportedDone) {
|
||||||
|
this.onLateError(expectationResult);
|
||||||
|
} else {
|
||||||
|
this.result.failedExpectations.push(expectationResult);
|
||||||
|
|
||||||
|
// TODO: refactor so that we don't need to override cached status
|
||||||
|
if (this.result.status) {
|
||||||
|
this.result.status = 'failed';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (this.throwOnExpectationFailure) {
|
if (this.throwOnExpectationFailure) {
|
||||||
throw new j$.errors.ExpectationFailed();
|
throw new j$.errors.ExpectationFailed();
|
||||||
}
|
}
|
||||||
@@ -262,7 +245,7 @@ getJasmineRequireObj().Suite = function(j$) {
|
|||||||
deprecation = { message: deprecation };
|
deprecation = { message: deprecation };
|
||||||
}
|
}
|
||||||
this.result.deprecationWarnings.push(
|
this.result.deprecationWarnings.push(
|
||||||
this.expectationResultFactory(deprecation)
|
j$.buildExpectationResult(deprecation)
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -279,6 +262,7 @@ getJasmineRequireObj().Suite = function(j$) {
|
|||||||
/**
|
/**
|
||||||
* @interface Suite
|
* @interface Suite
|
||||||
* @see Env#topSuite
|
* @see Env#topSuite
|
||||||
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
function SuiteMetadata(suite) {
|
function SuiteMetadata(suite) {
|
||||||
this.suite_ = suite;
|
this.suite_ = suite;
|
||||||
@@ -287,6 +271,7 @@ getJasmineRequireObj().Suite = function(j$) {
|
|||||||
* @name Suite#id
|
* @name Suite#id
|
||||||
* @readonly
|
* @readonly
|
||||||
* @type {string}
|
* @type {string}
|
||||||
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
this.id = suite.id;
|
this.id = suite.id;
|
||||||
|
|
||||||
@@ -303,6 +288,7 @@ getJasmineRequireObj().Suite = function(j$) {
|
|||||||
* @name Suite#description
|
* @name Suite#description
|
||||||
* @readonly
|
* @readonly
|
||||||
* @type {string}
|
* @type {string}
|
||||||
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
this.description = suite.description;
|
this.description = suite.description;
|
||||||
}
|
}
|
||||||
@@ -312,6 +298,7 @@ getJasmineRequireObj().Suite = function(j$) {
|
|||||||
* @name Suite#getFullName
|
* @name Suite#getFullName
|
||||||
* @function
|
* @function
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
SuiteMetadata.prototype.getFullName = function() {
|
SuiteMetadata.prototype.getFullName = function() {
|
||||||
return this.suite_.getFullName();
|
return this.suite_.getFullName();
|
||||||
@@ -321,6 +308,7 @@ getJasmineRequireObj().Suite = function(j$) {
|
|||||||
* The suite's children.
|
* The suite's children.
|
||||||
* @name Suite#children
|
* @name Suite#children
|
||||||
* @type {Array.<(Spec|Suite)>}
|
* @type {Array.<(Spec|Suite)>}
|
||||||
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
Object.defineProperty(SuiteMetadata.prototype, 'children', {
|
Object.defineProperty(SuiteMetadata.prototype, 'children', {
|
||||||
get: function() {
|
get: function() {
|
||||||
|
|||||||
302
src/core/SuiteBuilder.js
Normal file
302
src/core/SuiteBuilder.js
Normal file
@@ -0,0 +1,302 @@
|
|||||||
|
getJasmineRequireObj().SuiteBuilder = function(j$) {
|
||||||
|
class SuiteBuilder {
|
||||||
|
constructor(options) {
|
||||||
|
this.env_ = options.env;
|
||||||
|
this.expectationFactory_ = options.expectationFactory;
|
||||||
|
this.suiteAsyncExpectationFactory_ = function(actual, suite) {
|
||||||
|
return options.asyncExpectationFactory(actual, suite, 'Suite');
|
||||||
|
};
|
||||||
|
this.specAsyncExpectationFactory_ = function(actual, suite) {
|
||||||
|
return options.asyncExpectationFactory(actual, suite, 'Spec');
|
||||||
|
};
|
||||||
|
this.onLateError_ = options.onLateError;
|
||||||
|
this.specResultCallback_ = options.specResultCallback;
|
||||||
|
this.specStarted_ = options.specStarted;
|
||||||
|
|
||||||
|
this.nextSuiteId_ = 0;
|
||||||
|
this.nextSpecId_ = 0;
|
||||||
|
|
||||||
|
this.topSuite = this.suiteFactory_('Jasmine__TopLevel__Suite');
|
||||||
|
this.currentDeclarationSuite_ = this.topSuite;
|
||||||
|
this.totalSpecsDefined = 0;
|
||||||
|
this.focusedRunables = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
describe(description, definitionFn) {
|
||||||
|
ensureIsFunction(definitionFn, 'describe');
|
||||||
|
const suite = this.suiteFactory_(description);
|
||||||
|
if (definitionFn.length > 0) {
|
||||||
|
throw new Error('describe does not expect any arguments');
|
||||||
|
}
|
||||||
|
if (this.currentDeclarationSuite_.markedExcluding) {
|
||||||
|
suite.exclude();
|
||||||
|
}
|
||||||
|
this.addSpecsToSuite_(suite, definitionFn);
|
||||||
|
if (suite.parentSuite && !suite.children.length) {
|
||||||
|
throw new Error(
|
||||||
|
`describe with no children (describe() or it()): ${suite.getFullName()}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return suite;
|
||||||
|
}
|
||||||
|
|
||||||
|
fdescribe(description, definitionFn) {
|
||||||
|
ensureIsFunction(definitionFn, 'fdescribe');
|
||||||
|
const suite = this.suiteFactory_(description);
|
||||||
|
suite.isFocused = true;
|
||||||
|
|
||||||
|
this.focusedRunables.push(suite.id);
|
||||||
|
this.unfocusAncestor_();
|
||||||
|
this.addSpecsToSuite_(suite, definitionFn);
|
||||||
|
|
||||||
|
return suite;
|
||||||
|
}
|
||||||
|
|
||||||
|
xdescribe(description, definitionFn) {
|
||||||
|
ensureIsFunction(definitionFn, 'xdescribe');
|
||||||
|
const suite = this.suiteFactory_(description);
|
||||||
|
suite.exclude();
|
||||||
|
this.addSpecsToSuite_(suite, definitionFn);
|
||||||
|
|
||||||
|
return suite;
|
||||||
|
}
|
||||||
|
|
||||||
|
it(description, fn, timeout) {
|
||||||
|
// it() sometimes doesn't have a fn argument, so only check the type if
|
||||||
|
// it's given.
|
||||||
|
if (arguments.length > 1 && typeof fn !== 'undefined') {
|
||||||
|
ensureIsFunctionOrAsync(fn, 'it');
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.it_(description, fn, timeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
xit(description, fn, timeout) {
|
||||||
|
// xit(), like it(), doesn't always have a fn argument, so only check the
|
||||||
|
// type when needed.
|
||||||
|
if (arguments.length > 1 && typeof fn !== 'undefined') {
|
||||||
|
ensureIsFunctionOrAsync(fn, 'xit');
|
||||||
|
}
|
||||||
|
const spec = this.it_(description, fn, timeout);
|
||||||
|
spec.exclude('Temporarily disabled with xit');
|
||||||
|
return spec;
|
||||||
|
}
|
||||||
|
|
||||||
|
fit(description, fn, timeout) {
|
||||||
|
// Unlike it and xit, the function is required because it doesn't make
|
||||||
|
// sense to focus on nothing.
|
||||||
|
ensureIsFunctionOrAsync(fn, 'fit');
|
||||||
|
|
||||||
|
if (timeout) {
|
||||||
|
j$.util.validateTimeout(timeout);
|
||||||
|
}
|
||||||
|
const spec = this.specFactory_(description, fn, timeout);
|
||||||
|
this.currentDeclarationSuite_.addChild(spec);
|
||||||
|
this.focusedRunables.push(spec.id);
|
||||||
|
this.unfocusAncestor_();
|
||||||
|
return spec;
|
||||||
|
}
|
||||||
|
|
||||||
|
beforeEach(beforeEachFunction, timeout) {
|
||||||
|
ensureIsFunctionOrAsync(beforeEachFunction, 'beforeEach');
|
||||||
|
|
||||||
|
if (timeout) {
|
||||||
|
j$.util.validateTimeout(timeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.currentDeclarationSuite_.beforeEach({
|
||||||
|
fn: beforeEachFunction,
|
||||||
|
timeout: timeout || 0
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
beforeAll(beforeAllFunction, timeout) {
|
||||||
|
ensureIsFunctionOrAsync(beforeAllFunction, 'beforeAll');
|
||||||
|
|
||||||
|
if (timeout) {
|
||||||
|
j$.util.validateTimeout(timeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.currentDeclarationSuite_.beforeAll({
|
||||||
|
fn: beforeAllFunction,
|
||||||
|
timeout: timeout || 0
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
afterEach(afterEachFunction, timeout) {
|
||||||
|
ensureIsFunctionOrAsync(afterEachFunction, 'afterEach');
|
||||||
|
|
||||||
|
if (timeout) {
|
||||||
|
j$.util.validateTimeout(timeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
afterEachFunction.isCleanup = true;
|
||||||
|
this.currentDeclarationSuite_.afterEach({
|
||||||
|
fn: afterEachFunction,
|
||||||
|
timeout: timeout || 0
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
afterAll(afterAllFunction, timeout) {
|
||||||
|
ensureIsFunctionOrAsync(afterAllFunction, 'afterAll');
|
||||||
|
|
||||||
|
if (timeout) {
|
||||||
|
j$.util.validateTimeout(timeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.currentDeclarationSuite_.afterAll({
|
||||||
|
fn: afterAllFunction,
|
||||||
|
timeout: timeout || 0
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
it_(description, fn, timeout) {
|
||||||
|
if (timeout) {
|
||||||
|
j$.util.validateTimeout(timeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
const spec = this.specFactory_(description, fn, timeout);
|
||||||
|
if (this.currentDeclarationSuite_.markedExcluding) {
|
||||||
|
spec.exclude();
|
||||||
|
}
|
||||||
|
this.currentDeclarationSuite_.addChild(spec);
|
||||||
|
|
||||||
|
return spec;
|
||||||
|
}
|
||||||
|
|
||||||
|
suiteFactory_(description) {
|
||||||
|
const config = this.env_.configuration();
|
||||||
|
return new j$.Suite({
|
||||||
|
id: 'suite' + this.nextSuiteId_++,
|
||||||
|
description,
|
||||||
|
parentSuite: this.currentDeclarationSuite_,
|
||||||
|
timer: new j$.Timer(),
|
||||||
|
expectationFactory: this.expectationFactory_,
|
||||||
|
asyncExpectationFactory: this.suiteAsyncExpectationFactory_,
|
||||||
|
throwOnExpectationFailure: config.stopSpecOnExpectationFailure,
|
||||||
|
autoCleanClosures: config.autoCleanClosures,
|
||||||
|
onLateError: this.onLateError_
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
addSpecsToSuite_(suite, definitionFn) {
|
||||||
|
const parentSuite = this.currentDeclarationSuite_;
|
||||||
|
parentSuite.addChild(suite);
|
||||||
|
this.currentDeclarationSuite_ = suite;
|
||||||
|
|
||||||
|
try {
|
||||||
|
definitionFn();
|
||||||
|
} catch (e) {
|
||||||
|
suite.handleException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.currentDeclarationSuite_ = parentSuite;
|
||||||
|
}
|
||||||
|
|
||||||
|
specFactory_(description, fn, timeout) {
|
||||||
|
this.totalSpecsDefined++;
|
||||||
|
const config = this.env_.configuration();
|
||||||
|
const suite = this.currentDeclarationSuite_;
|
||||||
|
const spec = new j$.Spec({
|
||||||
|
id: 'spec' + this.nextSpecId_++,
|
||||||
|
beforeAndAfterFns: beforeAndAfterFns(suite),
|
||||||
|
expectationFactory: this.expectationFactory_,
|
||||||
|
asyncExpectationFactory: this.specAsyncExpectationFactory_,
|
||||||
|
onLateError: this.onLateError_,
|
||||||
|
resultCallback: (result, next) => {
|
||||||
|
this.specResultCallback_(spec, result, next);
|
||||||
|
},
|
||||||
|
getSpecName: function(spec) {
|
||||||
|
return getSpecName(spec, suite);
|
||||||
|
},
|
||||||
|
onStart: (spec, next) => this.specStarted_(spec, suite, next),
|
||||||
|
description: description,
|
||||||
|
userContext: function() {
|
||||||
|
return suite.clonedSharedUserContext();
|
||||||
|
},
|
||||||
|
queueableFn: {
|
||||||
|
fn: fn,
|
||||||
|
timeout: timeout || 0
|
||||||
|
},
|
||||||
|
throwOnExpectationFailure: config.stopSpecOnExpectationFailure,
|
||||||
|
autoCleanClosures: config.autoCleanClosures,
|
||||||
|
timer: new j$.Timer()
|
||||||
|
});
|
||||||
|
return spec;
|
||||||
|
}
|
||||||
|
|
||||||
|
unfocusAncestor_() {
|
||||||
|
const focusedAncestor = findFocusedAncestor(
|
||||||
|
this.currentDeclarationSuite_
|
||||||
|
);
|
||||||
|
|
||||||
|
if (focusedAncestor) {
|
||||||
|
for (let i = 0; i < this.focusedRunables.length; i++) {
|
||||||
|
if (this.focusedRunables[i] === focusedAncestor) {
|
||||||
|
this.focusedRunables.splice(i, 1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function findFocusedAncestor(suite) {
|
||||||
|
while (suite) {
|
||||||
|
if (suite.isFocused) {
|
||||||
|
return suite.id;
|
||||||
|
}
|
||||||
|
suite = suite.parentSuite;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function ensureIsFunction(fn, caller) {
|
||||||
|
if (!j$.isFunction_(fn)) {
|
||||||
|
throw new Error(
|
||||||
|
caller + ' expects a function argument; received ' + j$.getType_(fn)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function ensureIsFunctionOrAsync(fn, caller) {
|
||||||
|
if (!j$.isFunction_(fn) && !j$.isAsyncFunction_(fn)) {
|
||||||
|
throw new Error(
|
||||||
|
caller + ' expects a function argument; received ' + j$.getType_(fn)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function beforeAndAfterFns(targetSuite) {
|
||||||
|
return function() {
|
||||||
|
let befores = [],
|
||||||
|
afters = [],
|
||||||
|
suite = targetSuite;
|
||||||
|
|
||||||
|
while (suite) {
|
||||||
|
befores = befores.concat(suite.beforeFns);
|
||||||
|
afters = afters.concat(suite.afterFns);
|
||||||
|
|
||||||
|
suite = suite.parentSuite;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
befores: befores.reverse(),
|
||||||
|
afters: afters
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function getSpecName(spec, suite) {
|
||||||
|
const fullName = [spec.description],
|
||||||
|
suiteFullName = suite.getFullName();
|
||||||
|
|
||||||
|
if (suiteFullName !== '') {
|
||||||
|
fullName.unshift(suiteFullName);
|
||||||
|
}
|
||||||
|
return fullName.join(' ');
|
||||||
|
}
|
||||||
|
|
||||||
|
return SuiteBuilder;
|
||||||
|
};
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
getJasmineRequireObj().Timer = function() {
|
getJasmineRequireObj().Timer = function() {
|
||||||
var defaultNow = (function(Date) {
|
const defaultNow = (function(Date) {
|
||||||
return function() {
|
return function() {
|
||||||
return new Date().getTime();
|
return new Date().getTime();
|
||||||
};
|
};
|
||||||
@@ -8,8 +8,8 @@ getJasmineRequireObj().Timer = function() {
|
|||||||
function Timer(options) {
|
function Timer(options) {
|
||||||
options = options || {};
|
options = options || {};
|
||||||
|
|
||||||
var now = options.now || defaultNow,
|
const now = options.now || defaultNow;
|
||||||
startTime;
|
let startTime;
|
||||||
|
|
||||||
this.start = function() {
|
this.start = function() {
|
||||||
startTime = now();
|
startTime = now();
|
||||||
|
|||||||
@@ -1,25 +1,25 @@
|
|||||||
getJasmineRequireObj().TreeProcessor = function() {
|
getJasmineRequireObj().TreeProcessor = function() {
|
||||||
function TreeProcessor(attrs) {
|
function TreeProcessor(attrs) {
|
||||||
var tree = attrs.tree,
|
const tree = attrs.tree;
|
||||||
runnableIds = attrs.runnableIds,
|
const runnableIds = attrs.runnableIds;
|
||||||
queueRunnerFactory = attrs.queueRunnerFactory,
|
const queueRunnerFactory = attrs.queueRunnerFactory;
|
||||||
nodeStart = attrs.nodeStart || function() {},
|
const nodeStart = attrs.nodeStart || function() {};
|
||||||
nodeComplete = attrs.nodeComplete || function() {},
|
const nodeComplete = attrs.nodeComplete || function() {};
|
||||||
failSpecWithNoExpectations = !!attrs.failSpecWithNoExpectations,
|
const failSpecWithNoExpectations = !!attrs.failSpecWithNoExpectations;
|
||||||
orderChildren =
|
const orderChildren =
|
||||||
attrs.orderChildren ||
|
attrs.orderChildren ||
|
||||||
function(node) {
|
function(node) {
|
||||||
return node.children;
|
return node.children;
|
||||||
},
|
};
|
||||||
excludeNode =
|
const excludeNode =
|
||||||
attrs.excludeNode ||
|
attrs.excludeNode ||
|
||||||
function(node) {
|
function(node) {
|
||||||
return false;
|
return false;
|
||||||
},
|
};
|
||||||
stats = { valid: true },
|
let stats = { valid: true };
|
||||||
processed = false,
|
let processed = false;
|
||||||
defaultMin = Infinity,
|
const defaultMin = Infinity;
|
||||||
defaultMax = 1 - Infinity;
|
const defaultMax = 1 - Infinity;
|
||||||
|
|
||||||
this.processTree = function() {
|
this.processTree = function() {
|
||||||
processNode(tree, true);
|
processNode(tree, true);
|
||||||
@@ -36,13 +36,13 @@ getJasmineRequireObj().TreeProcessor = function() {
|
|||||||
throw 'invalid order';
|
throw 'invalid order';
|
||||||
}
|
}
|
||||||
|
|
||||||
var childFns = wrapChildren(tree, 0);
|
const childFns = wrapChildren(tree, 0);
|
||||||
|
|
||||||
queueRunnerFactory({
|
queueRunnerFactory({
|
||||||
queueableFns: childFns,
|
queueableFns: childFns,
|
||||||
userContext: tree.sharedUserContext(),
|
userContext: tree.sharedUserContext(),
|
||||||
onException: function() {
|
onException: function() {
|
||||||
tree.onException.apply(tree, arguments);
|
tree.handleException.apply(tree, arguments);
|
||||||
},
|
},
|
||||||
onComplete: done,
|
onComplete: done,
|
||||||
onMultipleDone: tree.onMultipleDone
|
onMultipleDone: tree.onMultipleDone
|
||||||
@@ -52,7 +52,7 @@ getJasmineRequireObj().TreeProcessor = function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function runnableIndex(id) {
|
function runnableIndex(id) {
|
||||||
for (var i = 0; i < runnableIds.length; i++) {
|
for (let i = 0; i < runnableIds.length; i++) {
|
||||||
if (runnableIds[i] === id) {
|
if (runnableIds[i] === id) {
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
@@ -60,14 +60,14 @@ getJasmineRequireObj().TreeProcessor = function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function processNode(node, parentExcluded) {
|
function processNode(node, parentExcluded) {
|
||||||
var executableIndex = runnableIndex(node.id);
|
const executableIndex = runnableIndex(node.id);
|
||||||
|
|
||||||
if (executableIndex !== undefined) {
|
if (executableIndex !== undefined) {
|
||||||
parentExcluded = false;
|
parentExcluded = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!node.children) {
|
if (!node.children) {
|
||||||
var excluded = parentExcluded || excludeNode(node);
|
const excluded = parentExcluded || excludeNode(node);
|
||||||
stats[node.id] = {
|
stats[node.id] = {
|
||||||
excluded: excluded,
|
excluded: excluded,
|
||||||
willExecute: !excluded && !node.markedPending,
|
willExecute: !excluded && !node.markedPending,
|
||||||
@@ -82,12 +82,12 @@ getJasmineRequireObj().TreeProcessor = function() {
|
|||||||
]
|
]
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
var hasExecutableChild = false;
|
let hasExecutableChild = false;
|
||||||
|
|
||||||
var orderedChildren = orderChildren(node);
|
const orderedChildren = orderChildren(node);
|
||||||
|
|
||||||
for (var i = 0; i < orderedChildren.length; i++) {
|
for (let i = 0; i < orderedChildren.length; i++) {
|
||||||
var child = orderedChildren[i];
|
const child = orderedChildren[i];
|
||||||
|
|
||||||
processNode(child, parentExcluded);
|
processNode(child, parentExcluded);
|
||||||
|
|
||||||
@@ -95,7 +95,7 @@ getJasmineRequireObj().TreeProcessor = function() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var childStats = stats[child.id];
|
const childStats = stats[child.id];
|
||||||
|
|
||||||
hasExecutableChild = hasExecutableChild || childStats.willExecute;
|
hasExecutableChild = hasExecutableChild || childStats.willExecute;
|
||||||
}
|
}
|
||||||
@@ -127,7 +127,7 @@ getJasmineRequireObj().TreeProcessor = function() {
|
|||||||
nodeStats,
|
nodeStats,
|
||||||
executableIndex
|
executableIndex
|
||||||
) {
|
) {
|
||||||
var currentSegment = {
|
let currentSegment = {
|
||||||
index: 0,
|
index: 0,
|
||||||
owner: node,
|
owner: node,
|
||||||
nodes: [],
|
nodes: [],
|
||||||
@@ -146,8 +146,8 @@ getJasmineRequireObj().TreeProcessor = function() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var i = 0; i < orderedChildSegments.length; i++) {
|
for (let i = 0; i < orderedChildSegments.length; i++) {
|
||||||
var childSegment = orderedChildSegments[i],
|
const childSegment = orderedChildSegments[i],
|
||||||
maxIndex = childSegment.max,
|
maxIndex = childSegment.max,
|
||||||
minIndex = childSegment.min;
|
minIndex = childSegment.min;
|
||||||
|
|
||||||
@@ -172,15 +172,15 @@ getJasmineRequireObj().TreeProcessor = function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function orderChildSegments(children) {
|
function orderChildSegments(children) {
|
||||||
var specifiedOrder = [],
|
const specifiedOrder = [],
|
||||||
unspecifiedOrder = [];
|
unspecifiedOrder = [];
|
||||||
|
|
||||||
for (var i = 0; i < children.length; i++) {
|
for (let i = 0; i < children.length; i++) {
|
||||||
var child = children[i],
|
const child = children[i],
|
||||||
segments = stats[child.id].segments;
|
segments = stats[child.id].segments;
|
||||||
|
|
||||||
for (var j = 0; j < segments.length; j++) {
|
for (let j = 0; j < segments.length; j++) {
|
||||||
var seg = segments[j];
|
const seg = segments[j];
|
||||||
|
|
||||||
if (seg.min === defaultMin) {
|
if (seg.min === defaultMin) {
|
||||||
unspecifiedOrder.push(seg);
|
unspecifiedOrder.push(seg);
|
||||||
@@ -201,7 +201,7 @@ getJasmineRequireObj().TreeProcessor = function() {
|
|||||||
if (node.children) {
|
if (node.children) {
|
||||||
return {
|
return {
|
||||||
fn: function(done) {
|
fn: function(done) {
|
||||||
var onStart = {
|
const onStart = {
|
||||||
fn: function(next) {
|
fn: function(next) {
|
||||||
nodeStart(node, next);
|
nodeStart(node, next);
|
||||||
}
|
}
|
||||||
@@ -209,7 +209,7 @@ getJasmineRequireObj().TreeProcessor = function() {
|
|||||||
|
|
||||||
queueRunnerFactory({
|
queueRunnerFactory({
|
||||||
onComplete: function() {
|
onComplete: function() {
|
||||||
var args = Array.prototype.slice.call(arguments, [0]);
|
const args = Array.prototype.slice.call(arguments, [0]);
|
||||||
node.cleanupBeforeAfter();
|
node.cleanupBeforeAfter();
|
||||||
nodeComplete(node, node.getResult(), function() {
|
nodeComplete(node, node.getResult(), function() {
|
||||||
done.apply(undefined, args);
|
done.apply(undefined, args);
|
||||||
@@ -218,7 +218,7 @@ getJasmineRequireObj().TreeProcessor = function() {
|
|||||||
queueableFns: [onStart].concat(wrapChildren(node, segmentNumber)),
|
queueableFns: [onStart].concat(wrapChildren(node, segmentNumber)),
|
||||||
userContext: node.sharedUserContext(),
|
userContext: node.sharedUserContext(),
|
||||||
onException: function() {
|
onException: function() {
|
||||||
node.onException.apply(node, arguments);
|
node.handleException.apply(node, arguments);
|
||||||
},
|
},
|
||||||
onMultipleDone: node.onMultipleDone
|
onMultipleDone: node.onMultipleDone
|
||||||
? node.onMultipleDone.bind(node)
|
? node.onMultipleDone.bind(node)
|
||||||
@@ -230,6 +230,7 @@ getJasmineRequireObj().TreeProcessor = function() {
|
|||||||
return {
|
return {
|
||||||
fn: function(done) {
|
fn: function(done) {
|
||||||
node.execute(
|
node.execute(
|
||||||
|
queueRunnerFactory,
|
||||||
done,
|
done,
|
||||||
stats[node.id].excluded,
|
stats[node.id].excluded,
|
||||||
failSpecWithNoExpectations
|
failSpecWithNoExpectations
|
||||||
@@ -240,10 +241,10 @@ getJasmineRequireObj().TreeProcessor = function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function wrapChildren(node, segmentNumber) {
|
function wrapChildren(node, segmentNumber) {
|
||||||
var result = [],
|
const result = [],
|
||||||
segmentChildren = stats[node.id].segments[segmentNumber].nodes;
|
segmentChildren = stats[node.id].segments[segmentNumber].nodes;
|
||||||
|
|
||||||
for (var i = 0; i < segmentChildren.length; i++) {
|
for (let i = 0; i < segmentChildren.length; i++) {
|
||||||
result.push(
|
result.push(
|
||||||
executeNode(segmentChildren[i].owner, segmentChildren[i].index)
|
executeNode(segmentChildren[i].owner, segmentChildren[i].index)
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -2,9 +2,9 @@ getJasmineRequireObj().UserContext = function(j$) {
|
|||||||
function UserContext() {}
|
function UserContext() {}
|
||||||
|
|
||||||
UserContext.fromExisting = function(oldContext) {
|
UserContext.fromExisting = function(oldContext) {
|
||||||
var context = new UserContext();
|
const context = new UserContext();
|
||||||
|
|
||||||
for (var prop in oldContext) {
|
for (const prop in oldContext) {
|
||||||
if (oldContext.hasOwnProperty(prop)) {
|
if (oldContext.hasOwnProperty(prop)) {
|
||||||
context[prop] = oldContext[prop];
|
context[prop] = oldContext[prop];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,12 +30,9 @@ getJasmineRequireObj().Any = function(j$) {
|
|||||||
return typeof other == 'boolean';
|
return typeof other == 'boolean';
|
||||||
}
|
}
|
||||||
|
|
||||||
/* jshint -W122 */
|
|
||||||
/* global Symbol */
|
|
||||||
if (typeof Symbol != 'undefined' && this.expectedObject == Symbol) {
|
if (typeof Symbol != 'undefined' && this.expectedObject == Symbol) {
|
||||||
return typeof other == 'symbol';
|
return typeof other == 'symbol';
|
||||||
}
|
}
|
||||||
/* jshint +W122 */
|
|
||||||
|
|
||||||
return other instanceof this.expectedObject;
|
return other instanceof this.expectedObject;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -19,8 +19,7 @@ getJasmineRequireObj().ArrayContaining = function(j$) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var i = 0; i < this.sample.length; i++) {
|
for (const item of this.sample) {
|
||||||
var item = this.sample[i];
|
|
||||||
if (!matchersUtil.contains(other, item)) {
|
if (!matchersUtil.contains(other, item)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,8 +19,7 @@ getJasmineRequireObj().ArrayWithExactContents = function(j$) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var i = 0; i < this.sample.length; i++) {
|
for (const item of this.sample) {
|
||||||
var item = this.sample[i];
|
|
||||||
if (!matchersUtil.contains(other, item)) {
|
if (!matchersUtil.contains(other, item)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
17
src/core/asymmetric_equality/Is.js
Normal file
17
src/core/asymmetric_equality/Is.js
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
getJasmineRequireObj().Is = function(j$) {
|
||||||
|
class Is {
|
||||||
|
constructor(expected) {
|
||||||
|
this.expected_ = expected;
|
||||||
|
}
|
||||||
|
|
||||||
|
asymmetricMatch(actual) {
|
||||||
|
return actual === this.expected_;
|
||||||
|
}
|
||||||
|
|
||||||
|
jasmineToString(pp) {
|
||||||
|
return `<jasmine.is(${pp(this.expected_)})>`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Is;
|
||||||
|
};
|
||||||
@@ -16,7 +16,7 @@ getJasmineRequireObj().MapContaining = function(j$) {
|
|||||||
for (const [key, value] of this.sample) {
|
for (const [key, value] of this.sample) {
|
||||||
// for each key/value pair in `sample`
|
// for each key/value pair in `sample`
|
||||||
// there should be at least one pair in `other` whose key and value both match
|
// there should be at least one pair in `other` whose key and value both match
|
||||||
var hasMatch = false;
|
let hasMatch = false;
|
||||||
for (const [oKey, oValue] of other) {
|
for (const [oKey, oValue] of other) {
|
||||||
if (
|
if (
|
||||||
matchersUtil.equals(oKey, key) &&
|
matchersUtil.equals(oKey, key) &&
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ getJasmineRequireObj().ObjectContaining = function(j$) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var property in this.sample) {
|
for (const property in this.sample) {
|
||||||
if (
|
if (
|
||||||
!hasProperty(other, property) ||
|
!hasProperty(other, property) ||
|
||||||
!matchersUtil.equals(this.sample[property], other[property])
|
!matchersUtil.equals(this.sample[property], other[property])
|
||||||
@@ -47,7 +47,7 @@ getJasmineRequireObj().ObjectContaining = function(j$) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
var filteredOther = {};
|
const filteredOther = {};
|
||||||
Object.keys(this.sample).forEach(function(k) {
|
Object.keys(this.sample).forEach(function(k) {
|
||||||
// eq short-circuits comparison of objects that have different key sets,
|
// eq short-circuits comparison of objects that have different key sets,
|
||||||
// so include all keys even if undefined.
|
// so include all keys even if undefined.
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ getJasmineRequireObj().SetContaining = function(j$) {
|
|||||||
// for each item in `sample` there should be at least one matching item in `other`
|
// for each item in `sample` there should be at least one matching item in `other`
|
||||||
// (not using `matchersUtil.contains` because it compares set members by reference,
|
// (not using `matchersUtil.contains` because it compares set members by reference,
|
||||||
// not by deep value equality)
|
// not by deep value equality)
|
||||||
var hasMatch = false;
|
let hasMatch = false;
|
||||||
for (const oItem of other) {
|
for (const oItem of other) {
|
||||||
if (matchersUtil.equals(oItem, item)) {
|
if (matchersUtil.equals(oItem, item)) {
|
||||||
hasMatch = true;
|
hasMatch = true;
|
||||||
|
|||||||
@@ -1,8 +1,4 @@
|
|||||||
getJasmineRequireObj().base = function(j$, jasmineGlobal) {
|
getJasmineRequireObj().base = function(j$, jasmineGlobal) {
|
||||||
j$.unimplementedMethod_ = function() {
|
|
||||||
throw new Error('unimplemented method');
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Maximum object depth the pretty printer will print to.
|
* Maximum object depth the pretty printer will print to.
|
||||||
* Set this to a lower value to speed up pretty printing if you have large objects.
|
* Set this to a lower value to speed up pretty printing if you have large objects.
|
||||||
@@ -43,7 +39,7 @@ getJasmineRequireObj().base = function(j$, jasmineGlobal) {
|
|||||||
* @default 5000
|
* @default 5000
|
||||||
* @since 1.3.0
|
* @since 1.3.0
|
||||||
*/
|
*/
|
||||||
var DEFAULT_TIMEOUT_INTERVAL = 5000;
|
let DEFAULT_TIMEOUT_INTERVAL = 5000;
|
||||||
Object.defineProperty(j$, 'DEFAULT_TIMEOUT_INTERVAL', {
|
Object.defineProperty(j$, 'DEFAULT_TIMEOUT_INTERVAL', {
|
||||||
get: function() {
|
get: function() {
|
||||||
return DEFAULT_TIMEOUT_INTERVAL;
|
return DEFAULT_TIMEOUT_INTERVAL;
|
||||||
@@ -67,7 +63,7 @@ getJasmineRequireObj().base = function(j$, jasmineGlobal) {
|
|||||||
* @return {Env}
|
* @return {Env}
|
||||||
*/
|
*/
|
||||||
j$.getEnv = function(options) {
|
j$.getEnv = function(options) {
|
||||||
var env = (j$.currentEnv_ = j$.currentEnv_ || new j$.Env(options));
|
const env = (j$.currentEnv_ = j$.currentEnv_ || new j$.Env(options));
|
||||||
//jasmine. singletons in here (setTimeout blah blah).
|
//jasmine. singletons in here (setTimeout blah blah).
|
||||||
return env;
|
return env;
|
||||||
};
|
};
|
||||||
@@ -208,7 +204,7 @@ getJasmineRequireObj().base = function(j$, jasmineGlobal) {
|
|||||||
return func.name;
|
return func.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
var matches =
|
const matches =
|
||||||
func.toString().match(/^\s*function\s*(\w+)\s*\(/) ||
|
func.toString().match(/^\s*function\s*(\w+)\s*\(/) ||
|
||||||
func.toString().match(/^\s*\[object\s*(\w+)Constructor\]/);
|
func.toString().match(/^\s*\[object\s*(\w+)Constructor\]/);
|
||||||
|
|
||||||
@@ -216,7 +212,7 @@ getJasmineRequireObj().base = function(j$, jasmineGlobal) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
j$.isPending_ = function(promise) {
|
j$.isPending_ = function(promise) {
|
||||||
var sentinel = {};
|
const sentinel = {};
|
||||||
return Promise.race([promise, Promise.resolve(sentinel)]).then(
|
return Promise.race([promise, Promise.resolve(sentinel)]).then(
|
||||||
function(result) {
|
function(result) {
|
||||||
return result === sentinel;
|
return result === sentinel;
|
||||||
@@ -283,6 +279,18 @@ getJasmineRequireObj().base = function(j$, jasmineGlobal) {
|
|||||||
return new j$.Empty();
|
return new j$.Empty();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get an {@link AsymmetricEqualityTester}, usable in any {@link matchers|matcher}
|
||||||
|
* that passes if the actual value is the same as the sample as determined
|
||||||
|
* by the `===` operator.
|
||||||
|
* @name jasmine.is
|
||||||
|
* @function
|
||||||
|
* @param {Object} sample - The value to compare the actual to.
|
||||||
|
*/
|
||||||
|
j$.is = function(sample) {
|
||||||
|
return new j$.Is(sample);
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get an {@link AsymmetricEqualityTester}, usable in any {@link matchers|matcher} that uses Jasmine's equality (e.g. {@link matchers#toEqual|toEqual}, {@link matchers#toContain|toContain}, or {@link matchers#toHaveBeenCalledWith|toHaveBeenCalledWith}),
|
* Get an {@link AsymmetricEqualityTester}, usable in any {@link matchers|matcher} that uses Jasmine's equality (e.g. {@link matchers#toEqual|toEqual}, {@link matchers#toContain|toContain}, or {@link matchers#toHaveBeenCalledWith|toHaveBeenCalledWith}),
|
||||||
* that will succeed if the actual value being compared is not empty.
|
* that will succeed if the actual value being compared is not empty.
|
||||||
@@ -413,4 +421,47 @@ getJasmineRequireObj().base = function(j$, jasmineGlobal) {
|
|||||||
j$.debugLog = function(msg) {
|
j$.debugLog = function(msg) {
|
||||||
j$.getEnv().debugLog(msg);
|
j$.getEnv().debugLog(msg);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Replaces Jasmine's global error handling with a spy. This prevents Jasmine
|
||||||
|
* from treating uncaught exceptions and unhandled promise rejections
|
||||||
|
* as spec failures and allows them to be inspected using the spy's
|
||||||
|
* {@link Spy#calls|calls property} and related matchers such as
|
||||||
|
* {@link matchers#toHaveBeenCalledWith|toHaveBeenCalledWith}.
|
||||||
|
*
|
||||||
|
* After installing the spy, spyOnGlobalErrorsAsync immediately calls its
|
||||||
|
* argument, which must be an async or promise-returning function. The spy
|
||||||
|
* will be passed as the first argument to that callback. Normal error
|
||||||
|
* handling will be restored when the promise returned from the callback is
|
||||||
|
* settled.
|
||||||
|
*
|
||||||
|
* Note: The JavaScript runtime may deliver uncaught error events and unhandled
|
||||||
|
* rejection events asynchronously, especially in browsers. If the event
|
||||||
|
* occurs after the promise returned from the callback is settled, it won't
|
||||||
|
* be routed to the spy even if the underlying error occurred previously.
|
||||||
|
* It's up to you to ensure that the returned promise isn't resolved until
|
||||||
|
* all of the error/rejection events that you want to handle have occurred.
|
||||||
|
*
|
||||||
|
* You must await the return value of spyOnGlobalErrorsAsync.
|
||||||
|
* @name jasmine.spyOnGlobalErrorsAsync
|
||||||
|
* @function
|
||||||
|
* @async
|
||||||
|
* @param {AsyncFunction} fn - A function to run, during which the global error spy will be effective
|
||||||
|
* @example
|
||||||
|
* it('demonstrates global error spies', async function() {
|
||||||
|
* await jasmine.spyOnGlobalErrorsAsync(async function(globalErrorSpy) {
|
||||||
|
* setTimeout(function() {
|
||||||
|
* throw new Error('the expected error');
|
||||||
|
* });
|
||||||
|
* await new Promise(function(resolve) {
|
||||||
|
* setTimeout(resolve);
|
||||||
|
* });
|
||||||
|
* const expected = new Error('the expected error');
|
||||||
|
* expect(globalErrorSpy).toHaveBeenCalledWith(expected);
|
||||||
|
* });
|
||||||
|
* });
|
||||||
|
*/
|
||||||
|
j$.spyOnGlobalErrorsAsync = async function(fn) {
|
||||||
|
await jasmine.getEnv().spyOnGlobalErrorsAsync(fn);
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
//TODO: expectation result may make more sense as a presentation of an expectation.
|
//TODO: expectation result may make more sense as a presentation of an expectation.
|
||||||
getJasmineRequireObj().buildExpectationResult = function(j$) {
|
getJasmineRequireObj().buildExpectationResult = function(j$) {
|
||||||
function buildExpectationResult(options) {
|
function buildExpectationResult(options) {
|
||||||
var messageFormatter = options.messageFormatter || function() {},
|
const exceptionFormatter = new j$.ExceptionFormatter();
|
||||||
stackFormatter = options.stackFormatter || function() {};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef Expectation
|
* @typedef Expectation
|
||||||
@@ -16,7 +15,7 @@ getJasmineRequireObj().buildExpectationResult = function(j$) {
|
|||||||
* is reported on the top suite. Valid values are undefined, "afterAll",
|
* is reported on the top suite. Valid values are undefined, "afterAll",
|
||||||
* "load", "lateExpectation", and "lateError".
|
* "load", "lateExpectation", and "lateError".
|
||||||
*/
|
*/
|
||||||
var result = {
|
const result = {
|
||||||
matcherName: options.matcherName,
|
matcherName: options.matcherName,
|
||||||
message: message(),
|
message: message(),
|
||||||
stack: options.omitStackTrace ? '' : stack(),
|
stack: options.omitStackTrace ? '' : stack(),
|
||||||
@@ -52,7 +51,7 @@ getJasmineRequireObj().buildExpectationResult = function(j$) {
|
|||||||
} else if (options.message) {
|
} else if (options.message) {
|
||||||
return options.message;
|
return options.message;
|
||||||
} else if (options.error) {
|
} else if (options.error) {
|
||||||
return messageFormatter(options.error);
|
return exceptionFormatter.message(options.error);
|
||||||
}
|
}
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
@@ -62,7 +61,8 @@ getJasmineRequireObj().buildExpectationResult = function(j$) {
|
|||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
var error = options.error;
|
let error = options.error;
|
||||||
|
|
||||||
if (!error) {
|
if (!error) {
|
||||||
if (options.errorForStack) {
|
if (options.errorForStack) {
|
||||||
error = options.errorForStack;
|
error = options.errorForStack;
|
||||||
@@ -78,7 +78,7 @@ getJasmineRequireObj().buildExpectationResult = function(j$) {
|
|||||||
}
|
}
|
||||||
// Omit the message from the stack trace because it will be
|
// Omit the message from the stack trace because it will be
|
||||||
// included elsewhere.
|
// included elsewhere.
|
||||||
return stackFormatter(error, { omitMessage: true });
|
return exceptionFormatter.stack(error, { omitMessage: true });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
getJasmineRequireObj().formatErrorMsg = function() {
|
getJasmineRequireObj().formatErrorMsg = function() {
|
||||||
function generateErrorMsg(domain, usage) {
|
function generateErrorMsg(domain, usage) {
|
||||||
var usageDefinition = usage ? '\nUsage: ' + usage : '';
|
const usageDefinition = usage ? '\nUsage: ' + usage : '';
|
||||||
|
|
||||||
return function errorMsg(msg) {
|
return function errorMsg(msg) {
|
||||||
return domain + ' : ' + msg + usageDefinition;
|
return domain + ' : ' + msg + usageDefinition;
|
||||||
|
|||||||
@@ -1,118 +1,112 @@
|
|||||||
getJasmineRequireObj().DiffBuilder = function(j$) {
|
getJasmineRequireObj().DiffBuilder = function(j$) {
|
||||||
return function DiffBuilder(config) {
|
class DiffBuilder {
|
||||||
var prettyPrinter = (config || {}).prettyPrinter || j$.makePrettyPrinter(),
|
constructor(config) {
|
||||||
mismatches = new j$.MismatchTree(),
|
this.prettyPrinter_ =
|
||||||
path = new j$.ObjectPath(),
|
(config || {}).prettyPrinter || j$.makePrettyPrinter();
|
||||||
actualRoot = undefined,
|
this.mismatches_ = new j$.MismatchTree();
|
||||||
expectedRoot = undefined;
|
this.path_ = new j$.ObjectPath();
|
||||||
|
this.actualRoot_ = undefined;
|
||||||
|
this.expectedRoot_ = undefined;
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
setRoots(actual, expected) {
|
||||||
setRoots: function(actual, expected) {
|
this.actualRoot_ = actual;
|
||||||
actualRoot = actual;
|
this.expectedRoot_ = expected;
|
||||||
expectedRoot = expected;
|
}
|
||||||
},
|
|
||||||
|
|
||||||
recordMismatch: function(formatter) {
|
recordMismatch(formatter) {
|
||||||
mismatches.add(path, formatter);
|
this.mismatches_.add(this.path_, formatter);
|
||||||
},
|
}
|
||||||
|
|
||||||
getMessage: function() {
|
getMessage() {
|
||||||
var messages = [];
|
const messages = [];
|
||||||
|
|
||||||
mismatches.traverse(function(path, isLeaf, formatter) {
|
this.mismatches_.traverse((path, isLeaf, formatter) => {
|
||||||
var actualCustom,
|
const { actual, expected } = this.dereferencePath_(path);
|
||||||
expectedCustom,
|
|
||||||
useCustom,
|
|
||||||
derefResult = dereferencePath(
|
|
||||||
path,
|
|
||||||
actualRoot,
|
|
||||||
expectedRoot,
|
|
||||||
prettyPrinter
|
|
||||||
),
|
|
||||||
actual = derefResult.actual,
|
|
||||||
expected = derefResult.expected;
|
|
||||||
|
|
||||||
if (formatter) {
|
|
||||||
messages.push(formatter(actual, expected, path, prettyPrinter));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
actualCustom = prettyPrinter.customFormat_(actual);
|
|
||||||
expectedCustom = prettyPrinter.customFormat_(expected);
|
|
||||||
useCustom = !(
|
|
||||||
j$.util.isUndefined(actualCustom) &&
|
|
||||||
j$.util.isUndefined(expectedCustom)
|
|
||||||
);
|
|
||||||
|
|
||||||
if (useCustom) {
|
|
||||||
messages.push(
|
|
||||||
wrapPrettyPrinted(actualCustom, expectedCustom, path)
|
|
||||||
);
|
|
||||||
return false; // don't recurse further
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isLeaf) {
|
|
||||||
messages.push(
|
|
||||||
defaultFormatter(actual, expected, path, prettyPrinter)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (formatter) {
|
||||||
|
messages.push(formatter(actual, expected, path, this.prettyPrinter_));
|
||||||
return true;
|
return true;
|
||||||
});
|
}
|
||||||
|
|
||||||
return messages.join('\n');
|
const actualCustom = this.prettyPrinter_.customFormat_(actual);
|
||||||
},
|
const expectedCustom = this.prettyPrinter_.customFormat_(expected);
|
||||||
|
const useCustom = !(
|
||||||
|
j$.util.isUndefined(actualCustom) &&
|
||||||
|
j$.util.isUndefined(expectedCustom)
|
||||||
|
);
|
||||||
|
|
||||||
withPath: function(pathComponent, block) {
|
if (useCustom) {
|
||||||
var oldPath = path;
|
messages.push(wrapPrettyPrinted(actualCustom, expectedCustom, path));
|
||||||
path = path.add(pathComponent);
|
return false; // don't recurse further
|
||||||
block();
|
}
|
||||||
path = oldPath;
|
|
||||||
|
if (isLeaf) {
|
||||||
|
messages.push(this.defaultFormatter_(actual, expected, path));
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
return messages.join('\n');
|
||||||
|
}
|
||||||
|
|
||||||
|
withPath(pathComponent, block) {
|
||||||
|
const oldPath = this.path_;
|
||||||
|
this.path_ = this.path_.add(pathComponent);
|
||||||
|
block();
|
||||||
|
this.path_ = oldPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
dereferencePath_(objectPath) {
|
||||||
|
let actual = this.actualRoot_;
|
||||||
|
let expected = this.expectedRoot_;
|
||||||
|
|
||||||
|
const handleAsymmetricExpected = () => {
|
||||||
|
if (
|
||||||
|
j$.isAsymmetricEqualityTester_(expected) &&
|
||||||
|
j$.isFunction_(expected.valuesForDiff_)
|
||||||
|
) {
|
||||||
|
const asymmetricResult = expected.valuesForDiff_(
|
||||||
|
actual,
|
||||||
|
this.prettyPrinter_
|
||||||
|
);
|
||||||
|
expected = asymmetricResult.self;
|
||||||
|
actual = asymmetricResult.other;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
handleAsymmetricExpected();
|
||||||
|
|
||||||
|
for (const pc of objectPath.components) {
|
||||||
|
actual = actual[pc];
|
||||||
|
expected = expected[pc];
|
||||||
|
handleAsymmetricExpected();
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
function defaultFormatter(actual, expected, path, prettyPrinter) {
|
return { actual: actual, expected: expected };
|
||||||
|
}
|
||||||
|
|
||||||
|
defaultFormatter_(actual, expected, path) {
|
||||||
return wrapPrettyPrinted(
|
return wrapPrettyPrinted(
|
||||||
prettyPrinter(actual),
|
this.prettyPrinter_(actual),
|
||||||
prettyPrinter(expected),
|
this.prettyPrinter_(expected),
|
||||||
path
|
path
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function wrapPrettyPrinted(actual, expected, path) {
|
|
||||||
return (
|
|
||||||
'Expected ' +
|
|
||||||
path +
|
|
||||||
(path.depth() ? ' = ' : '') +
|
|
||||||
actual +
|
|
||||||
' to equal ' +
|
|
||||||
expected +
|
|
||||||
'.'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
function dereferencePath(objectPath, actual, expected, pp) {
|
|
||||||
function handleAsymmetricExpected() {
|
|
||||||
if (
|
|
||||||
j$.isAsymmetricEqualityTester_(expected) &&
|
|
||||||
j$.isFunction_(expected.valuesForDiff_)
|
|
||||||
) {
|
|
||||||
var asymmetricResult = expected.valuesForDiff_(actual, pp);
|
|
||||||
expected = asymmetricResult.self;
|
|
||||||
actual = asymmetricResult.other;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var i;
|
|
||||||
handleAsymmetricExpected();
|
|
||||||
|
|
||||||
for (i = 0; i < objectPath.components.length; i++) {
|
|
||||||
actual = actual[objectPath.components[i]];
|
|
||||||
expected = expected[objectPath.components[i]];
|
|
||||||
handleAsymmetricExpected();
|
|
||||||
}
|
|
||||||
|
|
||||||
return { actual: actual, expected: expected };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function wrapPrettyPrinted(actual, expected, path) {
|
||||||
|
return (
|
||||||
|
'Expected ' +
|
||||||
|
path +
|
||||||
|
(path.depth() ? ' = ' : '') +
|
||||||
|
actual +
|
||||||
|
' to equal ' +
|
||||||
|
expected +
|
||||||
|
'.'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return DiffBuilder;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -6,56 +6,51 @@ getJasmineRequireObj().MismatchTree = function(j$) {
|
|||||||
the expected and actual object graphs. MismatchTree maintains that context
|
the expected and actual object graphs. MismatchTree maintains that context
|
||||||
and provides it via the traverse method.
|
and provides it via the traverse method.
|
||||||
*/
|
*/
|
||||||
function MismatchTree(path) {
|
class MismatchTree {
|
||||||
this.path = path || new j$.ObjectPath([]);
|
constructor(path) {
|
||||||
this.formatter = undefined;
|
this.path = path || new j$.ObjectPath([]);
|
||||||
this.children = [];
|
this.formatter = undefined;
|
||||||
this.isMismatch = false;
|
this.children = [];
|
||||||
}
|
this.isMismatch = false;
|
||||||
|
|
||||||
MismatchTree.prototype.add = function(path, formatter) {
|
|
||||||
var key, child;
|
|
||||||
|
|
||||||
if (path.depth() === 0) {
|
|
||||||
this.formatter = formatter;
|
|
||||||
this.isMismatch = true;
|
|
||||||
} else {
|
|
||||||
key = path.components[0];
|
|
||||||
path = path.shift();
|
|
||||||
child = this.child(key);
|
|
||||||
|
|
||||||
if (!child) {
|
|
||||||
child = new MismatchTree(this.path.add(key));
|
|
||||||
this.children.push(child);
|
|
||||||
}
|
|
||||||
|
|
||||||
child.add(path, formatter);
|
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
MismatchTree.prototype.traverse = function(visit) {
|
add(path, formatter) {
|
||||||
var i,
|
if (path.depth() === 0) {
|
||||||
hasChildren = this.children.length > 0;
|
this.formatter = formatter;
|
||||||
|
this.isMismatch = true;
|
||||||
|
} else {
|
||||||
|
const key = path.components[0];
|
||||||
|
path = path.shift();
|
||||||
|
let child = this.child(key);
|
||||||
|
|
||||||
if (this.isMismatch || hasChildren) {
|
if (!child) {
|
||||||
if (visit(this.path, !hasChildren, this.formatter)) {
|
child = new MismatchTree(this.path.add(key));
|
||||||
for (i = 0; i < this.children.length; i++) {
|
this.children.push(child);
|
||||||
this.children[i].traverse(visit);
|
}
|
||||||
|
|
||||||
|
child.add(path, formatter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
traverse(visit) {
|
||||||
|
const hasChildren = this.children.length > 0;
|
||||||
|
|
||||||
|
if (this.isMismatch || hasChildren) {
|
||||||
|
if (visit(this.path, !hasChildren, this.formatter)) {
|
||||||
|
for (const child of this.children) {
|
||||||
|
child.traverse(visit);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
MismatchTree.prototype.child = function(key) {
|
child(key) {
|
||||||
var i, pathEls;
|
return this.children.find(child => {
|
||||||
|
const pathEls = child.path.components;
|
||||||
for (i = 0; i < this.children.length; i++) {
|
return pathEls[pathEls.length - 1] === key;
|
||||||
pathEls = this.children[i].path.components;
|
});
|
||||||
if (pathEls[pathEls.length - 1] === key) {
|
|
||||||
return this.children[i];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
return MismatchTree;
|
return MismatchTree;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,27 +1,29 @@
|
|||||||
getJasmineRequireObj().ObjectPath = function(j$) {
|
getJasmineRequireObj().ObjectPath = function(j$) {
|
||||||
function ObjectPath(components) {
|
class ObjectPath {
|
||||||
this.components = components || [];
|
constructor(components) {
|
||||||
}
|
this.components = components || [];
|
||||||
|
|
||||||
ObjectPath.prototype.toString = function() {
|
|
||||||
if (this.components.length) {
|
|
||||||
return '$' + map(this.components, formatPropertyAccess).join('');
|
|
||||||
} else {
|
|
||||||
return '';
|
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
ObjectPath.prototype.add = function(component) {
|
toString() {
|
||||||
return new ObjectPath(this.components.concat([component]));
|
if (this.components.length) {
|
||||||
};
|
return '$' + this.components.map(formatPropertyAccess).join('');
|
||||||
|
} else {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ObjectPath.prototype.shift = function() {
|
add(component) {
|
||||||
return new ObjectPath(this.components.slice(1));
|
return new ObjectPath(this.components.concat([component]));
|
||||||
};
|
}
|
||||||
|
|
||||||
ObjectPath.prototype.depth = function() {
|
shift() {
|
||||||
return this.components.length;
|
return new ObjectPath(this.components.slice(1));
|
||||||
};
|
}
|
||||||
|
|
||||||
|
depth() {
|
||||||
|
return this.components.length;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function formatPropertyAccess(prop) {
|
function formatPropertyAccess(prop) {
|
||||||
if (typeof prop === 'number' || typeof prop === 'symbol') {
|
if (typeof prop === 'number' || typeof prop === 'symbol') {
|
||||||
@@ -32,15 +34,7 @@ getJasmineRequireObj().ObjectPath = function(j$) {
|
|||||||
return '.' + prop;
|
return '.' + prop;
|
||||||
}
|
}
|
||||||
|
|
||||||
return "['" + prop + "']";
|
return `['${prop}']`;
|
||||||
}
|
|
||||||
|
|
||||||
function map(array, fn) {
|
|
||||||
var results = [];
|
|
||||||
for (var i = 0; i < array.length; i++) {
|
|
||||||
results.push(fn(array[i]));
|
|
||||||
}
|
|
||||||
return results;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function isValidIdentifier(string) {
|
function isValidIdentifier(string) {
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ getJasmineRequireObj().toBePending = function(j$) {
|
|||||||
if (!j$.isPromiseLike(actual)) {
|
if (!j$.isPromiseLike(actual)) {
|
||||||
throw new Error('Expected toBePending to be called on a promise.');
|
throw new Error('Expected toBePending to be called on a promise.');
|
||||||
}
|
}
|
||||||
var want = {};
|
const want = {};
|
||||||
return Promise.race([actual, Promise.resolve(want)]).then(
|
return Promise.race([actual, Promise.resolve(want)]).then(
|
||||||
function(got) {
|
function(got) {
|
||||||
return { pass: want === got };
|
return { pass: want === got };
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ getJasmineRequireObj().toBeRejectedWithError = function(j$) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
var expected = getExpectedFromArgs(arg1, arg2, matchersUtil);
|
const expected = getExpectedFromArgs(arg1, arg2, matchersUtil);
|
||||||
|
|
||||||
return actualPromise.then(
|
return actualPromise.then(
|
||||||
function() {
|
function() {
|
||||||
@@ -52,7 +52,7 @@ getJasmineRequireObj().toBeRejectedWithError = function(j$) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
var actualMessage = actual.message;
|
const actualMessage = actual.message;
|
||||||
|
|
||||||
if (
|
if (
|
||||||
actualMessage === expected.message ||
|
actualMessage === expected.message ||
|
||||||
@@ -94,7 +94,7 @@ getJasmineRequireObj().toBeRejectedWithError = function(j$) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getExpectedFromArgs(arg1, arg2, matchersUtil) {
|
function getExpectedFromArgs(arg1, arg2, matchersUtil) {
|
||||||
var error, message;
|
let error, message;
|
||||||
|
|
||||||
if (isErrorConstructor(arg1)) {
|
if (isErrorConstructor(arg1)) {
|
||||||
error = arg1;
|
error = arg1;
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ getJasmineRequireObj().MatchersUtil = function(j$) {
|
|||||||
|
|
||||||
if (j$.isNumber_(haystack.length)) {
|
if (j$.isNumber_(haystack.length)) {
|
||||||
// Objects that are shaped like arrays but aren't iterable
|
// Objects that are shaped like arrays but aren't iterable
|
||||||
for (var i = 0; i < haystack.length; i++) {
|
for (let i = 0; i < haystack.length; i++) {
|
||||||
if (this.equals(haystack[i], needle)) {
|
if (this.equals(haystack[i], needle)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -74,8 +74,7 @@ getJasmineRequireObj().MatchersUtil = function(j$) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
MatchersUtil.prototype.buildFailureMessage = function() {
|
MatchersUtil.prototype.buildFailureMessage = function() {
|
||||||
var self = this;
|
const args = Array.prototype.slice.call(arguments, 0),
|
||||||
var args = Array.prototype.slice.call(arguments, 0),
|
|
||||||
matcherName = args[0],
|
matcherName = args[0],
|
||||||
isNot = args[1],
|
isNot = args[1],
|
||||||
actual = args[2],
|
actual = args[2],
|
||||||
@@ -84,18 +83,18 @@ getJasmineRequireObj().MatchersUtil = function(j$) {
|
|||||||
return ' ' + s.toLowerCase();
|
return ' ' + s.toLowerCase();
|
||||||
});
|
});
|
||||||
|
|
||||||
var message =
|
let message =
|
||||||
'Expected ' +
|
'Expected ' +
|
||||||
self.pp(actual) +
|
this.pp(actual) +
|
||||||
(isNot ? ' not ' : ' ') +
|
(isNot ? ' not ' : ' ') +
|
||||||
englishyPredicate;
|
englishyPredicate;
|
||||||
|
|
||||||
if (expected.length > 0) {
|
if (expected.length > 0) {
|
||||||
for (var i = 0; i < expected.length; i++) {
|
for (let i = 0; i < expected.length; i++) {
|
||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
message += ',';
|
message += ',';
|
||||||
}
|
}
|
||||||
message += ' ' + self.pp(expected[i]);
|
message += ' ' + this.pp(expected[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,7 +109,7 @@ getJasmineRequireObj().MatchersUtil = function(j$) {
|
|||||||
diffBuilder
|
diffBuilder
|
||||||
) {
|
) {
|
||||||
if (j$.isFunction_(b.valuesForDiff_)) {
|
if (j$.isFunction_(b.valuesForDiff_)) {
|
||||||
var values = b.valuesForDiff_(a, this.pp);
|
const values = b.valuesForDiff_(a, this.pp);
|
||||||
this.eq_(values.other, values.self, aStack, bStack, diffBuilder);
|
this.eq_(values.other, values.self, aStack, bStack, diffBuilder);
|
||||||
} else {
|
} else {
|
||||||
diffBuilder.recordMismatch();
|
diffBuilder.recordMismatch();
|
||||||
@@ -124,14 +123,15 @@ getJasmineRequireObj().MatchersUtil = function(j$) {
|
|||||||
bStack,
|
bStack,
|
||||||
diffBuilder
|
diffBuilder
|
||||||
) {
|
) {
|
||||||
var asymmetricA = j$.isAsymmetricEqualityTester_(a),
|
const asymmetricA = j$.isAsymmetricEqualityTester_(a);
|
||||||
asymmetricB = j$.isAsymmetricEqualityTester_(b),
|
const asymmetricB = j$.isAsymmetricEqualityTester_(b);
|
||||||
result;
|
|
||||||
|
|
||||||
if (asymmetricA === asymmetricB) {
|
if (asymmetricA === asymmetricB) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let result;
|
||||||
|
|
||||||
if (asymmetricA) {
|
if (asymmetricA) {
|
||||||
result = a.asymmetricMatch(b, this);
|
result = a.asymmetricMatch(b, this);
|
||||||
if (!result) {
|
if (!result) {
|
||||||
@@ -168,11 +168,9 @@ getJasmineRequireObj().MatchersUtil = function(j$) {
|
|||||||
// Equality function lovingly adapted from isEqual in
|
// Equality function lovingly adapted from isEqual in
|
||||||
// [Underscore](http://underscorejs.org)
|
// [Underscore](http://underscorejs.org)
|
||||||
MatchersUtil.prototype.eq_ = function(a, b, aStack, bStack, diffBuilder) {
|
MatchersUtil.prototype.eq_ = function(a, b, aStack, bStack, diffBuilder) {
|
||||||
var result = true,
|
let result = true;
|
||||||
self = this,
|
|
||||||
i;
|
|
||||||
|
|
||||||
var asymmetricResult = this.asymmetricMatch_(
|
const asymmetricResult = this.asymmetricMatch_(
|
||||||
a,
|
a,
|
||||||
b,
|
b,
|
||||||
aStack,
|
aStack,
|
||||||
@@ -183,8 +181,8 @@ getJasmineRequireObj().MatchersUtil = function(j$) {
|
|||||||
return asymmetricResult;
|
return asymmetricResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < this.customTesters_.length; i++) {
|
for (const tester of this.customTesters_) {
|
||||||
var customTesterResult = this.customTesters_[i](a, b);
|
const customTesterResult = tester(a, b);
|
||||||
if (!j$.util.isUndefined(customTesterResult)) {
|
if (!j$.util.isUndefined(customTesterResult)) {
|
||||||
if (!customTesterResult) {
|
if (!customTesterResult) {
|
||||||
diffBuilder.recordMismatch();
|
diffBuilder.recordMismatch();
|
||||||
@@ -218,7 +216,7 @@ getJasmineRequireObj().MatchersUtil = function(j$) {
|
|||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
var className = Object.prototype.toString.call(a);
|
const className = Object.prototype.toString.call(a);
|
||||||
if (className != Object.prototype.toString.call(b)) {
|
if (className != Object.prototype.toString.call(b)) {
|
||||||
diffBuilder.recordMismatch();
|
diffBuilder.recordMismatch();
|
||||||
return false;
|
return false;
|
||||||
@@ -255,7 +253,7 @@ getJasmineRequireObj().MatchersUtil = function(j$) {
|
|||||||
case '[object ArrayBuffer]':
|
case '[object ArrayBuffer]':
|
||||||
// If we have an instance of ArrayBuffer the Uint8Array ctor
|
// If we have an instance of ArrayBuffer the Uint8Array ctor
|
||||||
// will be defined as well
|
// will be defined as well
|
||||||
return self.eq_(
|
return this.eq_(
|
||||||
new Uint8Array(a),
|
new Uint8Array(a),
|
||||||
new Uint8Array(b),
|
new Uint8Array(b),
|
||||||
aStack,
|
aStack,
|
||||||
@@ -276,8 +274,8 @@ getJasmineRequireObj().MatchersUtil = function(j$) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var aIsDomNode = j$.isDomNode(a);
|
const aIsDomNode = j$.isDomNode(a);
|
||||||
var bIsDomNode = j$.isDomNode(b);
|
const bIsDomNode = j$.isDomNode(b);
|
||||||
if (aIsDomNode && bIsDomNode) {
|
if (aIsDomNode && bIsDomNode) {
|
||||||
// At first try to use DOM3 method isEqualNode
|
// At first try to use DOM3 method isEqualNode
|
||||||
result = a.isEqualNode(b);
|
result = a.isEqualNode(b);
|
||||||
@@ -291,15 +289,15 @@ getJasmineRequireObj().MatchersUtil = function(j$) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var aIsPromise = j$.isPromise(a);
|
const aIsPromise = j$.isPromise(a);
|
||||||
var bIsPromise = j$.isPromise(b);
|
const bIsPromise = j$.isPromise(b);
|
||||||
if (aIsPromise && bIsPromise) {
|
if (aIsPromise && bIsPromise) {
|
||||||
return a === b;
|
return a === b;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Assume equality for cyclic structures. The algorithm for detecting cyclic
|
// Assume equality for cyclic structures. The algorithm for detecting cyclic
|
||||||
// structures is adapted from ES 5.1 section 15.12.3, abstract operation `JO`.
|
// structures is adapted from ES 5.1 section 15.12.3, abstract operation `JO`.
|
||||||
var length = aStack.length;
|
let length = aStack.length;
|
||||||
while (length--) {
|
while (length--) {
|
||||||
// Linear search. Performance is inversely proportional to the number of
|
// Linear search. Performance is inversely proportional to the number of
|
||||||
// unique nested structures.
|
// unique nested structures.
|
||||||
@@ -310,12 +308,12 @@ getJasmineRequireObj().MatchersUtil = function(j$) {
|
|||||||
// Add the first object to the stack of traversed objects.
|
// Add the first object to the stack of traversed objects.
|
||||||
aStack.push(a);
|
aStack.push(a);
|
||||||
bStack.push(b);
|
bStack.push(b);
|
||||||
var size = 0;
|
let size = 0;
|
||||||
// Recursively compare objects and arrays.
|
// Recursively compare objects and arrays.
|
||||||
// Compare array lengths to determine if a deep comparison is necessary.
|
// Compare array lengths to determine if a deep comparison is necessary.
|
||||||
if (className == '[object Array]') {
|
if (className == '[object Array]') {
|
||||||
var aLength = a.length;
|
const aLength = a.length;
|
||||||
var bLength = b.length;
|
const bLength = b.length;
|
||||||
|
|
||||||
diffBuilder.withPath('length', function() {
|
diffBuilder.withPath('length', function() {
|
||||||
if (aLength !== bLength) {
|
if (aLength !== bLength) {
|
||||||
@@ -324,16 +322,16 @@ getJasmineRequireObj().MatchersUtil = function(j$) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
for (i = 0; i < aLength || i < bLength; i++) {
|
for (let i = 0; i < aLength || i < bLength; i++) {
|
||||||
diffBuilder.withPath(i, function() {
|
diffBuilder.withPath(i, () => {
|
||||||
if (i >= bLength) {
|
if (i >= bLength) {
|
||||||
diffBuilder.recordMismatch(
|
diffBuilder.recordMismatch(
|
||||||
actualArrayIsLongerFormatter.bind(null, self.pp)
|
actualArrayIsLongerFormatter.bind(null, this.pp)
|
||||||
);
|
);
|
||||||
result = false;
|
result = false;
|
||||||
} else {
|
} else {
|
||||||
result =
|
result =
|
||||||
self.eq_(
|
this.eq_(
|
||||||
i < aLength ? a[i] : void 0,
|
i < aLength ? a[i] : void 0,
|
||||||
i < bLength ? b[i] : void 0,
|
i < bLength ? b[i] : void 0,
|
||||||
aStack,
|
aStack,
|
||||||
@@ -352,8 +350,8 @@ getJasmineRequireObj().MatchersUtil = function(j$) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var keysA = [];
|
const keysA = [];
|
||||||
var keysB = [];
|
const keysB = [];
|
||||||
a.forEach(function(valueA, keyA) {
|
a.forEach(function(valueA, keyA) {
|
||||||
keysA.push(keyA);
|
keysA.push(keyA);
|
||||||
});
|
});
|
||||||
@@ -363,18 +361,17 @@ getJasmineRequireObj().MatchersUtil = function(j$) {
|
|||||||
|
|
||||||
// For both sets of keys, check they map to equal values in both maps.
|
// For both sets of keys, check they map to equal values in both maps.
|
||||||
// Keep track of corresponding keys (in insertion order) in order to handle asymmetric obj keys.
|
// Keep track of corresponding keys (in insertion order) in order to handle asymmetric obj keys.
|
||||||
var mapKeys = [keysA, keysB];
|
const mapKeys = [keysA, keysB];
|
||||||
var cmpKeys = [keysB, keysA];
|
const cmpKeys = [keysB, keysA];
|
||||||
var mapIter, mapKey, mapValueA, mapValueB;
|
for (let i = 0; result && i < mapKeys.length; i++) {
|
||||||
var cmpIter, cmpKey;
|
const mapIter = mapKeys[i];
|
||||||
for (i = 0; result && i < mapKeys.length; i++) {
|
const cmpIter = cmpKeys[i];
|
||||||
mapIter = mapKeys[i];
|
|
||||||
cmpIter = cmpKeys[i];
|
|
||||||
|
|
||||||
for (var j = 0; result && j < mapIter.length; j++) {
|
for (let j = 0; result && j < mapIter.length; j++) {
|
||||||
mapKey = mapIter[j];
|
const mapKey = mapIter[j];
|
||||||
cmpKey = cmpIter[j];
|
const cmpKey = cmpIter[j];
|
||||||
mapValueA = a.get(mapKey);
|
const mapValueA = a.get(mapKey);
|
||||||
|
let mapValueB;
|
||||||
|
|
||||||
// Only use the cmpKey when one of the keys is asymmetric and the corresponding key matches,
|
// Only use the cmpKey when one of the keys is asymmetric and the corresponding key matches,
|
||||||
// otherwise explicitly look up the mapKey in the other Map since we want keys with unique
|
// otherwise explicitly look up the mapKey in the other Map since we want keys with unique
|
||||||
@@ -408,35 +405,30 @@ getJasmineRequireObj().MatchersUtil = function(j$) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var valuesA = [];
|
const valuesA = [];
|
||||||
a.forEach(function(valueA) {
|
a.forEach(function(valueA) {
|
||||||
valuesA.push(valueA);
|
valuesA.push(valueA);
|
||||||
});
|
});
|
||||||
var valuesB = [];
|
const valuesB = [];
|
||||||
b.forEach(function(valueB) {
|
b.forEach(function(valueB) {
|
||||||
valuesB.push(valueB);
|
valuesB.push(valueB);
|
||||||
});
|
});
|
||||||
|
|
||||||
// For both sets, check they are all contained in the other set
|
// For both sets, check they are all contained in the other set
|
||||||
var setPairs = [[valuesA, valuesB], [valuesB, valuesA]];
|
const setPairs = [[valuesA, valuesB], [valuesB, valuesA]];
|
||||||
var stackPairs = [[aStack, bStack], [bStack, aStack]];
|
const stackPairs = [[aStack, bStack], [bStack, aStack]];
|
||||||
var baseValues, baseValue, baseStack;
|
for (let i = 0; result && i < setPairs.length; i++) {
|
||||||
var otherValues, otherValue, otherStack;
|
const baseValues = setPairs[i][0];
|
||||||
var found;
|
const otherValues = setPairs[i][1];
|
||||||
var prevStackSize;
|
const baseStack = stackPairs[i][0];
|
||||||
for (i = 0; result && i < setPairs.length; i++) {
|
const otherStack = stackPairs[i][1];
|
||||||
baseValues = setPairs[i][0];
|
|
||||||
otherValues = setPairs[i][1];
|
|
||||||
baseStack = stackPairs[i][0];
|
|
||||||
otherStack = stackPairs[i][1];
|
|
||||||
// For each value in the base set...
|
// For each value in the base set...
|
||||||
for (var k = 0; result && k < baseValues.length; k++) {
|
for (const baseValue of baseValues) {
|
||||||
baseValue = baseValues[k];
|
let found = false;
|
||||||
found = false;
|
|
||||||
// ... test that it is present in the other set
|
// ... test that it is present in the other set
|
||||||
for (var l = 0; !found && l < otherValues.length; l++) {
|
for (let j = 0; !found && j < otherValues.length; j++) {
|
||||||
otherValue = otherValues[l];
|
const otherValue = otherValues[j];
|
||||||
prevStackSize = baseStack.length;
|
const prevStackSize = baseStack.length;
|
||||||
// compare by value equality
|
// compare by value equality
|
||||||
found = this.eq_(
|
found = this.eq_(
|
||||||
baseValue,
|
baseValue,
|
||||||
@@ -465,7 +457,7 @@ getJasmineRequireObj().MatchersUtil = function(j$) {
|
|||||||
} else {
|
} else {
|
||||||
// Objects with different constructors are not equivalent, but `Object`s
|
// Objects with different constructors are not equivalent, but `Object`s
|
||||||
// or `Array`s from different frames are.
|
// or `Array`s from different frames are.
|
||||||
var aCtor = a.constructor,
|
const aCtor = a.constructor,
|
||||||
bCtor = b.constructor;
|
bCtor = b.constructor;
|
||||||
if (
|
if (
|
||||||
aCtor !== bCtor &&
|
aCtor !== bCtor &&
|
||||||
@@ -483,8 +475,7 @@ getJasmineRequireObj().MatchersUtil = function(j$) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Deep compare objects.
|
// Deep compare objects.
|
||||||
var aKeys = MatchersUtil.keys(a, className == '[object Array]'),
|
const aKeys = MatchersUtil.keys(a, className == '[object Array]');
|
||||||
key;
|
|
||||||
size = aKeys.length;
|
size = aKeys.length;
|
||||||
|
|
||||||
// Ensure that both objects contain the same number of properties before comparing deep equality.
|
// Ensure that both objects contain the same number of properties before comparing deep equality.
|
||||||
@@ -495,8 +486,7 @@ getJasmineRequireObj().MatchersUtil = function(j$) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < size; i++) {
|
for (const key of aKeys) {
|
||||||
key = aKeys[i];
|
|
||||||
// Deep compare each member
|
// Deep compare each member
|
||||||
if (!j$.util.has(b, key)) {
|
if (!j$.util.has(b, key)) {
|
||||||
diffBuilder.recordMismatch(
|
diffBuilder.recordMismatch(
|
||||||
@@ -506,8 +496,8 @@ getJasmineRequireObj().MatchersUtil = function(j$) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
diffBuilder.withPath(key, function() {
|
diffBuilder.withPath(key, () => {
|
||||||
if (!self.eq_(a[key], b[key], aStack, bStack, diffBuilder)) {
|
if (!this.eq_(a[key], b[key], aStack, bStack, diffBuilder)) {
|
||||||
result = false;
|
result = false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -525,18 +515,18 @@ getJasmineRequireObj().MatchersUtil = function(j$) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
MatchersUtil.keys = function(obj, isArray) {
|
MatchersUtil.keys = function(obj, isArray) {
|
||||||
var allKeys = (function(o) {
|
const allKeys = (function(o) {
|
||||||
var keys = [];
|
const keys = [];
|
||||||
for (var key in o) {
|
for (const key in o) {
|
||||||
if (j$.util.has(o, key)) {
|
if (j$.util.has(o, key)) {
|
||||||
keys.push(key);
|
keys.push(key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var symbols = Object.getOwnPropertySymbols(o);
|
const symbols = Object.getOwnPropertySymbols(o);
|
||||||
for (var i = 0; i < symbols.length; i++) {
|
for (const sym of symbols) {
|
||||||
if (o.propertyIsEnumerable(symbols[i])) {
|
if (o.propertyIsEnumerable(sym)) {
|
||||||
keys.push(symbols[i]);
|
keys.push(sym);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -551,10 +541,10 @@ getJasmineRequireObj().MatchersUtil = function(j$) {
|
|||||||
return allKeys;
|
return allKeys;
|
||||||
}
|
}
|
||||||
|
|
||||||
var extraKeys = [];
|
const extraKeys = [];
|
||||||
for (var i = 0; i < allKeys.length; i++) {
|
for (const k of allKeys) {
|
||||||
if (typeof allKeys[i] === 'symbol' || !/^[0-9]+$/.test(allKeys[i])) {
|
if (typeof k === 'symbol' || !/^[0-9]+$/.test(k)) {
|
||||||
extraKeys.push(allKeys[i]);
|
extraKeys.push(k);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -574,7 +564,7 @@ getJasmineRequireObj().MatchersUtil = function(j$) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function objectKeysAreDifferentFormatter(pp, actual, expected, path) {
|
function objectKeysAreDifferentFormatter(pp, actual, expected, path) {
|
||||||
var missingProperties = extraKeysAndValues(expected, actual),
|
const missingProperties = extraKeysAndValues(expected, actual),
|
||||||
extraProperties = extraKeysAndValues(actual, expected),
|
extraProperties = extraKeysAndValues(actual, expected),
|
||||||
missingPropertiesMessage = formatKeyValuePairs(pp, missingProperties),
|
missingPropertiesMessage = formatKeyValuePairs(pp, missingProperties),
|
||||||
extraPropertiesMessage = formatKeyValuePairs(pp, extraProperties),
|
extraPropertiesMessage = formatKeyValuePairs(pp, extraProperties),
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
getJasmineRequireObj().requireAsyncMatchers = function(jRequire, j$) {
|
getJasmineRequireObj().requireAsyncMatchers = function(jRequire, j$) {
|
||||||
var availableMatchers = [
|
const availableMatchers = [
|
||||||
'toBePending',
|
'toBePending',
|
||||||
'toBeResolved',
|
'toBeResolved',
|
||||||
'toBeRejected',
|
'toBeRejected',
|
||||||
@@ -9,8 +9,7 @@ getJasmineRequireObj().requireAsyncMatchers = function(jRequire, j$) {
|
|||||||
],
|
],
|
||||||
matchers = {};
|
matchers = {};
|
||||||
|
|
||||||
for (var i = 0; i < availableMatchers.length; i++) {
|
for (const name of availableMatchers) {
|
||||||
var name = availableMatchers[i];
|
|
||||||
matchers[name] = jRequire[name](j$);
|
matchers[name] = jRequire[name](j$);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
getJasmineRequireObj().requireMatchers = function(jRequire, j$) {
|
getJasmineRequireObj().requireMatchers = function(jRequire, j$) {
|
||||||
var availableMatchers = [
|
const availableMatchers = [
|
||||||
'nothing',
|
'nothing',
|
||||||
'toBe',
|
'toBe',
|
||||||
'toBeCloseTo',
|
'toBeCloseTo',
|
||||||
@@ -35,8 +35,7 @@ getJasmineRequireObj().requireMatchers = function(jRequire, j$) {
|
|||||||
],
|
],
|
||||||
matchers = {};
|
matchers = {};
|
||||||
|
|
||||||
for (var i = 0; i < availableMatchers.length; i++) {
|
for (const name of availableMatchers) {
|
||||||
var name = availableMatchers[i];
|
|
||||||
matchers[name] = jRequire[name](j$);
|
matchers[name] = jRequire[name](j$);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,12 +9,12 @@ getJasmineRequireObj().toBe = function(j$) {
|
|||||||
* expect(thing).toBe(realThing);
|
* expect(thing).toBe(realThing);
|
||||||
*/
|
*/
|
||||||
function toBe(matchersUtil) {
|
function toBe(matchersUtil) {
|
||||||
var tip =
|
const tip =
|
||||||
' Tip: To check for deep equality, use .toEqual() instead of .toBe().';
|
' Tip: To check for deep equality, use .toEqual() instead of .toBe().';
|
||||||
|
|
||||||
return {
|
return {
|
||||||
compare: function(actual, expected) {
|
compare: function(actual, expected) {
|
||||||
var result = {
|
const result = {
|
||||||
pass: actual === expected
|
pass: actual === expected
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -35,9 +35,9 @@ getJasmineRequireObj().toBeCloseTo = function() {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
var pow = Math.pow(10, precision + 1);
|
const pow = Math.pow(10, precision + 1);
|
||||||
var delta = Math.abs(expected - actual);
|
const delta = Math.abs(expected - actual);
|
||||||
var maxDelta = Math.pow(10, -precision) / 2;
|
const maxDelta = Math.pow(10, -precision) / 2;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
pass: Math.round(delta * pow) <= maxDelta * pow
|
pass: Math.round(delta * pow) <= maxDelta * pow
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
getJasmineRequireObj().toBeInstanceOf = function(j$) {
|
getJasmineRequireObj().toBeInstanceOf = function(j$) {
|
||||||
var usageError = j$.formatErrorMsg(
|
const usageError = j$.formatErrorMsg(
|
||||||
'<toBeInstanceOf>',
|
'<toBeInstanceOf>',
|
||||||
'expect(value).toBeInstanceOf(<ConstructorFunction>)'
|
'expect(value).toBeInstanceOf(<ConstructorFunction>)'
|
||||||
);
|
);
|
||||||
@@ -18,15 +18,15 @@ getJasmineRequireObj().toBeInstanceOf = function(j$) {
|
|||||||
function toBeInstanceOf(matchersUtil) {
|
function toBeInstanceOf(matchersUtil) {
|
||||||
return {
|
return {
|
||||||
compare: function(actual, expected) {
|
compare: function(actual, expected) {
|
||||||
var actualType =
|
const actualType =
|
||||||
actual && actual.constructor
|
actual && actual.constructor
|
||||||
? j$.fnNameFor(actual.constructor)
|
? j$.fnNameFor(actual.constructor)
|
||||||
: matchersUtil.pp(actual),
|
: matchersUtil.pp(actual);
|
||||||
expectedType = expected
|
const expectedType = expected
|
||||||
? j$.fnNameFor(expected)
|
? j$.fnNameFor(expected)
|
||||||
: matchersUtil.pp(expected),
|
: matchersUtil.pp(expected);
|
||||||
expectedMatcher,
|
let expectedMatcher;
|
||||||
pass;
|
let pass;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
expectedMatcher = new j$.Any(expected);
|
expectedMatcher = new j$.Any(expected);
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ getJasmineRequireObj().toBeNaN = function(j$) {
|
|||||||
function toBeNaN(matchersUtil) {
|
function toBeNaN(matchersUtil) {
|
||||||
return {
|
return {
|
||||||
compare: function(actual) {
|
compare: function(actual) {
|
||||||
var result = {
|
const result = {
|
||||||
pass: actual !== actual
|
pass: actual !== actual
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ getJasmineRequireObj().toBeNegativeInfinity = function(j$) {
|
|||||||
function toBeNegativeInfinity(matchersUtil) {
|
function toBeNegativeInfinity(matchersUtil) {
|
||||||
return {
|
return {
|
||||||
compare: function(actual) {
|
compare: function(actual) {
|
||||||
var result = {
|
const result = {
|
||||||
pass: actual === Number.NEGATIVE_INFINITY
|
pass: actual === Number.NEGATIVE_INFINITY
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ getJasmineRequireObj().toBePositiveInfinity = function(j$) {
|
|||||||
function toBePositiveInfinity(matchersUtil) {
|
function toBePositiveInfinity(matchersUtil) {
|
||||||
return {
|
return {
|
||||||
compare: function(actual) {
|
compare: function(actual) {
|
||||||
var result = {
|
const result = {
|
||||||
pass: actual === Number.POSITIVE_INFINITY
|
pass: actual === Number.POSITIVE_INFINITY
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -11,10 +11,10 @@ getJasmineRequireObj().toEqual = function(j$) {
|
|||||||
function toEqual(matchersUtil) {
|
function toEqual(matchersUtil) {
|
||||||
return {
|
return {
|
||||||
compare: function(actual, expected) {
|
compare: function(actual, expected) {
|
||||||
var result = {
|
const result = {
|
||||||
pass: false
|
pass: false
|
||||||
},
|
},
|
||||||
diffBuilder = j$.DiffBuilder({ prettyPrinter: matchersUtil.pp });
|
diffBuilder = new j$.DiffBuilder({ prettyPrinter: matchersUtil.pp });
|
||||||
|
|
||||||
result.pass = matchersUtil.equals(actual, expected, diffBuilder);
|
result.pass = matchersUtil.equals(actual, expected, diffBuilder);
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
getJasmineRequireObj().toHaveBeenCalled = function(j$) {
|
getJasmineRequireObj().toHaveBeenCalled = function(j$) {
|
||||||
var getErrorMsg = j$.formatErrorMsg(
|
const getErrorMsg = j$.formatErrorMsg(
|
||||||
'<toHaveBeenCalled>',
|
'<toHaveBeenCalled>',
|
||||||
'expect(<spyObj>).toHaveBeenCalled()'
|
'expect(<spyObj>).toHaveBeenCalled()'
|
||||||
);
|
);
|
||||||
@@ -16,7 +16,7 @@ getJasmineRequireObj().toHaveBeenCalled = function(j$) {
|
|||||||
function toHaveBeenCalled(matchersUtil) {
|
function toHaveBeenCalled(matchersUtil) {
|
||||||
return {
|
return {
|
||||||
compare: function(actual) {
|
compare: function(actual) {
|
||||||
var result = {};
|
const result = {};
|
||||||
|
|
||||||
if (!j$.isSpy(actual)) {
|
if (!j$.isSpy(actual)) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
getJasmineRequireObj().toHaveBeenCalledBefore = function(j$) {
|
getJasmineRequireObj().toHaveBeenCalledBefore = function(j$) {
|
||||||
var getErrorMsg = j$.formatErrorMsg(
|
const getErrorMsg = j$.formatErrorMsg(
|
||||||
'<toHaveBeenCalledBefore>',
|
'<toHaveBeenCalledBefore>',
|
||||||
'expect(<spyObj>).toHaveBeenCalledBefore(<spyObj>)'
|
'expect(<spyObj>).toHaveBeenCalledBefore(<spyObj>)'
|
||||||
);
|
);
|
||||||
@@ -31,7 +31,7 @@ getJasmineRequireObj().toHaveBeenCalledBefore = function(j$) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
var result = { pass: false };
|
const result = { pass: false };
|
||||||
|
|
||||||
if (!firstSpy.calls.count()) {
|
if (!firstSpy.calls.count()) {
|
||||||
result.message =
|
result.message =
|
||||||
@@ -44,8 +44,8 @@ getJasmineRequireObj().toHaveBeenCalledBefore = function(j$) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
var latest1stSpyCall = firstSpy.calls.mostRecent().invocationOrder;
|
const latest1stSpyCall = firstSpy.calls.mostRecent().invocationOrder;
|
||||||
var first2ndSpyCall = latterSpy.calls.first().invocationOrder;
|
const first2ndSpyCall = latterSpy.calls.first().invocationOrder;
|
||||||
|
|
||||||
result.pass = latest1stSpyCall < first2ndSpyCall;
|
result.pass = latest1stSpyCall < first2ndSpyCall;
|
||||||
|
|
||||||
@@ -57,8 +57,8 @@ getJasmineRequireObj().toHaveBeenCalledBefore = function(j$) {
|
|||||||
latterSpy.and.identity +
|
latterSpy.and.identity +
|
||||||
', but it was';
|
', but it was';
|
||||||
} else {
|
} else {
|
||||||
var first1stSpyCall = firstSpy.calls.first().invocationOrder;
|
const first1stSpyCall = firstSpy.calls.first().invocationOrder;
|
||||||
var latest2ndSpyCall = latterSpy.calls.mostRecent().invocationOrder;
|
const latest2ndSpyCall = latterSpy.calls.mostRecent().invocationOrder;
|
||||||
|
|
||||||
if (first1stSpyCall < first2ndSpyCall) {
|
if (first1stSpyCall < first2ndSpyCall) {
|
||||||
result.message =
|
result.message =
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
getJasmineRequireObj().toHaveBeenCalledOnceWith = function(j$) {
|
getJasmineRequireObj().toHaveBeenCalledOnceWith = function(j$) {
|
||||||
var getErrorMsg = j$.formatErrorMsg(
|
const getErrorMsg = j$.formatErrorMsg(
|
||||||
'<toHaveBeenCalledOnceWith>',
|
'<toHaveBeenCalledOnceWith>',
|
||||||
'expect(<spyObj>).toHaveBeenCalledOnceWith(...arguments)'
|
'expect(<spyObj>).toHaveBeenCalledOnceWith(...arguments)'
|
||||||
);
|
);
|
||||||
@@ -16,7 +16,7 @@ getJasmineRequireObj().toHaveBeenCalledOnceWith = function(j$) {
|
|||||||
function toHaveBeenCalledOnceWith(util) {
|
function toHaveBeenCalledOnceWith(util) {
|
||||||
return {
|
return {
|
||||||
compare: function() {
|
compare: function() {
|
||||||
var args = Array.prototype.slice.call(arguments, 0),
|
const args = Array.prototype.slice.call(arguments, 0),
|
||||||
actual = args[0],
|
actual = args[0],
|
||||||
expectedArgs = args.slice(1);
|
expectedArgs = args.slice(1);
|
||||||
|
|
||||||
@@ -26,7 +26,7 @@ getJasmineRequireObj().toHaveBeenCalledOnceWith = function(j$) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
var prettyPrintedCalls = actual.calls
|
const prettyPrintedCalls = actual.calls
|
||||||
.allArgs()
|
.allArgs()
|
||||||
.map(function(argsForCall) {
|
.map(function(argsForCall) {
|
||||||
return ' ' + util.pp(argsForCall);
|
return ' ' + util.pp(argsForCall);
|
||||||
@@ -53,7 +53,7 @@ getJasmineRequireObj().toHaveBeenCalledOnceWith = function(j$) {
|
|||||||
|
|
||||||
function getDiffs() {
|
function getDiffs() {
|
||||||
return actual.calls.allArgs().map(function(argsForCall, callIx) {
|
return actual.calls.allArgs().map(function(argsForCall, callIx) {
|
||||||
var diffBuilder = new j$.DiffBuilder();
|
const diffBuilder = new j$.DiffBuilder();
|
||||||
util.equals(argsForCall, expectedArgs, diffBuilder);
|
util.equals(argsForCall, expectedArgs, diffBuilder);
|
||||||
return diffBuilder.getMessage();
|
return diffBuilder.getMessage();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
getJasmineRequireObj().toHaveBeenCalledTimes = function(j$) {
|
getJasmineRequireObj().toHaveBeenCalledTimes = function(j$) {
|
||||||
var getErrorMsg = j$.formatErrorMsg(
|
const getErrorMsg = j$.formatErrorMsg(
|
||||||
'<toHaveBeenCalledTimes>',
|
'<toHaveBeenCalledTimes>',
|
||||||
'expect(<spyObj>).toHaveBeenCalledTimes(<Number>)'
|
'expect(<spyObj>).toHaveBeenCalledTimes(<Number>)'
|
||||||
);
|
);
|
||||||
@@ -24,7 +24,7 @@ getJasmineRequireObj().toHaveBeenCalledTimes = function(j$) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
var args = Array.prototype.slice.call(arguments, 0),
|
const args = Array.prototype.slice.call(arguments, 0),
|
||||||
result = { pass: false };
|
result = { pass: false };
|
||||||
|
|
||||||
if (!j$.isNumber_(expected)) {
|
if (!j$.isNumber_(expected)) {
|
||||||
@@ -36,8 +36,8 @@ getJasmineRequireObj().toHaveBeenCalledTimes = function(j$) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
actual = args[0];
|
actual = args[0];
|
||||||
var calls = actual.calls.count();
|
const calls = actual.calls.count();
|
||||||
var timesMessage = expected === 1 ? 'once' : expected + ' times';
|
const timesMessage = expected === 1 ? 'once' : expected + ' times';
|
||||||
result.pass = calls === expected;
|
result.pass = calls === expected;
|
||||||
result.message = result.pass
|
result.message = result.pass
|
||||||
? 'Expected spy ' +
|
? 'Expected spy ' +
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user