Compare commits
194 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c8c3325b56 | ||
|
|
84c7e2b21b | ||
|
|
dda25bb29e | ||
|
|
9ccf2ef96b | ||
|
|
c6fa55bfc8 | ||
|
|
06bcf1c2e1 | ||
|
|
40f402d117 | ||
|
|
71f6a95ce5 | ||
|
|
5cd7d47f72 | ||
|
|
d0fe5c4712 | ||
|
|
f602c4911c | ||
|
|
7aaf7eaf30 | ||
|
|
35f16e8125 | ||
|
|
acc777c267 | ||
|
|
1c74356691 | ||
|
|
bbebea0fa5 | ||
|
|
66eb27b0af | ||
|
|
7a63c06a65 | ||
|
|
554dfd4923 | ||
|
|
36a6e2aa1d | ||
|
|
3c4b73f136 | ||
|
|
bc3ed74336 | ||
|
|
97b6f33cc2 | ||
|
|
a9889ddb31 | ||
|
|
cd1b7ce9c7 | ||
|
|
3653d6e0ef | ||
|
|
c3387f8dbf | ||
|
|
3d54184c7f | ||
|
|
6f23e706d7 | ||
|
|
cc69edf92c | ||
|
|
ba7560f65e | ||
|
|
c3960c4a96 | ||
|
|
5c21f94bb1 | ||
|
|
8cd7c94490 | ||
|
|
6a6fa7b29a | ||
|
|
4984548cab | ||
|
|
6941bde7e2 | ||
|
|
1504f25ced | ||
|
|
99e350ac85 | ||
|
|
1624b07589 | ||
|
|
d06dce4614 | ||
|
|
03098e81f8 | ||
|
|
726c152f6e | ||
|
|
409d2e29e5 | ||
|
|
01e2bd5050 | ||
|
|
96033e38ea | ||
|
|
ed75290ef7 | ||
|
|
a14dbf012a | ||
|
|
17c11ba7b9 | ||
|
|
2a1daca1ca | ||
|
|
f0db5ce350 | ||
|
|
39f9c2e1a0 | ||
|
|
bff612a169 | ||
|
|
4ba42f3746 | ||
|
|
58bee05c36 | ||
|
|
c1871b0f0c | ||
|
|
c16974b091 | ||
|
|
bfedda9764 | ||
|
|
a67b7276be | ||
|
|
47f3105ef0 | ||
|
|
aeb56539c9 | ||
|
|
75d45efa16 | ||
|
|
59d1c5bebb | ||
|
|
040983c979 | ||
|
|
2ddb344bac | ||
|
|
e56bd3918b | ||
|
|
59600a1c29 | ||
|
|
f8e4ea868f | ||
|
|
0ff56c53b1 | ||
|
|
b617d983de | ||
|
|
8e0f0e8e8c | ||
|
|
d745d6b5f0 | ||
|
|
fc2c2a477d | ||
|
|
ff93277c0f | ||
|
|
90741b3cee | ||
|
|
d1de59f0ed | ||
|
|
73f8e001ad | ||
|
|
390cc45af2 | ||
|
|
33118ac6e2 | ||
|
|
31ff9a300c | ||
|
|
5cc739d879 | ||
|
|
1e7f07259e | ||
|
|
c36a5cfd96 | ||
|
|
299fd1f770 | ||
|
|
656427d328 | ||
|
|
621522fdd4 | ||
|
|
6e3589bf52 | ||
|
|
df2d9b282e | ||
|
|
726d35c5c5 | ||
|
|
f509078020 | ||
|
|
8308515210 | ||
|
|
ed838b3cbf | ||
|
|
04fac300e8 | ||
|
|
ff237f4b66 | ||
|
|
e42e3d9e00 | ||
|
|
61505f4c59 | ||
|
|
86eddb05b4 | ||
|
|
8af5509581 | ||
|
|
166e5f4d6c | ||
|
|
6ad8d20694 | ||
|
|
cbc03feb52 | ||
|
|
bc3a495160 | ||
|
|
b323631611 | ||
|
|
e8767ba660 | ||
|
|
af9a4114f4 | ||
|
|
75f97961f5 | ||
|
|
25a7168286 | ||
|
|
494e81f436 | ||
|
|
169a2a8ad2 | ||
|
|
b267029301 | ||
|
|
cf574634b8 | ||
|
|
f8c01574e6 | ||
|
|
481f1e7c5c | ||
|
|
5e650953cd | ||
|
|
ed5e902106 | ||
|
|
87f9ab29df | ||
|
|
47c64a86d5 | ||
|
|
bb497beeff | ||
|
|
e14d9c4be3 | ||
|
|
89e0b35c53 | ||
|
|
1e7b68236b | ||
|
|
394068f863 | ||
|
|
b831e81074 | ||
|
|
4c13c2b00b | ||
|
|
dd98a45003 | ||
|
|
fe6762b470 | ||
|
|
fa16b74500 | ||
|
|
4cd190b232 | ||
|
|
6ada55ff77 | ||
|
|
735ce6f758 | ||
|
|
430324885b | ||
|
|
7c2e8ce7ca | ||
|
|
d4025999b7 | ||
|
|
871111424d | ||
|
|
44f331f43d | ||
|
|
213144413f | ||
|
|
2272f9aead | ||
|
|
59848ca151 | ||
|
|
c14bfe3e5f | ||
|
|
26c48ab324 | ||
|
|
4c8d57e14c | ||
|
|
543689e206 | ||
|
|
ee524831f4 | ||
|
|
cfecab9f79 | ||
|
|
b3d9435dbb | ||
|
|
fec8dd37b0 | ||
|
|
0690500a0d | ||
|
|
0bfbda720d | ||
|
|
4fcdbd39fb | ||
|
|
f934e6d816 | ||
|
|
79c6bbc189 | ||
|
|
2e80ec0c22 | ||
|
|
588283cfe5 | ||
|
|
3a43871901 | ||
|
|
fcbab02b2d | ||
|
|
5f3475342e | ||
|
|
e022e6199c | ||
|
|
140c12e8fc | ||
|
|
21f25972bb | ||
|
|
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 |
@@ -4,25 +4,17 @@
|
||||
version: 2.1
|
||||
|
||||
executors:
|
||||
node22:
|
||||
docker:
|
||||
- image: cimg/node:22.0.0
|
||||
working_directory: ~/workspace
|
||||
node20:
|
||||
docker:
|
||||
- image: cimg/node:20.0.0
|
||||
working_directory: ~/workspace
|
||||
node18:
|
||||
docker:
|
||||
- image: cimg/node:18.0.0 # Latest 18.x
|
||||
working_directory: ~/workspace
|
||||
node16:
|
||||
docker:
|
||||
- image: cimg/node:16.14.2 # Latest 16.x
|
||||
working_directory: ~/workspace
|
||||
node14:
|
||||
docker:
|
||||
- image: cimg/node:14.17.4 # Latest 14.x
|
||||
working_directory: ~/workspace
|
||||
node12_latest:
|
||||
docker:
|
||||
- image: cimg/node:12.22.10 # Latest 12.x
|
||||
working_directory: ~/workspace
|
||||
node12_17:
|
||||
docker:
|
||||
- image: cimg/node:12.17.0 # Oldest version supported by Jasmine
|
||||
- image: cimg/node:18.0.0
|
||||
working_directory: ~/workspace
|
||||
|
||||
jobs:
|
||||
@@ -59,8 +51,20 @@ jobs:
|
||||
name: Run tests
|
||||
command: npm test
|
||||
|
||||
test_parallel: &test_parallel
|
||||
parameters:
|
||||
executor:
|
||||
type: executor
|
||||
executor: << parameters.executor >>
|
||||
steps:
|
||||
- attach_workspace:
|
||||
at: .
|
||||
- run:
|
||||
name: Run tests in parallel
|
||||
command: npx grunt execSpecsInParallel
|
||||
|
||||
test_browsers: &test_browsers
|
||||
executor: node14
|
||||
executor: node18
|
||||
steps:
|
||||
- attach_workspace:
|
||||
at: .
|
||||
@@ -80,7 +84,7 @@ jobs:
|
||||
# cleanly if we kill it from a different step than it started in.
|
||||
|
||||
export PATH=$PATH:$HOME/workspace/bin
|
||||
export SAUCE_TUNNEL_IDENTIFIER=$CIRCLE_BUILD_NUM
|
||||
export SAUCE_TUNNEL_IDENTIFIER=$CIRCLE_WORKFLOW_JOB_ID
|
||||
scripts/start-sauce-connect sauce-pidfile
|
||||
set +o errexit
|
||||
scripts/run-all-browsers
|
||||
@@ -94,49 +98,48 @@ workflows:
|
||||
|
||||
push:
|
||||
jobs:
|
||||
- build:
|
||||
executor: node22
|
||||
name: build_node_22
|
||||
- build:
|
||||
executor: node20
|
||||
name: build_node_20
|
||||
- build:
|
||||
executor: node18
|
||||
name: build_node_18
|
||||
- build:
|
||||
executor: node16
|
||||
name: build_node_16
|
||||
- build:
|
||||
executor: node14
|
||||
name: build_node_14
|
||||
- build:
|
||||
executor: node12_latest
|
||||
name: build_node_12_latest
|
||||
- build:
|
||||
executor: node12_17
|
||||
name: build_node_12_17
|
||||
- test_node:
|
||||
executor: node22
|
||||
name: test_node_22
|
||||
requires:
|
||||
- build_node_22
|
||||
- test_node:
|
||||
executor: node20
|
||||
name: test_node_20
|
||||
requires:
|
||||
- build_node_20
|
||||
- test_node:
|
||||
executor: node18
|
||||
name: test_node_18
|
||||
requires:
|
||||
- build_node_18
|
||||
- test_node:
|
||||
executor: node16
|
||||
name: test_node_16
|
||||
- build_node_18
|
||||
- test_parallel:
|
||||
executor: node18
|
||||
name: test_parallel_node_18
|
||||
requires:
|
||||
- build_node_16
|
||||
- test_node:
|
||||
executor: node14
|
||||
name: test_node_14
|
||||
- build_node_18
|
||||
- test_parallel:
|
||||
executor: node22
|
||||
name: test_parallel_node_22
|
||||
requires:
|
||||
- build_node_14
|
||||
- test_node:
|
||||
executor: node12_latest
|
||||
name: test_node_12_latest
|
||||
- build_node_22
|
||||
- test_parallel:
|
||||
executor: node20
|
||||
name: test_parallel_node_20
|
||||
requires:
|
||||
- build_node_12_latest
|
||||
- test_node:
|
||||
executor: node12_17
|
||||
name: test_node_12_17
|
||||
requires:
|
||||
- build_node_12_17
|
||||
- build_node_20
|
||||
- test_browsers:
|
||||
requires:
|
||||
- build_node_14
|
||||
- build_node_18
|
||||
filters:
|
||||
branches:
|
||||
ignore: /pull\/.*/ # Don't run on pull requests.
|
||||
|
||||
47
.eslintrc
Normal file
47
.eslintrc
Normal file
@@ -0,0 +1,47 @@
|
||||
{
|
||||
"extends": [
|
||||
"plugin:compat/recommended"
|
||||
],
|
||||
"env": {
|
||||
"browser": true,
|
||||
"node": true,
|
||||
"es2017": true
|
||||
},
|
||||
"parserOptions": {
|
||||
"ecmaVersion": 2018
|
||||
},
|
||||
"rules": {
|
||||
"curly": "error",
|
||||
"quotes": [
|
||||
"error",
|
||||
"single",
|
||||
{
|
||||
"avoidEscape": true
|
||||
}
|
||||
],
|
||||
"no-unused-vars": [
|
||||
"error",
|
||||
{
|
||||
"args": "none"
|
||||
}
|
||||
],
|
||||
"no-implicit-globals": "error",
|
||||
"block-spacing": "error",
|
||||
"func-call-spacing": [
|
||||
"error",
|
||||
"never"
|
||||
],
|
||||
"key-spacing": "error",
|
||||
"no-tabs": "error",
|
||||
"no-trailing-spaces": "error",
|
||||
"no-whitespace-before-property": "error",
|
||||
"semi": [
|
||||
"error",
|
||||
"always"
|
||||
],
|
||||
"space-before-blocks": "error",
|
||||
"no-eval": "error",
|
||||
"no-var": "error",
|
||||
"no-debugger": "error"
|
||||
}
|
||||
}
|
||||
31
.github/CONTRIBUTING.md
vendored
31
.github/CONTRIBUTING.md
vendored
@@ -1,19 +1,10 @@
|
||||
# Developing for Jasmine Core
|
||||
# Contributing to Jasmine
|
||||
|
||||
We welcome your contributions! Thanks for helping make Jasmine a better project
|
||||
for everyone. Please review the backlog and discussion lists before starting
|
||||
work. What you're looking for may already have been done. If it hasn't, the
|
||||
community can help make your contribution better. If you want to contribute but
|
||||
don't know what to work on,
|
||||
[issues tagged help needed](https://github.com/jasmine/jasmine/labels/help%20needed)
|
||||
for everyone. If you want to contribute but don't know what to work on,
|
||||
[issues tagged help needed](https://github.com/issues?q=is%3Aopen+is%3Aissue+org%3Ajasmine+label%3A%22help+needed%22+)
|
||||
should have enough detail to get started.
|
||||
|
||||
## Links
|
||||
|
||||
- [Jasmine Google Group](http://groups.google.com/group/jasmine-js)
|
||||
- [Jasmine-dev Google Group](http://groups.google.com/group/jasmine-js-dev)
|
||||
- [Jasmine backlog](https://www.pivotaltracker.com/n/projects/10606)
|
||||
|
||||
## Before Submitting a Pull Request
|
||||
|
||||
1. Ensure all specs are green in browsers *and* node.
|
||||
@@ -94,14 +85,7 @@ Or, How to make a successful pull request
|
||||
* _Write specs_ - Jasmine's a testing framework. Don't add functionality
|
||||
without test-driving it.
|
||||
* _Write code in the style of the rest of the repo_ - Jasmine should look like
|
||||
a cohesive whole.
|
||||
|
||||
Key exceptions:
|
||||
* Use `const` or `let` for new variable declarations, even if nearby code
|
||||
uses `var`.
|
||||
* New async specs should usually be async/await or promise-returning, not
|
||||
callback based.
|
||||
|
||||
a cohesive whole.
|
||||
* _Ensure the *entire* test suite is green_ in all the big browsers, Node, and
|
||||
ESLint/Prettier. Your contribution shouldn't break Jasmine for other users.
|
||||
|
||||
@@ -119,3 +103,10 @@ chromedriver), you can also use Jasmine's CI tooling:
|
||||
|
||||
$ JASMINE_BROWSER=<name of browser> npm run ci
|
||||
|
||||
### Submitting a Pull Requeset
|
||||
|
||||
Once you've done the steps listed under "Before Submitting a Pull Request"
|
||||
above, you can submit a pull request via the
|
||||
[standard GitHub process](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request).
|
||||
TL;DR: Fork the repository, push your work up to your fork, and create a PR from
|
||||
there.
|
||||
|
||||
47
.github/ISSUE_TEMPLATE.md
vendored
47
.github/ISSUE_TEMPLATE.md
vendored
@@ -1,47 +0,0 @@
|
||||
## Are you creating an issue in the correct repository?
|
||||
|
||||
- When in doubt, create an issue here.
|
||||
- If you have an issue with the Jasmine docs, file an issue in the docs repo
|
||||
here: https://github.com/jasmine/jasmine.github.io
|
||||
- If you have an issue with TypeScript typings, start a discussion at
|
||||
[DefinitelyTpyed](https://github.com/DefinitelyTyped/DefinitelyTyped/discussions/new?category=issues-with-a-types-package)
|
||||
- This repository is for the core Jasmine framework
|
||||
- If you are using a test runner that wraps Jasmine, consider filing an issue with that library if appropriate:
|
||||
- [Jasmine npm](https://github.com/jasmine/jasmine-npm/issues)
|
||||
- [Jasmine browser runner](https://github.com/jasmine/jasmine-browser/issues)
|
||||
- [Jasmine gem](https://github.com/jasmine/jasmine-gem/issues)
|
||||
- [Jasmine py](https://github.com/jasmine/jasmine-py/issues)
|
||||
- [Gulp Jasmine Browser](https://github.com/jasmine/gulp-jasmine-browser/issues)
|
||||
- [Karma](https://github.com/karma-runner/karma/issues)
|
||||
- [Grunt Contrib Jasmine](https://github.com/gruntjs/grunt-contrib-jasmine/issues)
|
||||
|
||||
<!--- Provide a general summary of the issue in the Title above -->
|
||||
|
||||
## Expected Behavior
|
||||
<!--- If you're describing a bug, tell us what should happen -->
|
||||
<!--- If you're suggesting a change/improvement, tell us how it should work -->
|
||||
|
||||
## Current Behavior
|
||||
<!--- If describing a bug, tell us what happens instead of the expected behavior -->
|
||||
<!--- If suggesting a change/improvement, explain the difference from current behavior -->
|
||||
|
||||
## Possible Solution
|
||||
<!--- Not obligatory, but suggest a fix/reason for the bug, -->
|
||||
<!--- or ideas how to implement the addition or change -->
|
||||
|
||||
## Suite that reproduces the behavior (for bugs)
|
||||
<!--- Provide a sample suite that reproduces the bug. -->
|
||||
```javascript
|
||||
describe("sample", function() {
|
||||
});
|
||||
```
|
||||
## Context
|
||||
<!--- How has this issue affected you? What are you trying to accomplish? -->
|
||||
<!--- Providing context helps us come up with a solution that is most useful in the real world -->
|
||||
|
||||
## Your Environment
|
||||
<!--- Include as many relevant details about the environment you experienced the bug in -->
|
||||
* Version used:
|
||||
* Environment name and version (e.g. Chrome 39, node.js 5.4):
|
||||
* Operating System and version (desktop or mobile):
|
||||
* Link to your project:
|
||||
98
.github/ISSUE_TEMPLATE/bug_report.yml
vendored
Normal file
98
.github/ISSUE_TEMPLATE/bug_report.yml
vendored
Normal file
@@ -0,0 +1,98 @@
|
||||
name: Bug Report
|
||||
description: I think I've found a bug in Jasmine
|
||||
labels: ["bug report"]
|
||||
body:
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: |
|
||||
Thanks for taking the time to report a bug. Please follow these steps first.
|
||||
|
||||
## Troubleshooting
|
||||
Please take the time to rule out issues with your code or third party libraries before filing a bug report. If you are reporting an error, try to determine whether the error is coming from Jasmine, another library, or your own code.
|
||||
|
||||
Check the [FAQ](https://jasmine.github.io/pages/faq.html) and any other relevant [documentation](https://jasmine.github.io/pages/docs_home.html) to see if your issue has already been addressed.
|
||||
|
||||
## Special troubleshooting steps for asynchronous scenarios
|
||||
If the issue has to do with testing asynchronous code, please read the [async tutorial](https://jasmine.github.io/tutorials/async) and the async section of the FAQ. In particular, check for the following common errors:
|
||||
|
||||
* Are you trying to write a synchronous test for asynchronous code?
|
||||
* Does the test signal completion before the code under test finishes?
|
||||
* Do expectations run before the code that they're trying to verify?
|
||||
|
||||
## Try the latest version of Jasmine
|
||||
If at all possible, upgrade to the latest versions of `jasmine-core` and any other relevant packages (e.g. `jasmine`, `jasmine-browser-runner`). If you can't do that, please check the [release notes](https://github.com/jasmine/jasmine/tree/main/release_notes) for all newer versions to make sure that the bug hasn't already been fixed.
|
||||
|
||||
## Put together a [minimal, reproducible example](https://stackoverflow.com/help/minimal-reproducible-example)
|
||||
Please help us help you by creating a minimal but complete setup that demonstrates the problem. Remove any code and libraries that aren't absolutely necessary, but make sure it doesn't depend on any code you haven't included. In many cases a simple code snippet is enough. In cases involving external libraries, *especially* Karma or Angular, we're likely to need a runable Git repository or jsbin/stackblitz/etc.
|
||||
|
||||
**If we can't reproduce it, we can't fix it. Bug reports without a minimal, reproducible example are very likely to be closed.**
|
||||
|
||||
- type: textarea
|
||||
id: steps-to-reproduce
|
||||
attributes:
|
||||
label: Steps to Reproduce
|
||||
placeholder: |
|
||||
Example steps:
|
||||
1. Paste the example code below into `mySpec.js`.
|
||||
2. Run `npx jasmine@<some version> mySpec.js`
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: expected-behavior
|
||||
attributes:
|
||||
label: Expected Behavior
|
||||
description: What do you think should have happened?
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: actual-behavior
|
||||
attributes:
|
||||
label: Actual Behavior
|
||||
description: What happened instead?
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: code-sample
|
||||
attributes:
|
||||
label: Example code that reproduces the problem
|
||||
description: Please include either a code snippet that reproduces the problem or a link to a repository or jsbin/stackblitz/etc containing a minimal, reproducible example as described above.
|
||||
render: JavaScript
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: possible-solution
|
||||
attributes:
|
||||
label: Possible Solution
|
||||
description: This is optional, but if you have an idea for how to fix the bug we'd like to hear it.
|
||||
- type: textarea
|
||||
id: context
|
||||
attributes:
|
||||
label: Context
|
||||
description: How has this issue affected you? What are you trying to accomplish? By providing context, you can help us come up with a solution that is most useful in the real world.
|
||||
- type: input
|
||||
id: jasmine-core-version
|
||||
attributes:
|
||||
label: jasmine-core version
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: other-versions
|
||||
attributes:
|
||||
label: Versions of other relevant packages
|
||||
placeholder: |
|
||||
jasmine-browser-runner 1.2.0
|
||||
fancy-reporter 132.4.8
|
||||
- type: input
|
||||
id: browser-or-node-version
|
||||
attributes:
|
||||
label: Node.js or browser version
|
||||
placeholder: E.g. "node 16.2.0" or "Safari 15"
|
||||
validations:
|
||||
required: true
|
||||
- type: input
|
||||
id: os
|
||||
attributes:
|
||||
label: Operating System
|
||||
placeholder: E.g. "Windows 10", "MacOS 12.5", "MCC Interim Linux 0.99.p8"
|
||||
validations:
|
||||
required: true
|
||||
14
.github/ISSUE_TEMPLATE/config.yml
vendored
Normal file
14
.github/ISSUE_TEMPLATE/config.yml
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
blank_issues_enabled: false
|
||||
contact_links:
|
||||
- name: Issues with the `jasmine` CLI
|
||||
url: https://github.com/jasmine/jasmine-npm/issues
|
||||
about: Please create issues related to the `jasmine` package in its repository.
|
||||
- name: Issues with jasmine-browser-runner
|
||||
url: https://github.com/jasmine/jasmine-browser-runner/issues
|
||||
about: Please create issues related to the `jasmine-browser-runner` package in its repository.
|
||||
- name: Documentation issues
|
||||
url: https://github.com/jasmine/jasmine.github.io/issues
|
||||
about: Please create documentation issues in the docs repository.
|
||||
- name: TypeScript issues
|
||||
url: https://github.com/DefinitelyTyped/DefinitelyTyped/discussions
|
||||
about: Please create issues related to TypeScript compilation errors or other problems with type definitions at DefinitelyTyped.
|
||||
31
.github/ISSUE_TEMPLATE/feature_proposal.yml
vendored
Normal file
31
.github/ISSUE_TEMPLATE/feature_proposal.yml
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
name: Feature Proposal
|
||||
description: I'd like to propose a new feature
|
||||
labels: ["feature request"]
|
||||
body:
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: Thanks for taking the time to propose a new feature. Although Jasmine is mostly feature complete, we're always open to hearing new ideas.
|
||||
- type: textarea
|
||||
id: description
|
||||
attributes:
|
||||
label: Feature Proposal
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: context
|
||||
attributes:
|
||||
label: Context
|
||||
description: How would this feature be useful to you? What are you trying to accomplish? By providing context, you can help us come up with a solution that is most useful in the real world.
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: example
|
||||
attributes:
|
||||
label: Example
|
||||
description: If you're proposing a new API or something similar, please show an example of how it would be used.
|
||||
render: JavaScript
|
||||
- type: textarea
|
||||
id: other-info
|
||||
attributes:
|
||||
label: Other Information
|
||||
description: Anything else that you think would be helpful.
|
||||
73
.github/ISSUE_TEMPLATE/support_request.yml
vendored
Normal file
73
.github/ISSUE_TEMPLATE/support_request.yml
vendored
Normal file
@@ -0,0 +1,73 @@
|
||||
name: Question or Support Request
|
||||
description: I need help using Jasmine
|
||||
labels: ["question"]
|
||||
body:
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: |
|
||||
Jasmine is supported by volunteers working in their free time. Although we're generally willing to help, we're going to ask you to put in some effort first to help us help you.
|
||||
|
||||
## Troubleshooting
|
||||
Please take the time to rule out problems with your code or third party libraries before opening an issue. If you're running into an error, try to determine whether the error is coming from Jasmine, another library, or your own code.
|
||||
|
||||
Check the [FAQ](https://jasmine.github.io/pages/faq.html) and any other relevant [documentation](https://jasmine.github.io/pages/docs_home.html) to see if your question has already been answered. Consider searching [Stack Overflow](https://stackoverflow.com/questions/tagged/jasmine) and past issues in this repository for related questions as well.
|
||||
|
||||
## Special troubleshooting steps for asynchronous scenarios
|
||||
If the issue has to do with testing asynchronous code, please read the [async tutorial](https://jasmine.github.io/tutorials/async) and the async section of the FAQ. In particular, check for the following common errors:
|
||||
|
||||
* Are you trying to write a synchronous test for asynchronous code?
|
||||
* Does the test signal completion before the code under test finishes?
|
||||
* Do expectations run before the code that they're trying to verify?
|
||||
|
||||
## Consider asking Angular questions in an Angular forum
|
||||
|
||||
Questions like "how do I test this Angular service" are mostly about Angular, not Jasmine. You'll likely get better responses in an Angular forum. Here's a rule of thumb: If you can't demonstrate the problem without Angular, you probably have an Angular question.
|
||||
|
||||
## Try the latest version of Jasmine
|
||||
If at all possible, upgrade to the latest versions of `jasmine-core` and any other relevant packages (e.g. `jasmine`, `jasmine-browser-runner`).
|
||||
|
||||
## Put together a [minimal, reproducible example](https://stackoverflow.com/help/minimal-reproducible-example)
|
||||
Please help us help you by creating a minimal but complete setup that demonstrates the problem. Remove any code and libraries that aren't absolutely necessary, but make sure it doesn't depend on any code you haven't included. In many cases a simple code snippet is enough. In cases involving external libraries, *especially* Karma or Angular, we're likely to need a runable Git repository or jsbin/stackblitz/etc.
|
||||
|
||||
- type: textarea
|
||||
id: question
|
||||
attributes:
|
||||
label: Your question
|
||||
description: Clearly describe what you'd like help with.
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: code-sample
|
||||
attributes:
|
||||
label: Example code that demonstrates the problem
|
||||
description: Please include either a code snippet that demonstrates the problem or a link to a repository or jsbin/stackblitz/etc containing a minimal, reproducible example as described above.
|
||||
render: JavaScript
|
||||
validations:
|
||||
required: true
|
||||
- type: input
|
||||
id: jasmine-core-version
|
||||
attributes:
|
||||
label: jasmine-core version
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: other-versions
|
||||
attributes:
|
||||
label: Versions of other relevant packages
|
||||
placeholder: |
|
||||
jasmine-browser-runner 1.2.0
|
||||
fancy-reporter 132.4.8
|
||||
- type: input
|
||||
id: browser-or-node-version
|
||||
attributes:
|
||||
label: Node.js or browser version
|
||||
placeholder: E.g. "node 16.2.0" or "Safari 15"
|
||||
validations:
|
||||
required: true
|
||||
- type: input
|
||||
id: os
|
||||
attributes:
|
||||
label: Operating System
|
||||
placeholder: E.g. "Windows 10", "MacOS 12.5", "MCC Interim Linux 0.99.p8"
|
||||
validations:
|
||||
required: true
|
||||
3
.prettierrc
Normal file
3
.prettierrc
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"singleQuote": true
|
||||
}
|
||||
46
Gruntfile.js
46
Gruntfile.js
@@ -30,9 +30,9 @@ module.exports = function(grunt) {
|
||||
function() {
|
||||
verifyNoGlobals(() => require('./lib/jasmine-core.js').noGlobals());
|
||||
const done = this.async(),
|
||||
Jasmine = require('jasmine'),
|
||||
jasmineCore = require('./lib/jasmine-core.js'),
|
||||
jasmine = new Jasmine({jasmineCore: jasmineCore});
|
||||
Jasmine = require('jasmine'),
|
||||
jasmineCore = require('./lib/jasmine-core.js'),
|
||||
jasmine = new Jasmine({jasmineCore: jasmineCore});
|
||||
|
||||
jasmine.loadConfigFile('./spec/support/jasmine.json');
|
||||
jasmine.exitOnCompletion = false;
|
||||
@@ -40,12 +40,50 @@ module.exports = function(grunt) {
|
||||
result => done(result.overallStatus === 'passed'),
|
||||
err => {
|
||||
console.error(err);
|
||||
exit(1);
|
||||
done(false);
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
grunt.registerTask("execSpecsInParallel",
|
||||
"Run Jasmine core specs in parallel in Node.js",
|
||||
function() {
|
||||
// Need to require this here rather than at the top of the file
|
||||
// so that we don't break verifyNoGlobals above by loading jasmine-core
|
||||
// too early
|
||||
const ParallelRunner = require('jasmine/parallel');
|
||||
let numWorkers = require('os').cpus().length;
|
||||
|
||||
if (process.env['CIRCLECI']) {
|
||||
// On Circle CI, the above gives the number of CPU cores on the host
|
||||
// computer, which is unrelated to the resources actually available
|
||||
// to the container. 2 workers gives peak performance with our current
|
||||
// configuration, but 4 might increase the odds of discovering any
|
||||
// parallel-specific bugs.
|
||||
numWorkers = 4;
|
||||
}
|
||||
|
||||
const done = this.async();
|
||||
const runner = new ParallelRunner({
|
||||
jasmineCore: require('./lib/jasmine-core.js'),
|
||||
numWorkers
|
||||
});
|
||||
|
||||
runner.loadConfigFile('./spec/support/jasmine.json')
|
||||
.then(() => {
|
||||
runner.exitOnCompletion = false;
|
||||
return runner.execute();
|
||||
}).then(
|
||||
jasmineDoneInfo => done(jasmineDoneInfo.overallStatus === 'passed'),
|
||||
err => {
|
||||
console.error(err);
|
||||
done(false);
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
grunt.registerTask("execSpecsInNode:performance",
|
||||
"Run Jasmine performance specs in Node.js",
|
||||
function() {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
Copyright (c) 2008-2019 Pivotal Labs
|
||||
Copyright (c) 2008-2023 The Jasmine developers
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
46
README.md
46
README.md
@@ -1,18 +1,10 @@
|
||||
<a name="README">[<img src="https://rawgithub.com/jasmine/jasmine/main/images/jasmine-horizontal.svg" width="400px" />](http://jasmine.github.io)</a>
|
||||
|
||||
[](https://circleci.com/gh/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
|
||||
|
||||
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/)
|
||||
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).
|
||||
Upgrading from Jasmine 4.x? Check out the [upgrade guide](https://jasmine.github.io/tutorials/upgrading_to_Jasmine_5.0).
|
||||
|
||||
## Contributing
|
||||
|
||||
@@ -28,34 +20,30 @@ for details.
|
||||
|
||||
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)
|
||||
for information on writing specs.
|
||||
for information on writing specs, and [the FAQ](https://jasmine.github.io/pages/faq.html).
|
||||
|
||||
## Supported environments
|
||||
|
||||
Jasmine tests itself across popular browsers (Safari, Chrome, Firefox, and
|
||||
Microsoft Edge) as well as Node.
|
||||
|
||||
| Environment | Supported versions |
|
||||
|-------------------|--------------------|
|
||||
| Node | 12.17+, 14, 16, 18 |
|
||||
| Safari | 14-15 |
|
||||
| Chrome | Evergreen |
|
||||
| Firefox | Evergreen, 91 |
|
||||
| Edge | Evergreen |
|
||||
| Environment | Supported versions |
|
||||
|-------------------|----------------------------|
|
||||
| Node | 18, 20, 22 |
|
||||
| Safari | 15-17 |
|
||||
| Chrome | Evergreen |
|
||||
| Firefox | Evergreen, 102*, 115*, 128 |
|
||||
| Edge | Evergreen |
|
||||
|
||||
For evergreen browsers, each version of Jasmine is tested against the version of the browser that is available to us
|
||||
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.
|
||||
|
||||
See the [release notes](https://github.com/jasmine/jasmine/tree/main/release_notes)
|
||||
for the supported environments for each Jasmine release.
|
||||
\* Environments that are past end of life are supported on a best-effort basis.
|
||||
They may be dropped in a future minor release of Jasmine if continued support
|
||||
becomes impractical.
|
||||
|
||||
## 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).
|
||||
To find out what environments work with a particular Jasmine release, see the [release notes](https://github.com/jasmine/jasmine/tree/main/release_notes).
|
||||
|
||||
## Maintainers
|
||||
|
||||
@@ -71,8 +59,6 @@ for the supported environments for each Jasmine release.
|
||||
* [Christian Williams](mailto:antixian666@gmail.com)
|
||||
* Sheel Choksi
|
||||
|
||||
Copyright (c) 2008-2022 Jasmine Maintainers. This software is licensed under the MIT License.
|
||||
|
||||
|
||||
## License
|
||||
[](https://app.fossa.io/projects/git%2Bgithub.com%2Fjasmine%2Fjasmine?ref=badge_large)
|
||||
Copyright (c) 2008-2019 Pivotal Labs<br>
|
||||
Copyright (c) 2008-2023 The Jasmine developers<br>
|
||||
This software is licensed under the [MIT License](https://github.com/jasmine/jasmine/blob/main/LICENSE).
|
||||
|
||||
40
RELEASE.md
40
RELEASE.md
@@ -18,12 +18,11 @@ copied to `jasmine.js` when the distribution is built. When releasing a new
|
||||
version, update `package.json` with the new version and `npm run build` to
|
||||
update the gem version number.
|
||||
|
||||
Note that Jasmine should only use the "patch" version number in the following cases:
|
||||
Note that Jasmine should only use the "patch" version number if the new release
|
||||
contains only bug fixes.
|
||||
|
||||
* Changes related to packaging for a specific binding library (npm or browser-runner)
|
||||
* Fixes for regressions.
|
||||
|
||||
When jasmine-core revs its major or minor version, the binding libraries should also rev to that version.
|
||||
When `jasmine-core` revs its major or minor version, the `jasmine` NPM package
|
||||
should also rev to that version.
|
||||
|
||||
## Release
|
||||
|
||||
@@ -35,10 +34,10 @@ When ready to release - specs are all green and the stories are done:
|
||||
|
||||
### 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. Push
|
||||
1. Wait for Circle CI to go green
|
||||
2. Push
|
||||
3. Tag the release and push the tag.
|
||||
4. Wait for Circle CI to go green
|
||||
|
||||
### Build standalone distribution
|
||||
|
||||
@@ -47,34 +46,27 @@ When ready to release - specs are all green and the stories are done:
|
||||
|
||||
### 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 publish .` to publish what's in `package.json`
|
||||
|
||||
### 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. `npm run jsdoc`
|
||||
1. `rake release[${version}]` to copy the current edge docs to the new version
|
||||
1. Commit and push.
|
||||
|
||||
### Release the binding libraries
|
||||
### Release the `jasmine` NPM package
|
||||
|
||||
#### NPM
|
||||
See <https://github.com/jasmine/jasmine-npm/blob/main/RELEASE.md>.
|
||||
|
||||
1. Create release notes using Anchorman as above
|
||||
1. In `package.json`, update both the package version and the jasmine-core dependency version
|
||||
1. Commit and push.
|
||||
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`.)
|
||||
### Publish the GitHub release
|
||||
|
||||
### Finally
|
||||
|
||||
For each of the above GitHub repos:
|
||||
1. Visit the releases page and find the tag just published.
|
||||
1. Paste in a link to the correct release notes for this release. The link should reference the blob and tag correctly, and the markdown file for the notes.
|
||||
1. If it is a pre-release, mark it as such.
|
||||
1. For core, attach the standalone zipfile.
|
||||
2. Paste in a link to the correct release notes for this release.
|
||||
3. If it is a pre-release, mark it as such.
|
||||
4. Attach the standalone zipfile.
|
||||
|
||||
@@ -11,7 +11,7 @@ module.exports = {
|
||||
},
|
||||
|
||||
files: [
|
||||
{ src: [ root("MIT.LICENSE") ] },
|
||||
{ src: [ root("LICENSE") ] },
|
||||
{
|
||||
src: [ "jasmine_favicon.png"],
|
||||
dest: standaloneLibDir,
|
||||
|
||||
@@ -45,10 +45,6 @@ module.exports = {
|
||||
src: ['src/boot/boot1.js'],
|
||||
dest: 'lib/jasmine-core/boot1.js'
|
||||
},
|
||||
nodeBoot: {
|
||||
src: ['src/boot/node_boot.js'],
|
||||
dest: 'lib/jasmine-core/node_boot.js'
|
||||
},
|
||||
options: {
|
||||
banner: license(),
|
||||
process: {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
Copyright (c) 2008-<%= currentYear %> Pivotal Labs
|
||||
Copyright (c) 2008-2019 Pivotal Labs
|
||||
Copyright (c) 2008-<%= currentYear %> The Jasmine developers
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
|
||||
@@ -6,47 +6,61 @@
|
||||
const jasmineRequire = require('./jasmine-core/jasmine.js');
|
||||
module.exports = jasmineRequire;
|
||||
|
||||
/**
|
||||
* Boots a copy of Jasmine and returns an object as described in {@link jasmine}.
|
||||
* @type {function}
|
||||
* @return {jasmine}
|
||||
*/
|
||||
module.exports.boot = require('./jasmine-core/node_boot.js');
|
||||
const boot = (function() {
|
||||
let jasmine, jasmineInterface;
|
||||
|
||||
/**
|
||||
* Boots a copy of Jasmine and returns an object containing the properties
|
||||
* that would normally be added to the global object. If noGlobals is called
|
||||
* multiple times, the same object is returned every time.
|
||||
*
|
||||
* Do not call boot() if you also call noGlobals().
|
||||
*
|
||||
* @example
|
||||
* const {describe, beforeEach, it, expect, jasmine} = require('jasmine-core').noGlobals();
|
||||
*/
|
||||
module.exports.noGlobals = (function() {
|
||||
let jasmineInterface;
|
||||
|
||||
return function bootWithoutGlobals() {
|
||||
if (!jasmineInterface) {
|
||||
const jasmine = jasmineRequire.core(jasmineRequire);
|
||||
return function bootWithoutGlobals(reinitialize) {
|
||||
if (!jasmineInterface || reinitialize === true) {
|
||||
jasmine = jasmineRequire.core(jasmineRequire);
|
||||
const env = jasmine.getEnv({ suppressLoadErrors: true });
|
||||
jasmineInterface = jasmineRequire.interface(jasmine, env);
|
||||
}
|
||||
|
||||
return jasmineInterface;
|
||||
return {jasmine, jasmineInterface};
|
||||
};
|
||||
}());
|
||||
|
||||
var path = require('path'),
|
||||
fs = require('fs');
|
||||
/**
|
||||
* Boots a copy of Jasmine and returns an object as described in {@link jasmine}.
|
||||
* If boot is called multiple times, the same object is returned every time
|
||||
* unless true is passed.
|
||||
* @param {boolean} [reinitialize=false] Whether to create a new copy of Jasmine if one already exists
|
||||
* @type {function}
|
||||
* @return {jasmine}
|
||||
*/
|
||||
module.exports.boot = function(reinitialize) {
|
||||
const {jasmine, jasmineInterface} = boot(reinitialize);
|
||||
|
||||
var rootPath = path.join(__dirname, "jasmine-core"),
|
||||
bootFiles = ['boot0.js', 'boot1.js'],
|
||||
legacyBootFiles = ['boot.js'],
|
||||
nodeBootFiles = ['node_boot.js'],
|
||||
cssFiles = [],
|
||||
jsFiles = [],
|
||||
jsFilesToSkip = ['jasmine.js'].concat(bootFiles, legacyBootFiles, nodeBootFiles);
|
||||
for (const k in jasmineInterface) {
|
||||
global[k] = jasmineInterface[k];
|
||||
}
|
||||
|
||||
return jasmine;
|
||||
};
|
||||
|
||||
/**
|
||||
* Boots a copy of Jasmine and returns an object containing the properties
|
||||
* that would normally be added to the global object. If noGlobals is called
|
||||
* multiple times, the same object is returned every time unless true is passed.
|
||||
*
|
||||
* @param {boolean} [reinitialize=false] Whether to create a new copy of Jasmine if one already exists
|
||||
* @example
|
||||
* const {describe, beforeEach, it, expect, jasmine} = require('jasmine-core').noGlobals();
|
||||
*/
|
||||
module.exports.noGlobals = function(reinitialize) {
|
||||
const {jasmineInterface} = boot(reinitialize);
|
||||
return jasmineInterface;
|
||||
};
|
||||
|
||||
const path = require('path'),
|
||||
fs = require('fs');
|
||||
|
||||
const rootPath = path.join(__dirname, 'jasmine-core'),
|
||||
bootFiles = ['boot0.js', 'boot1.js'],
|
||||
legacyBootFiles = ['boot.js'],
|
||||
cssFiles = [],
|
||||
jsFiles = [],
|
||||
jsFilesToSkip = ['jasmine.js'].concat(bootFiles, legacyBootFiles);
|
||||
|
||||
fs.readdirSync(rootPath).forEach(function(file) {
|
||||
if(fs.statSync(path.join(rootPath, file)).isFile()) {
|
||||
@@ -56,18 +70,18 @@ fs.readdirSync(rootPath).forEach(function(file) {
|
||||
break;
|
||||
case '.js':
|
||||
if (jsFilesToSkip.indexOf(file) < 0) {
|
||||
jsFiles.push(file);
|
||||
}
|
||||
jsFiles.push(file);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
module.exports.files = {
|
||||
self: __filename,
|
||||
path: rootPath,
|
||||
bootDir: rootPath,
|
||||
bootFiles: bootFiles,
|
||||
nodeBootFiles: nodeBootFiles,
|
||||
cssFiles: cssFiles,
|
||||
jsFiles: ['jasmine.js'].concat(jsFiles),
|
||||
imagesDir: path.join(__dirname, '../images')
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
Copyright (c) 2008-2022 Pivotal Labs
|
||||
Copyright (c) 2008-2019 Pivotal Labs
|
||||
Copyright (c) 2008-2024 The Jasmine developers
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
@@ -27,14 +28,14 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
source files or spec files are loaded.
|
||||
*/
|
||||
(function() {
|
||||
var jasmineRequire = window.jasmineRequire || require('./jasmine.js');
|
||||
const jasmineRequire = window.jasmineRequire || require('./jasmine.js');
|
||||
|
||||
/**
|
||||
* ## Require & Instantiate
|
||||
*
|
||||
* 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 = jasmine;
|
||||
|
||||
@@ -46,19 +47,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.
|
||||
*/
|
||||
var env = jasmine.getEnv();
|
||||
const env = jasmine.getEnv();
|
||||
|
||||
/**
|
||||
* ## 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.
|
||||
*/
|
||||
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`.
|
||||
*/
|
||||
for (var property in jasmineInterface) {
|
||||
for (const property in jasmineInterface) {
|
||||
global[property] = jasmineInterface[property];
|
||||
}
|
||||
})();
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
Copyright (c) 2008-2022 Pivotal Labs
|
||||
Copyright (c) 2008-2019 Pivotal Labs
|
||||
Copyright (c) 2008-2024 The Jasmine developers
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
@@ -34,7 +35,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
(function() {
|
||||
var env = jasmine.getEnv();
|
||||
const env = jasmine.getEnv();
|
||||
|
||||
/**
|
||||
* ## Runner Parameters
|
||||
@@ -42,15 +43,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.
|
||||
*/
|
||||
|
||||
var queryString = new jasmine.QueryString({
|
||||
const queryString = new jasmine.QueryString({
|
||||
getWindowLocation: function() {
|
||||
return window.location;
|
||||
}
|
||||
});
|
||||
|
||||
var filterSpecs = !!queryString.getParam('spec');
|
||||
const filterSpecs = !!queryString.getParam('spec');
|
||||
|
||||
var config = {
|
||||
const config = {
|
||||
stopOnSpecFailure: queryString.getParam('stopOnSpecFailure'),
|
||||
stopSpecOnExpectationFailure: queryString.getParam(
|
||||
'stopSpecOnExpectationFailure'
|
||||
@@ -58,13 +59,13 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
hideDisabled: queryString.getParam('hideDisabled')
|
||||
};
|
||||
|
||||
var random = queryString.getParam('random');
|
||||
const random = queryString.getParam('random');
|
||||
|
||||
if (random !== undefined && random !== '') {
|
||||
config.random = random;
|
||||
}
|
||||
|
||||
var seed = queryString.getParam('seed');
|
||||
const seed = queryString.getParam('seed');
|
||||
if (seed) {
|
||||
config.seed = seed;
|
||||
}
|
||||
@@ -73,7 +74,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
* ## 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).
|
||||
*/
|
||||
var htmlReporter = new jasmine.HtmlReporter({
|
||||
const htmlReporter = new jasmine.HtmlReporter({
|
||||
env: env,
|
||||
navigateWithNewParam: function(key, value) {
|
||||
return queryString.navigateWithNewParam(key, value);
|
||||
@@ -103,7 +104,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.
|
||||
*/
|
||||
var specFilter = new jasmine.HtmlSpecFilter({
|
||||
const specFilter = new jasmine.HtmlSpecFilter({
|
||||
filterString: function() {
|
||||
return queryString.getParam('spec');
|
||||
}
|
||||
@@ -120,7 +121,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.
|
||||
*/
|
||||
var currentWindowOnload = window.onload;
|
||||
const currentWindowOnload = window.onload;
|
||||
|
||||
window.onload = function() {
|
||||
if (currentWindowOnload) {
|
||||
|
||||
@@ -1,24 +1,24 @@
|
||||
function Player() {
|
||||
}
|
||||
Player.prototype.play = function(song) {
|
||||
this.currentlyPlayingSong = song;
|
||||
this.isPlaying = true;
|
||||
};
|
||||
|
||||
Player.prototype.pause = function() {
|
||||
this.isPlaying = false;
|
||||
};
|
||||
|
||||
Player.prototype.resume = function() {
|
||||
if (this.isPlaying) {
|
||||
throw new Error("song is already playing");
|
||||
class Player {
|
||||
play(song) {
|
||||
this.currentlyPlayingSong = song;
|
||||
this.isPlaying = true;
|
||||
}
|
||||
|
||||
this.isPlaying = true;
|
||||
};
|
||||
pause() {
|
||||
this.isPlaying = false;
|
||||
}
|
||||
|
||||
Player.prototype.makeFavorite = function() {
|
||||
this.currentlyPlayingSong.persistFavoriteStatus(true);
|
||||
};
|
||||
resume() {
|
||||
if (this.isPlaying) {
|
||||
throw new Error('song is already playing');
|
||||
}
|
||||
|
||||
this.isPlaying = true;
|
||||
}
|
||||
|
||||
makeFavorite() {
|
||||
this.currentlyPlayingSong.persistFavoriteStatus(true);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Player;
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
function Song() {
|
||||
class Song {
|
||||
persistFavoriteStatus(value) {
|
||||
// something complicated
|
||||
throw new Error('not yet implemented');
|
||||
}
|
||||
}
|
||||
|
||||
Song.prototype.persistFavoriteStatus = function(value) {
|
||||
// something complicated
|
||||
throw new Error("not yet implemented");
|
||||
};
|
||||
|
||||
module.exports = Song;
|
||||
|
||||
@@ -3,11 +3,11 @@ beforeEach(function () {
|
||||
toBePlaying: function () {
|
||||
return {
|
||||
compare: function (actual, expected) {
|
||||
var player = actual;
|
||||
const player = actual;
|
||||
|
||||
return {
|
||||
pass: player.currentlyPlayingSong === expected && player.isPlaying
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,36 +1,37 @@
|
||||
describe("Player", function() {
|
||||
var Player = require('../../lib/jasmine_examples/Player');
|
||||
var Song = require('../../lib/jasmine_examples/Song');
|
||||
var player;
|
||||
var song;
|
||||
const Player = require('../../lib/jasmine_examples/Player');
|
||||
const Song = require('../../lib/jasmine_examples/Song');
|
||||
|
||||
describe('Player', function() {
|
||||
let player;
|
||||
let song;
|
||||
|
||||
beforeEach(function() {
|
||||
player = new Player();
|
||||
song = new Song();
|
||||
});
|
||||
|
||||
it("should be able to play a Song", function() {
|
||||
it('should be able to play a Song', function() {
|
||||
player.play(song);
|
||||
expect(player.currentlyPlayingSong).toEqual(song);
|
||||
|
||||
//demonstrates use of custom matcher
|
||||
// demonstrates use of custom matcher
|
||||
expect(player).toBePlaying(song);
|
||||
});
|
||||
|
||||
describe("when song has been paused", function() {
|
||||
describe('when song has been paused', function() {
|
||||
beforeEach(function() {
|
||||
player.play(song);
|
||||
player.pause();
|
||||
});
|
||||
|
||||
it("should indicate that the song is currently paused", function() {
|
||||
it('should indicate that the song is currently paused', function() {
|
||||
expect(player.isPlaying).toBeFalsy();
|
||||
|
||||
// demonstrates use of 'not' with a custom matcher
|
||||
expect(player).not.toBePlaying(song);
|
||||
});
|
||||
|
||||
it("should be possible to resume", function() {
|
||||
it('should be possible to resume', function() {
|
||||
player.resume();
|
||||
expect(player.isPlaying).toBeTruthy();
|
||||
expect(player.currentlyPlayingSong).toEqual(song);
|
||||
@@ -38,7 +39,7 @@ describe("Player", function() {
|
||||
});
|
||||
|
||||
// demonstrates use of spies to intercept and test method calls
|
||||
it("tells the current song if the user has made it a favorite", function() {
|
||||
it('tells the current song if the user has made it a favorite', function() {
|
||||
spyOn(song, 'persistFavoriteStatus');
|
||||
|
||||
player.play(song);
|
||||
@@ -48,13 +49,13 @@ describe("Player", function() {
|
||||
});
|
||||
|
||||
//demonstrates use of expected exceptions
|
||||
describe("#resume", function() {
|
||||
it("should throw an exception if song is already playing", function() {
|
||||
describe('#resume', function() {
|
||||
it('should throw an exception if song is already playing', function() {
|
||||
player.play(song);
|
||||
|
||||
expect(function() {
|
||||
player.resume();
|
||||
}).toThrowError("song is already playing");
|
||||
}).toThrowError('song is already playing');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,34 +1,34 @@
|
||||
describe("Player", function() {
|
||||
var player;
|
||||
var song;
|
||||
describe('Player', function() {
|
||||
let player;
|
||||
let song;
|
||||
|
||||
beforeEach(function() {
|
||||
player = new Player();
|
||||
song = new Song();
|
||||
});
|
||||
|
||||
it("should be able to play a Song", function() {
|
||||
it('should be able to play a Song', function() {
|
||||
player.play(song);
|
||||
expect(player.currentlyPlayingSong).toEqual(song);
|
||||
|
||||
//demonstrates use of custom matcher
|
||||
// demonstrates use of custom matcher
|
||||
expect(player).toBePlaying(song);
|
||||
});
|
||||
|
||||
describe("when song has been paused", function() {
|
||||
describe('when song has been paused', function() {
|
||||
beforeEach(function() {
|
||||
player.play(song);
|
||||
player.pause();
|
||||
});
|
||||
|
||||
it("should indicate that the song is currently paused", function() {
|
||||
it('should indicate that the song is currently paused', function() {
|
||||
expect(player.isPlaying).toBeFalsy();
|
||||
|
||||
// demonstrates use of 'not' with a custom matcher
|
||||
expect(player).not.toBePlaying(song);
|
||||
});
|
||||
|
||||
it("should be possible to resume", function() {
|
||||
it('should be possible to resume', function() {
|
||||
player.resume();
|
||||
expect(player.isPlaying).toBeTruthy();
|
||||
expect(player.currentlyPlayingSong).toEqual(song);
|
||||
@@ -36,7 +36,7 @@ describe("Player", function() {
|
||||
});
|
||||
|
||||
// demonstrates use of spies to intercept and test method calls
|
||||
it("tells the current song if the user has made it a favorite", function() {
|
||||
it('tells the current song if the user has made it a favorite', function() {
|
||||
spyOn(song, 'persistFavoriteStatus');
|
||||
|
||||
player.play(song);
|
||||
@@ -46,13 +46,13 @@ describe("Player", function() {
|
||||
});
|
||||
|
||||
//demonstrates use of expected exceptions
|
||||
describe("#resume", function() {
|
||||
it("should throw an exception if song is already playing", function() {
|
||||
describe('#resume', function() {
|
||||
it('should throw an exception if song is already playing', function() {
|
||||
player.play(song);
|
||||
|
||||
expect(function() {
|
||||
player.resume();
|
||||
}).toThrowError("song is already playing");
|
||||
}).toThrowError('song is already playing');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -3,7 +3,7 @@ beforeEach(function () {
|
||||
toBePlaying: function () {
|
||||
return {
|
||||
compare: function (actual, expected) {
|
||||
var player = actual;
|
||||
const player = actual;
|
||||
|
||||
return {
|
||||
pass: player.currentlyPlayingSong === expected && player.isPlaying
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
function Player() {
|
||||
}
|
||||
Player.prototype.play = function(song) {
|
||||
this.currentlyPlayingSong = song;
|
||||
this.isPlaying = true;
|
||||
};
|
||||
|
||||
Player.prototype.pause = function() {
|
||||
this.isPlaying = false;
|
||||
};
|
||||
|
||||
Player.prototype.resume = function() {
|
||||
if (this.isPlaying) {
|
||||
throw new Error("song is already playing");
|
||||
class Player {
|
||||
play(song) {
|
||||
this.currentlyPlayingSong = song;
|
||||
this.isPlaying = true;
|
||||
}
|
||||
|
||||
this.isPlaying = true;
|
||||
};
|
||||
pause() {
|
||||
this.isPlaying = false;
|
||||
}
|
||||
|
||||
Player.prototype.makeFavorite = function() {
|
||||
this.currentlyPlayingSong.persistFavoriteStatus(true);
|
||||
};
|
||||
resume() {
|
||||
if (this.isPlaying) {
|
||||
throw new Error('song is already playing');
|
||||
}
|
||||
|
||||
this.isPlaying = true;
|
||||
}
|
||||
|
||||
makeFavorite() {
|
||||
this.currentlyPlayingSong.persistFavoriteStatus(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
function Song() {
|
||||
class Song {
|
||||
persistFavoriteStatus(value) {
|
||||
// something complicated
|
||||
throw new Error('not yet implemented');
|
||||
}
|
||||
}
|
||||
|
||||
Song.prototype.persistFavoriteStatus = function(value) {
|
||||
// something complicated
|
||||
throw new Error("not yet implemented");
|
||||
};
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
Copyright (c) 2008-2022 Pivotal Labs
|
||||
Copyright (c) 2008-2019 Pivotal Labs
|
||||
Copyright (c) 2008-2024 The Jasmine developers
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
@@ -20,6 +21,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
|
||||
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');
|
||||
|
||||
jasmineRequire.html = function(j$) {
|
||||
@@ -79,19 +81,21 @@ jasmineRequire.HtmlReporter = function(j$) {
|
||||
};
|
||||
|
||||
function HtmlReporter(options) {
|
||||
var config = function() {
|
||||
return (options.env && options.env.configuration()) || {};
|
||||
},
|
||||
getContainer = options.getContainer,
|
||||
createElement = options.createElement,
|
||||
createTextNode = options.createTextNode,
|
||||
navigateWithNewParam = options.navigateWithNewParam || function() {},
|
||||
addToExistingQueryString =
|
||||
options.addToExistingQueryString || defaultQueryString,
|
||||
filterSpecs = options.filterSpecs,
|
||||
htmlReporterMain,
|
||||
symbols,
|
||||
deprecationWarnings = [];
|
||||
function config() {
|
||||
return (options.env && options.env.configuration()) || {};
|
||||
}
|
||||
|
||||
const getContainer = options.getContainer;
|
||||
const createElement = options.createElement;
|
||||
const createTextNode = options.createTextNode;
|
||||
const navigateWithNewParam = options.navigateWithNewParam || function() {};
|
||||
const addToExistingQueryString =
|
||||
options.addToExistingQueryString || defaultQueryString;
|
||||
const filterSpecs = options.filterSpecs;
|
||||
let htmlReporterMain;
|
||||
let symbols;
|
||||
const deprecationWarnings = [];
|
||||
const failures = [];
|
||||
|
||||
this.initialize = function() {
|
||||
clearPrior();
|
||||
@@ -119,14 +123,14 @@ jasmineRequire.HtmlReporter = function(j$) {
|
||||
getContainer().appendChild(htmlReporterMain);
|
||||
};
|
||||
|
||||
var totalSpecsDefined;
|
||||
let totalSpecsDefined;
|
||||
this.jasmineStarted = function(options) {
|
||||
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) {
|
||||
stateBuilder.suiteStarted(result);
|
||||
@@ -145,12 +149,11 @@ jasmineRequire.HtmlReporter = function(j$) {
|
||||
stateBuilder.specStarted(result);
|
||||
};
|
||||
|
||||
var failures = [];
|
||||
this.specDone = function(result) {
|
||||
stateBuilder.specDone(result);
|
||||
|
||||
if (noExpectations(result)) {
|
||||
var noSpecMsg = "Spec '" + result.fullName + "' has no expectations.";
|
||||
const noSpecMsg = "Spec '" + result.fullName + "' has no expectations.";
|
||||
if (result.status === 'failed') {
|
||||
console.error(noSpecMsg);
|
||||
} else {
|
||||
@@ -194,10 +197,10 @@ jasmineRequire.HtmlReporter = function(j$) {
|
||||
|
||||
this.jasmineDone = function(doneResult) {
|
||||
stateBuilder.jasmineDone(doneResult);
|
||||
var banner = find('.jasmine-banner');
|
||||
var alert = find('.jasmine-alert');
|
||||
var order = doneResult && doneResult.order;
|
||||
var i;
|
||||
const banner = find('.jasmine-banner');
|
||||
const alert = find('.jasmine-alert');
|
||||
const order = doneResult && doneResult.order;
|
||||
|
||||
alert.appendChild(
|
||||
createDom(
|
||||
'span',
|
||||
@@ -209,14 +212,14 @@ jasmineRequire.HtmlReporter = function(j$) {
|
||||
banner.appendChild(optionsMenu(config()));
|
||||
|
||||
if (stateBuilder.specsExecuted < totalSpecsDefined) {
|
||||
var skippedMessage =
|
||||
const skippedMessage =
|
||||
'Ran ' +
|
||||
stateBuilder.specsExecuted +
|
||||
' of ' +
|
||||
totalSpecsDefined +
|
||||
' 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
|
||||
var skippedLink =
|
||||
const skippedLink =
|
||||
(window.location.pathname || '') +
|
||||
addToExistingQueryString('spec', '');
|
||||
alert.appendChild(
|
||||
@@ -231,10 +234,11 @@ jasmineRequire.HtmlReporter = function(j$) {
|
||||
)
|
||||
);
|
||||
}
|
||||
var statusBarMessage = '';
|
||||
var statusBarClassName = 'jasmine-overall-result jasmine-bar ';
|
||||
var globalFailures = (doneResult && doneResult.failedExpectations) || [];
|
||||
var failed = stateBuilder.failureCount + globalFailures.length > 0;
|
||||
let statusBarMessage = '';
|
||||
let statusBarClassName = 'jasmine-overall-result jasmine-bar ';
|
||||
const globalFailures =
|
||||
(doneResult && doneResult.failedExpectations) || [];
|
||||
const failed = stateBuilder.failureCount + globalFailures.length > 0;
|
||||
|
||||
if (totalSpecsDefined > 0 || failed) {
|
||||
statusBarMessage +=
|
||||
@@ -260,7 +264,7 @@ jasmineRequire.HtmlReporter = function(j$) {
|
||||
statusBarClassName += ' jasmine-failed ';
|
||||
}
|
||||
|
||||
var seedBar;
|
||||
let seedBar;
|
||||
if (order && order.random) {
|
||||
seedBar = createDom(
|
||||
'span',
|
||||
@@ -286,10 +290,10 @@ jasmineRequire.HtmlReporter = function(j$) {
|
||||
)
|
||||
);
|
||||
|
||||
var errorBarClassName = 'jasmine-bar jasmine-errored';
|
||||
var afterAllMessagePrefix = 'AfterAll ';
|
||||
const errorBarClassName = 'jasmine-bar jasmine-errored';
|
||||
const afterAllMessagePrefix = 'AfterAll ';
|
||||
|
||||
for (i = 0; i < globalFailures.length; i++) {
|
||||
for (let i = 0; i < globalFailures.length; i++) {
|
||||
alert.appendChild(
|
||||
createDom(
|
||||
'span',
|
||||
@@ -301,7 +305,7 @@ jasmineRequire.HtmlReporter = function(j$) {
|
||||
|
||||
function globalFailureMessage(failure) {
|
||||
if (failure.globalErrorType === 'load') {
|
||||
var prefix = 'Error during loading: ' + failure.message;
|
||||
const prefix = 'Error during loading: ' + failure.message;
|
||||
|
||||
if (failure.filename) {
|
||||
return (
|
||||
@@ -319,9 +323,9 @@ jasmineRequire.HtmlReporter = function(j$) {
|
||||
|
||||
addDeprecationWarnings(doneResult);
|
||||
|
||||
for (i = 0; i < deprecationWarnings.length; i++) {
|
||||
var children = [],
|
||||
context;
|
||||
for (let i = 0; i < deprecationWarnings.length; i++) {
|
||||
const children = [];
|
||||
let context;
|
||||
|
||||
switch (deprecationWarnings[i].runnableType) {
|
||||
case 'spec':
|
||||
@@ -355,7 +359,7 @@ jasmineRequire.HtmlReporter = function(j$) {
|
||||
);
|
||||
}
|
||||
|
||||
var results = find('.jasmine-results');
|
||||
const results = find('.jasmine-results');
|
||||
results.appendChild(summary);
|
||||
|
||||
summaryList(stateBuilder.topResults, summary);
|
||||
@@ -397,8 +401,8 @@ jasmineRequire.HtmlReporter = function(j$) {
|
||||
|
||||
setMenuModeTo('jasmine-failure-list');
|
||||
|
||||
var failureNode = find('.jasmine-failures');
|
||||
for (i = 0; i < failures.length; i++) {
|
||||
const failureNode = find('.jasmine-failures');
|
||||
for (let i = 0; i < failures.length; i++) {
|
||||
failureNode.appendChild(failures[i]);
|
||||
}
|
||||
}
|
||||
@@ -407,16 +411,16 @@ jasmineRequire.HtmlReporter = function(j$) {
|
||||
return this;
|
||||
|
||||
function failureDom(result) {
|
||||
var failure = createDom(
|
||||
const failure = createDom(
|
||||
'div',
|
||||
{ className: 'jasmine-spec-detail jasmine-failed' },
|
||||
failureDescription(result, stateBuilder.currentParent),
|
||||
createDom('div', { className: 'jasmine-messages' })
|
||||
);
|
||||
var messages = failure.childNodes[1];
|
||||
const messages = failure.childNodes[1];
|
||||
|
||||
for (var i = 0; i < result.failedExpectations.length; i++) {
|
||||
var expectation = result.failedExpectations[i];
|
||||
for (let i = 0; i < result.failedExpectations.length; i++) {
|
||||
const expectation = result.failedExpectations[i];
|
||||
messages.appendChild(
|
||||
createDom(
|
||||
'div',
|
||||
@@ -451,7 +455,7 @@ jasmineRequire.HtmlReporter = function(j$) {
|
||||
}
|
||||
|
||||
function debugLogTable(debugLogs) {
|
||||
var tbody = createDom('tbody');
|
||||
const tbody = createDom('tbody');
|
||||
|
||||
debugLogs.forEach(function(entry) {
|
||||
tbody.appendChild(
|
||||
@@ -459,7 +463,11 @@ jasmineRequire.HtmlReporter = function(j$) {
|
||||
'tr',
|
||||
{},
|
||||
createDom('td', {}, entry.timestamp.toString()),
|
||||
createDom('td', {}, entry.message)
|
||||
createDom(
|
||||
'td',
|
||||
{ className: 'jasmine-debug-log-msg' },
|
||||
entry.message
|
||||
)
|
||||
)
|
||||
);
|
||||
});
|
||||
@@ -491,14 +499,14 @@ jasmineRequire.HtmlReporter = function(j$) {
|
||||
}
|
||||
|
||||
function summaryList(resultsTree, domParent) {
|
||||
var specListNode;
|
||||
for (var i = 0; i < resultsTree.children.length; i++) {
|
||||
var resultNode = resultsTree.children[i];
|
||||
let specListNode;
|
||||
for (let i = 0; i < resultsTree.children.length; i++) {
|
||||
const resultNode = resultsTree.children[i];
|
||||
if (filterSpecs && !hasActiveSpec(resultNode)) {
|
||||
continue;
|
||||
}
|
||||
if (resultNode.type === 'suite') {
|
||||
var suiteListNode = createDom(
|
||||
const suiteListNode = createDom(
|
||||
'ul',
|
||||
{ className: 'jasmine-suite', id: 'suite-' + resultNode.result.id },
|
||||
createDom(
|
||||
@@ -523,18 +531,17 @@ jasmineRequire.HtmlReporter = function(j$) {
|
||||
specListNode = createDom('ul', { className: 'jasmine-specs' });
|
||||
domParent.appendChild(specListNode);
|
||||
}
|
||||
var specDescription = resultNode.result.description;
|
||||
let specDescription = resultNode.result.description;
|
||||
if (noExpectations(resultNode.result)) {
|
||||
specDescription = 'SPEC HAS NO EXPECTATIONS ' + specDescription;
|
||||
}
|
||||
if (
|
||||
resultNode.result.status === 'pending' &&
|
||||
resultNode.result.pendingReason !== ''
|
||||
) {
|
||||
specDescription =
|
||||
specDescription +
|
||||
' PENDING WITH MESSAGE: ' +
|
||||
resultNode.result.pendingReason;
|
||||
if (resultNode.result.status === 'pending') {
|
||||
if (resultNode.result.pendingReason !== '') {
|
||||
specDescription +=
|
||||
' PENDING WITH MESSAGE: ' + resultNode.result.pendingReason;
|
||||
} else {
|
||||
specDescription += ' PENDING';
|
||||
}
|
||||
}
|
||||
specListNode.appendChild(
|
||||
createDom(
|
||||
@@ -555,7 +562,7 @@ jasmineRequire.HtmlReporter = function(j$) {
|
||||
}
|
||||
|
||||
function optionsMenu(config) {
|
||||
var optionsMenuDom = createDom(
|
||||
const optionsMenuDom = createDom(
|
||||
'div',
|
||||
{ className: 'jasmine-run-options' },
|
||||
createDom('span', { className: 'jasmine-trigger' }, 'Options'),
|
||||
@@ -621,13 +628,15 @@ jasmineRequire.HtmlReporter = function(j$) {
|
||||
)
|
||||
);
|
||||
|
||||
var failFastCheckbox = optionsMenuDom.querySelector('#jasmine-fail-fast');
|
||||
const failFastCheckbox = optionsMenuDom.querySelector(
|
||||
'#jasmine-fail-fast'
|
||||
);
|
||||
failFastCheckbox.checked = config.stopOnSpecFailure;
|
||||
failFastCheckbox.onclick = function() {
|
||||
navigateWithNewParam('stopOnSpecFailure', !config.stopOnSpecFailure);
|
||||
};
|
||||
|
||||
var throwCheckbox = optionsMenuDom.querySelector(
|
||||
const throwCheckbox = optionsMenuDom.querySelector(
|
||||
'#jasmine-throw-failures'
|
||||
);
|
||||
throwCheckbox.checked = config.stopSpecOnExpectationFailure;
|
||||
@@ -638,7 +647,7 @@ jasmineRequire.HtmlReporter = function(j$) {
|
||||
);
|
||||
};
|
||||
|
||||
var randomCheckbox = optionsMenuDom.querySelector(
|
||||
const randomCheckbox = optionsMenuDom.querySelector(
|
||||
'#jasmine-random-order'
|
||||
);
|
||||
randomCheckbox.checked = config.random;
|
||||
@@ -646,13 +655,15 @@ jasmineRequire.HtmlReporter = function(j$) {
|
||||
navigateWithNewParam('random', !config.random);
|
||||
};
|
||||
|
||||
var hideDisabled = optionsMenuDom.querySelector('#jasmine-hide-disabled');
|
||||
const hideDisabled = optionsMenuDom.querySelector(
|
||||
'#jasmine-hide-disabled'
|
||||
);
|
||||
hideDisabled.checked = config.hideDisabled;
|
||||
hideDisabled.onclick = function() {
|
||||
navigateWithNewParam('hideDisabled', !config.hideDisabled);
|
||||
};
|
||||
|
||||
var optionsTrigger = optionsMenuDom.querySelector('.jasmine-trigger'),
|
||||
const optionsTrigger = optionsMenuDom.querySelector('.jasmine-trigger'),
|
||||
optionsPayload = optionsMenuDom.querySelector('.jasmine-payload'),
|
||||
isOpen = /\bjasmine-open\b/;
|
||||
|
||||
@@ -671,7 +682,7 @@ jasmineRequire.HtmlReporter = function(j$) {
|
||||
}
|
||||
|
||||
function failureDescription(result, suite) {
|
||||
var wrapper = createDom(
|
||||
const wrapper = createDom(
|
||||
'div',
|
||||
{ className: 'jasmine-description' },
|
||||
createDom(
|
||||
@@ -680,7 +691,7 @@ jasmineRequire.HtmlReporter = function(j$) {
|
||||
result.description
|
||||
)
|
||||
);
|
||||
var suiteLink;
|
||||
let suiteLink;
|
||||
|
||||
while (suite && suite.parent) {
|
||||
wrapper.insertBefore(createTextNode(' > '), wrapper.firstChild);
|
||||
@@ -698,7 +709,7 @@ jasmineRequire.HtmlReporter = function(j$) {
|
||||
}
|
||||
|
||||
function suiteHref(suite) {
|
||||
var els = [];
|
||||
const els = [];
|
||||
|
||||
while (suite && suite.parent) {
|
||||
els.unshift(suite.result.description);
|
||||
@@ -714,8 +725,8 @@ jasmineRequire.HtmlReporter = function(j$) {
|
||||
|
||||
function addDeprecationWarnings(result, runnableType) {
|
||||
if (result && result.deprecationWarnings) {
|
||||
for (var i = 0; i < result.deprecationWarnings.length; i++) {
|
||||
var warning = result.deprecationWarnings[i].message;
|
||||
for (let i = 0; i < result.deprecationWarnings.length; i++) {
|
||||
const warning = result.deprecationWarnings[i].message;
|
||||
deprecationWarnings.push({
|
||||
message: warning,
|
||||
stack: result.deprecationWarnings[i].stack,
|
||||
@@ -727,8 +738,8 @@ jasmineRequire.HtmlReporter = function(j$) {
|
||||
}
|
||||
|
||||
function createExpander(stackTrace) {
|
||||
var expandLink = createDom('a', { href: '#' }, 'Show stack trace');
|
||||
var root = createDom(
|
||||
const expandLink = createDom('a', { href: '#' }, 'Show stack trace');
|
||||
const root = createDom(
|
||||
'div',
|
||||
{ className: 'jasmine-expander' },
|
||||
expandLink,
|
||||
@@ -759,8 +770,7 @@ jasmineRequire.HtmlReporter = function(j$) {
|
||||
}
|
||||
|
||||
function clearPrior() {
|
||||
// return the reporter
|
||||
var oldReporter = find('');
|
||||
const oldReporter = find('');
|
||||
|
||||
if (oldReporter) {
|
||||
getContainer().removeChild(oldReporter);
|
||||
@@ -768,22 +778,21 @@ jasmineRequire.HtmlReporter = function(j$) {
|
||||
}
|
||||
|
||||
function createDom(type, attrs, childrenArrayOrVarArgs) {
|
||||
var el = createElement(type),
|
||||
children,
|
||||
i;
|
||||
const el = createElement(type);
|
||||
let children;
|
||||
|
||||
if (j$.isArray_(childrenArrayOrVarArgs)) {
|
||||
children = childrenArrayOrVarArgs;
|
||||
} else {
|
||||
children = [];
|
||||
|
||||
for (i = 2; i < arguments.length; i++) {
|
||||
for (let i = 2; i < arguments.length; i++) {
|
||||
children.push(arguments[i]);
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < children.length; i++) {
|
||||
var child = children[i];
|
||||
for (let i = 0; i < children.length; i++) {
|
||||
const child = children[i];
|
||||
|
||||
if (typeof child === 'string') {
|
||||
el.appendChild(createTextNode(child));
|
||||
@@ -794,7 +803,7 @@ jasmineRequire.HtmlReporter = function(j$) {
|
||||
}
|
||||
}
|
||||
|
||||
for (var attr in attrs) {
|
||||
for (const attr in attrs) {
|
||||
if (attr == 'className') {
|
||||
el[attr] = attrs[attr];
|
||||
} else {
|
||||
@@ -806,7 +815,7 @@ jasmineRequire.HtmlReporter = function(j$) {
|
||||
}
|
||||
|
||||
function pluralize(singular, count) {
|
||||
var word = count == 1 ? singular : singular + 's';
|
||||
const word = count == 1 ? singular : singular + 's';
|
||||
|
||||
return '' + count + ' ' + word;
|
||||
}
|
||||
@@ -836,7 +845,7 @@ jasmineRequire.HtmlReporter = function(j$) {
|
||||
}
|
||||
|
||||
function noExpectations(result) {
|
||||
var allExpectations =
|
||||
const allExpectations =
|
||||
result.failedExpectations.length + result.passedExpectations.length;
|
||||
|
||||
return (
|
||||
@@ -851,7 +860,7 @@ jasmineRequire.HtmlReporter = function(j$) {
|
||||
}
|
||||
|
||||
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])) {
|
||||
return true;
|
||||
}
|
||||
@@ -865,11 +874,11 @@ jasmineRequire.HtmlReporter = function(j$) {
|
||||
|
||||
jasmineRequire.HtmlSpecFilter = function() {
|
||||
function HtmlSpecFilter(options) {
|
||||
var filterString =
|
||||
const filterString =
|
||||
options &&
|
||||
options.filterString() &&
|
||||
options.filterString().replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
|
||||
var filterPattern = new RegExp(filterString);
|
||||
const filterPattern = new RegExp(filterString);
|
||||
|
||||
this.matches = function(specName) {
|
||||
return filterPattern.test(specName);
|
||||
@@ -913,7 +922,7 @@ jasmineRequire.QueryString = function() {
|
||||
};
|
||||
|
||||
this.fullStringWithNewParam = function(key, value) {
|
||||
var paramMap = queryStringToParamMap();
|
||||
const paramMap = queryStringToParamMap();
|
||||
paramMap[key] = value;
|
||||
return toQueryString(paramMap);
|
||||
};
|
||||
@@ -925,8 +934,8 @@ jasmineRequire.QueryString = function() {
|
||||
return this;
|
||||
|
||||
function toQueryString(paramMap) {
|
||||
var qStrPairs = [];
|
||||
for (var prop in paramMap) {
|
||||
const qStrPairs = [];
|
||||
for (const prop in paramMap) {
|
||||
qStrPairs.push(
|
||||
encodeURIComponent(prop) + '=' + encodeURIComponent(paramMap[prop])
|
||||
);
|
||||
@@ -935,15 +944,15 @@ jasmineRequire.QueryString = function() {
|
||||
}
|
||||
|
||||
function queryStringToParamMap() {
|
||||
var paramStr = options.getWindowLocation().search.substring(1),
|
||||
params = [],
|
||||
paramMap = {};
|
||||
const paramStr = options.getWindowLocation().search.substring(1);
|
||||
let params = [];
|
||||
const paramMap = {};
|
||||
|
||||
if (paramStr.length > 0) {
|
||||
params = paramStr.split('&');
|
||||
for (var i = 0; i < params.length; i++) {
|
||||
var p = params[i].split('=');
|
||||
var value = decodeURIComponent(p[1]);
|
||||
for (let i = 0; i < params.length; i++) {
|
||||
const p = params[i].split('=');
|
||||
let value = decodeURIComponent(p[1]);
|
||||
if (value === 'true' || value === 'false') {
|
||||
value = JSON.parse(value);
|
||||
}
|
||||
|
||||
@@ -55,9 +55,6 @@ body {
|
||||
position: fixed;
|
||||
right: 100%;
|
||||
}
|
||||
.jasmine_html-reporter .jasmine-version {
|
||||
color: #aaa;
|
||||
}
|
||||
.jasmine_html-reporter .jasmine-banner {
|
||||
margin-top: 14px;
|
||||
}
|
||||
@@ -169,10 +166,11 @@ body {
|
||||
}
|
||||
.jasmine_html-reporter .jasmine-bar.jasmine-menu {
|
||||
background-color: #fff;
|
||||
color: #aaa;
|
||||
color: #000;
|
||||
}
|
||||
.jasmine_html-reporter .jasmine-bar.jasmine-menu a {
|
||||
color: #333;
|
||||
color: blue;
|
||||
text-decoration: underline;
|
||||
}
|
||||
.jasmine_html-reporter .jasmine-bar a {
|
||||
color: white;
|
||||
@@ -297,4 +295,7 @@ body {
|
||||
}
|
||||
.jasmine_html-reporter .jasmine-debug-log table, .jasmine_html-reporter .jasmine-debug-log th, .jasmine_html-reporter .jasmine-debug-log td {
|
||||
border: 1px solid #ddd;
|
||||
}
|
||||
.jasmine_html-reporter .jasmine-debug-log .jasmine-debug-log-msg {
|
||||
white-space: pre;
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,38 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2008-2022 Pivotal Labs
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
module.exports = function(jasmineRequire) {
|
||||
var jasmine = jasmineRequire.core(jasmineRequire);
|
||||
|
||||
var env = jasmine.getEnv({ suppressLoadErrors: true });
|
||||
|
||||
var jasmineInterface = jasmineRequire.interface(jasmine, env);
|
||||
|
||||
extend(global, jasmineInterface);
|
||||
|
||||
function extend(destination, source) {
|
||||
for (var property in source) destination[property] = source[property];
|
||||
return destination;
|
||||
}
|
||||
|
||||
return jasmine;
|
||||
};
|
||||
67
package.json
67
package.json
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "jasmine-core",
|
||||
"license": "MIT",
|
||||
"version": "4.1.1",
|
||||
"version": "5.4.0",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/jasmine/jasmine.git"
|
||||
@@ -27,82 +27,35 @@
|
||||
"homepage": "https://jasmine.github.io",
|
||||
"main": "./lib/jasmine-core.js",
|
||||
"files": [
|
||||
"MIT.LICENSE",
|
||||
"LICENSE",
|
||||
"README.md",
|
||||
"images/*.{png,svg}",
|
||||
"lib/**/*.{js,css}",
|
||||
"package.json"
|
||||
],
|
||||
"devDependencies": {
|
||||
"eslint": "^7.32.0",
|
||||
"eslint": "^8.36.0",
|
||||
"eslint-plugin-compat": "^4.0.0",
|
||||
"glob": "^7.2.0",
|
||||
"glob": "^10.2.3",
|
||||
"grunt": "^1.0.4",
|
||||
"grunt-cli": "^1.3.2",
|
||||
"grunt-contrib-compress": "^2.0.0",
|
||||
"grunt-contrib-concat": "^2.0.0",
|
||||
"grunt-css-url-embed": "^1.11.1",
|
||||
"grunt-sass": "^3.0.2",
|
||||
"jasmine": "github:jasmine/jasmine-npm#main",
|
||||
"jasmine-browser-runner": "github:jasmine/jasmine-browser#main",
|
||||
"jsdom": "^19.0.0",
|
||||
"jasmine": "^5.0.0",
|
||||
"jasmine-browser-runner": "github:jasmine/jasmine-browser-runner",
|
||||
"jsdom": "^22.0.0",
|
||||
"load-grunt-tasks": "^5.1.0",
|
||||
"prettier": "1.17.1",
|
||||
"sass": "^1.45.1",
|
||||
"sass": "^1.58.3",
|
||||
"shelljs": "^0.8.3",
|
||||
"temp": "^0.9.0"
|
||||
},
|
||||
"prettier": {
|
||||
"singleQuote": true
|
||||
},
|
||||
"eslintConfig": {
|
||||
"extends": [
|
||||
"plugin:compat/recommended"
|
||||
],
|
||||
"env": {
|
||||
"browser": true,
|
||||
"node": true,
|
||||
"es2017": true
|
||||
},
|
||||
"parserOptions": {
|
||||
"ecmaVersion": 2018
|
||||
},
|
||||
"rules": {
|
||||
"quotes": [
|
||||
"error",
|
||||
"single",
|
||||
{
|
||||
"avoidEscape": true
|
||||
}
|
||||
],
|
||||
"no-unused-vars": [
|
||||
"error",
|
||||
{
|
||||
"args": "none"
|
||||
}
|
||||
],
|
||||
"no-implicit-globals": "error",
|
||||
"block-spacing": "error",
|
||||
"func-call-spacing": [
|
||||
"error",
|
||||
"never"
|
||||
],
|
||||
"key-spacing": "error",
|
||||
"no-tabs": "error",
|
||||
"no-trailing-spaces": "error",
|
||||
"no-whitespace-before-property": "error",
|
||||
"semi": [
|
||||
"error",
|
||||
"always"
|
||||
],
|
||||
"space-before-blocks": "error"
|
||||
}
|
||||
},
|
||||
"browserslist": [
|
||||
"Safari >= 13",
|
||||
"Safari >= 15",
|
||||
"Firefox >= 102",
|
||||
"last 2 Chrome versions",
|
||||
"last 2 Firefox versions",
|
||||
"Firefox >= 68",
|
||||
"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)_
|
||||
28
release_notes/4.4.0.md
Normal file
28
release_notes/4.4.0.md
Normal file
@@ -0,0 +1,28 @@
|
||||
# Jasmine 4.4.0 Release Notes
|
||||
|
||||
## Changes
|
||||
|
||||
* Optimized the process of transitioning between specs in Node, Safari, and
|
||||
Edge. This change reduces the run time of jasmine-core's own test suite by
|
||||
50-70% in Node, about 20% in Edge, and 75-90% in Safari. Your results may
|
||||
vary. In general, suites with many fast specs will see the greatest
|
||||
performance improvement.
|
||||
|
||||
* Removed old code to support browsers that don't provide
|
||||
addEventListener/removeEventListener.
|
||||
|
||||
## Supported environments
|
||||
|
||||
jasmine-core 4.4.0 has been tested in the following environments.
|
||||
|
||||
| Environment | Supported versions |
|
||||
|-------------------|--------------------|
|
||||
| Node | 12.17+, 14, 16, 18 |
|
||||
| Safari | 14-15 |
|
||||
| Chrome | 105 |
|
||||
| Firefox | 91, 102, 104 |
|
||||
| Edge | 104 |
|
||||
|
||||
------
|
||||
|
||||
_Release Notes generated with _[Anchorman](http://github.com/infews/anchorman)_
|
||||
40
release_notes/4.5.0.md
Normal file
40
release_notes/4.5.0.md
Normal file
@@ -0,0 +1,40 @@
|
||||
# Jasmine 4.5.0 Release Notes
|
||||
|
||||
## New Features
|
||||
|
||||
* Added Safari 16 to supported browsers
|
||||
* Include inner exceptions in stack traces
|
||||
|
||||
## Bug Fixes
|
||||
|
||||
* Report exceptions thrown by a describe before any it calls
|
||||
* Coerce the random string to a seed before sending it to reporters
|
||||
* This fixes an error in HTMLReporter when the configured seed is a
|
||||
number rather than a string, which has been allowed since 3.8.0
|
||||
|
||||
## Documentation updates
|
||||
|
||||
* Fixed the jsdoc types of SuiteResult and SpecResult ids
|
||||
* Replaced var with const in API doc examples
|
||||
* Updated the style of the examples that are included in jasmine-core
|
||||
|
||||
## Internal improvements
|
||||
|
||||
* Converted TreeProcessor to async/await
|
||||
* Converted ReportDispatcher to promises
|
||||
|
||||
## Supported environments
|
||||
|
||||
jasmine-core 4.5.0 has been tested in the following environments.
|
||||
|
||||
| Environment | Supported versions |
|
||||
|-------------------|--------------------|
|
||||
| Node | 12.17+, 14, 16, 18 |
|
||||
| Safari | 14-16 |
|
||||
| Chrome | 107 |
|
||||
| Firefox | 91, 102, 106 |
|
||||
| Edge | 106 |
|
||||
|
||||
------
|
||||
|
||||
_Release Notes generated with _[Anchorman](http://github.com/infews/anchorman)_
|
||||
19
release_notes/4.6.0.md
Normal file
19
release_notes/4.6.0.md
Normal file
@@ -0,0 +1,19 @@
|
||||
# Jasmine Core 4.6.0 Release Notes
|
||||
|
||||
## New Features
|
||||
|
||||
* Report the ID of each suite/spec's parent
|
||||
* Report the path/url of the file that the spec/suite was defined in
|
||||
* Fixes [#1884](https://github.com/jasmine/jasmine/issues/1884)
|
||||
* Added Firefox 102 (current ESR) to supported browsers
|
||||
|
||||
|
||||
## Internal improvements
|
||||
|
||||
* Pinned sass to 1.58.3 for compatibility with Node 12
|
||||
* Pinned eslint-plugin-compat to <4.1.0 for compatibility with Node 12
|
||||
* Pinned Grunt to <1.6.0 for compatibility with Node 12
|
||||
|
||||
------
|
||||
|
||||
_Release Notes generated with _[Anchorman](http://github.com/infews/anchorman)_
|
||||
51
release_notes/4.6.1.md
Normal file
51
release_notes/4.6.1.md
Normal file
@@ -0,0 +1,51 @@
|
||||
# Jasmine Core 4.6.1 Release Notes
|
||||
|
||||
## Summary
|
||||
|
||||
This is a one-time backport of bug fixes from 5.x, for the benefit of Karma
|
||||
users who may not be aware that they're still using 4.x.
|
||||
|
||||
No further 4.x releases are planned. If possible, you should upgrade to the
|
||||
latest 5.x instead of 4.6.1. If you're using Karma, you can do this by
|
||||
installing jasmine-core 5.x and adding an override to package.json:
|
||||
|
||||
```
|
||||
{
|
||||
// ...
|
||||
"overrides": {
|
||||
"karma-jasmine": {
|
||||
"jasmine-core": "^5.0.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Bug Fixes
|
||||
|
||||
* Removed unnecessary throw when building stack trace
|
||||
|
||||
* Fixed error when formatting Error object with non-Error cause property
|
||||
|
||||
Merges [#2013](https://github.com/jasmine/jasmine/pull/2013) from @angrycat9000.
|
||||
|
||||
Fixes [#2011](https://github.com/jasmine/jasmine/issues/2011).
|
||||
|
||||
* Accessibility: Always provide a non-color indication that a spec is pending
|
||||
|
||||
* Accessibility: Improved contrast of version number and inactive tab links
|
||||
|
||||
## Supported environments
|
||||
|
||||
jasmine-core 4.6.1 has been tested in the following environments.
|
||||
|
||||
| Environment | Supported versions |
|
||||
|-------------------|--------------------|
|
||||
| Node | 12.17+, 14, 16, 18 |
|
||||
| Safari | 14-16 |
|
||||
| Chrome | 125 |
|
||||
| Firefox | 91, 102, 126 |
|
||||
| Edge | 124 |
|
||||
|
||||
------
|
||||
|
||||
_Release Notes generated with _[Anchorman](http://github.com/infews/anchorman)_
|
||||
68
release_notes/5.0.0-alpha.0.md
Normal file
68
release_notes/5.0.0-alpha.0.md
Normal file
@@ -0,0 +1,68 @@
|
||||
# Jasmine Core 5.0.0-alpha.0 Release Notes
|
||||
|
||||
## Summary
|
||||
|
||||
This release primarily adds support for parallel execution via the `jasmine`
|
||||
package. Please see its release notes and the
|
||||
[parallel documentation](https://jasmine.github.io/tutorials/running_specs_in_parallel)
|
||||
for more information. Additionally, this release cleans up a few outdated
|
||||
interfaces.
|
||||
|
||||
This is a pre-release for a major version. It contains breaking changes, and
|
||||
there may be further breaking changes between this release and the final 5.0.0
|
||||
release.
|
||||
|
||||
## Breaking changes
|
||||
|
||||
* Use addEventListener in browsers rather than setting window.onerror
|
||||
|
||||
This simplifies error handling in browsers, makes Jasmine's own integration
|
||||
tests easier to debug, and provides stack traces for more unhandled
|
||||
exceptions. However, some browsers will provide less error information when
|
||||
the error comes from a file:// URL. Additionally, Jasmine will no longer
|
||||
override existing onerror handlers, and setting window.onerror will no longer
|
||||
override Jasmine's global error handling. (Use `jasmine.spyOnGlobalErrors`
|
||||
instead.)
|
||||
|
||||
* Made Env#execute async
|
||||
* Env#execute no longer takes a callback
|
||||
* The `boot` function exported by the core module returns the same object
|
||||
every time it's called.
|
||||
* Removed node_boot.js. Use the exported `boot` function instead.
|
||||
|
||||
### Changes to supported environments
|
||||
|
||||
The following previously supported environments are no longer supported:
|
||||
|
||||
* Node <16.14
|
||||
* Safari 14
|
||||
* Firefox 91
|
||||
|
||||
Although this release may still work in some of those environments, we no
|
||||
longer test against them and won't try to maintain compatibility with them in
|
||||
future releases.
|
||||
|
||||
## New features
|
||||
|
||||
* Support for parallel execution in Node.js using the `jasmine` package
|
||||
|
||||
## Bug fixes
|
||||
|
||||
* The global error handler is uninstalled at the end of env execution.
|
||||
|
||||
## Supported environments
|
||||
|
||||
jasmine-core 5.0.0-alpha.0 has been tested in the following environments.
|
||||
|
||||
| Environment | Supported versions |
|
||||
|-------------------|--------------------|
|
||||
| Node | 16.14+, 18 |
|
||||
| Safari | 15-16 |
|
||||
| Chrome | 111 |
|
||||
| Firefox | 102, 111 |
|
||||
| Edge | 111 |
|
||||
|
||||
|
||||
------
|
||||
|
||||
_Release Notes generated with _[Anchorman](http://github.com/infews/anchorman)_
|
||||
39
release_notes/5.0.0-alpha.1.md
Normal file
39
release_notes/5.0.0-alpha.1.md
Normal file
@@ -0,0 +1,39 @@
|
||||
# Jasmine Core 5.0.0-alpha.1 Release Notes
|
||||
|
||||
## Summary
|
||||
|
||||
This release provides improved support for parallel execution via the `jasmine`
|
||||
package. Please see its release notes and the
|
||||
[parallel documentation](https://jasmine.github.io/tutorials/running_specs_in_parallel)
|
||||
for more information.
|
||||
|
||||
## New features and bug fixes
|
||||
|
||||
* Parallel: Cleaner interface for reporter dispatching
|
||||
* When Env#config is called from spec and helper files in parallel mode, throw
|
||||
an error rather than behaving unpredictably.
|
||||
|
||||
## Documentation improvements
|
||||
|
||||
* API reference docs for parallel support APIs that jasmine-npm uses
|
||||
|
||||
## Internal improvements
|
||||
|
||||
* Updated dev dependencies
|
||||
|
||||
## Supported environments
|
||||
|
||||
jasmine-core 5.0.0-alpha.1 has been tested in the following environments.
|
||||
|
||||
| Environment | Supported versions |
|
||||
|-------------------|--------------------|
|
||||
| Node | 16.14+, 18 |
|
||||
| Safari | 15-16 |
|
||||
| Chrome | 112 |
|
||||
| Firefox | 102, 111 |
|
||||
| Edge | 111 |
|
||||
|
||||
|
||||
------
|
||||
|
||||
_Release Notes generated with _[Anchorman](http://github.com/infews/anchorman)_
|
||||
28
release_notes/5.0.0-beta.0.md
Normal file
28
release_notes/5.0.0-beta.0.md
Normal file
@@ -0,0 +1,28 @@
|
||||
# Jasmine Core 5.0.0-beta.0 Release Notes
|
||||
|
||||
This release supports the 5.0.0-beta-0 release of the `jasmine` package.
|
||||
|
||||
## Breaking changes
|
||||
|
||||
* Dropped support for Node 16
|
||||
|
||||
## New features
|
||||
|
||||
* Added support for Node 20
|
||||
|
||||
## Supported environments
|
||||
|
||||
jasmine-core 5.0.0-beta.0 has been tested in the following environments.
|
||||
|
||||
| Environment | Supported versions |
|
||||
|-------------------|--------------------|
|
||||
| Node | 18, 20 |
|
||||
| Safari | 15-16 |
|
||||
| Chrome | 112 |
|
||||
| Firefox | 102, 112 |
|
||||
| Edge | 112 |
|
||||
|
||||
|
||||
------
|
||||
|
||||
_Release Notes generated with _[Anchorman](http://github.com/infews/anchorman)_
|
||||
55
release_notes/5.0.0.md
Normal file
55
release_notes/5.0.0.md
Normal file
@@ -0,0 +1,55 @@
|
||||
# Jasmine Core 5.0.0 Release Notes
|
||||
|
||||
## Summary
|
||||
|
||||
This is a major release that includes breaking changes. It primarily adds
|
||||
support for parallel execution in Node via the `jasmine` package. Most users
|
||||
should be able to upgrade without changes, but please read the list of breaking
|
||||
changes below and see the [migration guide](https://jasmine.github.io/tutorials/upgrading_to_Jasmine_5.0)
|
||||
for more information.
|
||||
|
||||
## Breaking changes
|
||||
|
||||
* Dropped support for Node 12, 14, and 16
|
||||
* Dropped support for Safari 14 and Firefox 91
|
||||
* Made Env#execute async and removed the callback parameter
|
||||
* Global errors are detected via addEventListener rather than setting window.onerror
|
||||
* The `boot` function exported by the core module returns the same object
|
||||
every time it's called.
|
||||
* Removed node_boot.js. Use the exported `boot` function instead.
|
||||
|
||||
## New features
|
||||
|
||||
* Support for parallel execution in Node via the `jasmine` package
|
||||
See the [parallel guide](https://jasmine.github.io/tutorials/running_specs_in_parallel)
|
||||
for more information.
|
||||
* Added Node 20 to supported environments
|
||||
|
||||
## Bug fixes
|
||||
|
||||
* Accessibility: Always provide a non-color indication that a spec is pending
|
||||
* Accessibility: Improved contrast of version number and inactive tab links
|
||||
* Uninstall the global error handler at the end of env execution
|
||||
|
||||
## Internal improvements
|
||||
|
||||
* Updated dev dependencies
|
||||
* Dogfood parallel execution feature in CI
|
||||
|
||||
## Supported environments
|
||||
|
||||
jasmine-core 5.0.0 has been tested in the following environments.
|
||||
|
||||
| Environment | Supported versions |
|
||||
|-------------------|--------------------|
|
||||
| Node | 18, 20 |
|
||||
| Safari | 15-16 |
|
||||
| Chrome | 113 |
|
||||
| Firefox | 102, 113 |
|
||||
| Edge | 113 |
|
||||
|
||||
|
||||
|
||||
------
|
||||
|
||||
_Release Notes generated with _[Anchorman](http://github.com/infews/anchorman)_
|
||||
25
release_notes/5.0.1.md
Normal file
25
release_notes/5.0.1.md
Normal file
@@ -0,0 +1,25 @@
|
||||
# Jasmine Core 5.0.1 Release Notes
|
||||
|
||||
## Changes
|
||||
|
||||
* Optionally restore the pre-5.0 behavior of boot() always creating a new instance
|
||||
|
||||
This is needed by jasmine-npm (and likely other tools like it) that may
|
||||
need to create and use multiple envs in sequence.
|
||||
|
||||
## Supported environments
|
||||
|
||||
jasmine-core 5.0.1 has been tested in the following environments.
|
||||
|
||||
| Environment | Supported versions |
|
||||
|-------------------|--------------------|
|
||||
| Node | 18, 20 |
|
||||
| Safari | 15-16 |
|
||||
| Chrome | 114 |
|
||||
| Firefox | 102, 113 |
|
||||
| Edge | 113 |
|
||||
|
||||
|
||||
------
|
||||
|
||||
_Release Notes generated with _[Anchorman](http://github.com/infews/anchorman)_
|
||||
39
release_notes/5.1.0.md
Normal file
39
release_notes/5.1.0.md
Normal file
@@ -0,0 +1,39 @@
|
||||
# Jasmine Core 5.1.0 Release Notes
|
||||
|
||||
## Changes
|
||||
|
||||
* Exclude inherited Error properties from stack trace
|
||||
|
||||
* Fixed error when formatting Error object with non-Error cause property
|
||||
|
||||
Merges [#2013](https://github.com/jasmine/jasmine/pull/2013) from @angrycat9000.
|
||||
|
||||
Fixes [#2011](https://github.com/jasmine/jasmine/issues/2011).
|
||||
|
||||
* Added `throwUnless` and `throwUnlessAsync`
|
||||
|
||||
These are similar to `expect` and `expectAsync` except that they throw
|
||||
exceptions rather than recording matcher failures as spec/suite failures.
|
||||
They're intended to support using Jasmine matchers in [testing-library's](https://testing-library.com/)
|
||||
`waitFor`, and also provide a way to integration-test custom matchers.
|
||||
|
||||
Fixes [#2003](https://github.com/jasmine/jasmine/issues/2003).
|
||||
|
||||
Fixes [#1980](https://github.com/jasmine/jasmine/issues/1980).
|
||||
|
||||
## Supported environments
|
||||
|
||||
jasmine-core 5.1.0 has been tested in the following environments.
|
||||
|
||||
| Environment | Supported versions |
|
||||
|-------------------|--------------------|
|
||||
| Node | 18, 20 |
|
||||
| Safari | 15-16 |
|
||||
| Chrome | 114 |
|
||||
| Firefox | 102, 113 |
|
||||
| Edge | 113 |
|
||||
|
||||
|
||||
------
|
||||
|
||||
_Release Notes generated with _[Anchorman](http://github.com/infews/anchorman)_
|
||||
28
release_notes/5.1.1.md
Normal file
28
release_notes/5.1.1.md
Normal file
@@ -0,0 +1,28 @@
|
||||
# Jasmine Core 5.1.1 Release Notes
|
||||
|
||||
## Bug Fixes
|
||||
|
||||
* Fixed global variable leak in the main process when running in parallel mode
|
||||
* Removed unnecessary throw when building expectation results
|
||||
|
||||
## Documentation Improvements
|
||||
|
||||
* Improved jsdocs for originalFn argument to createSpy
|
||||
* Link to 5.0 upgrade guide in README, not 4.0
|
||||
|
||||
## Supported environments
|
||||
|
||||
jasmine-core 5.1.1 has been tested in the following environments.
|
||||
|
||||
| Environment | Supported versions |
|
||||
|-------------------|--------------------|
|
||||
| Node | 18, 20 |
|
||||
| Safari | 15-16 |
|
||||
| Chrome | 116 |
|
||||
| Firefox | 102, 116 |
|
||||
| Edge | 115 |
|
||||
|
||||
|
||||
------
|
||||
|
||||
_Release Notes generated with _[Anchorman](http://github.com/infews/anchorman)_
|
||||
27
release_notes/5.1.2.md
Normal file
27
release_notes/5.1.2.md
Normal file
@@ -0,0 +1,27 @@
|
||||
# Jasmine Core 5.1.2 Release Notes
|
||||
|
||||
## Bug Fixes
|
||||
|
||||
* Fixed `throwUnlessAsync`
|
||||
* Fixes [#2026](https://github.com/jasmine/jasmine/issues/2026)
|
||||
|
||||
# Documentation improvements
|
||||
|
||||
* Added Safari 17 to supported browsers
|
||||
* Added Firefox 115 (current ESR) to supported browsers
|
||||
|
||||
## Supported environments
|
||||
|
||||
This version has been tested in the following environments.
|
||||
|
||||
| Environment | Supported versions |
|
||||
|-------------------|--------------------|
|
||||
| Node | 18, 20 |
|
||||
| Safari | 15-17 |
|
||||
| Chrome | 121 |
|
||||
| Firefox | 102, 115, 122 |
|
||||
| Edge | 121 |
|
||||
|
||||
------
|
||||
|
||||
_Release Notes generated with _[Anchorman](http://github.com/infews/anchorman)_
|
||||
35
release_notes/5.2.0.md
Normal file
35
release_notes/5.2.0.md
Normal file
@@ -0,0 +1,35 @@
|
||||
# Jasmine Core 5.2.0 Release Notes
|
||||
|
||||
## Bug Fixes
|
||||
|
||||
* Fixed stack trace filtering in FF when the developer tools are open
|
||||
* Fixed handling of browser `error` events with message but no error
|
||||
|
||||
## New Features
|
||||
|
||||
* Improved the error message of the toHaveSize matcher.
|
||||
* Merges [#2033](https://github.com/jasmine/jasmine/pull/2033) from @stephanreiter
|
||||
* HTML reporter: show debug logs with white-space: pre
|
||||
|
||||
## Documentation improvements
|
||||
|
||||
* Improved discoverability of asymmetric equality testers
|
||||
* Added an example for withContext()
|
||||
* Clarified spyOnGlobalErrorsAsync API docs
|
||||
* Added Node 22 to supported environments
|
||||
|
||||
## Supported environments
|
||||
|
||||
This version has been tested in the following environments.
|
||||
|
||||
| Environment | Supported versions |
|
||||
|-------------------|--------------------|
|
||||
| Node | 18, 20, 22 |
|
||||
| Safari | 15-17 |
|
||||
| Chrome | 126 |
|
||||
| Firefox | 102, 115, 128 |
|
||||
| Edge | 126 |
|
||||
|
||||
------
|
||||
|
||||
_Release Notes generated with _[Anchorman](http://github.com/infews/anchorman)_
|
||||
35
release_notes/5.3.0.md
Normal file
35
release_notes/5.3.0.md
Normal file
@@ -0,0 +1,35 @@
|
||||
# Jasmine Core 5.3.0 Release Notes
|
||||
|
||||
## Changes
|
||||
|
||||
* Improved performance in Safari
|
||||
* Merges [#2040](https://github.com/jasmine/jasmine/pull/2040) from @dcsaszar
|
||||
* Fixes [#2008](https://github.com/jasmine/jasmine/issues/2008)
|
||||
|
||||
* Improved performance in Playwright Webkit on Windows
|
||||
* Merges [#2034](https://github.com/jasmine/jasmine/pull/2034) from @m-akinc
|
||||
|
||||
* Throw if spying has no effect, as when spying on localStorage methods in Firefox and Safari 17
|
||||
* See [#2036](https://github.com/jasmine/jasmine/issues/2036) and [#2007](https://github.com/jasmine/jasmine/issues/2007)
|
||||
|
||||
|
||||
## Documentation improvements
|
||||
|
||||
* Added API reference for reporter capabilities
|
||||
|
||||
## Supported environments
|
||||
|
||||
This version has been tested in the following environments.
|
||||
|
||||
| Environment | Supported versions |
|
||||
|-------------------|--------------------|
|
||||
| Node | 18, 20, 22 |
|
||||
| Safari | 15-17 |
|
||||
| Chrome | 128 |
|
||||
| Firefox | 102, 115, 130 |
|
||||
| Edge | 128 |
|
||||
|
||||
|
||||
------
|
||||
|
||||
_Release Notes generated with _[Anchorman](http://github.com/infews/anchorman)_
|
||||
39
release_notes/5.4.0.md
Normal file
39
release_notes/5.4.0.md
Normal file
@@ -0,0 +1,39 @@
|
||||
# Jasmine Core 5.4.0 Release Notes
|
||||
|
||||
## Changes
|
||||
|
||||
* Fixed de-duplication of exception messages containing blank lines on Node and Chrome
|
||||
|
||||
This is particularly helpful when reporting testing-library errors, which
|
||||
have messages that contain blank lines and can be hundreds or even thousands
|
||||
of lines long.
|
||||
|
||||
* Document that the expected and actual properties of expectation results are deprecated
|
||||
|
||||
The values of these properties are not reliable in configurations where
|
||||
reporter messages are JSON serialized. They appear to have been seldom if ever
|
||||
used. They will be removed in the next major release.
|
||||
|
||||
* Added Firefox 128 (current ESR) to supported browsers
|
||||
|
||||
## Supported environments
|
||||
|
||||
This version has been tested in the following environments.
|
||||
|
||||
| Environment | Supported versions |
|
||||
|-------------------|-------------------------|
|
||||
| Node | 18, 20, 22 |
|
||||
| Safari | 15-17 |
|
||||
| Chrome | 129* |
|
||||
| Firefox | 102**, 115**, 128, 131* |
|
||||
| Edge | 129* |
|
||||
|
||||
\* Evergreen browser. Each version of Jasmine is tested against the latest
|
||||
version available at release time.<br>
|
||||
\** Environments that are past end of life are supported on a best-effort basis.
|
||||
They may be dropped in a future minor release of Jasmine if continued support
|
||||
becomes impractical.
|
||||
|
||||
------
|
||||
|
||||
_Release Notes generated with _[Anchorman](http://github.com/infews/anchorman)_
|
||||
@@ -3,6 +3,7 @@
|
||||
run_browser() {
|
||||
browser=$1
|
||||
version=$2
|
||||
os="$3"
|
||||
description="$browser $version"
|
||||
if [ $version = "latest" ]; then
|
||||
version=""
|
||||
@@ -12,7 +13,7 @@ run_browser() {
|
||||
echo
|
||||
echo "Running $description"
|
||||
echo
|
||||
USE_SAUCE=true JASMINE_BROWSER=$browser SAUCE_BROWSER_VERSION=$version npm run ci
|
||||
USE_SAUCE=true JASMINE_BROWSER=$browser SAUCE_BROWSER_VERSION=$version SAUCE_OS="$os" npm run ci
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "PASS: $description" >> "$passfile"
|
||||
@@ -23,11 +24,24 @@ run_browser() {
|
||||
|
||||
passfile=`mktemp -t jasmine-results.XXXXXX` || exit 1
|
||||
failfile=`mktemp -t jasmine-results.XXXXXX` || exit 1
|
||||
run_browser chrome latest
|
||||
|
||||
# As of 2023-09-30, Sauce Connect doesn't work with the latest Chrome version
|
||||
# on the default Linux. Run on Mac OS instead. The OS specification may need to
|
||||
# be updated or removed when new Chrome versions stop being available on Mac OS
|
||||
# 12, although historically this has taken several major OS versions.
|
||||
# See <https://saucelabs.com/products/supported-browsers-devices>.
|
||||
# On Saucelabs, the test suite frequently runs ~30s slower on Mac OS than it
|
||||
# does on Linux, so it's probably worth removing the OS specification once Sauce
|
||||
# Connect works with Chrome latest on Linux again.
|
||||
run_browser chrome latest "macOS 12"
|
||||
|
||||
run_browser firefox latest
|
||||
run_browser firefox 91
|
||||
run_browser firefox 128
|
||||
run_browser firefox 115
|
||||
run_browser firefox 102
|
||||
run_browser safari 17
|
||||
run_browser safari 16
|
||||
run_browser safari 15
|
||||
run_browser safari 14
|
||||
run_browser MicrosoftEdge latest
|
||||
|
||||
echo
|
||||
|
||||
@@ -14,8 +14,6 @@ module.exports = {
|
||||
// TODO: consider doing this in src files as well as specs
|
||||
'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
|
||||
// from running tests, it makes sense to fail if debugger statements
|
||||
// or console references are present.
|
||||
|
||||
@@ -29,7 +29,7 @@ describe('AsyncExpectation', function() {
|
||||
|
||||
it('converts a fail to a pass', function() {
|
||||
const addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||
actual = Promise.reject(),
|
||||
actual = Promise.reject(new Error('nope')),
|
||||
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
||||
matchersUtil: new jasmineUnderTest.MatchersUtil({
|
||||
pp: function() {}
|
||||
@@ -138,7 +138,7 @@ describe('AsyncExpectation', function() {
|
||||
}
|
||||
},
|
||||
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||
actual = Promise.reject(),
|
||||
actual = Promise.reject(new Error('nope')),
|
||||
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
||||
actual: actual,
|
||||
addExpectationResult: addExpectationResult,
|
||||
|
||||
@@ -9,160 +9,257 @@ describe('ClearStack', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('uses setImmediate when available', function() {
|
||||
const setImmediate = jasmine
|
||||
.createSpy('setImmediate')
|
||||
.and.callFake(function(fn) {
|
||||
fn();
|
||||
}),
|
||||
global = { setImmediate: setImmediate },
|
||||
clearStack = jasmineUnderTest.getClearStack(global);
|
||||
let called = false;
|
||||
|
||||
clearStack(function() {
|
||||
called = true;
|
||||
describe('in Safari', function() {
|
||||
usesQueueMicrotaskWithSetTimeout(function() {
|
||||
return {
|
||||
navigator: {
|
||||
userAgent:
|
||||
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/605.0.8 (KHTML, like Gecko) Version/15.1 Safari/605.0.8'
|
||||
},
|
||||
// queueMicrotask should be used even though MessageChannel is present
|
||||
MessageChannel: fakeMessageChannel
|
||||
};
|
||||
});
|
||||
|
||||
expect(called).toBe(true);
|
||||
expect(setImmediate).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('uses setTimeout instead of setImmediate every 10 calls to make sure we release the CPU', function() {
|
||||
const setImmediate = jasmine.createSpy('setImmediate'),
|
||||
setTimeout = jasmine.createSpy('setTimeout'),
|
||||
global = { setImmediate: setImmediate, setTimeout: setTimeout },
|
||||
clearStack = jasmineUnderTest.getClearStack(global);
|
||||
|
||||
clearStack(function() {});
|
||||
clearStack(function() {});
|
||||
clearStack(function() {});
|
||||
clearStack(function() {});
|
||||
clearStack(function() {});
|
||||
clearStack(function() {});
|
||||
clearStack(function() {});
|
||||
clearStack(function() {});
|
||||
clearStack(function() {});
|
||||
|
||||
expect(setImmediate).toHaveBeenCalled();
|
||||
expect(setTimeout).not.toHaveBeenCalled();
|
||||
|
||||
clearStack(function() {});
|
||||
expect(setImmediate.calls.count()).toEqual(9);
|
||||
expect(setTimeout.calls.count()).toEqual(1);
|
||||
|
||||
clearStack(function() {});
|
||||
expect(setImmediate.calls.count()).toEqual(10);
|
||||
expect(setTimeout.calls.count()).toEqual(1);
|
||||
});
|
||||
|
||||
it('uses MessageChannels when available', function() {
|
||||
const fakeChannel = {
|
||||
port1: {},
|
||||
port2: {
|
||||
postMessage: function() {
|
||||
fakeChannel.port1.onmessage();
|
||||
}
|
||||
}
|
||||
},
|
||||
global = {
|
||||
MessageChannel: function() {
|
||||
return fakeChannel;
|
||||
}
|
||||
},
|
||||
clearStack = jasmineUnderTest.getClearStack(global);
|
||||
let called = false;
|
||||
|
||||
clearStack(function() {
|
||||
called = true;
|
||||
});
|
||||
|
||||
expect(called).toBe(true);
|
||||
});
|
||||
|
||||
it('uses setTimeout instead of MessageChannel every 10 calls to make sure we release the CPU', function() {
|
||||
const fakeChannel = {
|
||||
port1: {},
|
||||
port2: {
|
||||
postMessage: jasmine
|
||||
.createSpy('postMessage')
|
||||
.and.callFake(function() {
|
||||
fakeChannel.port1.onmessage();
|
||||
})
|
||||
}
|
||||
},
|
||||
setTimeout = jasmine.createSpy('setTimeout'),
|
||||
global = {
|
||||
it('uses MessageChannel to reduce setTimeout clamping', function() {
|
||||
const fakeChannel = fakeMessageChannel();
|
||||
spyOn(fakeChannel.port2, 'postMessage');
|
||||
const queueMicrotask = jasmine.createSpy('queueMicrotask');
|
||||
const global = {
|
||||
navigator: {
|
||||
userAgent:
|
||||
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/605.0.8 (KHTML, like Gecko) Version/15.1 Safari/605.0.8'
|
||||
},
|
||||
MessageChannel: function() {
|
||||
return fakeChannel;
|
||||
},
|
||||
setTimeout: setTimeout
|
||||
},
|
||||
clearStack = jasmineUnderTest.getClearStack(global);
|
||||
queueMicrotask
|
||||
};
|
||||
|
||||
clearStack(function() {});
|
||||
clearStack(function() {});
|
||||
clearStack(function() {});
|
||||
clearStack(function() {});
|
||||
clearStack(function() {});
|
||||
clearStack(function() {});
|
||||
clearStack(function() {});
|
||||
clearStack(function() {});
|
||||
clearStack(function() {});
|
||||
const clearStack = jasmineUnderTest.getClearStack(global);
|
||||
|
||||
expect(fakeChannel.port2.postMessage).toHaveBeenCalled();
|
||||
expect(setTimeout).not.toHaveBeenCalled();
|
||||
for (let i = 0; i < 9; i++) {
|
||||
clearStack(function() {});
|
||||
}
|
||||
|
||||
clearStack(function() {});
|
||||
expect(fakeChannel.port2.postMessage.calls.count()).toEqual(9);
|
||||
expect(setTimeout.calls.count()).toEqual(1);
|
||||
expect(fakeChannel.port2.postMessage).not.toHaveBeenCalled();
|
||||
|
||||
clearStack(function() {});
|
||||
expect(fakeChannel.port2.postMessage.calls.count()).toEqual(10);
|
||||
expect(setTimeout.calls.count()).toEqual(1);
|
||||
clearStack(function() {});
|
||||
|
||||
expect(fakeChannel.port2.postMessage).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
|
||||
it('calls setTimeout when onmessage is called recursively', function() {
|
||||
const fakeChannel = {
|
||||
port1: {},
|
||||
port2: {
|
||||
postMessage: function() {
|
||||
fakeChannel.port1.onmessage();
|
||||
describe("in WebKit (Playwright's build for Windows)", function() {
|
||||
usesQueueMicrotaskWithSetTimeout(function() {
|
||||
return {
|
||||
navigator: {
|
||||
userAgent:
|
||||
'Mozilla/5.0 (Windows NT 6.2; Win64; x64) AppleWebKit/605.1.15 (KHTML, like Gecko)'
|
||||
},
|
||||
// queueMicrotask should be used even though MessageChannel is present
|
||||
MessageChannel: fakeMessageChannel
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
describe('in browsers other than Safari', function() {
|
||||
usesMessageChannel(function() {
|
||||
return {
|
||||
navigator: {
|
||||
// Chrome's user agent string contains "Safari" so it's a good test case
|
||||
userAgent:
|
||||
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36'
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
describe('when MessageChannel is unavailable', function() {
|
||||
usesQueueMicrotaskWithSetTimeout(function() {
|
||||
return {
|
||||
navigator: {
|
||||
userAgent: 'CERN-LineMode/2.15 libwww/2.17b3',
|
||||
MessageChannel: undefined
|
||||
}
|
||||
};
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('in Node', function() {
|
||||
usesQueueMicrotaskWithoutSetTimeout(function() {
|
||||
return {
|
||||
process: {
|
||||
versions: {
|
||||
node: '3.1415927'
|
||||
}
|
||||
}
|
||||
},
|
||||
setTimeout = jasmine.createSpy('setTimeout'),
|
||||
global = {
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
function usesMessageChannel(makeGlobal) {
|
||||
it('uses MessageChannel', function() {
|
||||
const global = {
|
||||
...makeGlobal(),
|
||||
MessageChannel: fakeMessageChannel
|
||||
};
|
||||
const clearStack = jasmineUnderTest.getClearStack(global);
|
||||
let called = false;
|
||||
|
||||
clearStack(function() {
|
||||
called = true;
|
||||
});
|
||||
|
||||
expect(called).toBe(true);
|
||||
});
|
||||
|
||||
it('uses setTimeout instead of MessageChannel every 10 calls to make sure we release the CPU', function() {
|
||||
const fakeChannel = fakeMessageChannel();
|
||||
spyOn(fakeChannel.port2, 'postMessage');
|
||||
const setTimeout = jasmine.createSpy('setTimeout');
|
||||
const global = {
|
||||
...makeGlobal(),
|
||||
setTimeout,
|
||||
MessageChannel: function() {
|
||||
return fakeChannel;
|
||||
},
|
||||
setTimeout: setTimeout
|
||||
},
|
||||
clearStack = jasmineUnderTest.getClearStack(global),
|
||||
fn = jasmine.createSpy('second clearStack function');
|
||||
}
|
||||
};
|
||||
const clearStack = jasmineUnderTest.getClearStack(global);
|
||||
|
||||
clearStack(function() {
|
||||
clearStack(fn);
|
||||
for (let i = 0; i < 9; i++) {
|
||||
clearStack(function() {});
|
||||
}
|
||||
|
||||
expect(fakeChannel.port2.postMessage).toHaveBeenCalled();
|
||||
expect(setTimeout).not.toHaveBeenCalled();
|
||||
|
||||
clearStack(function() {});
|
||||
expect(fakeChannel.port2.postMessage).toHaveBeenCalledTimes(9);
|
||||
expect(setTimeout).toHaveBeenCalledTimes(1);
|
||||
|
||||
clearStack(function() {});
|
||||
expect(fakeChannel.port2.postMessage).toHaveBeenCalledTimes(10);
|
||||
expect(setTimeout).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
expect(fn).not.toHaveBeenCalled();
|
||||
expect(setTimeout).toHaveBeenCalledWith(fn, 0);
|
||||
});
|
||||
it('calls setTimeout when onmessage is called recursively', function() {
|
||||
const setTimeout = jasmine.createSpy('setTimeout');
|
||||
const global = {
|
||||
...makeGlobal(),
|
||||
setTimeout,
|
||||
MessageChannel: fakeMessageChannel
|
||||
};
|
||||
const clearStack = jasmineUnderTest.getClearStack(global);
|
||||
const fn = jasmine.createSpy('second clearStack function');
|
||||
|
||||
it('falls back to setTimeout', function() {
|
||||
const setTimeout = jasmine
|
||||
.createSpy('setTimeout')
|
||||
.and.callFake(function(fn) {
|
||||
clearStack(function() {
|
||||
clearStack(fn);
|
||||
});
|
||||
|
||||
expect(fn).not.toHaveBeenCalled();
|
||||
expect(setTimeout).toHaveBeenCalledWith(fn, 0);
|
||||
});
|
||||
}
|
||||
|
||||
function usesQueueMicrotaskWithSetTimeout(makeGlobal) {
|
||||
it('uses queueMicrotask', function() {
|
||||
const global = {
|
||||
...makeGlobal(),
|
||||
queueMicrotask: function(fn) {
|
||||
fn();
|
||||
}),
|
||||
global = { setTimeout: setTimeout },
|
||||
clearStack = jasmineUnderTest.getClearStack(global);
|
||||
let called = false;
|
||||
}
|
||||
};
|
||||
const clearStack = jasmineUnderTest.getClearStack(global);
|
||||
let called = false;
|
||||
|
||||
clearStack(function() {
|
||||
called = true;
|
||||
clearStack(function() {
|
||||
called = true;
|
||||
});
|
||||
|
||||
expect(called).toBe(true);
|
||||
});
|
||||
|
||||
expect(called).toBe(true);
|
||||
expect(setTimeout).toHaveBeenCalledWith(jasmine.any(Function), 0);
|
||||
});
|
||||
it('uses setTimeout instead of queueMicrotask every 10 calls to make sure we release the CPU', function() {
|
||||
const queueMicrotask = jasmine.createSpy('queueMicrotask');
|
||||
const setTimeout = jasmine.createSpy('setTimeout');
|
||||
const global = {
|
||||
...makeGlobal(),
|
||||
queueMicrotask,
|
||||
setTimeout
|
||||
};
|
||||
const clearStack = jasmineUnderTest.getClearStack(global);
|
||||
|
||||
for (let i = 0; i < 9; i++) {
|
||||
clearStack(function() {});
|
||||
}
|
||||
|
||||
expect(queueMicrotask).toHaveBeenCalled();
|
||||
expect(setTimeout).not.toHaveBeenCalled();
|
||||
|
||||
clearStack(function() {});
|
||||
expect(queueMicrotask).toHaveBeenCalledTimes(9);
|
||||
expect(setTimeout).toHaveBeenCalledTimes(1);
|
||||
|
||||
clearStack(function() {});
|
||||
expect(queueMicrotask).toHaveBeenCalledTimes(10);
|
||||
expect(setTimeout).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
}
|
||||
|
||||
function usesQueueMicrotaskWithoutSetTimeout(makeGlobal) {
|
||||
it('uses queueMicrotask', function() {
|
||||
const global = {
|
||||
...makeGlobal(),
|
||||
queueMicrotask: function(fn) {
|
||||
fn();
|
||||
}
|
||||
};
|
||||
const clearStack = jasmineUnderTest.getClearStack(global);
|
||||
let called = false;
|
||||
|
||||
clearStack(function() {
|
||||
called = true;
|
||||
});
|
||||
|
||||
expect(called).toBe(true);
|
||||
});
|
||||
|
||||
it('does not use setTimeout', function() {
|
||||
const queueMicrotask = jasmine.createSpy('queueMicrotask');
|
||||
const setTimeout = jasmine.createSpy('setTimeout');
|
||||
const global = {
|
||||
...makeGlobal(),
|
||||
queueMicrotask,
|
||||
setTimeout
|
||||
};
|
||||
const clearStack = jasmineUnderTest.getClearStack(global);
|
||||
|
||||
clearStack(function() {});
|
||||
clearStack(function() {});
|
||||
clearStack(function() {});
|
||||
clearStack(function() {});
|
||||
clearStack(function() {});
|
||||
clearStack(function() {});
|
||||
clearStack(function() {});
|
||||
clearStack(function() {});
|
||||
clearStack(function() {});
|
||||
clearStack(function() {});
|
||||
|
||||
expect(queueMicrotask).toHaveBeenCalledTimes(10);
|
||||
expect(setTimeout).not.toHaveBeenCalled();
|
||||
});
|
||||
}
|
||||
|
||||
function fakeMessageChannel() {
|
||||
const channel = {
|
||||
port1: {},
|
||||
port2: {
|
||||
postMessage: function() {
|
||||
channel.port1.onmessage();
|
||||
}
|
||||
}
|
||||
};
|
||||
return channel;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -80,6 +80,19 @@ describe('Env', function() {
|
||||
);
|
||||
expect(suite.children[1].children[1].children[0].children).toBeFalsy();
|
||||
});
|
||||
|
||||
it('throws if called in parallel mode', function() {
|
||||
env.setParallelLoadingState('helpers');
|
||||
check();
|
||||
env.setParallelLoadingState('specs');
|
||||
check();
|
||||
|
||||
function check() {
|
||||
expect(function() {
|
||||
env.topSuite();
|
||||
}).toThrowError("'topSuite' is not available in parallel mode");
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it('accepts its own current configureation', function() {
|
||||
@@ -251,6 +264,15 @@ describe('Env', function() {
|
||||
|
||||
describe('#fdescribe', function() {
|
||||
behavesLikeDescribe('fdescribe');
|
||||
|
||||
it('throws an error in parallel mode', function() {
|
||||
env.setParallelLoadingState('specs');
|
||||
expect(function() {
|
||||
env.fdescribe('a suite', function() {
|
||||
env.it('a spec');
|
||||
});
|
||||
}).toThrowError("'fdescribe' is not available in parallel mode");
|
||||
});
|
||||
});
|
||||
|
||||
describe('xdescribe', function() {
|
||||
@@ -316,7 +338,7 @@ describe('Env', function() {
|
||||
|
||||
it('calls spec.exclude with "Temporarily disabled with xit"', function() {
|
||||
const excludeSpy = jasmine.createSpy();
|
||||
spyOn(env, 'it_').and.returnValue({
|
||||
spyOn(jasmineUnderTest.SuiteBuilder.prototype, 'it_').and.returnValue({
|
||||
exclude: excludeSpy
|
||||
});
|
||||
env.xit('foo', function() {});
|
||||
@@ -327,7 +349,7 @@ describe('Env', function() {
|
||||
const pendSpy = jasmine.createSpy();
|
||||
const realExclude = jasmineUnderTest.Spec.prototype.exclude;
|
||||
|
||||
spyOn(env, 'it_').and.returnValue({
|
||||
spyOn(jasmineUnderTest.SuiteBuilder.prototype, 'it_').and.returnValue({
|
||||
exclude: realExclude,
|
||||
pend: pendSpy
|
||||
});
|
||||
@@ -372,6 +394,13 @@ describe('Env', function() {
|
||||
env.fit('huge timeout', function() {}, 2147483648);
|
||||
}).toThrowError('Timeout value cannot be greater than 2147483647');
|
||||
});
|
||||
|
||||
it('throws an error in parallel mode', function() {
|
||||
env.setParallelLoadingState('specs');
|
||||
expect(function() {
|
||||
env.fit('a spec', function() {});
|
||||
}).toThrowError("'fit' is not available in parallel mode");
|
||||
});
|
||||
});
|
||||
|
||||
describe('#beforeEach', function() {
|
||||
@@ -394,6 +423,28 @@ describe('Env', function() {
|
||||
env.beforeEach(function() {}, 2147483648);
|
||||
}).toThrowError('Timeout value cannot be greater than 2147483647');
|
||||
});
|
||||
|
||||
it('throws when called at the top level in a spec file in parallel mode', function() {
|
||||
env.setParallelLoadingState('specs');
|
||||
expect(function() {
|
||||
env.beforeEach(function() {});
|
||||
}).toThrowError(
|
||||
'In parallel mode, beforeEach must be in a describe block or in a helper file'
|
||||
);
|
||||
});
|
||||
|
||||
it('does not throw when called at the top level in a helper file in parallel mode', function() {
|
||||
env.setParallelLoadingState('helpers');
|
||||
env.beforeEach(function() {});
|
||||
});
|
||||
|
||||
it('does not throw when called in a describe in a spec file in parallel mode', function() {
|
||||
env.setParallelLoadingState('specs');
|
||||
env.describe('a suite', function() {
|
||||
env.beforeEach(function() {});
|
||||
env.it('a spec');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#beforeAll', function() {
|
||||
@@ -416,6 +467,47 @@ describe('Env', function() {
|
||||
env.beforeAll(function() {}, 2147483648);
|
||||
}).toThrowError('Timeout value cannot be greater than 2147483647');
|
||||
});
|
||||
|
||||
describe('in parallel mode', function() {
|
||||
it('throws an error when called at the top level', function() {
|
||||
env.setParallelLoadingState('helpers');
|
||||
check();
|
||||
env.setParallelLoadingState('specs');
|
||||
check();
|
||||
|
||||
function check() {
|
||||
expect(function() {
|
||||
env.beforeAll(function() {});
|
||||
}).toThrowError(
|
||||
"In parallel mode, 'beforeAll' must be in a describe block. " +
|
||||
'Use the globalSetup config property for exactly-once setup in' +
|
||||
' parallel mode.'
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
it('does not throw an error when called in a describe', function() {
|
||||
env.setParallelLoadingState('helpers');
|
||||
check();
|
||||
env.setParallelLoadingState('specs');
|
||||
check();
|
||||
|
||||
function check() {
|
||||
let done = false;
|
||||
|
||||
env.describe('a suite', function() {
|
||||
expect(function() {
|
||||
env.it('a spec');
|
||||
env.beforeAll(function() {});
|
||||
}).not.toThrow();
|
||||
|
||||
done = true;
|
||||
});
|
||||
|
||||
expect(done).toBeTrue();
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#afterEach', function() {
|
||||
@@ -438,6 +530,28 @@ describe('Env', function() {
|
||||
env.afterEach(function() {}, 2147483648);
|
||||
}).toThrowError('Timeout value cannot be greater than 2147483647');
|
||||
});
|
||||
|
||||
it('throws when called at the top level in a spec file in parallel mode', function() {
|
||||
env.setParallelLoadingState('specs');
|
||||
expect(function() {
|
||||
env.afterEach(function() {});
|
||||
}).toThrowError(
|
||||
'In parallel mode, afterEach must be in a describe block or in a helper file'
|
||||
);
|
||||
});
|
||||
|
||||
it('does not throw when called at the top level in a helper file in parallel mode', function() {
|
||||
env.setParallelLoadingState('helpers');
|
||||
env.afterEach(function() {});
|
||||
});
|
||||
|
||||
it('does not throw when called in a describe in a spec file in parallel mode', function() {
|
||||
env.setParallelLoadingState('specs');
|
||||
env.describe('a suite', function() {
|
||||
env.afterEach(function() {});
|
||||
env.it('a spec');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#afterAll', function() {
|
||||
@@ -460,6 +574,47 @@ describe('Env', function() {
|
||||
env.afterAll(function() {}, 2147483648);
|
||||
}).toThrowError('Timeout value cannot be greater than 2147483647');
|
||||
});
|
||||
|
||||
describe('in parallel mode', function() {
|
||||
it('throws an error when called at the top level', function() {
|
||||
env.setParallelLoadingState('helpers');
|
||||
check();
|
||||
env.setParallelLoadingState('specs');
|
||||
check();
|
||||
|
||||
function check() {
|
||||
expect(function() {
|
||||
env.afterAll(function() {});
|
||||
}).toThrowError(
|
||||
"In parallel mode, 'afterAll' must be in a describe block. " +
|
||||
'Use the globalTeardown config property for exactly-once ' +
|
||||
'teardown in parallel mode.'
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
it('does not throw an error when called in a describe', function() {
|
||||
env.setParallelLoadingState('helpers');
|
||||
check();
|
||||
env.setParallelLoadingState('specs');
|
||||
check();
|
||||
|
||||
function check() {
|
||||
let done = false;
|
||||
|
||||
env.describe('a suite', function() {
|
||||
expect(function() {
|
||||
env.it('a spec');
|
||||
env.afterAll(function() {});
|
||||
}).not.toThrow();
|
||||
|
||||
done = true;
|
||||
});
|
||||
|
||||
expect(done).toBeTrue();
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('when not constructed with suppressLoadErrors: true', function() {
|
||||
@@ -468,7 +623,8 @@ describe('Env', function() {
|
||||
'install',
|
||||
'uninstall',
|
||||
'pushListener',
|
||||
'popListener'
|
||||
'popListener',
|
||||
'removeOverrideListener'
|
||||
]);
|
||||
spyOn(jasmineUnderTest, 'GlobalErrors').and.returnValue(globalErrors);
|
||||
env.cleanup_();
|
||||
@@ -483,7 +639,8 @@ describe('Env', function() {
|
||||
'install',
|
||||
'uninstall',
|
||||
'pushListener',
|
||||
'popListener'
|
||||
'popListener',
|
||||
'removeOverrideListener'
|
||||
]);
|
||||
spyOn(jasmineUnderTest, 'GlobalErrors').and.returnValue(globalErrors);
|
||||
env.cleanup_();
|
||||
@@ -494,7 +651,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 customObjectFormatter() {}
|
||||
function prettyPrinter() {}
|
||||
@@ -515,19 +672,17 @@ describe('Env', function() {
|
||||
expectationFactory('actual', specInstance);
|
||||
});
|
||||
|
||||
env.execute(null, function() {
|
||||
expect(jasmineUnderTest.makePrettyPrinter).toHaveBeenCalledWith([
|
||||
customObjectFormatter
|
||||
]);
|
||||
expect(jasmineUnderTest.MatchersUtil).toHaveBeenCalledWith({
|
||||
customTesters: [customEqualityTester],
|
||||
pp: prettyPrinter
|
||||
});
|
||||
done();
|
||||
await env.execute();
|
||||
expect(jasmineUnderTest.makePrettyPrinter).toHaveBeenCalledWith([
|
||||
customObjectFormatter
|
||||
]);
|
||||
expect(jasmineUnderTest.MatchersUtil).toHaveBeenCalledWith({
|
||||
customTesters: [customEqualityTester],
|
||||
pp: prettyPrinter
|
||||
});
|
||||
});
|
||||
|
||||
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 customObjectFormatter() {}
|
||||
function prettyPrinter() {}
|
||||
@@ -548,15 +703,14 @@ describe('Env', function() {
|
||||
asyncExpectationFactory('actual', specInstance);
|
||||
});
|
||||
|
||||
env.execute(null, function() {
|
||||
expect(jasmineUnderTest.makePrettyPrinter).toHaveBeenCalledWith([
|
||||
customObjectFormatter
|
||||
]);
|
||||
expect(jasmineUnderTest.MatchersUtil).toHaveBeenCalledWith({
|
||||
customTesters: [customEqualityTester],
|
||||
pp: prettyPrinter
|
||||
});
|
||||
done();
|
||||
await env.execute();
|
||||
|
||||
expect(jasmineUnderTest.makePrettyPrinter).toHaveBeenCalledWith([
|
||||
customObjectFormatter
|
||||
]);
|
||||
expect(jasmineUnderTest.MatchersUtil).toHaveBeenCalledWith({
|
||||
customTesters: [customEqualityTester],
|
||||
pp: prettyPrinter
|
||||
});
|
||||
});
|
||||
|
||||
@@ -593,5 +747,88 @@ describe('Env', function() {
|
||||
expect(id).toEqual(env.topSuite().id);
|
||||
});
|
||||
});
|
||||
|
||||
it('should not reset the topSuite if parallelReset was called since the last run', async function() {
|
||||
await env.execute();
|
||||
env.parallelReset();
|
||||
spyOn(jasmineUnderTest.Suite.prototype, 'reset');
|
||||
await env.execute();
|
||||
expect(jasmineUnderTest.Suite.prototype.reset).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
describe('In parallel mode', function() {
|
||||
it('rejects if random is set to false', async function() {
|
||||
env.configure({ random: false });
|
||||
env.setParallelLoadingState('specs');
|
||||
await expectAsync(env.execute()).toBeRejectedWithError(
|
||||
'Randomization cannot be disabled in parallel mode'
|
||||
);
|
||||
});
|
||||
|
||||
it('rejects if seed is set', async function() {
|
||||
env.configure({ seed: 1234 });
|
||||
env.setParallelLoadingState('specs');
|
||||
await expectAsync(env.execute()).toBeRejectedWithError(
|
||||
'Random seed cannot be set in parallel mode'
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
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);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#addReporter', function() {
|
||||
it('throws when called in parallel mode', function() {
|
||||
env.setParallelLoadingState('helpers');
|
||||
expect(function() {
|
||||
env.addReporter({});
|
||||
}).toThrowError('Reporters cannot be added via Env in parallel mode');
|
||||
|
||||
env.setParallelLoadingState('specs');
|
||||
expect(function() {
|
||||
env.addReporter({});
|
||||
}).toThrowError('Reporters cannot be added via Env in parallel mode');
|
||||
});
|
||||
});
|
||||
|
||||
describe('#clearReporters', function() {
|
||||
it('throws when called in parallel mode', function() {
|
||||
env.setParallelLoadingState('helpers');
|
||||
expect(function() {
|
||||
env.clearReporters();
|
||||
}).toThrowError('Reporters cannot be removed via Env in parallel mode');
|
||||
|
||||
env.setParallelLoadingState('specs');
|
||||
expect(function() {
|
||||
env.clearReporters();
|
||||
}).toThrowError('Reporters cannot be removed via Env in parallel mode');
|
||||
});
|
||||
});
|
||||
|
||||
describe('#configure', function() {
|
||||
it('throws when called in parallel mode', function() {
|
||||
env.setParallelLoadingState('helpers');
|
||||
expect(function() {
|
||||
env.configure({});
|
||||
}).toThrowError('Jasmine cannot be configured via Env in parallel mode');
|
||||
|
||||
env.setParallelLoadingState('specs');
|
||||
expect(function() {
|
||||
env.configure({});
|
||||
}).toThrowError('Jasmine cannot be configured via Env in parallel mode');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -153,12 +153,33 @@ describe('ExceptionFormatter', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('filters Jasmine stack frames with Firefox async annotations', function() {
|
||||
const error = {
|
||||
stack:
|
||||
'http://localhost:8888/__spec__/core/UtilSpec.js:115:28\n' +
|
||||
'promise callback*fn1@http://localhost:8888/__jasmine__/jasmine.js:4320:27\n' +
|
||||
'setTimeout handler*fn2@http://localhost:8888/__jasmine__/jasmine.js:4320:27\n' +
|
||||
'http://localhost:8888/__spec__/core/UtilSpec.js:115:28'
|
||||
};
|
||||
const subject = new jasmineUnderTest.ExceptionFormatter({
|
||||
jasmineFile: 'http://localhost:8888/__jasmine__/jasmine.js'
|
||||
});
|
||||
const result = subject.stack(error);
|
||||
expect(result).toEqual(
|
||||
'http://localhost:8888/__spec__/core/UtilSpec.js:115:28\n' +
|
||||
'<Jasmine>\n' +
|
||||
'http://localhost:8888/__spec__/core/UtilSpec.js:115:28'
|
||||
);
|
||||
});
|
||||
|
||||
it('filters Jasmine stack frames in this environment', function() {
|
||||
const error = new Error('an error');
|
||||
const subject = new jasmineUnderTest.ExceptionFormatter({
|
||||
jasmineFile: jasmine.util.jasmineFile()
|
||||
});
|
||||
const result = subject.stack(error);
|
||||
jasmine.debugLog('Original stack trace: ' + error.stack);
|
||||
jasmine.debugLog('Filtered stack trace: ' + result);
|
||||
const lines = result.split('\n');
|
||||
|
||||
if (lines[0].match(/an error/)) {
|
||||
@@ -197,7 +218,7 @@ describe('ExceptionFormatter', function() {
|
||||
expect(new jasmineUnderTest.ExceptionFormatter().stack()).toBeNull();
|
||||
});
|
||||
|
||||
it('includes error properties in stack', function() {
|
||||
it("includes the error's own properties in stack", function() {
|
||||
const error = new Error('an error');
|
||||
error.someProperty = 'hello there';
|
||||
|
||||
@@ -206,6 +227,19 @@ describe('ExceptionFormatter', function() {
|
||||
expect(result).toMatch(/error properties:.*someProperty.*hello there/);
|
||||
});
|
||||
|
||||
it('does not include inherited error properties', function() {
|
||||
function CustomError(msg) {
|
||||
Error.call(this, msg);
|
||||
}
|
||||
|
||||
CustomError.prototype = new Error();
|
||||
CustomError.prototype.anInheritedProp = 'something';
|
||||
const error = new CustomError('nope');
|
||||
|
||||
const result = new jasmineUnderTest.ExceptionFormatter().stack(error);
|
||||
expect(result).not.toContain('anInheritedProp');
|
||||
});
|
||||
|
||||
describe('When omitMessage is true', function() {
|
||||
it('filters the message from V8-style stack traces', function() {
|
||||
const error = {
|
||||
@@ -256,5 +290,61 @@ describe('ExceptionFormatter', function() {
|
||||
expect(result).not.toContain('an error');
|
||||
});
|
||||
});
|
||||
|
||||
describe('when the error has a cause property', function() {
|
||||
it('recursively includes the cause in the stack trace in this environment', function() {
|
||||
const subject = new jasmineUnderTest.ExceptionFormatter();
|
||||
const rootCause = new Error('root cause');
|
||||
const proximateCause = new Error('proximate cause', {
|
||||
cause: rootCause
|
||||
});
|
||||
const symptom = new Error('symptom', { cause: proximateCause });
|
||||
|
||||
const lines = subject.stack(symptom).split('\n');
|
||||
// Not all environments include the message in the stack trace.
|
||||
const hasRootMessage = lines[0].indexOf('symptom') !== -1;
|
||||
const firstSymptomStackIx = hasRootMessage ? 1 : 0;
|
||||
|
||||
expect(lines[firstSymptomStackIx])
|
||||
.withContext('first symptom stack frame')
|
||||
.toContain('ExceptionFormatterSpec.js');
|
||||
const proximateCauseMsgIx = lines.indexOf(
|
||||
'Caused by: Error: proximate cause'
|
||||
);
|
||||
expect(proximateCauseMsgIx)
|
||||
.withContext('index of proximate cause message')
|
||||
.toBeGreaterThan(firstSymptomStackIx);
|
||||
expect(lines[proximateCauseMsgIx + 1])
|
||||
.withContext('first proximate cause stack frame')
|
||||
.toContain('ExceptionFormatterSpec.js');
|
||||
const rootCauseMsgIx = lines.indexOf('Caused by: Error: root cause');
|
||||
expect(rootCauseMsgIx)
|
||||
.withContext('index of root cause message')
|
||||
.toBeGreaterThan(proximateCauseMsgIx + 1);
|
||||
expect(lines[rootCauseMsgIx + 1])
|
||||
.withContext('first root cause stack frame')
|
||||
.toContain('ExceptionFormatterSpec.js');
|
||||
});
|
||||
|
||||
it('does not throw if cause is a non Error', function() {
|
||||
const formatter = new jasmineUnderTest.ExceptionFormatter();
|
||||
|
||||
expect(function() {
|
||||
formatter.stack(
|
||||
new Error('error', {
|
||||
cause: function() {}
|
||||
})
|
||||
);
|
||||
}).not.toThrowError();
|
||||
|
||||
expect(function() {
|
||||
formatter.stack(
|
||||
new Error('error', {
|
||||
cause: 'another error'
|
||||
})
|
||||
);
|
||||
}).not.toThrowError();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -9,7 +9,7 @@ describe('Exceptions:', function() {
|
||||
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');
|
||||
env.describe('Suite for handles exceptions', function() {
|
||||
env.it(
|
||||
@@ -24,15 +24,12 @@ describe('Exceptions:', function() {
|
||||
);
|
||||
});
|
||||
|
||||
const expectations = function() {
|
||||
expect(secondTest).toHaveBeenCalled();
|
||||
done();
|
||||
};
|
||||
await env.execute();
|
||||
|
||||
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
|
||||
.createSpy('second describe')
|
||||
.and.callFake(function() {
|
||||
@@ -47,11 +44,8 @@ describe('Exceptions:', function() {
|
||||
});
|
||||
env.describe("a suite that doesn't throw an exception", secondDescribe);
|
||||
|
||||
const expectations = function() {
|
||||
expect(secondDescribe).toHaveBeenCalled();
|
||||
done();
|
||||
};
|
||||
await env.execute();
|
||||
|
||||
env.execute(null, expectations);
|
||||
expect(secondDescribe).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,75 +1,65 @@
|
||||
describe('GlobalErrors', function() {
|
||||
it('calls the added handler on error', function() {
|
||||
const fakeGlobal = { onerror: null },
|
||||
handler = jasmine.createSpy('errorHandler'),
|
||||
errors = new jasmineUnderTest.GlobalErrors(fakeGlobal);
|
||||
const fakeGlobal = browserGlobal();
|
||||
const handler = jasmine.createSpy('errorHandler');
|
||||
const errors = new jasmineUnderTest.GlobalErrors(fakeGlobal);
|
||||
|
||||
errors.install();
|
||||
errors.pushListener(handler);
|
||||
|
||||
fakeGlobal.onerror('foo');
|
||||
|
||||
expect(handler).toHaveBeenCalledWith('foo');
|
||||
});
|
||||
|
||||
it('enables external interception of error by overriding global.onerror', function() {
|
||||
const fakeGlobal = { onerror: null },
|
||||
handler = jasmine.createSpy('errorHandler'),
|
||||
hijackHandler = jasmine.createSpy('hijackErrorHandler'),
|
||||
errors = new jasmineUnderTest.GlobalErrors(fakeGlobal);
|
||||
|
||||
errors.install();
|
||||
errors.pushListener(handler);
|
||||
|
||||
fakeGlobal.onerror = hijackHandler;
|
||||
|
||||
fakeGlobal.onerror('foo');
|
||||
|
||||
expect(hijackHandler).toHaveBeenCalledWith('foo');
|
||||
expect(handler).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('calls the global error handler with all parameters', function() {
|
||||
const fakeGlobal = { onerror: null },
|
||||
handler = jasmine.createSpy('errorHandler'),
|
||||
errors = new jasmineUnderTest.GlobalErrors(fakeGlobal),
|
||||
fooError = new Error('foo');
|
||||
|
||||
errors.install();
|
||||
errors.pushListener(handler);
|
||||
|
||||
fakeGlobal.onerror(fooError.message, 'foo.js', 1, 1, fooError);
|
||||
const error = new Error('nope');
|
||||
dispatchErrorEvent(fakeGlobal, { error });
|
||||
|
||||
expect(handler).toHaveBeenCalledWith(
|
||||
fooError.message,
|
||||
'foo.js',
|
||||
1,
|
||||
1,
|
||||
fooError
|
||||
jasmine.is(error),
|
||||
jasmine.objectContaining({ error: jasmine.is(error) })
|
||||
);
|
||||
});
|
||||
|
||||
it('is not affected by overriding global.onerror', function() {
|
||||
const fakeGlobal = browserGlobal();
|
||||
const handler = jasmine.createSpy('errorHandler');
|
||||
const errors = new jasmineUnderTest.GlobalErrors(fakeGlobal);
|
||||
|
||||
errors.install();
|
||||
errors.pushListener(handler);
|
||||
|
||||
fakeGlobal.onerror = () => {};
|
||||
|
||||
const error = new Error('nope');
|
||||
dispatchErrorEvent(fakeGlobal, { error });
|
||||
|
||||
expect(handler).toHaveBeenCalledWith(
|
||||
jasmine.is(error),
|
||||
jasmine.objectContaining({ error: jasmine.is(error) })
|
||||
);
|
||||
});
|
||||
|
||||
it('only calls the most recent handler', function() {
|
||||
const fakeGlobal = { onerror: null },
|
||||
handler1 = jasmine.createSpy('errorHandler1'),
|
||||
handler2 = jasmine.createSpy('errorHandler2'),
|
||||
errors = new jasmineUnderTest.GlobalErrors(fakeGlobal);
|
||||
const fakeGlobal = browserGlobal();
|
||||
const handler1 = jasmine.createSpy('errorHandler1');
|
||||
const handler2 = jasmine.createSpy('errorHandler2');
|
||||
const errors = new jasmineUnderTest.GlobalErrors(fakeGlobal);
|
||||
|
||||
errors.install();
|
||||
errors.pushListener(handler1);
|
||||
errors.pushListener(handler2);
|
||||
|
||||
fakeGlobal.onerror('foo');
|
||||
const error = new Error('nope');
|
||||
dispatchErrorEvent(fakeGlobal, { error });
|
||||
|
||||
expect(handler1).not.toHaveBeenCalled();
|
||||
expect(handler2).toHaveBeenCalledWith('foo');
|
||||
expect(handler2).toHaveBeenCalledWith(
|
||||
jasmine.is(error),
|
||||
jasmine.objectContaining({ error: jasmine.is(error) })
|
||||
);
|
||||
});
|
||||
|
||||
it('calls previous handlers when one is removed', function() {
|
||||
const fakeGlobal = { onerror: null },
|
||||
handler1 = jasmine.createSpy('errorHandler1'),
|
||||
handler2 = jasmine.createSpy('errorHandler2'),
|
||||
errors = new jasmineUnderTest.GlobalErrors(fakeGlobal);
|
||||
const fakeGlobal = browserGlobal();
|
||||
const handler1 = jasmine.createSpy('errorHandler1');
|
||||
const handler2 = jasmine.createSpy('errorHandler2');
|
||||
const errors = new jasmineUnderTest.GlobalErrors(fakeGlobal);
|
||||
|
||||
errors.install();
|
||||
errors.pushListener(handler1);
|
||||
@@ -77,9 +67,13 @@ describe('GlobalErrors', function() {
|
||||
|
||||
errors.popListener(handler2);
|
||||
|
||||
fakeGlobal.onerror('foo');
|
||||
const error = new Error('nope');
|
||||
dispatchErrorEvent(fakeGlobal, { error });
|
||||
|
||||
expect(handler1).toHaveBeenCalledWith('foo');
|
||||
expect(handler1).toHaveBeenCalledWith(
|
||||
jasmine.is(error),
|
||||
jasmine.objectContaining({ error: jasmine.is(error) })
|
||||
);
|
||||
expect(handler2).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
@@ -90,31 +84,27 @@ describe('GlobalErrors', function() {
|
||||
}).toThrowError('popListener expects a listener');
|
||||
});
|
||||
|
||||
it('uninstalls itself, putting back a previous callback', function() {
|
||||
const originalCallback = jasmine.createSpy('error'),
|
||||
fakeGlobal = { onerror: originalCallback },
|
||||
errors = new jasmineUnderTest.GlobalErrors(fakeGlobal);
|
||||
|
||||
expect(fakeGlobal.onerror).toBe(originalCallback);
|
||||
it('uninstalls itself', function() {
|
||||
const fakeGlobal = browserGlobal();
|
||||
const errors = new jasmineUnderTest.GlobalErrors(fakeGlobal);
|
||||
function unrelatedListener() {}
|
||||
|
||||
errors.install();
|
||||
|
||||
expect(fakeGlobal.onerror).not.toBe(originalCallback);
|
||||
|
||||
fakeGlobal.addEventListener('error', unrelatedListener);
|
||||
errors.uninstall();
|
||||
|
||||
expect(fakeGlobal.onerror).toBe(originalCallback);
|
||||
expect(fakeGlobal.listeners_.error).toEqual([unrelatedListener]);
|
||||
});
|
||||
|
||||
it('rethrows the original error when there is no handler', function() {
|
||||
const fakeGlobal = {},
|
||||
errors = new jasmineUnderTest.GlobalErrors(fakeGlobal),
|
||||
originalError = new Error('nope');
|
||||
const fakeGlobal = browserGlobal();
|
||||
const errors = new jasmineUnderTest.GlobalErrors(fakeGlobal);
|
||||
const originalError = new Error('nope');
|
||||
|
||||
errors.install();
|
||||
|
||||
try {
|
||||
fakeGlobal.onerror(originalError);
|
||||
dispatchErrorEvent(fakeGlobal, { error: originalError });
|
||||
} catch (e) {
|
||||
expect(e).toBe(originalError);
|
||||
}
|
||||
@@ -286,122 +276,295 @@ describe('GlobalErrors', function() {
|
||||
|
||||
describe('Reporting unhandled promise rejections in the browser', function() {
|
||||
it('subscribes and unsubscribes from the unhandledrejection event', function() {
|
||||
const fakeGlobal = jasmine.createSpyObj('globalErrors', [
|
||||
'addEventListener',
|
||||
'removeEventListener',
|
||||
'onerror'
|
||||
]),
|
||||
errors = new jasmineUnderTest.GlobalErrors(fakeGlobal);
|
||||
const fakeGlobal = browserGlobal();
|
||||
const errors = new jasmineUnderTest.GlobalErrors(fakeGlobal);
|
||||
|
||||
errors.install();
|
||||
expect(fakeGlobal.addEventListener).toHaveBeenCalledWith(
|
||||
'unhandledrejection',
|
||||
expect(fakeGlobal.listeners_.unhandledrejection).toEqual([
|
||||
jasmine.any(Function)
|
||||
);
|
||||
]);
|
||||
|
||||
const addedListener = fakeGlobal.addEventListener.calls.argsFor(0)[1];
|
||||
errors.uninstall();
|
||||
|
||||
expect(fakeGlobal.removeEventListener).toHaveBeenCalledWith(
|
||||
'unhandledrejection',
|
||||
addedListener
|
||||
);
|
||||
expect(fakeGlobal.listeners_.unhandledrejection).toEqual([]);
|
||||
});
|
||||
|
||||
it('reports rejections whose reason is a string', function() {
|
||||
const fakeGlobal = jasmine.createSpyObj('globalErrors', [
|
||||
'addEventListener',
|
||||
'removeEventListener',
|
||||
'onerror'
|
||||
]),
|
||||
handler = jasmine.createSpy('errorHandler'),
|
||||
errors = new jasmineUnderTest.GlobalErrors(fakeGlobal);
|
||||
const fakeGlobal = browserGlobal();
|
||||
const handler = jasmine.createSpy('errorHandler');
|
||||
const errors = new jasmineUnderTest.GlobalErrors(fakeGlobal);
|
||||
|
||||
errors.install();
|
||||
errors.pushListener(handler);
|
||||
|
||||
const addedListener = fakeGlobal.addEventListener.calls.argsFor(0)[1];
|
||||
addedListener({ reason: 'nope' });
|
||||
const event = { reason: 'nope' };
|
||||
dispatchUnhandledRejectionEvent(fakeGlobal, event);
|
||||
|
||||
expect(handler).toHaveBeenCalledWith('Unhandled promise rejection: nope');
|
||||
expect(handler).toHaveBeenCalledWith(
|
||||
'Unhandled promise rejection: nope',
|
||||
event
|
||||
);
|
||||
});
|
||||
|
||||
it('reports rejections whose reason is an Error', function() {
|
||||
const fakeGlobal = jasmine.createSpyObj('globalErrors', [
|
||||
'addEventListener',
|
||||
'removeEventListener',
|
||||
'onerror'
|
||||
]),
|
||||
handler = jasmine.createSpy('errorHandler'),
|
||||
errors = new jasmineUnderTest.GlobalErrors(fakeGlobal);
|
||||
const fakeGlobal = browserGlobal();
|
||||
const handler = jasmine.createSpy('errorHandler');
|
||||
const errors = new jasmineUnderTest.GlobalErrors(fakeGlobal);
|
||||
|
||||
errors.install();
|
||||
errors.pushListener(handler);
|
||||
|
||||
const addedListener = fakeGlobal.addEventListener.calls.argsFor(0)[1];
|
||||
const reason = new Error('bar');
|
||||
|
||||
addedListener({ reason: reason });
|
||||
const event = { reason };
|
||||
dispatchUnhandledRejectionEvent(fakeGlobal, event);
|
||||
|
||||
expect(handler).toHaveBeenCalledWith(
|
||||
jasmine.objectContaining({
|
||||
jasmineMessage: 'Unhandled promise rejection: Error: bar',
|
||||
message: reason.message,
|
||||
stack: reason.stack
|
||||
})
|
||||
}),
|
||||
event
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Reporting uncaught exceptions in node.js', function() {
|
||||
it('prepends a descriptive message when the error is not an `Error`', function() {
|
||||
const fakeGlobal = {
|
||||
process: {
|
||||
on: jasmine.createSpy('process.on'),
|
||||
removeListener: function() {},
|
||||
listeners: function() {
|
||||
return [];
|
||||
},
|
||||
removeAllListeners: function() {}
|
||||
}
|
||||
};
|
||||
const handler = jasmine.createSpy('errorHandler');
|
||||
const errors = new jasmineUnderTest.GlobalErrors(fakeGlobal);
|
||||
|
||||
errors.install();
|
||||
errors.pushListener(handler);
|
||||
|
||||
uncaughtExceptionListener(fakeGlobal)(17);
|
||||
|
||||
expect(handler).toHaveBeenCalledWith(new Error('Uncaught exception: 17'));
|
||||
});
|
||||
|
||||
it('substitutes a descriptive message when the error is falsy', function() {
|
||||
const fakeGlobal = {
|
||||
process: {
|
||||
on: jasmine.createSpy('process.on'),
|
||||
removeListener: function() {},
|
||||
listeners: function() {
|
||||
return [];
|
||||
},
|
||||
removeAllListeners: function() {}
|
||||
}
|
||||
};
|
||||
const handler = jasmine.createSpy('errorHandler');
|
||||
const errors = new jasmineUnderTest.GlobalErrors(fakeGlobal);
|
||||
|
||||
errors.install();
|
||||
errors.pushListener(handler);
|
||||
|
||||
uncaughtExceptionListener(fakeGlobal)();
|
||||
|
||||
expect(handler).toHaveBeenCalledWith(
|
||||
new Error('Uncaught exception with no error or message')
|
||||
);
|
||||
});
|
||||
|
||||
describe('Enabling external interception of reported rejections by overriding global.onerror', function() {
|
||||
it('overriding global.onerror intercepts rejections whose reason is a string', function() {
|
||||
const fakeGlobal = jasmine.createSpyObj('globalErrors', [
|
||||
'addEventListener'
|
||||
]),
|
||||
handler = jasmine.createSpy('errorHandler'),
|
||||
hijackHandler = jasmine.createSpy('hijackErrorHandler'),
|
||||
errors = new jasmineUnderTest.GlobalErrors(fakeGlobal);
|
||||
function uncaughtExceptionListener(global) {
|
||||
// Grab the right listener
|
||||
expect(global.process.on.calls.argsFor(0)[0]).toEqual(
|
||||
'uncaughtException'
|
||||
);
|
||||
return global.process.on.calls.argsFor(0)[1];
|
||||
}
|
||||
});
|
||||
|
||||
errors.install();
|
||||
errors.pushListener(handler);
|
||||
describe('#setOverrideListener', function() {
|
||||
it('overrides the existing handlers in browsers until removed', function() {
|
||||
const fakeGlobal = browserGlobal();
|
||||
const handler0 = jasmine.createSpy('handler0');
|
||||
const handler1 = jasmine.createSpy('handler1');
|
||||
const overrideHandler = jasmine.createSpy('overrideHandler');
|
||||
const errors = new jasmineUnderTest.GlobalErrors(fakeGlobal);
|
||||
|
||||
fakeGlobal.onerror = hijackHandler;
|
||||
errors.install();
|
||||
errors.pushListener(handler0);
|
||||
errors.setOverrideListener(overrideHandler, () => {});
|
||||
errors.pushListener(handler1);
|
||||
dispatchErrorEvent(fakeGlobal, { error: 'foo' });
|
||||
|
||||
const addedListener = fakeGlobal.addEventListener.calls.argsFor(0)[1];
|
||||
addedListener({ reason: 'nope' });
|
||||
expect(overrideHandler).toHaveBeenCalledWith('foo');
|
||||
expect(handler0).not.toHaveBeenCalled();
|
||||
expect(handler1).not.toHaveBeenCalled();
|
||||
|
||||
expect(hijackHandler).toHaveBeenCalledWith(
|
||||
'Unhandled promise rejection: nope'
|
||||
);
|
||||
expect(handler).not.toHaveBeenCalled();
|
||||
});
|
||||
errors.removeOverrideListener();
|
||||
|
||||
it('overriding global.onerror intercepts rejections whose reason is an Error', function() {
|
||||
const fakeGlobal = jasmine.createSpyObj('globalErrors', [
|
||||
'addEventListener'
|
||||
]),
|
||||
handler = jasmine.createSpy('errorHandler'),
|
||||
hijackHandler = jasmine.createSpy('hijackErrorHandler'),
|
||||
errors = new jasmineUnderTest.GlobalErrors(fakeGlobal);
|
||||
const event = { error: 'baz' };
|
||||
dispatchErrorEvent(fakeGlobal, event);
|
||||
expect(overrideHandler).not.toHaveBeenCalledWith('baz');
|
||||
expect(handler1).toHaveBeenCalledWith('baz', event);
|
||||
});
|
||||
|
||||
errors.install();
|
||||
errors.pushListener(handler);
|
||||
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);
|
||||
|
||||
fakeGlobal.onerror = hijackHandler;
|
||||
errors.install();
|
||||
errors.pushListener(handler0);
|
||||
errors.setOverrideListener(overrideHandler);
|
||||
errors.pushListener(handler1);
|
||||
|
||||
const addedListener = fakeGlobal.addEventListener.calls.argsFor(0)[1];
|
||||
const reason = new Error('bar');
|
||||
globalEventListeners['uncaughtException'](new Error('foo'));
|
||||
|
||||
addedListener({ reason: reason });
|
||||
expect(overrideHandler).toHaveBeenCalledWith(new Error('foo'));
|
||||
expect(handler0).not.toHaveBeenCalled();
|
||||
expect(handler1).not.toHaveBeenCalled();
|
||||
|
||||
expect(hijackHandler).toHaveBeenCalledWith(
|
||||
jasmine.objectContaining({
|
||||
jasmineMessage: 'Unhandled promise rejection: Error: bar',
|
||||
message: reason.message,
|
||||
stack: reason.stack
|
||||
})
|
||||
);
|
||||
expect(handler).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 errors = new jasmineUnderTest.GlobalErrors(browserGlobal());
|
||||
|
||||
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 onRemove = jasmine.createSpy('onRemove');
|
||||
const errors = new jasmineUnderTest.GlobalErrors(browserGlobal());
|
||||
|
||||
errors.setOverrideListener(() => {}, onRemove);
|
||||
errors.removeOverrideListener();
|
||||
|
||||
expect(onRemove).toHaveBeenCalledWith();
|
||||
});
|
||||
|
||||
it('does not throw if there is no handler', function() {
|
||||
const errors = new jasmineUnderTest.GlobalErrors(browserGlobal());
|
||||
|
||||
expect(() => errors.removeOverrideListener()).not.toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
function browserGlobal() {
|
||||
return {
|
||||
listeners_: { error: [], unhandledrejection: [] },
|
||||
addEventListener(eventName, listener) {
|
||||
this.listeners_[eventName].push(listener);
|
||||
},
|
||||
removeEventListener(eventName, listener) {
|
||||
this.listeners_[eventName] = this.listeners_[eventName].filter(
|
||||
l => l !== listener
|
||||
);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function dispatchErrorEvent(global, event) {
|
||||
expect(global.listeners_.error.length)
|
||||
.withContext('number of error listeners')
|
||||
.toBeGreaterThan(0);
|
||||
|
||||
for (const l of global.listeners_.error) {
|
||||
l(event);
|
||||
}
|
||||
}
|
||||
|
||||
function dispatchUnhandledRejectionEvent(global, event) {
|
||||
expect(global.listeners_.unhandledrejection.length)
|
||||
.withContext('number of unhandledrejection listeners')
|
||||
.toBeGreaterThan(0);
|
||||
|
||||
for (const l of global.listeners_.unhandledrejection) {
|
||||
l(event);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
176
spec/core/ParallelReportDispatcherSpec.js
Normal file
176
spec/core/ParallelReportDispatcherSpec.js
Normal file
@@ -0,0 +1,176 @@
|
||||
describe('ParallelReportDispatcher', function() {
|
||||
it('dispatches the standard reporter events', async function() {
|
||||
const subject = new jasmineUnderTest.ParallelReportDispatcher(() => {}, {
|
||||
globalErrors: mockGlobalErrors()
|
||||
});
|
||||
const events = [
|
||||
'jasmineStarted',
|
||||
'jasmineDone',
|
||||
'suiteStarted',
|
||||
'suiteDone',
|
||||
'specStarted',
|
||||
'specDone'
|
||||
];
|
||||
const reporter = jasmine.createSpyObj('reporter', events);
|
||||
subject.addReporter(reporter);
|
||||
|
||||
for (const eventName of events) {
|
||||
const payload = { payloadFor: eventName };
|
||||
await subject[eventName](payload);
|
||||
expect(reporter[eventName]).toHaveBeenCalledWith(payload);
|
||||
}
|
||||
});
|
||||
|
||||
it('installs and uninstalls the global error handler', function() {
|
||||
const globalErrors = mockGlobalErrors();
|
||||
const subject = new jasmineUnderTest.ParallelReportDispatcher(() => {}, {
|
||||
globalErrors
|
||||
});
|
||||
|
||||
subject.installGlobalErrors();
|
||||
expect(globalErrors.install).toHaveBeenCalled();
|
||||
|
||||
subject.uninstallGlobalErrors();
|
||||
expect(globalErrors.uninstall).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('handles global errors from async reporters', async function() {
|
||||
const globalErrors = mockGlobalErrors();
|
||||
const onError = jasmine.createSpy('onError');
|
||||
const subject = new jasmineUnderTest.ParallelReportDispatcher(onError, {
|
||||
globalErrors
|
||||
});
|
||||
const reporter = jasmine.createSpyObj('reporter', [
|
||||
'jasmineStarted',
|
||||
'jasmineDone'
|
||||
]);
|
||||
let resolveStarted;
|
||||
reporter.jasmineStarted.and.callFake(function() {
|
||||
return new Promise(function(res) {
|
||||
resolveStarted = res;
|
||||
});
|
||||
});
|
||||
subject.addReporter(reporter);
|
||||
|
||||
const promise = subject.jasmineStarted({});
|
||||
expect(globalErrors.pushListener).toHaveBeenCalled();
|
||||
expect(globalErrors.popListener).not.toHaveBeenCalled();
|
||||
const error = new Error('nope');
|
||||
globalErrors.pushListener.calls.argsFor(0)[0](error);
|
||||
expect(onError).toHaveBeenCalledWith(error);
|
||||
|
||||
resolveStarted();
|
||||
await promise;
|
||||
expect(globalErrors.popListener).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('handles done(error) from callback-style async reporters', function() {
|
||||
const globalErrors = mockGlobalErrors();
|
||||
const onError = jasmine.createSpy('onError');
|
||||
const subject = new jasmineUnderTest.ParallelReportDispatcher(onError, {
|
||||
globalErrors
|
||||
});
|
||||
const reporter = jasmine.createSpyObj('reporter', [
|
||||
'jasmineStarted',
|
||||
'jasmineDone'
|
||||
]);
|
||||
let callback;
|
||||
reporter.jasmineStarted = function(event, cb) {
|
||||
callback = cb;
|
||||
};
|
||||
subject.addReporter(reporter);
|
||||
|
||||
subject.jasmineStarted({});
|
||||
|
||||
expect(callback).toBeInstanceOf(Function);
|
||||
const error = new Error('nope');
|
||||
callback(error);
|
||||
|
||||
expect(onError).toHaveBeenCalledWith(error);
|
||||
});
|
||||
|
||||
it('handles done.fail() from callback-style async reporters', function() {
|
||||
const globalErrors = mockGlobalErrors();
|
||||
const onError = jasmine.createSpy('onError');
|
||||
const subject = new jasmineUnderTest.ParallelReportDispatcher(onError, {
|
||||
globalErrors
|
||||
});
|
||||
const reporter = jasmine.createSpyObj('reporter', [
|
||||
'jasmineStarted',
|
||||
'jasmineDone'
|
||||
]);
|
||||
let callback;
|
||||
reporter.jasmineStarted = function(event, cb) {
|
||||
callback = cb;
|
||||
};
|
||||
subject.addReporter(reporter);
|
||||
|
||||
subject.jasmineStarted({});
|
||||
|
||||
expect(callback).toBeInstanceOf(Function);
|
||||
const error = new Error('nope');
|
||||
callback.fail(error);
|
||||
expect(onError).toHaveBeenCalledWith(error);
|
||||
onError.calls.reset();
|
||||
|
||||
callback.fail();
|
||||
expect(onError).toHaveBeenCalledWith(
|
||||
new Error('A reporter called done.fail()')
|
||||
);
|
||||
});
|
||||
|
||||
it('handles errors due to mixed async style in reporters', async function() {
|
||||
const globalErrors = mockGlobalErrors();
|
||||
const onError = jasmine.createSpy('onError');
|
||||
const subject = new jasmineUnderTest.ParallelReportDispatcher(onError, {
|
||||
globalErrors
|
||||
});
|
||||
subject.addReporter({
|
||||
async jasmineStarted(event, done) {
|
||||
done();
|
||||
}
|
||||
});
|
||||
|
||||
await subject.jasmineStarted({});
|
||||
expect(onError).toHaveBeenCalledWith(
|
||||
new Error(
|
||||
'An asynchronous before/it/after function took a done callback but also returned a promise. Either remove the done callback (recommended) or change the function to not return a promise.'
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
it('handles errors due to multiple done calls in reporters', async function() {
|
||||
const globalErrors = mockGlobalErrors();
|
||||
const onError = jasmine.createSpy('onError');
|
||||
const subject = new jasmineUnderTest.ParallelReportDispatcher(onError, {
|
||||
globalErrors
|
||||
});
|
||||
subject.addReporter({
|
||||
jasmineStarted(event, done) {
|
||||
done();
|
||||
done();
|
||||
}
|
||||
});
|
||||
|
||||
await subject.jasmineStarted({});
|
||||
expect(onError).toHaveBeenCalledWith(
|
||||
new Error(
|
||||
"An asynchronous reporter callback called its 'done' callback more than once."
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
function mockGlobalErrors() {
|
||||
const globalErrors = jasmine.createSpyObj('globalErrors', [
|
||||
'install',
|
||||
'pushListener',
|
||||
'popListener'
|
||||
]);
|
||||
|
||||
globalErrors.install.and.callFake(function() {
|
||||
globalErrors.uninstall = jasmine.createSpy('globalErrors.uninstall');
|
||||
});
|
||||
|
||||
return globalErrors;
|
||||
}
|
||||
});
|
||||
@@ -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 sampleValue = {
|
||||
id: 1,
|
||||
get calculatedValue() {
|
||||
throw new Error("don't call me!");
|
||||
return 'the getter return value';
|
||||
}
|
||||
};
|
||||
expect(pp(sampleValue)).toEqual(
|
||||
'Object({ id: 1, calculatedValue: <getter> })'
|
||||
"Object({ id: 1, calculatedValue: 'the getter return value' })"
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
@@ -185,43 +185,20 @@ describe('QueueRunner', function() {
|
||||
|
||||
queueRunner.execute();
|
||||
});
|
||||
|
||||
it('does not log a deprecation', function(done) {
|
||||
const err = new Error('foo'),
|
||||
queueableFn1 = {
|
||||
fn: function() {
|
||||
return Promise.resolve(err);
|
||||
}
|
||||
},
|
||||
deprecated = jasmine.createSpy('deprecated'),
|
||||
queueRunner = new jasmineUnderTest.QueueRunner({
|
||||
queueableFns: [queueableFn1],
|
||||
deprecated: deprecated,
|
||||
onComplete: function() {
|
||||
expect(deprecated).not.toHaveBeenCalled();
|
||||
done();
|
||||
}
|
||||
});
|
||||
|
||||
queueRunner.execute();
|
||||
});
|
||||
});
|
||||
|
||||
describe('and the argument is not an Error', function() {
|
||||
it('does not log a deprecation or report a failure', function(done) {
|
||||
it('does not report a failure', function(done) {
|
||||
const queueableFn1 = {
|
||||
fn: function() {
|
||||
return Promise.resolve('not an error');
|
||||
}
|
||||
},
|
||||
failFn = jasmine.createSpy('fail'),
|
||||
deprecated = jasmine.createSpy('deprecated'),
|
||||
queueRunner = new jasmineUnderTest.QueueRunner({
|
||||
queueableFns: [queueableFn1],
|
||||
deprecated: deprecated,
|
||||
fail: failFn,
|
||||
onComplete: function() {
|
||||
expect(deprecated).not.toHaveBeenCalled();
|
||||
expect(failFn).not.toHaveBeenCalled();
|
||||
done();
|
||||
}
|
||||
@@ -406,17 +383,12 @@ describe('QueueRunner', function() {
|
||||
}
|
||||
},
|
||||
nextQueueableFn = { fn: jasmine.createSpy('nextFn') },
|
||||
deprecated = jasmine.createSpy('deprecated'),
|
||||
queueRunner = new jasmineUnderTest.QueueRunner({
|
||||
deprecated: deprecated,
|
||||
queueableFns: [queueableFn, nextQueueableFn]
|
||||
});
|
||||
queueRunner.execute();
|
||||
jasmine.clock().tick(1);
|
||||
expect(nextQueueableFn.fn.calls.count()).toEqual(1);
|
||||
// Don't issue a deprecation. The error already tells the user that
|
||||
// something went wrong.
|
||||
expect(deprecated).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should return a null when you call done', function() {
|
||||
@@ -487,6 +459,32 @@ describe('QueueRunner', function() {
|
||||
expect(nextQueueableFn.fn).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('handles a global error event with a message but no error', function() {
|
||||
const queueableFn = {
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
fn: function(done) {
|
||||
const currentHandler = globalErrors.pushListener.calls.mostRecent()
|
||||
.args[0];
|
||||
currentHandler(undefined, { message: 'nope' });
|
||||
},
|
||||
timeout: 1
|
||||
};
|
||||
const onException = jasmine.createSpy('onException');
|
||||
const globalErrors = {
|
||||
pushListener: jasmine.createSpy('pushListener'),
|
||||
popListener: jasmine.createSpy('popListener')
|
||||
};
|
||||
const queueRunner = new jasmineUnderTest.QueueRunner({
|
||||
queueableFns: [queueableFn],
|
||||
onException: onException,
|
||||
globalErrors: globalErrors
|
||||
});
|
||||
|
||||
queueRunner.execute();
|
||||
|
||||
expect(onException).toHaveBeenCalledWith('nope');
|
||||
});
|
||||
|
||||
it('handles exceptions thrown while waiting for the stack to clear', function() {
|
||||
const queueableFn = {
|
||||
fn: function(done) {
|
||||
@@ -520,6 +518,40 @@ describe('QueueRunner', function() {
|
||||
clearStack.calls.argsFor(0)[0]();
|
||||
expect(onException).toHaveBeenCalledWith(error);
|
||||
});
|
||||
|
||||
it('handles a global error event with no error while waiting for the stack to clear', function() {
|
||||
const queueableFn = {
|
||||
fn: function(done) {
|
||||
done();
|
||||
}
|
||||
};
|
||||
const errorListeners = [];
|
||||
const globalErrors = {
|
||||
pushListener: function(f) {
|
||||
errorListeners.push(f);
|
||||
},
|
||||
popListener: function() {
|
||||
errorListeners.pop();
|
||||
}
|
||||
};
|
||||
const clearStack = jasmine.createSpy('clearStack');
|
||||
const onException = jasmine.createSpy('onException');
|
||||
const queueRunner = new jasmineUnderTest.QueueRunner({
|
||||
queueableFns: [queueableFn],
|
||||
globalErrors: globalErrors,
|
||||
clearStack: clearStack,
|
||||
onException: onException
|
||||
});
|
||||
|
||||
queueRunner.execute();
|
||||
jasmine.clock().tick();
|
||||
expect(clearStack).toHaveBeenCalled();
|
||||
expect(errorListeners.length).toEqual(1);
|
||||
errorListeners[0](undefined, { message: 'nope' });
|
||||
|
||||
clearStack.calls.argsFor(0)[0]();
|
||||
expect(onException).toHaveBeenCalledWith('nope');
|
||||
});
|
||||
});
|
||||
|
||||
describe('with a function that returns a promise', function() {
|
||||
@@ -623,16 +655,19 @@ describe('QueueRunner', function() {
|
||||
queueRunner.execute();
|
||||
|
||||
expect(onException).toHaveBeenCalledWith(
|
||||
'An asynchronous ' +
|
||||
'before/it/after function took a done callback but also returned a ' +
|
||||
'promise. ' +
|
||||
'Either remove the done callback (recommended) or change the function ' +
|
||||
'to not return a promise.'
|
||||
new Error(
|
||||
'An asynchronous ' +
|
||||
'before/it/after function took a done callback but also returned a ' +
|
||||
'promise. ' +
|
||||
'Either remove the done callback (recommended) or change the function ' +
|
||||
'to not return a promise.'
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
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'),
|
||||
queueRunner = new jasmineUnderTest.QueueRunner({
|
||||
queueableFns: [{ fn: fn }],
|
||||
@@ -642,15 +677,17 @@ describe('QueueRunner', function() {
|
||||
queueRunner.execute();
|
||||
|
||||
expect(onException).toHaveBeenCalledWith(
|
||||
'An asynchronous ' +
|
||||
'before/it/after function was defined with the async keyword but ' +
|
||||
'also took a done callback. Either remove the done callback ' +
|
||||
'(recommended) or remove the async keyword.'
|
||||
new Error(
|
||||
'An asynchronous ' +
|
||||
'before/it/after function was defined with the async keyword but ' +
|
||||
'also took a done callback. Either remove the done callback ' +
|
||||
'(recommended) or remove the async keyword.'
|
||||
)
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('passes the error instance to exception handlers in HTML browsers', function() {
|
||||
it('passes final errors to exception handlers', function() {
|
||||
const error = new Error('fake error'),
|
||||
onExceptionCallback = jasmine.createSpy('on exception callback'),
|
||||
queueRunner = new jasmineUnderTest.QueueRunner({
|
||||
@@ -658,24 +695,11 @@ describe('QueueRunner', function() {
|
||||
});
|
||||
|
||||
queueRunner.execute();
|
||||
queueRunner.handleFinalError(error.message, 'fake.js', 1, 1, error);
|
||||
queueRunner.handleFinalError(error);
|
||||
|
||||
expect(onExceptionCallback).toHaveBeenCalledWith(error);
|
||||
});
|
||||
|
||||
it('passes the first argument to exception handlers for compatibility', function() {
|
||||
const error = new Error('fake error'),
|
||||
onExceptionCallback = jasmine.createSpy('on exception callback'),
|
||||
queueRunner = new jasmineUnderTest.QueueRunner({
|
||||
onException: onExceptionCallback
|
||||
});
|
||||
|
||||
queueRunner.execute();
|
||||
queueRunner.handleFinalError(error.message);
|
||||
|
||||
expect(onExceptionCallback).toHaveBeenCalledWith(error.message);
|
||||
});
|
||||
|
||||
it('calls exception handlers when an exception is thrown in a fn', function() {
|
||||
const queueableFn = {
|
||||
type: 'queueable',
|
||||
|
||||
@@ -18,13 +18,12 @@ describe('ReportDispatcher', function() {
|
||||
queueRunnerFactory
|
||||
),
|
||||
reporter = jasmine.createSpyObj('reporter', ['foo', 'bar']),
|
||||
anotherReporter = jasmine.createSpyObj('reporter', ['foo', 'bar']),
|
||||
completeCallback = jasmine.createSpy('complete');
|
||||
anotherReporter = jasmine.createSpyObj('reporter', ['foo', 'bar']);
|
||||
|
||||
dispatcher.addReporter(reporter);
|
||||
dispatcher.addReporter(anotherReporter);
|
||||
|
||||
dispatcher.foo(123, 456, completeCallback);
|
||||
dispatcher.foo(123, 456);
|
||||
|
||||
expect(queueRunnerFactory).toHaveBeenCalledWith(
|
||||
jasmine.objectContaining({
|
||||
@@ -47,7 +46,7 @@ describe('ReportDispatcher', function() {
|
||||
|
||||
queueRunnerFactory.calls.reset();
|
||||
|
||||
dispatcher.bar('a', 'b', completeCallback);
|
||||
dispatcher.bar('a', 'b');
|
||||
|
||||
expect(queueRunnerFactory).toHaveBeenCalledWith(
|
||||
jasmine.objectContaining({
|
||||
@@ -91,11 +90,10 @@ describe('ReportDispatcher', function() {
|
||||
['foo', 'bar'],
|
||||
queueRunnerFactory
|
||||
),
|
||||
reporter = jasmine.createSpyObj('reporter', ['foo', 'bar']),
|
||||
completeCallback = jasmine.createSpy('complete');
|
||||
reporter = jasmine.createSpyObj('reporter', ['foo', 'bar']);
|
||||
|
||||
dispatcher.provideFallbackReporter(reporter);
|
||||
dispatcher.foo(123, 456, completeCallback);
|
||||
dispatcher.foo(123, 456);
|
||||
|
||||
expect(queueRunnerFactory).toHaveBeenCalledWith(
|
||||
jasmine.objectContaining({
|
||||
@@ -116,12 +114,11 @@ describe('ReportDispatcher', function() {
|
||||
queueRunnerFactory
|
||||
),
|
||||
reporter = jasmine.createSpyObj('reporter', ['foo', 'bar']),
|
||||
fallbackReporter = jasmine.createSpyObj('otherReporter', ['foo', 'bar']),
|
||||
completeCallback = jasmine.createSpy('complete');
|
||||
fallbackReporter = jasmine.createSpyObj('otherReporter', ['foo', 'bar']);
|
||||
|
||||
dispatcher.provideFallbackReporter(fallbackReporter);
|
||||
dispatcher.addReporter(reporter);
|
||||
dispatcher.foo(123, 456, completeCallback);
|
||||
dispatcher.foo(123, 456);
|
||||
|
||||
expect(queueRunnerFactory).toHaveBeenCalledWith(
|
||||
jasmine.objectContaining({
|
||||
@@ -143,11 +140,10 @@ describe('ReportDispatcher', function() {
|
||||
queueRunnerFactory
|
||||
),
|
||||
reporter1 = jasmine.createSpyObj('reporter1', ['foo', 'bar']),
|
||||
reporter2 = jasmine.createSpyObj('reporter2', ['foo', 'bar']),
|
||||
completeCallback = jasmine.createSpy('complete');
|
||||
reporter2 = jasmine.createSpyObj('reporter2', ['foo', 'bar']);
|
||||
|
||||
dispatcher.addReporter(reporter1);
|
||||
dispatcher.foo(123, completeCallback);
|
||||
dispatcher.foo(123);
|
||||
expect(queueRunnerFactory).toHaveBeenCalledWith(
|
||||
jasmine.objectContaining({
|
||||
queueableFns: [{ fn: jasmine.any(Function) }],
|
||||
@@ -161,7 +157,7 @@ describe('ReportDispatcher', function() {
|
||||
|
||||
dispatcher.clearReporters();
|
||||
dispatcher.addReporter(reporter2);
|
||||
dispatcher.bar(456, completeCallback);
|
||||
dispatcher.bar(456);
|
||||
|
||||
expect(queueRunnerFactory).toHaveBeenCalledWith(
|
||||
jasmine.objectContaining({
|
||||
|
||||
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({
|
||||
description: 'my test',
|
||||
id: 'some-id',
|
||||
queueableFn: { fn: function() {} },
|
||||
queueRunnerFactory: fakeQueueRunner
|
||||
queueableFn: { fn: function() {} }
|
||||
});
|
||||
|
||||
spec.execute();
|
||||
spec.execute(fakeQueueRunner);
|
||||
|
||||
expect(fakeQueueRunner).toHaveBeenCalled();
|
||||
});
|
||||
@@ -54,11 +53,10 @@ describe('Spec', function() {
|
||||
id: 123,
|
||||
description: 'foo bar',
|
||||
queueableFn: { fn: function() {} },
|
||||
onStart: startCallback,
|
||||
queueRunnerFactory: fakeQueueRunner
|
||||
onStart: startCallback
|
||||
});
|
||||
|
||||
spec.execute();
|
||||
spec.execute(fakeQueueRunner);
|
||||
|
||||
fakeQueueRunner.calls.mostRecent().args[0].queueableFns[0].fn();
|
||||
expect(startCallback).toHaveBeenCalled();
|
||||
@@ -82,11 +80,10 @@ describe('Spec', function() {
|
||||
}
|
||||
];
|
||||
},
|
||||
onStart: startCallback,
|
||||
queueRunnerFactory: fakeQueueRunner
|
||||
onStart: startCallback
|
||||
});
|
||||
|
||||
spec.execute();
|
||||
spec.execute(fakeQueueRunner);
|
||||
|
||||
fakeQueueRunner.calls.mostRecent().args[0].queueableFns[0].fn();
|
||||
expect(startCallback).toHaveBeenCalled();
|
||||
@@ -106,11 +103,10 @@ describe('Spec', function() {
|
||||
queueableFn: queueableFn,
|
||||
beforeAndAfterFns: function() {
|
||||
return { befores: [before], afters: [after] };
|
||||
},
|
||||
queueRunnerFactory: fakeQueueRunner
|
||||
}
|
||||
});
|
||||
|
||||
spec.execute();
|
||||
spec.execute(fakeQueueRunner);
|
||||
|
||||
const options = fakeQueueRunner.calls.mostRecent().args[0];
|
||||
expect(options.queueableFns).toEqual([
|
||||
@@ -131,11 +127,10 @@ describe('Spec', function() {
|
||||
queueableFn: { fn: function() {} },
|
||||
beforeAndAfterFns: function() {
|
||||
return { befores: [], afters: [] };
|
||||
},
|
||||
queueRunnerFactory: fakeQueueRunner
|
||||
}
|
||||
});
|
||||
|
||||
spec.execute();
|
||||
spec.execute(fakeQueueRunner);
|
||||
|
||||
expect(fakeQueueRunner).toHaveBeenCalledWith(
|
||||
jasmine.objectContaining({
|
||||
@@ -145,14 +140,12 @@ describe('Spec', function() {
|
||||
});
|
||||
|
||||
it('is marked pending if created without a function body', function() {
|
||||
const fakeQueueRunner = jasmine.createSpy('fakeQueueRunner'),
|
||||
startCallback = jasmine.createSpy('startCallback'),
|
||||
const startCallback = jasmine.createSpy('startCallback'),
|
||||
resultCallback = jasmine.createSpy('resultCallback'),
|
||||
spec = new jasmineUnderTest.Spec({
|
||||
onStart: startCallback,
|
||||
queueableFn: { fn: null },
|
||||
resultCallback: resultCallback,
|
||||
queueRunnerFactory: fakeQueueRunner
|
||||
resultCallback: resultCallback
|
||||
});
|
||||
|
||||
expect(spec.status()).toBe('pending');
|
||||
@@ -166,11 +159,10 @@ describe('Spec', function() {
|
||||
spec = new jasmineUnderTest.Spec({
|
||||
onStart: startCallback,
|
||||
queueableFn: { fn: specBody },
|
||||
resultCallback: resultCallback,
|
||||
queueRunnerFactory: fakeQueueRunner
|
||||
resultCallback: resultCallback
|
||||
});
|
||||
|
||||
spec.execute('cally-back', true);
|
||||
spec.execute(fakeQueueRunner, 'cally-back', true);
|
||||
|
||||
expect(fakeQueueRunner).toHaveBeenCalledWith(
|
||||
jasmine.objectContaining({
|
||||
@@ -203,10 +195,11 @@ describe('Spec', function() {
|
||||
onStart: startCallback,
|
||||
resultCallback: resultCallback,
|
||||
description: 'with a spec',
|
||||
parentSuiteId: 'suite1',
|
||||
filename: 'someSpecFile.js',
|
||||
getSpecName: function() {
|
||||
return 'a suite with a spec';
|
||||
},
|
||||
queueRunnerFactory: fakeQueueRunner,
|
||||
queueableFn: { fn: null }
|
||||
});
|
||||
|
||||
@@ -214,7 +207,7 @@ describe('Spec', function() {
|
||||
|
||||
expect(spec.status()).toBe('pending');
|
||||
|
||||
spec.execute();
|
||||
spec.execute(fakeQueueRunner);
|
||||
|
||||
expect(fakeQueueRunner).toHaveBeenCalled();
|
||||
|
||||
@@ -228,6 +221,8 @@ describe('Spec', function() {
|
||||
status: 'pending',
|
||||
description: 'with a spec',
|
||||
fullName: 'a suite with a spec',
|
||||
parentSuiteId: 'suite1',
|
||||
filename: 'someSpecFile.js',
|
||||
failedExpectations: [],
|
||||
passedExpectations: [],
|
||||
deprecationWarnings: [],
|
||||
@@ -247,13 +242,10 @@ describe('Spec', function() {
|
||||
catchExceptions: function() {
|
||||
return false;
|
||||
},
|
||||
resultCallback: function() {},
|
||||
queueRunnerFactory: function(attrs) {
|
||||
attrs.onComplete();
|
||||
}
|
||||
resultCallback: function() {}
|
||||
});
|
||||
|
||||
spec.execute(done);
|
||||
spec.execute(attrs => attrs.onComplete(), done);
|
||||
|
||||
expect(done).toHaveBeenCalled();
|
||||
});
|
||||
@@ -265,14 +257,14 @@ describe('Spec', function() {
|
||||
catchExceptions: function() {
|
||||
return false;
|
||||
},
|
||||
resultCallback: function() {},
|
||||
queueRunnerFactory: function(attrs) {
|
||||
spec.result.status = 'failed';
|
||||
attrs.onComplete();
|
||||
}
|
||||
resultCallback: function() {}
|
||||
});
|
||||
|
||||
spec.execute(done);
|
||||
function queueRunnerFactory(attrs) {
|
||||
spec.result.status = 'failed';
|
||||
attrs.onComplete();
|
||||
}
|
||||
spec.execute(queueRunnerFactory, done);
|
||||
|
||||
expect(done).toHaveBeenCalledWith(
|
||||
jasmine.any(jasmineUnderTest.StopExecutionError)
|
||||
@@ -293,16 +285,17 @@ describe('Spec', function() {
|
||||
resultCallback: function(result) {
|
||||
duration = result.duration;
|
||||
},
|
||||
queueRunnerFactory: function(config) {
|
||||
config.queueableFns.forEach(function(qf) {
|
||||
qf.fn();
|
||||
});
|
||||
config.onComplete();
|
||||
},
|
||||
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);
|
||||
});
|
||||
|
||||
@@ -313,13 +306,10 @@ describe('Spec', function() {
|
||||
catchExceptions: function() {
|
||||
return false;
|
||||
},
|
||||
resultCallback: function() {},
|
||||
queueRunnerFactory: function(attrs) {
|
||||
attrs.onComplete();
|
||||
}
|
||||
resultCallback: function() {}
|
||||
});
|
||||
spec.setSpecProperty('a', 4);
|
||||
spec.execute(done);
|
||||
spec.execute(attrs => attrs.onComplete(), done);
|
||||
expect(spec.result.properties).toEqual({ a: 4 });
|
||||
});
|
||||
|
||||
@@ -334,7 +324,7 @@ describe('Spec', function() {
|
||||
const spec = new jasmineUnderTest.Spec({
|
||||
queueableFn: { fn: jasmine.createSpy('spec body') }
|
||||
});
|
||||
spec.addExpectationResult(true);
|
||||
spec.addExpectationResult(true, {});
|
||||
expect(spec.status()).toBe('passed');
|
||||
});
|
||||
|
||||
@@ -342,8 +332,8 @@ describe('Spec', function() {
|
||||
const spec = new jasmineUnderTest.Spec({
|
||||
queueableFn: { fn: jasmine.createSpy('spec body') }
|
||||
});
|
||||
spec.addExpectationResult(true);
|
||||
spec.addExpectationResult(false);
|
||||
spec.addExpectationResult(true, {});
|
||||
spec.addExpectationResult(false, {});
|
||||
expect(spec.status()).toBe('failed');
|
||||
});
|
||||
|
||||
@@ -352,25 +342,21 @@ describe('Spec', function() {
|
||||
resultCallback = jasmine.createSpy('resultCallback'),
|
||||
spec = new jasmineUnderTest.Spec({
|
||||
queueableFn: { fn: jasmine.createSpy('spec body') },
|
||||
expectationResultFactory: function(data) {
|
||||
return data;
|
||||
},
|
||||
queueRunnerFactory: fakeQueueRunner,
|
||||
resultCallback: resultCallback
|
||||
});
|
||||
spec.addExpectationResult(true, 'expectation1');
|
||||
spec.addExpectationResult(false, 'expectation2');
|
||||
spec.addExpectationResult(true, { message: 'expectation1' });
|
||||
spec.addExpectationResult(false, { message: 'expectation2' });
|
||||
|
||||
spec.execute();
|
||||
spec.execute(fakeQueueRunner);
|
||||
|
||||
const fns = fakeQueueRunner.calls.mostRecent().args[0].queueableFns;
|
||||
fns[fns.length - 1].fn();
|
||||
|
||||
expect(resultCallback.calls.first().args[0].passedExpectations).toEqual([
|
||||
'expectation1'
|
||||
jasmine.objectContaining({ message: 'expectation1' })
|
||||
]);
|
||||
expect(resultCallback.calls.first().args[0].failedExpectations).toEqual([
|
||||
'expectation2'
|
||||
jasmine.objectContaining({ message: 'expectation2' })
|
||||
]);
|
||||
});
|
||||
|
||||
@@ -379,46 +365,123 @@ describe('Spec', function() {
|
||||
resultCallback = jasmine.createSpy('resultCallback'),
|
||||
spec = new jasmineUnderTest.Spec({
|
||||
queueableFn: { fn: function() {} },
|
||||
expectationResultFactory: function(data) {
|
||||
return data;
|
||||
},
|
||||
queueRunnerFactory: fakeQueueRunner,
|
||||
resultCallback: resultCallback,
|
||||
throwOnExpectationFailure: true
|
||||
});
|
||||
|
||||
spec.addExpectationResult(true, 'passed');
|
||||
spec.addExpectationResult(true, { message: 'passed' });
|
||||
expect(function() {
|
||||
spec.addExpectationResult(false, 'failed');
|
||||
spec.addExpectationResult(false, { message: 'failed' });
|
||||
}).toThrowError(jasmineUnderTest.errors.ExpectationFailed);
|
||||
|
||||
spec.execute();
|
||||
spec.execute(fakeQueueRunner);
|
||||
|
||||
const fns = fakeQueueRunner.calls.mostRecent().args[0].queueableFns;
|
||||
fns[fns.length - 1].fn();
|
||||
expect(resultCallback.calls.first().args[0].passedExpectations).toEqual([
|
||||
'passed'
|
||||
jasmine.objectContaining({ message: 'passed' })
|
||||
]);
|
||||
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() {
|
||||
const resultCallback = jasmine.createSpy('resultCallback'),
|
||||
spec = new jasmineUnderTest.Spec({
|
||||
queueableFn: { fn: function() {} },
|
||||
expectationResultFactory: function(data) {
|
||||
return data;
|
||||
},
|
||||
queueRunnerFactory: function(attrs) {
|
||||
attrs.onComplete();
|
||||
},
|
||||
resultCallback: resultCallback,
|
||||
throwOnExpectationFailure: true
|
||||
});
|
||||
|
||||
spec.onException('failing exception');
|
||||
spec.handleException('failing exception');
|
||||
});
|
||||
|
||||
it('can return its full name', function() {
|
||||
@@ -445,11 +508,10 @@ describe('Spec', function() {
|
||||
spec = new jasmineUnderTest.Spec({
|
||||
description: 'my test',
|
||||
id: 'some-id',
|
||||
queueableFn: { fn: function() {} },
|
||||
queueRunnerFactory: fakeQueueRunner
|
||||
queueableFn: { fn: function() {} }
|
||||
});
|
||||
|
||||
spec.execute();
|
||||
spec.execute(fakeQueueRunner);
|
||||
|
||||
expect(spec.status()).toEqual('pending');
|
||||
expect(spec.result.pendingReason).toEqual('');
|
||||
@@ -467,11 +529,10 @@ describe('Spec', function() {
|
||||
spec = new jasmineUnderTest.Spec({
|
||||
description: 'my test',
|
||||
id: 'some-id',
|
||||
queueableFn: { fn: function() {} },
|
||||
queueRunnerFactory: fakeQueueRunner
|
||||
queueableFn: { fn: function() {} }
|
||||
});
|
||||
|
||||
spec.execute();
|
||||
spec.execute(fakeQueueRunner);
|
||||
|
||||
expect(spec.status()).toEqual('pending');
|
||||
expect(spec.result.pendingReason).toEqual('custom message');
|
||||
@@ -483,25 +544,22 @@ describe('Spec', function() {
|
||||
resultCallback = jasmine.createSpy('resultCallback'),
|
||||
spec = new jasmineUnderTest.Spec({
|
||||
queueableFn: { fn: function() {} },
|
||||
expectationResultFactory: function(data) {
|
||||
return data;
|
||||
},
|
||||
queueRunnerFactory: fakeQueueRunner,
|
||||
resultCallback: resultCallback
|
||||
});
|
||||
|
||||
spec.onException('foo');
|
||||
spec.execute();
|
||||
spec.handleException('foo');
|
||||
spec.execute(fakeQueueRunner);
|
||||
|
||||
const args = fakeQueueRunner.calls.mostRecent().args[0];
|
||||
args.queueableFns[args.queueableFns.length - 1].fn();
|
||||
expect(resultCallback.calls.first().args[0].failedExpectations).toEqual([
|
||||
{
|
||||
error: 'foo',
|
||||
message: 'foo thrown',
|
||||
matcherName: '',
|
||||
passed: false,
|
||||
expected: '',
|
||||
actual: ''
|
||||
actual: '',
|
||||
stack: null
|
||||
}
|
||||
]);
|
||||
});
|
||||
@@ -511,15 +569,11 @@ describe('Spec', function() {
|
||||
resultCallback = jasmine.createSpy('resultCallback'),
|
||||
spec = new jasmineUnderTest.Spec({
|
||||
queueableFn: { fn: function() {} },
|
||||
expectationResultFactory: function(data) {
|
||||
return data;
|
||||
},
|
||||
queueRunnerFactory: fakeQueueRunner,
|
||||
resultCallback: resultCallback
|
||||
});
|
||||
|
||||
spec.onException(new jasmineUnderTest.errors.ExpectationFailed());
|
||||
spec.execute();
|
||||
spec.handleException(new jasmineUnderTest.errors.ExpectationFailed());
|
||||
spec.execute(fakeQueueRunner);
|
||||
|
||||
const args = fakeQueueRunner.calls.mostRecent().args[0];
|
||||
args.queueableFns[args.queueableFns.length - 1].fn();
|
||||
@@ -532,13 +586,12 @@ describe('Spec', function() {
|
||||
spec = new jasmineUnderTest.Spec({
|
||||
onLateError: onLateError,
|
||||
queueableFn: { fn: function() {} },
|
||||
queueRunnerFactory: queueRunnerFactory,
|
||||
getSpecName: function() {
|
||||
return 'a spec';
|
||||
}
|
||||
});
|
||||
|
||||
spec.execute();
|
||||
spec.execute(queueRunnerFactory);
|
||||
|
||||
expect(queueRunnerFactory).toHaveBeenCalled();
|
||||
queueRunnerFactory.calls.argsFor(0)[0].onMultipleDone();
|
||||
@@ -558,13 +611,12 @@ describe('Spec', function() {
|
||||
queueableFn: {
|
||||
fn: function() {}
|
||||
},
|
||||
queueRunnerFactory: function() {},
|
||||
timer: timer
|
||||
}),
|
||||
t1 = 123,
|
||||
t2 = 456;
|
||||
|
||||
spec.execute();
|
||||
spec.execute(() => {});
|
||||
expect(spec.result.debugLogs).toBeNull();
|
||||
timer.elapsed.and.returnValue(t1);
|
||||
spec.debugLog('msg 1');
|
||||
@@ -586,17 +638,18 @@ describe('Spec', function() {
|
||||
queueableFn: {
|
||||
fn: function() {}
|
||||
},
|
||||
resultCallback: resultCallback,
|
||||
queueRunnerFactory: function(config) {
|
||||
spec.debugLog('msg');
|
||||
for (const fn of config.queueableFns) {
|
||||
fn.fn();
|
||||
}
|
||||
config.onComplete(false);
|
||||
}
|
||||
resultCallback: resultCallback
|
||||
});
|
||||
|
||||
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(
|
||||
jasmine.objectContaining({ debugLogs: null }),
|
||||
undefined
|
||||
@@ -609,17 +662,18 @@ describe('Spec', function() {
|
||||
queueableFn: {
|
||||
fn: function() {}
|
||||
},
|
||||
resultCallback: resultCallback,
|
||||
queueRunnerFactory: function(config) {
|
||||
spec.debugLog('msg');
|
||||
for (const fn of config.queueableFns) {
|
||||
fn.fn();
|
||||
}
|
||||
config.onComplete(false);
|
||||
}
|
||||
resultCallback: resultCallback
|
||||
});
|
||||
|
||||
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(spec.result.debugLogs).toBeNull();
|
||||
});
|
||||
@@ -634,21 +688,22 @@ describe('Spec', function() {
|
||||
fn: function() {}
|
||||
},
|
||||
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
|
||||
}),
|
||||
timestamp = 12345;
|
||||
|
||||
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(
|
||||
jasmine.objectContaining({
|
||||
debugLogs: [{ message: 'msg', timestamp: timestamp }]
|
||||
|
||||
@@ -94,6 +94,30 @@ describe('SpyRegistry', function() {
|
||||
}).not.toThrowError(/is not declared writable or has no setter/);
|
||||
});
|
||||
|
||||
it('throws if assigning to the property is a no-op', function() {
|
||||
const scope = {};
|
||||
|
||||
function original() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
Object.defineProperty(scope, 'myFunc', {
|
||||
get() {
|
||||
return original;
|
||||
},
|
||||
set() {}
|
||||
});
|
||||
|
||||
const spyRegistry = new jasmineUnderTest.SpyRegistry({
|
||||
createSpy: createSpy
|
||||
});
|
||||
expect(function() {
|
||||
spyRegistry.spyOn(scope, 'myFunc');
|
||||
}).toThrowError(
|
||||
"<spyOn> : Can't spy on myFunc because assigning to it had no effect"
|
||||
);
|
||||
});
|
||||
|
||||
it('overrides the method on the object and returns the spy', function() {
|
||||
const originalFunctionWasCalled = false,
|
||||
spyRegistry = new jasmineUnderTest.SpyRegistry({
|
||||
|
||||
@@ -106,9 +106,9 @@ describe('SpyStrategy', function() {
|
||||
|
||||
it('allows a fake async function to be called instead', function(done) {
|
||||
const originalFn = jasmine.createSpy('original'),
|
||||
fakeFn = jasmine
|
||||
.createSpy('fake')
|
||||
.and.callFake(eval('async () => { return 67; }')),
|
||||
fakeFn = jasmine.createSpy('fake').and.callFake(async () => {
|
||||
return 67;
|
||||
}),
|
||||
spyStrategy = new jasmineUnderTest.SpyStrategy({ fn: originalFn });
|
||||
|
||||
spyStrategy.callFake(fakeFn);
|
||||
|
||||
@@ -51,6 +51,27 @@ describe('StackTrace', function() {
|
||||
]);
|
||||
});
|
||||
|
||||
it('understands Chrome/Edge style traces with messages containing blank lines', function() {
|
||||
const error = {
|
||||
message: 'line 1\n\nline 2',
|
||||
stack:
|
||||
'Error: line 1\n\nline 2\n' +
|
||||
' at UserContext.<anonymous> (http://localhost:8888/__spec__/core/UtilSpec.js:115:19)\n' +
|
||||
' at QueueRunner.run (http://localhost:8888/__jasmine__/jasmine.js:4320:20)'
|
||||
};
|
||||
|
||||
const result = new jasmineUnderTest.StackTrace(error);
|
||||
|
||||
expect(result.message).toEqual('Error: line 1\n\nline 2');
|
||||
const rawFrames = result.frames.map(function(f) {
|
||||
return f.raw;
|
||||
});
|
||||
expect(rawFrames).toEqual([
|
||||
' at UserContext.<anonymous> (http://localhost:8888/__spec__/core/UtilSpec.js:115:19)',
|
||||
' at QueueRunner.run (http://localhost:8888/__jasmine__/jasmine.js:4320:20)'
|
||||
]);
|
||||
});
|
||||
|
||||
it('understands Node style traces', function() {
|
||||
const error = {
|
||||
message: 'nope',
|
||||
@@ -95,7 +116,7 @@ describe('StackTrace', function() {
|
||||
]);
|
||||
});
|
||||
|
||||
it('understands Safari <=14/Firefox/Phantom-OS X style traces', function() {
|
||||
it('understands Safari <=14/Firefox style traces', function() {
|
||||
const error = {
|
||||
message: 'nope',
|
||||
stack:
|
||||
@@ -149,7 +170,7 @@ describe('StackTrace', function() {
|
||||
]);
|
||||
});
|
||||
|
||||
it('does not mistake gibberish for Safari/Firefox/Phantom-OS X style traces', function() {
|
||||
it('does not mistake gibberish for Safari/Firefox style traces', function() {
|
||||
const error = {
|
||||
message: 'nope',
|
||||
stack: 'randomcharsnotincludingwhitespace'
|
||||
@@ -159,36 +180,6 @@ describe('StackTrace', function() {
|
||||
expect(result.frames).toEqual([{ raw: error.stack }]);
|
||||
});
|
||||
|
||||
it('understands Phantom-Linux style traces', function() {
|
||||
const error = {
|
||||
message: 'nope',
|
||||
stack:
|
||||
' at UserContext.<anonymous> (http://localhost:8888/__spec__/core/UtilSpec.js:115:19)\n' +
|
||||
' at QueueRunner.run (http://localhost:8888/__jasmine__/jasmine.js:4320:20)'
|
||||
};
|
||||
|
||||
const result = new jasmineUnderTest.StackTrace(error);
|
||||
|
||||
expect(result.message).toBeFalsy();
|
||||
expect(result.style).toEqual('v8');
|
||||
expect(result.frames).toEqual([
|
||||
{
|
||||
raw:
|
||||
' at UserContext.<anonymous> (http://localhost:8888/__spec__/core/UtilSpec.js:115:19)',
|
||||
func: 'UserContext.<anonymous>',
|
||||
file: 'http://localhost:8888/__spec__/core/UtilSpec.js',
|
||||
line: 115
|
||||
},
|
||||
{
|
||||
raw:
|
||||
' at QueueRunner.run (http://localhost:8888/__jasmine__/jasmine.js:4320:20)',
|
||||
func: 'QueueRunner.run',
|
||||
file: 'http://localhost:8888/__jasmine__/jasmine.js',
|
||||
line: 4320
|
||||
}
|
||||
]);
|
||||
});
|
||||
|
||||
it('ignores blank lines', function() {
|
||||
const error = {
|
||||
message: 'nope',
|
||||
@@ -241,7 +232,7 @@ describe('StackTrace', function() {
|
||||
]);
|
||||
});
|
||||
|
||||
it('consideres different types of errors', function() {
|
||||
it('considers different types of errors', function() {
|
||||
const error = {
|
||||
message: 'nope',
|
||||
stack:
|
||||
|
||||
265
spec/core/SuiteBuilderSpec.js
Normal file
265
spec/core/SuiteBuilderSpec.js
Normal file
@@ -0,0 +1,265 @@
|
||||
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) + '>';
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
describe('#parallelReset', function() {
|
||||
it('resets the top suite result', function() {
|
||||
jasmineUnderTest.Suite.prototype.handleException.and.callThrough();
|
||||
|
||||
const env = { configuration: () => ({}) };
|
||||
const suiteBuilder = new jasmineUnderTest.SuiteBuilder({ env });
|
||||
|
||||
suiteBuilder.topSuite.handleException(new Error('nope'));
|
||||
suiteBuilder.parallelReset();
|
||||
|
||||
expect(suiteBuilder.topSuite.result).toEqual({
|
||||
id: suiteBuilder.topSuite.id,
|
||||
description: 'Jasmine__TopLevel__Suite',
|
||||
fullName: '',
|
||||
failedExpectations: [],
|
||||
deprecationWarnings: [],
|
||||
duration: null,
|
||||
properties: null,
|
||||
parentSuiteId: null,
|
||||
filename: undefined
|
||||
});
|
||||
});
|
||||
|
||||
it('removes children of the top suite', function() {
|
||||
const env = { configuration: () => ({}) };
|
||||
const suiteBuilder = new jasmineUnderTest.SuiteBuilder({ env });
|
||||
suiteBuilder.describe('a suite', function() {
|
||||
suiteBuilder.it('a nested spec');
|
||||
});
|
||||
suiteBuilder.it('a spec');
|
||||
|
||||
suiteBuilder.parallelReset();
|
||||
|
||||
expect(suiteBuilder.topSuite.children).toEqual([]);
|
||||
});
|
||||
|
||||
it('preserves top suite befores and afters', function() {
|
||||
const env = { configuration: () => ({}) };
|
||||
const suiteBuilder = new jasmineUnderTest.SuiteBuilder({ env });
|
||||
|
||||
function beforeAll() {}
|
||||
function beforeEach() {}
|
||||
function afterEach() {}
|
||||
function afterAll() {}
|
||||
|
||||
suiteBuilder.beforeAll(beforeAll);
|
||||
suiteBuilder.beforeEach(beforeEach);
|
||||
suiteBuilder.afterEach(afterEach);
|
||||
suiteBuilder.afterAll(afterAll);
|
||||
|
||||
suiteBuilder.parallelReset();
|
||||
|
||||
expect(suiteBuilder.topSuite.beforeAllFns).toEqual([
|
||||
jasmine.objectContaining({ fn: beforeAll })
|
||||
]);
|
||||
expect(suiteBuilder.topSuite.beforeFns).toEqual([
|
||||
jasmine.objectContaining({ fn: beforeEach })
|
||||
]);
|
||||
expect(suiteBuilder.topSuite.afterFns).toEqual([
|
||||
jasmine.objectContaining({ fn: afterEach })
|
||||
]);
|
||||
expect(suiteBuilder.topSuite.afterAllFns).toEqual([
|
||||
jasmine.objectContaining({ fn: afterAll })
|
||||
]);
|
||||
});
|
||||
|
||||
it('resets totalSpecsDefined', function() {
|
||||
const env = { configuration: () => ({}) };
|
||||
const suiteBuilder = new jasmineUnderTest.SuiteBuilder({ env });
|
||||
suiteBuilder.it('a spec');
|
||||
|
||||
suiteBuilder.parallelReset();
|
||||
|
||||
expect(suiteBuilder.totalSpecsDefined).toEqual(0);
|
||||
});
|
||||
|
||||
it('resets focusedRunables', function() {
|
||||
const env = { configuration: () => ({}) };
|
||||
const suiteBuilder = new jasmineUnderTest.SuiteBuilder({ env });
|
||||
suiteBuilder.fit('a spec', function() {});
|
||||
|
||||
suiteBuilder.parallelReset();
|
||||
|
||||
expect(suiteBuilder.focusedRunables).toEqual([]);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -71,20 +71,9 @@ describe('Suite', function() {
|
||||
suite.beforeAll(outerBefore);
|
||||
suite.beforeAll(innerBefore);
|
||||
|
||||
function sameInstance(expected) {
|
||||
return {
|
||||
asymmetricMatch: function(actual) {
|
||||
return actual === expected;
|
||||
},
|
||||
jasmineToString: function() {
|
||||
return `<same instance as ${expected}>`;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
expect(suite.beforeAllFns).toEqual([
|
||||
{ fn: outerBefore.fn, type: 'beforeAll', suite: sameInstance(suite) },
|
||||
{ fn: innerBefore.fn, type: 'beforeAll', suite: sameInstance(suite) }
|
||||
{ fn: outerBefore.fn, type: 'beforeAll', suite: jasmine.is(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() {
|
||||
const suite = new jasmineUnderTest.Suite({
|
||||
expectationResultFactory: function() {
|
||||
return 'hi';
|
||||
}
|
||||
});
|
||||
const suite = new jasmineUnderTest.Suite({});
|
||||
|
||||
suite.addExpectationResult(false);
|
||||
suite.addExpectationResult(false, {});
|
||||
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() {
|
||||
const suite = new jasmineUnderTest.Suite({
|
||||
expectationResultFactory: function(data) {
|
||||
return data;
|
||||
},
|
||||
throwOnExpectationFailure: true
|
||||
});
|
||||
|
||||
expect(function() {
|
||||
suite.addExpectationResult(false, 'failed');
|
||||
suite.addExpectationResult(false, { message: 'failed' });
|
||||
}).toThrowError(jasmineUnderTest.errors.ExpectationFailed);
|
||||
|
||||
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() {
|
||||
const suite = new jasmineUnderTest.Suite({});
|
||||
|
||||
suite.onException(new jasmineUnderTest.errors.ExpectationFailed());
|
||||
suite.handleException(new jasmineUnderTest.errors.ExpectationFailed());
|
||||
|
||||
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() {
|
||||
const suite = new jasmineUnderTest.Suite({
|
||||
env: env,
|
||||
@@ -261,12 +328,8 @@ describe('Suite', function() {
|
||||
});
|
||||
|
||||
it('should reset the failedExpectations', function() {
|
||||
const suite = new jasmineUnderTest.Suite({
|
||||
expectationResultFactory: function(error) {
|
||||
return error;
|
||||
}
|
||||
});
|
||||
suite.onException(new Error());
|
||||
const suite = new jasmineUnderTest.Suite({});
|
||||
suite.handleException(new Error());
|
||||
|
||||
suite.reset();
|
||||
|
||||
|
||||
@@ -274,7 +274,7 @@ describe('TreeProcessor', function() {
|
||||
expect(result.valid).toBe(true);
|
||||
});
|
||||
|
||||
it('runs a single leaf', function() {
|
||||
it('runs a single leaf', async function() {
|
||||
const leaf = new Leaf(),
|
||||
node = new Node({ children: [leaf], userContext: { root: 'context' } }),
|
||||
queueRunner = jasmine.createSpy('queueRunner'),
|
||||
@@ -282,25 +282,27 @@ describe('TreeProcessor', function() {
|
||||
tree: node,
|
||||
runnableIds: [leaf.id],
|
||||
queueRunnerFactory: queueRunner
|
||||
}),
|
||||
treeComplete = jasmine.createSpy('treeComplete');
|
||||
});
|
||||
|
||||
processor.execute(treeComplete);
|
||||
const promise = processor.execute();
|
||||
|
||||
expect(queueRunner).toHaveBeenCalledWith({
|
||||
onComplete: treeComplete,
|
||||
onComplete: jasmine.any(Function),
|
||||
onException: jasmine.any(Function),
|
||||
userContext: { root: 'context' },
|
||||
queueableFns: [{ fn: jasmine.any(Function) }],
|
||||
onMultipleDone: null
|
||||
});
|
||||
|
||||
queueRunner.calls.mostRecent().args[0].queueableFns[0].fn('foo');
|
||||
const queueRunnerArgs = queueRunner.calls.mostRecent().args[0];
|
||||
queueRunnerArgs.queueableFns[0].fn('foo');
|
||||
expect(leaf.execute).toHaveBeenCalledWith(queueRunner, 'foo', false, false);
|
||||
|
||||
expect(leaf.execute).toHaveBeenCalledWith('foo', false, false);
|
||||
queueRunnerArgs.onComplete();
|
||||
await expectAsync(promise).toBeResolvedTo(undefined);
|
||||
});
|
||||
|
||||
it('runs a node with no children', function() {
|
||||
it('runs a node with no children', async function() {
|
||||
const node = new Node({ userContext: { node: 'context' } }),
|
||||
root = new Node({ children: [node], userContext: { root: 'context' } }),
|
||||
nodeStart = jasmine.createSpy('nodeStart'),
|
||||
@@ -313,21 +315,20 @@ describe('TreeProcessor', function() {
|
||||
nodeComplete: nodeComplete,
|
||||
queueRunnerFactory: queueRunner
|
||||
}),
|
||||
treeComplete = jasmine.createSpy('treeComplete'),
|
||||
nodeDone = jasmine.createSpy('nodeDone');
|
||||
|
||||
processor.execute(treeComplete);
|
||||
const promise = processor.execute();
|
||||
|
||||
expect(queueRunner).toHaveBeenCalledWith({
|
||||
onComplete: treeComplete,
|
||||
onComplete: jasmine.any(Function),
|
||||
onException: jasmine.any(Function),
|
||||
userContext: { root: 'context' },
|
||||
queueableFns: [{ fn: jasmine.any(Function) }],
|
||||
onMultipleDone: null
|
||||
});
|
||||
|
||||
queueRunner.calls.mostRecent().args[0].queueableFns[0].fn(nodeDone);
|
||||
|
||||
const queueRunnerArgs = queueRunner.calls.mostRecent().args[0];
|
||||
queueRunnerArgs.queueableFns[0].fn(nodeDone);
|
||||
expect(queueRunner).toHaveBeenCalledWith({
|
||||
onComplete: jasmine.any(Function),
|
||||
onMultipleDone: null,
|
||||
@@ -348,6 +349,9 @@ describe('TreeProcessor', function() {
|
||||
{ my: 'result' },
|
||||
jasmine.any(Function)
|
||||
);
|
||||
|
||||
queueRunnerArgs.onComplete();
|
||||
await expectAsync(promise).toBeResolvedTo(undefined);
|
||||
});
|
||||
|
||||
it('runs a node with children', function() {
|
||||
@@ -372,10 +376,20 @@ describe('TreeProcessor', function() {
|
||||
expect(queueableFns.length).toBe(3);
|
||||
|
||||
queueableFns[1].fn('foo');
|
||||
expect(leaf1.execute).toHaveBeenCalledWith('foo', false, false);
|
||||
expect(leaf1.execute).toHaveBeenCalledWith(
|
||||
queueRunner,
|
||||
'foo',
|
||||
false,
|
||||
false
|
||||
);
|
||||
|
||||
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() {
|
||||
@@ -401,7 +415,7 @@ describe('TreeProcessor', function() {
|
||||
expect(queueableFns.length).toBe(2);
|
||||
|
||||
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');
|
||||
expect(nodeComplete).toHaveBeenCalled();
|
||||
@@ -437,7 +451,7 @@ describe('TreeProcessor', function() {
|
||||
expect(nodeStart).toHaveBeenCalledWith(node, 'bar');
|
||||
|
||||
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' });
|
||||
|
||||
@@ -475,7 +489,7 @@ describe('TreeProcessor', function() {
|
||||
expect(queueableFns.length).toBe(2);
|
||||
|
||||
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() {
|
||||
@@ -637,11 +651,21 @@ describe('TreeProcessor', function() {
|
||||
queueableFns[0].fn();
|
||||
|
||||
expect(nonSpecified.execute).not.toHaveBeenCalled();
|
||||
expect(specified.execute).toHaveBeenCalledWith(undefined, false, false);
|
||||
expect(specified.execute).toHaveBeenCalledWith(
|
||||
queueRunner,
|
||||
undefined,
|
||||
false,
|
||||
false
|
||||
);
|
||||
|
||||
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() {
|
||||
|
||||
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' ] }))>"
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -145,7 +145,7 @@ describe('base helpers', function() {
|
||||
});
|
||||
|
||||
it('returns a promise that resolves to false when the promise is rejected', function() {
|
||||
const promise = Promise.reject();
|
||||
const promise = Promise.reject(new Error('nope'));
|
||||
return expectAsync(jasmineUnderTest.isPending_(promise)).toBeResolvedTo(
|
||||
false
|
||||
);
|
||||
@@ -179,7 +179,10 @@ describe('base helpers', function() {
|
||||
f2 = jasmine.createSpy('setTimeout callback for ' + (max + 1));
|
||||
|
||||
// Suppress printing of TimeoutOverflowWarning in node
|
||||
spyOn(console, 'error');
|
||||
if (typeof process !== 'undefined' && process.emitWarning) {
|
||||
spyOn(process, 'emitWarning'); // Node 22
|
||||
}
|
||||
spyOn(console, 'error'); // Node <22
|
||||
|
||||
let id = setTimeout(f1, max);
|
||||
setTimeout(function() {
|
||||
|
||||
@@ -22,56 +22,38 @@ describe('buildExpectationResult', function() {
|
||||
expect(result.message).toBe('some-value');
|
||||
});
|
||||
|
||||
it('delegates message formatting to the provided formatter if there was an Error', function() {
|
||||
const fakeError = { message: 'foo' },
|
||||
messageFormatter = jasmine
|
||||
.createSpy('exception message formatter')
|
||||
.and.returnValue(fakeError.message);
|
||||
describe('When the error property is provided', function() {
|
||||
it('sets the message to the formatted error', function() {
|
||||
const result = jasmineUnderTest.buildExpectationResult({
|
||||
passed: false,
|
||||
error: { message: 'foo', fileName: 'somefile.js' }
|
||||
});
|
||||
|
||||
const result = jasmineUnderTest.buildExpectationResult({
|
||||
passed: false,
|
||||
error: fakeError,
|
||||
messageFormatter: messageFormatter
|
||||
expect(result.message).toEqual('foo in somefile.js');
|
||||
});
|
||||
|
||||
expect(messageFormatter).toHaveBeenCalledWith(fakeError);
|
||||
expect(result.message).toEqual('foo');
|
||||
it('delegates stack formatting to the provided formatter', function() {
|
||||
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() {
|
||||
const fakeError = { stack: 'foo' },
|
||||
stackFormatter = jasmine
|
||||
.createSpy('stack formatter')
|
||||
.and.returnValue(fakeError.stack);
|
||||
describe('When the errorForStack property is provided', function() {
|
||||
it('builds the stack trace using errorForStack instead of Error', function() {
|
||||
const result = jasmineUnderTest.buildExpectationResult({
|
||||
passed: false,
|
||||
errorForStack: { stack: 'foo' },
|
||||
error: { stack: 'bar' }
|
||||
});
|
||||
|
||||
const result = jasmineUnderTest.buildExpectationResult({
|
||||
passed: false,
|
||||
error: fakeError,
|
||||
stackFormatter: stackFormatter
|
||||
expect(result.stack).toEqual('bar');
|
||||
});
|
||||
|
||||
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() {
|
||||
@@ -1,55 +1,57 @@
|
||||
describe('Asymmetric equality testers (Integration)', function() {
|
||||
function verifyPasses(expectations) {
|
||||
it('passes', function(done) {
|
||||
it('passes', async function() {
|
||||
const env = new jasmineUnderTest.Env();
|
||||
env.it('a spec', function() {
|
||||
expectations(env);
|
||||
});
|
||||
|
||||
const specExpectations = function(result) {
|
||||
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();
|
||||
};
|
||||
const reporter = jasmine.createSpyObj('reporter', ['specDone']);
|
||||
env.addReporter(reporter);
|
||||
await env.execute();
|
||||
|
||||
env.addReporter({ specDone: specExpectations });
|
||||
env.execute(null, done);
|
||||
expect(reporter.specDone).toHaveBeenCalledTimes(1);
|
||||
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) {
|
||||
it('fails', function(done) {
|
||||
it('fails', async function() {
|
||||
const env = new jasmineUnderTest.Env();
|
||||
env.it('a spec', function() {
|
||||
expectations(env);
|
||||
});
|
||||
|
||||
const specExpectations = function(result) {
|
||||
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('');
|
||||
};
|
||||
const reporter = jasmine.createSpyObj('reporter', ['specDone']);
|
||||
env.addReporter(reporter);
|
||||
await env.execute();
|
||||
|
||||
env.addReporter({ specDone: specExpectations });
|
||||
env.execute(null, done);
|
||||
expect(reporter.specDone).toHaveBeenCalledTimes(1);
|
||||
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_();
|
||||
});
|
||||
|
||||
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.addAsyncMatchers({
|
||||
toBeReal: function() {
|
||||
@@ -30,10 +30,10 @@ describe('Custom Async Matchers (Integration)', function() {
|
||||
};
|
||||
|
||||
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.addAsyncMatchers({
|
||||
toBeReal: function() {
|
||||
@@ -56,10 +56,10 @@ describe('Custom Async Matchers (Integration)', function() {
|
||||
};
|
||||
|
||||
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.addAsyncMatchers({
|
||||
toBeReal: function() {
|
||||
@@ -81,10 +81,10 @@ describe('Custom Async Matchers (Integration)', function() {
|
||||
};
|
||||
|
||||
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() {
|
||||
return {
|
||||
compare: function() {
|
||||
@@ -112,10 +112,10 @@ describe('Custom Async Matchers (Integration)', function() {
|
||||
};
|
||||
|
||||
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) {
|
||||
return {
|
||||
compare: function(actual, expected) {
|
||||
@@ -146,6 +146,6 @@ describe('Custom Async Matchers (Integration)', function() {
|
||||
};
|
||||
|
||||
env.addReporter({ specDone: specExpectations });
|
||||
env.execute(null, done);
|
||||
await env.execute();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -10,7 +10,7 @@ describe('Custom Matchers (Integration)', function() {
|
||||
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.addMatchers({
|
||||
matcherForSpec: function() {
|
||||
@@ -37,20 +37,18 @@ describe('Custom Matchers (Integration)', function() {
|
||||
});
|
||||
|
||||
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.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.addMatchers({
|
||||
toBeReal: function() {
|
||||
@@ -65,15 +63,16 @@ describe('Custom Matchers (Integration)', function() {
|
||||
env.expect(true).toBeReal();
|
||||
});
|
||||
|
||||
const specExpectations = function(result) {
|
||||
expect(result.status).toEqual('passed');
|
||||
};
|
||||
const reporter = jasmine.createSpyObj('reporter', ['specDone']);
|
||||
env.addReporter(reporter);
|
||||
await env.execute();
|
||||
|
||||
env.addReporter({ specDone: specExpectations });
|
||||
env.execute(null, done);
|
||||
expect(reporter.specDone).toHaveBeenCalledTimes(1);
|
||||
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() {
|
||||
const customEqualityFn = function(a, b) {
|
||||
// All "foo*" strings match each other.
|
||||
@@ -99,15 +98,16 @@ describe('Custom Matchers (Integration)', function() {
|
||||
.toEqual(jasmineUnderTest.arrayWithExactContents(['fooBar']));
|
||||
});
|
||||
|
||||
const specExpectations = function(result) {
|
||||
expect(result.status).toEqual('passed');
|
||||
};
|
||||
const reporter = jasmine.createSpyObj('reporter', ['specDone']);
|
||||
env.addReporter(reporter);
|
||||
await env.execute();
|
||||
|
||||
env.addReporter({ specDone: specExpectations });
|
||||
env.execute(null, done);
|
||||
expect(reporter.specDone).toHaveBeenCalledTimes(1);
|
||||
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() {
|
||||
const customEqualityFn = function(a, b) {
|
||||
// "foo" is not equal to anything
|
||||
@@ -120,18 +120,19 @@ describe('Custom Matchers (Integration)', function() {
|
||||
env.expect({ foo: 'foo' }).toEqual({ foo: 'foo' });
|
||||
});
|
||||
|
||||
const specExpectations = function(result) {
|
||||
expect(result.status).toEqual('failed');
|
||||
expect(result.failedExpectations[0].message).toEqual(
|
||||
"Expected $.foo = 'foo' to equal 'foo'."
|
||||
);
|
||||
};
|
||||
const reporter = jasmine.createSpyObj('reporter', ['specDone']);
|
||||
env.addReporter(reporter);
|
||||
await env.execute();
|
||||
|
||||
env.addReporter({ specDone: specExpectations });
|
||||
env.execute(null, done);
|
||||
expect(reporter.specDone).toHaveBeenCalledTimes(1);
|
||||
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.addMatchers({
|
||||
toBeReal: function() {
|
||||
@@ -149,15 +150,16 @@ describe('Custom Matchers (Integration)', function() {
|
||||
env.expect(true).not.toBeReal();
|
||||
});
|
||||
|
||||
const specExpectations = function(result) {
|
||||
expect(result.status).toEqual('passed');
|
||||
};
|
||||
const reporter = jasmine.createSpyObj('reporter', ['specDone']);
|
||||
env.addReporter(reporter);
|
||||
await env.execute();
|
||||
|
||||
env.addReporter({ specDone: specExpectations });
|
||||
env.execute(null, done);
|
||||
expect(reporter.specDone).toHaveBeenCalledTimes(1);
|
||||
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.addMatchers({
|
||||
toBeReal: function() {
|
||||
@@ -172,17 +174,18 @@ describe('Custom Matchers (Integration)', function() {
|
||||
env.expect('a').toBeReal();
|
||||
});
|
||||
|
||||
const specExpectations = function(result) {
|
||||
expect(result.failedExpectations[0].message).toEqual(
|
||||
"Expected 'a' to be real."
|
||||
);
|
||||
};
|
||||
const reporter = jasmine.createSpyObj('reporter', ['specDone']);
|
||||
env.addReporter(reporter);
|
||||
await env.execute();
|
||||
|
||||
env.addReporter({ specDone: specExpectations });
|
||||
env.execute(null, done);
|
||||
expect(reporter.specDone).toHaveBeenCalledTimes(1);
|
||||
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
|
||||
.createSpy('argument spy')
|
||||
.and.returnValue({ pass: true });
|
||||
@@ -199,17 +202,13 @@ describe('Custom Matchers (Integration)', function() {
|
||||
env.expect(true).toBeReal('arg1', 'arg2');
|
||||
});
|
||||
|
||||
const specExpectations = function() {
|
||||
expect(argumentSpy).toHaveBeenCalledWith(true);
|
||||
expect(argumentSpy).toHaveBeenCalledWith(true, 'arg');
|
||||
expect(argumentSpy).toHaveBeenCalledWith(true, 'arg1', 'arg2');
|
||||
};
|
||||
|
||||
env.addReporter({ specDone: specExpectations });
|
||||
env.execute(null, done);
|
||||
await env.execute();
|
||||
expect(argumentSpy).toHaveBeenCalledWith(true);
|
||||
expect(argumentSpy).toHaveBeenCalledWith(true, 'arg');
|
||||
expect(argumentSpy).toHaveBeenCalledWith(true, 'arg1', 'arg2');
|
||||
});
|
||||
|
||||
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() {
|
||||
return {
|
||||
compare: function() {
|
||||
@@ -229,17 +228,13 @@ describe('Custom Matchers (Integration)', function() {
|
||||
env.expect(true).toBeReal();
|
||||
});
|
||||
|
||||
const specExpectations = function() {
|
||||
expect(matcherFactorySpy).toHaveBeenCalledWith(
|
||||
jasmine.any(jasmineUnderTest.MatchersUtil)
|
||||
);
|
||||
};
|
||||
|
||||
env.addReporter({ specDone: specExpectations });
|
||||
env.execute(null, done);
|
||||
await env.execute();
|
||||
expect(matcherFactorySpy).toHaveBeenCalledWith(
|
||||
jasmine.any(jasmineUnderTest.MatchersUtil)
|
||||
);
|
||||
});
|
||||
|
||||
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) {
|
||||
return {
|
||||
compare: function(actual, expected) {
|
||||
@@ -262,12 +257,13 @@ describe('Custom Matchers (Integration)', function() {
|
||||
env.expect([1, 2]).toBeArrayWithFirstElement('1');
|
||||
});
|
||||
|
||||
const specExpectations = function(result) {
|
||||
expect(customEqualityFn).toHaveBeenCalledWith(1, '1');
|
||||
expect(result.failedExpectations).toEqual([]);
|
||||
};
|
||||
const reporter = jasmine.createSpyObj('reporter', ['specDone']);
|
||||
env.addReporter(reporter);
|
||||
await env.execute();
|
||||
|
||||
env.addReporter({ specDone: specExpectations });
|
||||
env.execute(null, done);
|
||||
expect(reporter.specDone).toHaveBeenCalledTimes(1);
|
||||
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 });
|
||||
});
|
||||
|
||||
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.addCustomObjectFormatter(function(obj) {
|
||||
return 'custom(' + obj + ')';
|
||||
@@ -22,21 +22,19 @@ describe('Custom object formatters', function() {
|
||||
const specDone = function(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.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.expect(42).toBeUndefined();
|
||||
});
|
||||
@@ -57,18 +55,16 @@ describe('Custom object formatters', function() {
|
||||
const specDone = function(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.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() {
|
||||
|
||||
@@ -33,6 +33,67 @@ describe('Default Spy Strategy (Integration)', function() {
|
||||
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() {
|
||||
env.it('spec', function() {
|
||||
const a = env.createSpy('a');
|
||||
|
||||
@@ -10,7 +10,7 @@ describe('Deprecation (integration)', function() {
|
||||
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']);
|
||||
env.addReporter(reporter);
|
||||
spyOn(console, 'error');
|
||||
@@ -20,24 +20,23 @@ describe('Deprecation (integration)', function() {
|
||||
});
|
||||
env.it('a spec', function() {});
|
||||
|
||||
env.execute(null, function() {
|
||||
expect(reporter.jasmineDone).toHaveBeenCalledWith(
|
||||
jasmine.objectContaining({
|
||||
deprecationWarnings: [
|
||||
jasmine.objectContaining({
|
||||
message: jasmine.stringMatching(/^the message/)
|
||||
})
|
||||
]
|
||||
})
|
||||
);
|
||||
expect(console.error).toHaveBeenCalledWith(
|
||||
jasmine.stringMatching(/^DEPRECATION: the message/)
|
||||
);
|
||||
done();
|
||||
});
|
||||
await env.execute();
|
||||
|
||||
expect(reporter.jasmineDone).toHaveBeenCalledWith(
|
||||
jasmine.objectContaining({
|
||||
deprecationWarnings: [
|
||||
jasmine.objectContaining({
|
||||
message: jasmine.stringMatching(/^the message/)
|
||||
})
|
||||
]
|
||||
})
|
||||
);
|
||||
expect(console.error).toHaveBeenCalledWith(
|
||||
jasmine.stringMatching(/^DEPRECATION: the message/)
|
||||
);
|
||||
});
|
||||
|
||||
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']);
|
||||
env.addReporter(reporter);
|
||||
spyOn(console, 'error');
|
||||
@@ -49,26 +48,23 @@ describe('Deprecation (integration)', function() {
|
||||
env.it('a spec', function() {});
|
||||
});
|
||||
|
||||
env.execute(null, function() {
|
||||
expect(reporter.suiteDone).toHaveBeenCalledWith(
|
||||
jasmine.objectContaining({
|
||||
deprecationWarnings: [
|
||||
jasmine.objectContaining({
|
||||
message: jasmine.stringMatching(/^the message/)
|
||||
})
|
||||
]
|
||||
})
|
||||
);
|
||||
expect(console.error).toHaveBeenCalledWith(
|
||||
jasmine.stringMatching(
|
||||
/^DEPRECATION: the message \(in suite: a suite\)/
|
||||
)
|
||||
);
|
||||
done();
|
||||
});
|
||||
await env.execute();
|
||||
|
||||
expect(reporter.suiteDone).toHaveBeenCalledWith(
|
||||
jasmine.objectContaining({
|
||||
deprecationWarnings: [
|
||||
jasmine.objectContaining({
|
||||
message: jasmine.stringMatching(/^the message/)
|
||||
})
|
||||
]
|
||||
})
|
||||
);
|
||||
expect(console.error).toHaveBeenCalledWith(
|
||||
jasmine.stringMatching(/^DEPRECATION: the message \(in suite: a suite\)/)
|
||||
);
|
||||
});
|
||||
|
||||
it('reports a deprecation on a spec', function(done) {
|
||||
it('reports a deprecation on a spec', async function() {
|
||||
const reporter = jasmine.createSpyObj('reporter', ['specDone']);
|
||||
env.addReporter(reporter);
|
||||
spyOn(console, 'error');
|
||||
@@ -79,26 +75,25 @@ describe('Deprecation (integration)', function() {
|
||||
});
|
||||
});
|
||||
|
||||
env.execute(null, function() {
|
||||
expect(reporter.specDone).toHaveBeenCalledWith(
|
||||
jasmine.objectContaining({
|
||||
deprecationWarnings: [
|
||||
jasmine.objectContaining({
|
||||
message: jasmine.stringMatching(/^the message/)
|
||||
})
|
||||
]
|
||||
})
|
||||
);
|
||||
expect(console.error).toHaveBeenCalledWith(
|
||||
jasmine.stringMatching(
|
||||
/^DEPRECATION: the message \(in spec: a suite a spec\)/
|
||||
)
|
||||
);
|
||||
done();
|
||||
});
|
||||
await env.execute();
|
||||
|
||||
expect(reporter.specDone).toHaveBeenCalledWith(
|
||||
jasmine.objectContaining({
|
||||
deprecationWarnings: [
|
||||
jasmine.objectContaining({
|
||||
message: jasmine.stringMatching(/^the message/)
|
||||
})
|
||||
]
|
||||
})
|
||||
);
|
||||
expect(console.error).toHaveBeenCalledWith(
|
||||
jasmine.stringMatching(
|
||||
/^DEPRECATION: the message \(in spec: a suite a spec\)/
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
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']);
|
||||
env.addReporter(reporter);
|
||||
spyOn(console, 'error');
|
||||
@@ -107,27 +102,26 @@ describe('Deprecation (integration)', function() {
|
||||
env.deprecated('the message', { ignoreRunnable: true });
|
||||
});
|
||||
|
||||
env.execute(null, function() {
|
||||
expect(reporter.jasmineDone).toHaveBeenCalledWith(
|
||||
jasmine.objectContaining({
|
||||
deprecationWarnings: [
|
||||
jasmine.objectContaining({
|
||||
message: jasmine.stringMatching(/^the message/)
|
||||
})
|
||||
]
|
||||
})
|
||||
);
|
||||
expect(console.error).toHaveBeenCalledWith(
|
||||
jasmine.stringMatching(/the message/)
|
||||
);
|
||||
expect(console.error).not.toHaveBeenCalledWith(
|
||||
jasmine.stringMatching(/a spec/)
|
||||
);
|
||||
done();
|
||||
});
|
||||
await env.execute();
|
||||
|
||||
expect(reporter.jasmineDone).toHaveBeenCalledWith(
|
||||
jasmine.objectContaining({
|
||||
deprecationWarnings: [
|
||||
jasmine.objectContaining({
|
||||
message: jasmine.stringMatching(/^the message/)
|
||||
})
|
||||
]
|
||||
})
|
||||
);
|
||||
expect(console.error).toHaveBeenCalledWith(
|
||||
jasmine.stringMatching(/the message/)
|
||||
);
|
||||
expect(console.error).not.toHaveBeenCalledWith(
|
||||
jasmine.stringMatching(/a spec/)
|
||||
);
|
||||
});
|
||||
|
||||
it('includes the stack trace', function(done) {
|
||||
it('includes the stack trace', async function() {
|
||||
const reporter = jasmine.createSpyObj('reporter', ['specDone']);
|
||||
env.addReporter(reporter);
|
||||
spyOn(console, 'error');
|
||||
@@ -138,25 +132,24 @@ describe('Deprecation (integration)', function() {
|
||||
});
|
||||
});
|
||||
|
||||
env.execute(null, function() {
|
||||
expect(reporter.specDone).toHaveBeenCalledWith(
|
||||
jasmine.objectContaining({
|
||||
deprecationWarnings: [
|
||||
jasmine.objectContaining({
|
||||
stack: jasmine.stringMatching(/DeprecationSpec.js/)
|
||||
})
|
||||
]
|
||||
})
|
||||
);
|
||||
expect(console.error).toHaveBeenCalled();
|
||||
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();
|
||||
});
|
||||
await env.execute();
|
||||
|
||||
expect(reporter.specDone).toHaveBeenCalledWith(
|
||||
jasmine.objectContaining({
|
||||
deprecationWarnings: [
|
||||
jasmine.objectContaining({
|
||||
stack: jasmine.stringMatching(/DeprecationSpec.js/)
|
||||
})
|
||||
]
|
||||
})
|
||||
);
|
||||
expect(console.error).toHaveBeenCalled();
|
||||
expect(console.error.calls.argsFor(0)[0].replace(/\n/g, 'NL')).toMatch(
|
||||
/^DEPRECATION: the message \(in spec: a suite a spec\)NL.*DeprecationSpec.js/
|
||||
);
|
||||
});
|
||||
|
||||
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']);
|
||||
env.addReporter(reporter);
|
||||
spyOn(console, 'error');
|
||||
@@ -167,25 +160,24 @@ describe('Deprecation (integration)', function() {
|
||||
});
|
||||
});
|
||||
|
||||
env.execute(null, function() {
|
||||
expect(reporter.specDone).toHaveBeenCalledWith(
|
||||
jasmine.objectContaining({
|
||||
deprecationWarnings: [
|
||||
jasmine.objectContaining({
|
||||
stack: jasmine.falsy()
|
||||
})
|
||||
]
|
||||
})
|
||||
);
|
||||
expect(console.error).toHaveBeenCalled();
|
||||
expect(console.error).not.toHaveBeenCalledWith(
|
||||
jasmine.stringMatching(/DeprecationSpec.js/)
|
||||
);
|
||||
done();
|
||||
});
|
||||
await env.execute();
|
||||
|
||||
expect(reporter.specDone).toHaveBeenCalledWith(
|
||||
jasmine.objectContaining({
|
||||
deprecationWarnings: [
|
||||
jasmine.objectContaining({
|
||||
stack: jasmine.falsy()
|
||||
})
|
||||
]
|
||||
})
|
||||
);
|
||||
expect(console.error).toHaveBeenCalled();
|
||||
expect(console.error).not.toHaveBeenCalledWith(
|
||||
jasmine.stringMatching(/DeprecationSpec.js/)
|
||||
);
|
||||
});
|
||||
|
||||
it('emits a given deprecation only once', function(done) {
|
||||
it('emits a given deprecation only once', async function() {
|
||||
const reporter = jasmine.createSpyObj('reporter', [
|
||||
'specDone',
|
||||
'suiteDone'
|
||||
@@ -205,43 +197,40 @@ describe('Deprecation (integration)', function() {
|
||||
});
|
||||
});
|
||||
|
||||
env.execute(null, function() {
|
||||
expect(reporter.suiteDone).toHaveBeenCalledWith(
|
||||
jasmine.objectContaining({
|
||||
deprecationWarnings: [
|
||||
// only one
|
||||
jasmine.objectContaining({
|
||||
message: jasmine.stringMatching(/^the message/)
|
||||
})
|
||||
]
|
||||
})
|
||||
);
|
||||
expect(reporter.specDone).toHaveBeenCalledWith(
|
||||
jasmine.objectContaining({
|
||||
deprecationWarnings: [
|
||||
// only the other one
|
||||
jasmine.objectContaining({
|
||||
message: jasmine.stringMatching(/^a different message/)
|
||||
})
|
||||
]
|
||||
})
|
||||
);
|
||||
expect(console.error).toHaveBeenCalledTimes(2);
|
||||
expect(console.error).toHaveBeenCalledWith(
|
||||
jasmine.stringMatching(
|
||||
/^DEPRECATION: the message \(in suite: a suite\)/
|
||||
)
|
||||
);
|
||||
expect(console.error).toHaveBeenCalledWith(
|
||||
jasmine.stringMatching(
|
||||
/^DEPRECATION: a different message \(in spec: a suite a spec\)/
|
||||
)
|
||||
);
|
||||
done();
|
||||
});
|
||||
await env.execute();
|
||||
|
||||
expect(reporter.suiteDone).toHaveBeenCalledWith(
|
||||
jasmine.objectContaining({
|
||||
deprecationWarnings: [
|
||||
// only one
|
||||
jasmine.objectContaining({
|
||||
message: jasmine.stringMatching(/^the message/)
|
||||
})
|
||||
]
|
||||
})
|
||||
);
|
||||
expect(reporter.specDone).toHaveBeenCalledWith(
|
||||
jasmine.objectContaining({
|
||||
deprecationWarnings: [
|
||||
// only the other one
|
||||
jasmine.objectContaining({
|
||||
message: jasmine.stringMatching(/^a different message/)
|
||||
})
|
||||
]
|
||||
})
|
||||
);
|
||||
expect(console.error).toHaveBeenCalledTimes(2);
|
||||
expect(console.error).toHaveBeenCalledWith(
|
||||
jasmine.stringMatching(/^DEPRECATION: the message \(in suite: a suite\)/)
|
||||
);
|
||||
expect(console.error).toHaveBeenCalledWith(
|
||||
jasmine.stringMatching(
|
||||
/^DEPRECATION: a different message \(in spec: a suite a spec\)/
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
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', [
|
||||
'specDone',
|
||||
'suiteDone'
|
||||
@@ -262,46 +251,45 @@ describe('Deprecation (integration)', function() {
|
||||
});
|
||||
});
|
||||
|
||||
env.execute(null, function() {
|
||||
expect(reporter.suiteDone).toHaveBeenCalledWith(
|
||||
jasmine.objectContaining({
|
||||
deprecationWarnings: [
|
||||
jasmine.objectContaining({
|
||||
message: jasmine.stringMatching(/^the message/)
|
||||
}),
|
||||
jasmine.objectContaining({
|
||||
message: jasmine.stringMatching(/^the message/)
|
||||
})
|
||||
]
|
||||
})
|
||||
);
|
||||
expect(reporter.specDone).toHaveBeenCalledWith(
|
||||
jasmine.objectContaining({
|
||||
deprecationWarnings: [
|
||||
jasmine.objectContaining({
|
||||
message: jasmine.stringMatching(/^the message/)
|
||||
})
|
||||
]
|
||||
})
|
||||
);
|
||||
expect(console.error).toHaveBeenCalledTimes(3);
|
||||
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(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();
|
||||
});
|
||||
await env.execute();
|
||||
|
||||
expect(reporter.suiteDone).toHaveBeenCalledWith(
|
||||
jasmine.objectContaining({
|
||||
deprecationWarnings: [
|
||||
jasmine.objectContaining({
|
||||
message: jasmine.stringMatching(/^the message/)
|
||||
}),
|
||||
jasmine.objectContaining({
|
||||
message: jasmine.stringMatching(/^the message/)
|
||||
})
|
||||
]
|
||||
})
|
||||
);
|
||||
expect(reporter.specDone).toHaveBeenCalledWith(
|
||||
jasmine.objectContaining({
|
||||
deprecationWarnings: [
|
||||
jasmine.objectContaining({
|
||||
message: jasmine.stringMatching(/^the message/)
|
||||
})
|
||||
]
|
||||
})
|
||||
);
|
||||
expect(console.error).toHaveBeenCalledTimes(3);
|
||||
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(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\)/
|
||||
);
|
||||
});
|
||||
|
||||
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']);
|
||||
env.addReporter(reporter);
|
||||
spyOn(console, 'error');
|
||||
@@ -309,20 +297,19 @@ describe('Deprecation (integration)', function() {
|
||||
env.deprecated('the message');
|
||||
env.it('a spec', function() {});
|
||||
|
||||
env.execute(null, function() {
|
||||
expect(reporter.jasmineDone).toHaveBeenCalledWith(
|
||||
jasmine.objectContaining({
|
||||
deprecationWarnings: [
|
||||
jasmine.objectContaining({
|
||||
message: jasmine.stringMatching(/^the message/)
|
||||
})
|
||||
]
|
||||
})
|
||||
);
|
||||
expect(console.error).toHaveBeenCalledWith(
|
||||
jasmine.stringMatching(/^DEPRECATION: the message/)
|
||||
);
|
||||
done();
|
||||
});
|
||||
await env.execute();
|
||||
|
||||
expect(reporter.jasmineDone).toHaveBeenCalledWith(
|
||||
jasmine.objectContaining({
|
||||
deprecationWarnings: [
|
||||
jasmine.objectContaining({
|
||||
message: jasmine.stringMatching(/^the message/)
|
||||
})
|
||||
]
|
||||
})
|
||||
);
|
||||
expect(console.error).toHaveBeenCalledWith(
|
||||
jasmine.stringMatching(/^DEPRECATION: the message/)
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -10,156 +10,158 @@ describe('Matchers (Integration)', function() {
|
||||
});
|
||||
|
||||
function verifyPasses(expectations) {
|
||||
it('passes', function(done) {
|
||||
it('passes', async function() {
|
||||
env.it('a spec', function() {
|
||||
expectations(env);
|
||||
});
|
||||
|
||||
const specExpectations = function(result) {
|
||||
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();
|
||||
};
|
||||
const reporter = jasmine.createSpyObj('reporter', ['specDone']);
|
||||
env.addReporter(reporter);
|
||||
await env.execute();
|
||||
|
||||
env.addReporter({ specDone: specExpectations });
|
||||
env.execute(null, done);
|
||||
expect(reporter.specDone).toHaveBeenCalledTimes(1);
|
||||
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) {
|
||||
it('fails', function(done) {
|
||||
it('fails', async function() {
|
||||
env.it('a spec', function() {
|
||||
expectations(env);
|
||||
});
|
||||
|
||||
const specExpectations = function(result) {
|
||||
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('');
|
||||
};
|
||||
const reporter = jasmine.createSpyObj('reporter', ['specDone']);
|
||||
env.addReporter(reporter);
|
||||
await env.execute();
|
||||
|
||||
env.addReporter({ specDone: specExpectations });
|
||||
env.execute(null, done);
|
||||
expect(reporter.specDone).toHaveBeenCalledTimes(1);
|
||||
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) {
|
||||
it('uses custom object formatters', function(done) {
|
||||
it('uses custom object formatters', async function() {
|
||||
env.it('a spec', function() {
|
||||
env.addCustomObjectFormatter(config.formatter);
|
||||
config.expectations(env);
|
||||
});
|
||||
|
||||
const specExpectations = function(result) {
|
||||
expect(result.status).toEqual('failed');
|
||||
expect(result.failedExpectations.length)
|
||||
.withContext('Number of failed expectations')
|
||||
.toEqual(1);
|
||||
expect(result.failedExpectations[0].message).toEqual(
|
||||
config.expectedMessage
|
||||
);
|
||||
};
|
||||
const reporter = jasmine.createSpyObj('reporter', ['specDone']);
|
||||
env.addReporter(reporter);
|
||||
await env.execute();
|
||||
|
||||
env.addReporter({ specDone: specExpectations });
|
||||
env.execute(null, done);
|
||||
expect(reporter.specDone).toHaveBeenCalledTimes(1);
|
||||
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) {
|
||||
it('passes', function(done) {
|
||||
it('passes', async function() {
|
||||
env.it('a spec', function() {
|
||||
return expectations(env);
|
||||
});
|
||||
|
||||
const specExpectations = function(result) {
|
||||
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();
|
||||
};
|
||||
const reporter = jasmine.createSpyObj('reporter', ['specDone']);
|
||||
env.addReporter(reporter);
|
||||
await env.execute();
|
||||
|
||||
env.addReporter({ specDone: specExpectations });
|
||||
env.execute(null, done);
|
||||
expect(reporter.specDone).toHaveBeenCalledTimes(1);
|
||||
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) {
|
||||
it('fails', function(done) {
|
||||
it('fails', async function() {
|
||||
env.it('a spec', function() {
|
||||
return expectations(env);
|
||||
});
|
||||
|
||||
const specExpectations = function(result) {
|
||||
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('');
|
||||
};
|
||||
const reporter = jasmine.createSpyObj('reporter', ['specDone']);
|
||||
env.addReporter(reporter);
|
||||
await env.execute();
|
||||
|
||||
env.addReporter({ specDone: specExpectations });
|
||||
env.execute(null, done);
|
||||
expect(reporter.specDone).toHaveBeenCalledTimes(1);
|
||||
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) {
|
||||
it('uses custom object formatters', function(done) {
|
||||
it('uses custom object formatters', async function() {
|
||||
const env = new jasmineUnderTest.Env();
|
||||
env.it('a spec', function() {
|
||||
env.addCustomObjectFormatter(config.formatter);
|
||||
return config.expectations(env);
|
||||
});
|
||||
|
||||
const specExpectations = function(result) {
|
||||
expect(result.status).toEqual('failed');
|
||||
expect(result.failedExpectations.length)
|
||||
.withContext('Number of failed expectations')
|
||||
.toEqual(1);
|
||||
expect(result.failedExpectations[0].message).toEqual(
|
||||
config.expectedMessage
|
||||
);
|
||||
};
|
||||
const reporter = jasmine.createSpyObj('reporter', ['specDone']);
|
||||
env.addReporter(reporter);
|
||||
await env.execute();
|
||||
|
||||
env.addReporter({ specDone: specExpectations });
|
||||
env.execute(null, done);
|
||||
expect(reporter.specDone).toHaveBeenCalledTimes(1);
|
||||
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
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -347,7 +349,7 @@ describe('Matchers (Integration)', function() {
|
||||
});
|
||||
|
||||
verifyFailsAsync(function(env) {
|
||||
return env.expectAsync(Promise.reject()).toBeResolved();
|
||||
return env.expectAsync(Promise.reject(new Error('nope'))).toBeResolved();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -608,19 +610,13 @@ describe('Matchers (Integration)', function() {
|
||||
});
|
||||
|
||||
describe('toHaveClass', function() {
|
||||
beforeEach(function() {
|
||||
this.domHelpers = jasmine.getEnv().domHelpers();
|
||||
});
|
||||
|
||||
verifyPasses(function(env) {
|
||||
const domHelpers = jasmine.getEnv().domHelpers();
|
||||
const el = domHelpers.createElementWithClassName('foo');
|
||||
const el = specHelpers.domHelpers.createElementWithClassName('foo');
|
||||
env.expect(el).toHaveClass('foo');
|
||||
});
|
||||
|
||||
verifyFails(function(env) {
|
||||
const domHelpers = jasmine.getEnv().domHelpers();
|
||||
const el = domHelpers.createElementWithClassName('foo');
|
||||
const el = specHelpers.domHelpers.createElementWithClassName('foo');
|
||||
env.expect(el).toHaveClass('bar');
|
||||
});
|
||||
});
|
||||
@@ -753,76 +749,79 @@ describe('Matchers (Integration)', 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() {
|
||||
return env.expectAsync(Promise.resolve()).already.toBeRejected();
|
||||
});
|
||||
|
||||
const specExpectations = function(result) {
|
||||
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('');
|
||||
};
|
||||
const reporter = jasmine.createSpyObj('reporter', ['specDone']);
|
||||
env.addReporter(reporter);
|
||||
await env.execute();
|
||||
|
||||
env.addReporter({ specDone: specExpectations });
|
||||
env.execute(null, done);
|
||||
expect(reporter.specDone).toHaveBeenCalledTimes(1);
|
||||
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() {
|
||||
return env
|
||||
.expectAsync(Promise.reject(new Error('nope')))
|
||||
.already.toBeResolved();
|
||||
});
|
||||
|
||||
const specExpectations = function(result) {
|
||||
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('');
|
||||
};
|
||||
const reporter = jasmine.createSpyObj('reporter', ['specDone']);
|
||||
env.addReporter(reporter);
|
||||
await env.execute();
|
||||
|
||||
env.addReporter({ specDone: specExpectations });
|
||||
env.execute(null, done);
|
||||
expect(reporter.specDone).toHaveBeenCalledTimes(1);
|
||||
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() {});
|
||||
|
||||
env.it('a spec', function() {
|
||||
return env.expectAsync(promise).already.toBeResolved();
|
||||
});
|
||||
|
||||
const specExpectations = function(result) {
|
||||
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('');
|
||||
};
|
||||
const reporter = jasmine.createSpyObj('reporter', ['specDone']);
|
||||
env.addReporter(reporter);
|
||||
await env.execute();
|
||||
|
||||
env.addReporter({ specDone: specExpectations });
|
||||
env.execute(null, done);
|
||||
expect(reporter.specDone).toHaveBeenCalledTimes(1);
|
||||
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('');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
162
spec/core/integration/ParallelSpec.js
Normal file
162
spec/core/integration/ParallelSpec.js
Normal file
@@ -0,0 +1,162 @@
|
||||
describe('Support for parallel execution', function() {
|
||||
let env;
|
||||
|
||||
beforeEach(function() {
|
||||
env = new jasmineUnderTest.Env();
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
env.cleanup_();
|
||||
});
|
||||
|
||||
it('removes specs and suites from previous batches', async function() {
|
||||
env.describe('a suite', function() {
|
||||
env.it('a spec', function() {});
|
||||
});
|
||||
env.it('a spec', function() {});
|
||||
|
||||
await env.execute();
|
||||
env.parallelReset();
|
||||
|
||||
env.describe('a suite in a new batch', function() {
|
||||
env.it('a spec in a new batch', function() {});
|
||||
});
|
||||
const reporter = jasmine.createSpyObj('reporter', [
|
||||
'suiteDone',
|
||||
'specDone'
|
||||
]);
|
||||
env.addReporter(reporter);
|
||||
|
||||
await env.execute();
|
||||
|
||||
expect(reporter.suiteDone).toHaveBeenCalledOnceWith(
|
||||
jasmine.objectContaining({
|
||||
fullName: 'a suite in a new batch'
|
||||
})
|
||||
);
|
||||
expect(reporter.specDone).toHaveBeenCalledOnceWith(
|
||||
jasmine.objectContaining({
|
||||
fullName: 'a suite in a new batch a spec in a new batch'
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
it('preserves top-level before and after fns from previous batches', async function() {
|
||||
const beforeAll = jasmine.createSpy('beforeAll');
|
||||
const beforeEach = jasmine.createSpy('beforeEach');
|
||||
const afterEach = jasmine.createSpy('afterEach');
|
||||
const afterAll = jasmine.createSpy('afterAll');
|
||||
env.beforeAll(beforeAll);
|
||||
env.beforeEach(beforeEach);
|
||||
env.afterEach(afterEach);
|
||||
env.afterAll(afterAll);
|
||||
|
||||
env.parallelReset();
|
||||
env.it('a spec', function() {});
|
||||
await env.execute();
|
||||
|
||||
expect(beforeAll).toHaveBeenCalled();
|
||||
expect(beforeEach).toHaveBeenCalled();
|
||||
expect(afterEach).toHaveBeenCalled();
|
||||
expect(afterAll).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('does not remember focused runables from previous batches', async function() {
|
||||
env.fit('a focused spec', function() {});
|
||||
env.parallelReset();
|
||||
env.it('a spec', function() {});
|
||||
const reporter = jasmine.createSpyObj('reporter', [
|
||||
'specDone',
|
||||
'jasmineDone'
|
||||
]);
|
||||
env.addReporter(reporter);
|
||||
await env.execute();
|
||||
|
||||
expect(reporter.specDone).toHaveBeenCalledOnceWith(
|
||||
jasmine.objectContaining({
|
||||
fullName: 'a spec',
|
||||
status: 'passed'
|
||||
})
|
||||
);
|
||||
expect(reporter.jasmineDone).toHaveBeenCalledWith(
|
||||
jasmine.objectContaining({ overallStatus: 'passed' })
|
||||
);
|
||||
});
|
||||
|
||||
it('does not remember failures from previous batches', async function() {
|
||||
env.it('a failing spec', function() {
|
||||
env.expect(true).toBe(false);
|
||||
});
|
||||
await env.execute();
|
||||
env.parallelReset();
|
||||
env.it('a spec', function() {});
|
||||
const reporter = jasmine.createSpyObj('reporter', [
|
||||
'specDone',
|
||||
'jasmineDone'
|
||||
]);
|
||||
env.addReporter(reporter);
|
||||
await env.execute();
|
||||
|
||||
expect(reporter.jasmineDone).toHaveBeenCalledWith(
|
||||
jasmine.objectContaining({ overallStatus: 'passed' })
|
||||
);
|
||||
});
|
||||
|
||||
it('reports errors thrown from describe', async function() {
|
||||
const reporter = jasmine.createSpyObj('reporter', ['suiteDone']);
|
||||
env.addReporter(reporter);
|
||||
|
||||
env.describe('borken', function() {
|
||||
throw new Error('nope');
|
||||
});
|
||||
await env.execute();
|
||||
|
||||
expect(reporter.suiteDone).toHaveBeenCalledWith(
|
||||
jasmine.objectContaining({
|
||||
description: 'borken',
|
||||
status: 'failed',
|
||||
failedExpectations: [
|
||||
jasmine.objectContaining({
|
||||
message: jasmine.stringContaining('Error: nope')
|
||||
})
|
||||
]
|
||||
})
|
||||
);
|
||||
|
||||
// Errors in subsequent suites should also be reported
|
||||
reporter.suiteDone.calls.reset();
|
||||
env.parallelReset();
|
||||
env.describe('zarro boogs', function() {
|
||||
throw new Error('nor that either');
|
||||
});
|
||||
await env.execute();
|
||||
|
||||
expect(reporter.suiteDone).toHaveBeenCalledOnceWith(
|
||||
jasmine.objectContaining({
|
||||
description: 'zarro boogs',
|
||||
status: 'failed',
|
||||
failedExpectations: [
|
||||
jasmine.objectContaining({
|
||||
message: jasmine.stringContaining('Error: nor that either')
|
||||
})
|
||||
]
|
||||
})
|
||||
);
|
||||
|
||||
// Failure state should not persist across resets
|
||||
reporter.suiteDone.calls.reset();
|
||||
env.parallelReset();
|
||||
env.describe('actually works', function() {
|
||||
env.it('a spec', function() {});
|
||||
});
|
||||
await env.execute();
|
||||
|
||||
expect(reporter.suiteDone).toHaveBeenCalledOnceWith(
|
||||
jasmine.objectContaining({
|
||||
description: 'actually works',
|
||||
status: 'passed',
|
||||
failedExpectations: []
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -2,7 +2,7 @@ describe('spec running', function() {
|
||||
let env;
|
||||
|
||||
beforeEach(function() {
|
||||
jasmine.getEnv().registerIntegrationMatchers();
|
||||
specHelpers.registerIntegrationMatchers();
|
||||
env = new jasmineUnderTest.Env();
|
||||
env.configure({ random: false });
|
||||
});
|
||||
@@ -30,7 +30,7 @@ describe('spec running', function() {
|
||||
expect(it4.id).toEqual('spec4');
|
||||
});
|
||||
|
||||
it('nested suites', function(done) {
|
||||
it('nested suites', async function() {
|
||||
let foo = 0;
|
||||
let bar = 0;
|
||||
let baz = 0;
|
||||
@@ -61,16 +61,15 @@ describe('spec running', function() {
|
||||
expect(baz).toEqual(0);
|
||||
expect(quux).toEqual(0);
|
||||
|
||||
env.execute(null, function() {
|
||||
expect(foo).toEqual(1);
|
||||
expect(bar).toEqual(1);
|
||||
expect(baz).toEqual(1);
|
||||
expect(quux).toEqual(1);
|
||||
done();
|
||||
});
|
||||
await env.execute();
|
||||
|
||||
expect(foo).toEqual(1);
|
||||
expect(bar).toEqual(1);
|
||||
expect(baz).toEqual(1);
|
||||
expect(quux).toEqual(1);
|
||||
});
|
||||
|
||||
it('should permit nested describes', function(done) {
|
||||
it('should permit nested describes', async function() {
|
||||
const actions = [];
|
||||
|
||||
env.beforeEach(function() {
|
||||
@@ -127,42 +126,41 @@ describe('spec running', function() {
|
||||
});
|
||||
});
|
||||
|
||||
env.execute(null, function() {
|
||||
const expected = [
|
||||
'topSuite beforeEach',
|
||||
'outer beforeEach',
|
||||
'outer it 1',
|
||||
'outer afterEach',
|
||||
'topSuite afterEach',
|
||||
await env.execute();
|
||||
|
||||
'topSuite beforeEach',
|
||||
'outer beforeEach',
|
||||
'inner 1 beforeEach',
|
||||
'inner 1 it',
|
||||
'inner 1 afterEach',
|
||||
'outer afterEach',
|
||||
'topSuite afterEach',
|
||||
const expected = [
|
||||
'topSuite beforeEach',
|
||||
'outer beforeEach',
|
||||
'outer it 1',
|
||||
'outer afterEach',
|
||||
'topSuite afterEach',
|
||||
|
||||
'topSuite beforeEach',
|
||||
'outer beforeEach',
|
||||
'outer it 2',
|
||||
'outer afterEach',
|
||||
'topSuite afterEach',
|
||||
'topSuite beforeEach',
|
||||
'outer beforeEach',
|
||||
'inner 1 beforeEach',
|
||||
'inner 1 it',
|
||||
'inner 1 afterEach',
|
||||
'outer afterEach',
|
||||
'topSuite afterEach',
|
||||
|
||||
'topSuite beforeEach',
|
||||
'outer beforeEach',
|
||||
'inner 2 beforeEach',
|
||||
'inner 2 it',
|
||||
'inner 2 afterEach',
|
||||
'outer afterEach',
|
||||
'topSuite afterEach'
|
||||
];
|
||||
expect(actions).toEqual(expected);
|
||||
done();
|
||||
});
|
||||
'topSuite beforeEach',
|
||||
'outer beforeEach',
|
||||
'outer it 2',
|
||||
'outer afterEach',
|
||||
'topSuite afterEach',
|
||||
|
||||
'topSuite beforeEach',
|
||||
'outer beforeEach',
|
||||
'inner 2 beforeEach',
|
||||
'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 = [];
|
||||
|
||||
env.beforeAll(function() {
|
||||
@@ -219,28 +217,27 @@ describe('spec running', function() {
|
||||
});
|
||||
});
|
||||
|
||||
env.execute(null, function() {
|
||||
const expected = [
|
||||
'runner beforeAll1',
|
||||
'runner beforeAll2',
|
||||
'runner beforeEach1',
|
||||
'runner beforeEach2',
|
||||
'beforeEach1',
|
||||
'beforeEach2',
|
||||
'outer it 1',
|
||||
'afterEach2',
|
||||
'afterEach1',
|
||||
'runner afterEach2',
|
||||
'runner afterEach1',
|
||||
'runner afterAll2',
|
||||
'runner afterAll1'
|
||||
];
|
||||
expect(actions).toEqual(expected);
|
||||
done();
|
||||
});
|
||||
await env.execute();
|
||||
|
||||
const expected = [
|
||||
'runner beforeAll1',
|
||||
'runner beforeAll2',
|
||||
'runner beforeEach1',
|
||||
'runner beforeEach2',
|
||||
'beforeEach1',
|
||||
'beforeEach2',
|
||||
'outer it 1',
|
||||
'afterEach2',
|
||||
'afterEach1',
|
||||
'runner afterEach2',
|
||||
'runner afterEach1',
|
||||
'runner afterAll2',
|
||||
'runner afterAll1'
|
||||
];
|
||||
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 = [];
|
||||
|
||||
env.beforeAll(function() {
|
||||
@@ -281,24 +278,23 @@ describe('spec running', function() {
|
||||
});
|
||||
});
|
||||
|
||||
env.execute(null, function() {
|
||||
const expected = [
|
||||
'runner beforeAll',
|
||||
'inner beforeAll',
|
||||
'runner beforeEach',
|
||||
'inner beforeEach',
|
||||
'it',
|
||||
'inner afterEach',
|
||||
'runner afterEach',
|
||||
'inner afterAll',
|
||||
'runner afterAll'
|
||||
];
|
||||
expect(actions).toEqual(expected);
|
||||
done();
|
||||
});
|
||||
await env.execute();
|
||||
|
||||
const expected = [
|
||||
'runner beforeAll',
|
||||
'inner beforeAll',
|
||||
'runner beforeEach',
|
||||
'inner beforeEach',
|
||||
'it',
|
||||
'inner afterEach',
|
||||
'runner afterEach',
|
||||
'inner afterAll',
|
||||
'runner afterAll'
|
||||
];
|
||||
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 = [];
|
||||
let spec;
|
||||
let spec2;
|
||||
@@ -345,30 +341,29 @@ describe('spec running', function() {
|
||||
});
|
||||
});
|
||||
|
||||
env.execute([spec2.id, spec.id], function() {
|
||||
const expected = [
|
||||
'runner beforeAll',
|
||||
'inner beforeAll',
|
||||
'runner beforeEach',
|
||||
'inner beforeEach',
|
||||
'it2',
|
||||
'inner afterEach',
|
||||
'runner afterEach',
|
||||
await env.execute([spec2.id, spec.id]);
|
||||
|
||||
'runner beforeEach',
|
||||
'inner beforeEach',
|
||||
'it',
|
||||
'inner afterEach',
|
||||
'runner afterEach',
|
||||
'inner afterAll',
|
||||
'runner afterAll'
|
||||
];
|
||||
expect(actions).toEqual(expected);
|
||||
done();
|
||||
});
|
||||
const expected = [
|
||||
'runner beforeAll',
|
||||
'inner beforeAll',
|
||||
'runner beforeEach',
|
||||
'inner beforeEach',
|
||||
'it2',
|
||||
'inner afterEach',
|
||||
'runner afterEach',
|
||||
|
||||
'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 = [];
|
||||
|
||||
env.fdescribe('Suite', function() {
|
||||
@@ -383,14 +378,13 @@ describe('spec running', function() {
|
||||
});
|
||||
});
|
||||
|
||||
env.execute(null, function() {
|
||||
expect(actions).toEqual(['beforeAll', 'spec', 'afterAll']);
|
||||
done();
|
||||
});
|
||||
await env.execute();
|
||||
|
||||
expect(actions).toEqual(['beforeAll', 'spec', 'afterAll']);
|
||||
});
|
||||
|
||||
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 = [];
|
||||
env.beforeAll(function() {
|
||||
actions.push('beforeAll');
|
||||
@@ -417,24 +411,23 @@ describe('spec running', function() {
|
||||
});
|
||||
});
|
||||
|
||||
env.execute(null, function() {
|
||||
const expected = [
|
||||
'beforeAll',
|
||||
'beforeEach',
|
||||
'spec in fdescribe',
|
||||
'afterEach',
|
||||
await env.execute();
|
||||
|
||||
'beforeEach',
|
||||
'focused spec',
|
||||
'afterEach',
|
||||
'afterAll'
|
||||
];
|
||||
expect(actions).toEqual(expected);
|
||||
done();
|
||||
});
|
||||
const expected = [
|
||||
'beforeAll',
|
||||
'beforeEach',
|
||||
'spec in fdescribe',
|
||||
'afterEach',
|
||||
|
||||
'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 = [];
|
||||
|
||||
env.fdescribe('focused suite', function() {
|
||||
@@ -446,14 +439,13 @@ describe('spec running', function() {
|
||||
});
|
||||
});
|
||||
|
||||
env.execute(null, function() {
|
||||
const expected = ['focused spec'];
|
||||
expect(actions).toEqual(expected);
|
||||
done();
|
||||
});
|
||||
await env.execute();
|
||||
|
||||
const expected = ['focused spec'];
|
||||
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 = [];
|
||||
|
||||
env.fdescribe('focused suite', function() {
|
||||
@@ -467,14 +459,13 @@ describe('spec running', function() {
|
||||
});
|
||||
});
|
||||
|
||||
env.execute(null, function() {
|
||||
const expected = ['inner spec'];
|
||||
expect(actions).toEqual(expected);
|
||||
done();
|
||||
});
|
||||
await env.execute();
|
||||
|
||||
const expected = ['inner spec'];
|
||||
expect(actions).toEqual(expected);
|
||||
});
|
||||
|
||||
it('focused runnables unfocus ancestor focused suites', function(done) {
|
||||
it('focused runnables unfocus ancestor focused suites', async function() {
|
||||
const actions = [];
|
||||
|
||||
env.fdescribe('focused suite', function() {
|
||||
@@ -488,15 +479,14 @@ describe('spec running', function() {
|
||||
});
|
||||
});
|
||||
|
||||
env.execute(null, function() {
|
||||
const expected = ['focused spec'];
|
||||
expect(actions).toEqual(expected);
|
||||
done();
|
||||
});
|
||||
await env.execute();
|
||||
|
||||
const expected = ['focused spec'];
|
||||
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');
|
||||
env.describe('A Suite', function() {
|
||||
env.xdescribe('with a disabled suite', function() {
|
||||
@@ -504,13 +494,12 @@ describe('spec running', function() {
|
||||
});
|
||||
});
|
||||
|
||||
env.execute(null, function() {
|
||||
expect(specInADisabledSuite).not.toHaveBeenCalled();
|
||||
done();
|
||||
});
|
||||
await env.execute();
|
||||
|
||||
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');
|
||||
env.xdescribe('A disabled Suite', function() {
|
||||
// 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.execute(null, function() {
|
||||
expect(shouldNotRun).not.toHaveBeenCalled();
|
||||
done();
|
||||
});
|
||||
await env.execute();
|
||||
|
||||
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'),
|
||||
otherSpec = jasmine.createSpy('otherSpec');
|
||||
|
||||
@@ -539,14 +527,13 @@ describe('spec running', function() {
|
||||
env.it('another spec', otherSpec);
|
||||
});
|
||||
|
||||
env.execute(null, function() {
|
||||
expect(specInADisabledSuite).not.toHaveBeenCalled();
|
||||
expect(otherSpec).toHaveBeenCalled();
|
||||
done();
|
||||
});
|
||||
await env.execute();
|
||||
|
||||
expect(specInADisabledSuite).not.toHaveBeenCalled();
|
||||
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.it('I am a pending spec');
|
||||
});
|
||||
@@ -554,17 +541,16 @@ describe('spec running', function() {
|
||||
|
||||
env.addReporter(reporter);
|
||||
|
||||
env.execute(null, function() {
|
||||
expect(reporter.specDone).toHaveBeenCalledWith(
|
||||
jasmine.objectContaining({
|
||||
status: 'pending'
|
||||
})
|
||||
);
|
||||
done();
|
||||
});
|
||||
await env.execute();
|
||||
|
||||
expect(reporter.specDone).toHaveBeenCalledWith(
|
||||
jasmine.objectContaining({
|
||||
status: 'pending'
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
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 = [],
|
||||
reporter = jasmine.createSpyObj(['specDone', 'suiteDone']);
|
||||
|
||||
@@ -599,24 +585,23 @@ describe('spec running', function() {
|
||||
});
|
||||
|
||||
env.addReporter(reporter);
|
||||
env.execute(null, function() {
|
||||
expect(specs).toEqual([
|
||||
'outer1 inner1 should thingy',
|
||||
'outer1 inner2 should other thingy',
|
||||
'outer2 should xxx'
|
||||
]);
|
||||
expect(reporter.suiteDone).toHaveFailedExpectationsForRunnable(
|
||||
'outer1 inner1',
|
||||
[/inner error/]
|
||||
);
|
||||
expect(reporter.suiteDone).toHaveFailedExpectationsForRunnable('outer1', [
|
||||
/outer error/
|
||||
]);
|
||||
done();
|
||||
});
|
||||
await env.execute();
|
||||
|
||||
expect(specs).toEqual([
|
||||
'outer1 inner1 should thingy',
|
||||
'outer1 inner2 should other thingy',
|
||||
'outer2 should xxx'
|
||||
]);
|
||||
expect(reporter.suiteDone).toHaveFailedExpectationsForRunnable(
|
||||
'outer1 inner1',
|
||||
[/inner error/]
|
||||
);
|
||||
expect(reporter.suiteDone).toHaveFailedExpectationsForRunnable('outer1', [
|
||||
/outer error/
|
||||
]);
|
||||
});
|
||||
|
||||
it('re-enters suites that have no *Alls', function(done) {
|
||||
it('re-enters suites that have no *Alls', async function() {
|
||||
const actions = [];
|
||||
let spec1;
|
||||
let spec2;
|
||||
@@ -636,13 +621,12 @@ describe('spec running', function() {
|
||||
actions.push('spec3');
|
||||
});
|
||||
|
||||
env.execute([spec2.id, spec3.id, spec1.id], function() {
|
||||
expect(actions).toEqual(['spec2', 'spec3', 'spec1']);
|
||||
done();
|
||||
});
|
||||
await env.execute([spec2.id, spec3.id, spec1.id]);
|
||||
|
||||
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', async function() {
|
||||
const actions = [];
|
||||
let spec1;
|
||||
let spec2;
|
||||
@@ -664,13 +648,12 @@ describe('spec running', function() {
|
||||
actions.push('spec3');
|
||||
});
|
||||
|
||||
expect(function() {
|
||||
env.execute([spec2.id, spec3.id, spec1.id]);
|
||||
}).toThrowError(/beforeAll/);
|
||||
const promise = env.execute([spec2.id, spec3.id, spec1.id]);
|
||||
await expectAsync(promise).toBeRejectedWithError(/beforeAll/);
|
||||
expect(actions).toEqual([]);
|
||||
});
|
||||
|
||||
it('refuses to re-enter suites with a afterAll', function() {
|
||||
it('refuses to re-enter suites with a afterAll', async function() {
|
||||
const actions = [];
|
||||
let spec1;
|
||||
let spec2;
|
||||
@@ -692,13 +675,12 @@ describe('spec running', function() {
|
||||
actions.push('spec3');
|
||||
});
|
||||
|
||||
expect(function() {
|
||||
env.execute([spec2.id, spec3.id, spec1.id]);
|
||||
}).toThrowError(/afterAll/);
|
||||
const promise = env.execute([spec2.id, spec3.id, spec1.id]);
|
||||
await expectAsync(promise).toBeRejectedWithError(/afterAll/);
|
||||
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 = [];
|
||||
env.configure({ random: true, seed: '123456' });
|
||||
|
||||
@@ -756,39 +738,38 @@ describe('spec running', function() {
|
||||
});
|
||||
});
|
||||
|
||||
env.execute(null, function() {
|
||||
const expected = [
|
||||
'topSuite beforeEach',
|
||||
'outer beforeEach',
|
||||
'outer it 2',
|
||||
'outer afterEach',
|
||||
'topSuite afterEach',
|
||||
await env.execute();
|
||||
|
||||
'topSuite beforeEach',
|
||||
'outer beforeEach',
|
||||
'inner 2 beforeEach',
|
||||
'inner 2 it',
|
||||
'inner 2 afterEach',
|
||||
'outer afterEach',
|
||||
'topSuite afterEach',
|
||||
const expected = [
|
||||
'topSuite beforeEach',
|
||||
'outer beforeEach',
|
||||
'outer it 2',
|
||||
'outer afterEach',
|
||||
'topSuite afterEach',
|
||||
|
||||
'topSuite beforeEach',
|
||||
'outer beforeEach',
|
||||
'inner 1 beforeEach',
|
||||
'inner 1 it',
|
||||
'inner 1 afterEach',
|
||||
'outer afterEach',
|
||||
'topSuite afterEach',
|
||||
'topSuite beforeEach',
|
||||
'outer beforeEach',
|
||||
'inner 2 beforeEach',
|
||||
'inner 2 it',
|
||||
'inner 2 afterEach',
|
||||
'outer afterEach',
|
||||
'topSuite afterEach',
|
||||
|
||||
'topSuite beforeEach',
|
||||
'outer beforeEach',
|
||||
'outer it 1',
|
||||
'outer afterEach',
|
||||
'topSuite afterEach'
|
||||
];
|
||||
expect(actions).toEqual(expected);
|
||||
done();
|
||||
});
|
||||
'topSuite beforeEach',
|
||||
'outer beforeEach',
|
||||
'inner 1 beforeEach',
|
||||
'inner 1 it',
|
||||
'inner 1 afterEach',
|
||||
'outer afterEach',
|
||||
'topSuite afterEach',
|
||||
|
||||
'topSuite beforeEach',
|
||||
'outer beforeEach',
|
||||
'outer it 1',
|
||||
'outer afterEach',
|
||||
'topSuite afterEach'
|
||||
];
|
||||
expect(actions).toEqual(expected);
|
||||
});
|
||||
|
||||
function hasStandardErrorHandlingBehavior() {
|
||||
@@ -1298,7 +1279,7 @@ describe('spec running', 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 = [];
|
||||
|
||||
env.describe('wrapper', function() {
|
||||
@@ -1317,10 +1298,9 @@ describe('spec running', function() {
|
||||
env.configure({ random: false });
|
||||
env.configure({ stopOnSpecFailure: true });
|
||||
|
||||
env.execute(null, function() {
|
||||
expect(actions).toEqual(['fails']);
|
||||
done();
|
||||
});
|
||||
await env.execute();
|
||||
|
||||
expect(actions).toEqual(['fails']);
|
||||
});
|
||||
|
||||
it('runs afterAll functions', async function() {
|
||||
@@ -1364,7 +1344,7 @@ describe('spec running', function() {
|
||||
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 = [];
|
||||
|
||||
env.describe('Suite', function() {
|
||||
@@ -1378,16 +1358,14 @@ describe('spec running', function() {
|
||||
});
|
||||
});
|
||||
|
||||
env.execute(null, function() {
|
||||
expect(actions).toEqual(['spec1', 'spec2']);
|
||||
env.execute(null, function() {
|
||||
expect(actions).toEqual(['spec1', 'spec2', 'spec1', 'spec2']);
|
||||
done();
|
||||
});
|
||||
});
|
||||
await env.execute();
|
||||
expect(actions).toEqual(['spec1', 'spec2']);
|
||||
|
||||
await env.execute();
|
||||
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 suiteResults = {};
|
||||
let firstExecution = true;
|
||||
@@ -1440,48 +1418,46 @@ describe('spec running', function() {
|
||||
});
|
||||
});
|
||||
|
||||
env.execute(null, function() {
|
||||
expect(specResults).toEqual({
|
||||
spec1: 'failed',
|
||||
spec2: 'pending',
|
||||
spec3: 'pending',
|
||||
spec4: 'failed',
|
||||
spec5: 'failed',
|
||||
spec6: 'pending',
|
||||
spec7: 'pending'
|
||||
});
|
||||
expect(suiteResults).toEqual({
|
||||
suite0: 'passed',
|
||||
suite1: 'passed',
|
||||
suite2: 'passed',
|
||||
suite3: 'passed',
|
||||
suite4: 'pending',
|
||||
suite5: 'passed'
|
||||
});
|
||||
env.execute(null, function() {
|
||||
expect(specResults).toEqual({
|
||||
spec1: 'passed',
|
||||
spec2: 'passed',
|
||||
spec3: 'pending',
|
||||
spec4: 'passed',
|
||||
spec5: 'failed',
|
||||
spec6: 'pending',
|
||||
spec7: 'pending'
|
||||
});
|
||||
expect(suiteResults).toEqual({
|
||||
suite0: 'passed',
|
||||
suite1: 'passed',
|
||||
suite2: 'passed',
|
||||
suite3: 'passed',
|
||||
suite4: 'pending',
|
||||
suite5: 'passed'
|
||||
});
|
||||
done();
|
||||
});
|
||||
await env.execute();
|
||||
expect(specResults).toEqual({
|
||||
spec1: 'failed',
|
||||
spec2: 'pending',
|
||||
spec3: 'pending',
|
||||
spec4: 'failed',
|
||||
spec5: 'failed',
|
||||
spec6: 'pending',
|
||||
spec7: 'pending'
|
||||
});
|
||||
expect(suiteResults).toEqual({
|
||||
suite0: 'passed',
|
||||
suite1: 'passed',
|
||||
suite2: 'passed',
|
||||
suite3: 'passed',
|
||||
suite4: 'pending',
|
||||
suite5: 'passed'
|
||||
});
|
||||
|
||||
await env.execute();
|
||||
expect(specResults).toEqual({
|
||||
spec1: 'passed',
|
||||
spec2: 'passed',
|
||||
spec3: 'pending',
|
||||
spec4: 'passed',
|
||||
spec5: 'failed',
|
||||
spec6: 'pending',
|
||||
spec7: 'pending'
|
||||
});
|
||||
expect(suiteResults).toEqual({
|
||||
suite0: 'passed',
|
||||
suite1: 'passed',
|
||||
suite2: 'passed',
|
||||
suite3: 'passed',
|
||||
suite4: 'pending',
|
||||
suite5: 'passed'
|
||||
});
|
||||
});
|
||||
|
||||
it('should execute before and after hooks per run', function(done) {
|
||||
it('should execute before and after hooks per run', async function() {
|
||||
let timeline = [];
|
||||
const timelineFn = function(hookName) {
|
||||
return function() {
|
||||
@@ -1507,17 +1483,15 @@ describe('spec running', function() {
|
||||
env.it('spec1', timelineFn('spec1'));
|
||||
env.it('spec2', timelineFn('spec2'));
|
||||
});
|
||||
env.execute(null, function() {
|
||||
expect(timeline).toEqual(expectedTimeLine);
|
||||
timeline = [];
|
||||
env.execute(null, function() {
|
||||
expect(timeline).toEqual(expectedTimeLine);
|
||||
done();
|
||||
});
|
||||
});
|
||||
await env.execute();
|
||||
expect(timeline).toEqual(expectedTimeLine);
|
||||
|
||||
timeline = [];
|
||||
await env.execute();
|
||||
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 = {};
|
||||
let focussedSpec = 'spec1';
|
||||
|
||||
@@ -1539,29 +1513,27 @@ describe('spec running', function() {
|
||||
env.it('spec3', function() {});
|
||||
});
|
||||
|
||||
env.execute(null, function() {
|
||||
expect(specResults).toEqual({
|
||||
spec1: 'passed',
|
||||
spec2: 'excluded',
|
||||
spec3: 'excluded'
|
||||
});
|
||||
focussedSpec = 'spec2';
|
||||
env.execute(null, function() {
|
||||
expect(specResults).toEqual({
|
||||
spec1: 'excluded',
|
||||
spec2: 'passed',
|
||||
spec3: 'excluded'
|
||||
});
|
||||
focussedSpec = 'spec3';
|
||||
env.execute(null, function() {
|
||||
expect(specResults).toEqual({
|
||||
spec1: 'excluded',
|
||||
spec2: 'excluded',
|
||||
spec3: 'passed'
|
||||
});
|
||||
done();
|
||||
});
|
||||
});
|
||||
await env.execute();
|
||||
expect(specResults).toEqual({
|
||||
spec1: 'passed',
|
||||
spec2: 'excluded',
|
||||
spec3: 'excluded'
|
||||
});
|
||||
|
||||
focussedSpec = 'spec2';
|
||||
await env.execute();
|
||||
expect(specResults).toEqual({
|
||||
spec1: 'excluded',
|
||||
spec2: 'passed',
|
||||
spec3: 'excluded'
|
||||
});
|
||||
|
||||
focussedSpec = 'spec3';
|
||||
await env.execute();
|
||||
expect(specResults).toEqual({
|
||||
spec1: 'excluded',
|
||||
spec2: 'excluded',
|
||||
spec3: 'passed'
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
describe('DiffBuilder', 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.recordMismatch();
|
||||
|
||||
@@ -10,7 +10,7 @@ describe('DiffBuilder', 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.withPath('foo', function() {
|
||||
@@ -23,7 +23,7 @@ describe('DiffBuilder', 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.withPath('foo', function() {
|
||||
@@ -40,7 +40,7 @@ describe('DiffBuilder', function() {
|
||||
});
|
||||
|
||||
it('allows customization of the message', function() {
|
||||
const diffBuilder = jasmineUnderTest.DiffBuilder();
|
||||
const diffBuilder = new jasmineUnderTest.DiffBuilder();
|
||||
diffBuilder.setRoots({ x: 'bar' }, { x: 'foo' });
|
||||
|
||||
function darthVaderFormatter(actual, expected, path) {
|
||||
@@ -68,7 +68,7 @@ describe('DiffBuilder', function() {
|
||||
const prettyPrinter = function(val) {
|
||||
return '|' + val + '|';
|
||||
},
|
||||
diffBuilder = jasmineUnderTest.DiffBuilder({
|
||||
diffBuilder = new jasmineUnderTest.DiffBuilder({
|
||||
prettyPrinter: prettyPrinter
|
||||
});
|
||||
prettyPrinter.customFormat_ = function() {};
|
||||
@@ -86,7 +86,7 @@ describe('DiffBuilder', function() {
|
||||
it('passes the injected pretty-printer to the diff formatter', function() {
|
||||
const diffFormatter = jasmine.createSpy('diffFormatter'),
|
||||
prettyPrinter = function() {},
|
||||
diffBuilder = jasmineUnderTest.DiffBuilder({
|
||||
diffBuilder = new jasmineUnderTest.DiffBuilder({
|
||||
prettyPrinter: prettyPrinter
|
||||
});
|
||||
prettyPrinter.customFormat_ = function() {};
|
||||
|
||||
@@ -104,7 +104,9 @@ describe('toBeInstanceOf', 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 result = matcher.compare(fn, Function);
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
describe('toHaveClass', function() {
|
||||
beforeEach(function() {
|
||||
this.domHelpers = jasmine.getEnv().domHelpers();
|
||||
});
|
||||
|
||||
it('fails for a DOM element that lacks the expected class', function() {
|
||||
const matcher = jasmineUnderTest.matchers.toHaveClass(),
|
||||
result = matcher.compare(
|
||||
this.domHelpers.createElementWithClassName(''),
|
||||
specHelpers.domHelpers.createElementWithClassName(''),
|
||||
'foo'
|
||||
);
|
||||
|
||||
@@ -15,7 +11,7 @@ describe('toHaveClass', function() {
|
||||
|
||||
it('passes for a DOM element that has the expected class', function() {
|
||||
const matcher = jasmineUnderTest.matchers.toHaveClass(),
|
||||
el = this.domHelpers.createElementWithClassName('foo bar baz');
|
||||
el = specHelpers.domHelpers.createElementWithClassName('foo bar baz');
|
||||
|
||||
expect(matcher.compare(el, 'foo').pass).toBe(true);
|
||||
expect(matcher.compare(el, 'bar').pass).toBe(true);
|
||||
@@ -24,7 +20,7 @@ describe('toHaveClass', function() {
|
||||
|
||||
it('fails for a DOM element that only has other classes', function() {
|
||||
const matcher = jasmineUnderTest.matchers.toHaveClass(),
|
||||
el = this.domHelpers.createElementWithClassName('foo bar');
|
||||
el = specHelpers.domHelpers.createElementWithClassName('foo bar');
|
||||
|
||||
expect(matcher.compare(el, 'fo').pass).toBe(false);
|
||||
});
|
||||
@@ -42,7 +38,7 @@ describe('toHaveClass', function() {
|
||||
matcher.compare(undefined, 'foo');
|
||||
}).toThrowError('undefined is not a DOM element');
|
||||
|
||||
const textNode = this.domHelpers.document.createTextNode('');
|
||||
const textNode = specHelpers.domHelpers.document.createTextNode('');
|
||||
expect(function() {
|
||||
matcher.compare(textNode, 'foo');
|
||||
}).toThrowError('HTMLNode is not a DOM element');
|
||||
|
||||
@@ -15,6 +15,17 @@ describe('toHaveSize', function() {
|
||||
expect(result.pass).toBe(false);
|
||||
});
|
||||
|
||||
it('informs about the size of an array whose length does not match', function() {
|
||||
const matcher = jasmineUnderTest.matchers.toHaveSize({
|
||||
pp: jasmineUnderTest.makePrettyPrinter()
|
||||
}),
|
||||
result = matcher.compare([1, 2, 3], 2);
|
||||
|
||||
expect(result.message()).toEqual(
|
||||
'Expected [ 1, 2, 3 ] with size 3 to have size 2.'
|
||||
);
|
||||
});
|
||||
|
||||
it('passes for an object with the proper number of keys', function() {
|
||||
const matcher = jasmineUnderTest.matchers.toHaveSize(),
|
||||
result = matcher.compare({ a: 1, b: 2 }, 2);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
(function(env) {
|
||||
(function() {
|
||||
function browserVersion(matchFn) {
|
||||
const userAgent = jasmine.getGlobal().navigator.userAgent;
|
||||
if (!userAgent) {
|
||||
@@ -10,7 +10,7 @@
|
||||
return match ? parseFloat(match[1]) : void 0;
|
||||
}
|
||||
|
||||
env.firefoxVersion = browserVersion(function(userAgent) {
|
||||
specHelpers.firefoxVersion = browserVersion(function(userAgent) {
|
||||
return /Firefox\/([0-9]{0,})/.exec(userAgent);
|
||||
});
|
||||
})(jasmine.getEnv());
|
||||
})();
|
||||
|
||||
@@ -1,24 +1,20 @@
|
||||
(function(env) {
|
||||
function domHelpers() {
|
||||
let doc;
|
||||
(function() {
|
||||
let doc;
|
||||
|
||||
if (typeof document !== 'undefined') {
|
||||
doc = document;
|
||||
} else {
|
||||
const JSDOM = require('jsdom').JSDOM;
|
||||
const dom = new JSDOM();
|
||||
doc = dom.window.document;
|
||||
}
|
||||
|
||||
return {
|
||||
document: doc,
|
||||
createElementWithClassName: function(className) {
|
||||
const el = this.document.createElement('div');
|
||||
el.className = className;
|
||||
return el;
|
||||
}
|
||||
};
|
||||
if (typeof document !== 'undefined') {
|
||||
doc = document;
|
||||
} else {
|
||||
const JSDOM = require('jsdom').JSDOM;
|
||||
const dom = new JSDOM();
|
||||
doc = dom.window.document;
|
||||
}
|
||||
|
||||
env.domHelpers = domHelpers;
|
||||
})(jasmine.getEnv());
|
||||
specHelpers.domHelpers = {
|
||||
document: doc,
|
||||
createElementWithClassName(className) {
|
||||
const el = this.document.createElement('div');
|
||||
el.className = className;
|
||||
return el;
|
||||
}
|
||||
};
|
||||
})();
|
||||
|
||||
1
spec/helpers/init.js
Normal file
1
spec/helpers/init.js
Normal file
@@ -0,0 +1 @@
|
||||
globalThis.specHelpers = {};
|
||||
@@ -1,5 +1,5 @@
|
||||
(function(env) {
|
||||
env.registerIntegrationMatchers = function() {
|
||||
(function() {
|
||||
specHelpers.registerIntegrationMatchers = function() {
|
||||
jasmine.addMatchers({
|
||||
toHaveFailedExpectationsForRunnable: function() {
|
||||
return {
|
||||
@@ -51,4 +51,4 @@
|
||||
}
|
||||
});
|
||||
};
|
||||
})(jasmine.getEnv());
|
||||
})();
|
||||
|
||||
@@ -12,14 +12,12 @@
|
||||
};
|
||||
|
||||
function getSourceFiles() {
|
||||
const src_files = ['core/**/*.js', 'version.js'].map(function(file) {
|
||||
return path.join(__dirname, '../../', 'src/', file);
|
||||
});
|
||||
const globs = ['../../src/core/**/*.js', '../../src/version.js'];
|
||||
const srcFiles = globs.flatMap(g => glob.sync(g, { cwd: __dirname }));
|
||||
|
||||
const files = src_files.flatMap(g => glob.sync(g));
|
||||
files.forEach(function(resolvedFile) {
|
||||
require(resolvedFile);
|
||||
});
|
||||
for (const file of srcFiles) {
|
||||
require(file);
|
||||
}
|
||||
}
|
||||
|
||||
getSourceFiles();
|
||||
|
||||
@@ -1411,6 +1411,23 @@ describe('HtmlReporter', function() {
|
||||
describe('and there are pending specs', function() {
|
||||
let container, reporter;
|
||||
|
||||
function pendingSpecStatus() {
|
||||
return {
|
||||
id: 123,
|
||||
description: 'with a spec',
|
||||
fullName: 'A Suite with a spec',
|
||||
status: 'pending',
|
||||
passedExpectations: [],
|
||||
failedExpectations: []
|
||||
};
|
||||
}
|
||||
|
||||
function reportWithSpecStatus(specStatus) {
|
||||
reporter.specStarted(specStatus);
|
||||
reporter.specDone(specStatus);
|
||||
reporter.jasmineDone({});
|
||||
}
|
||||
|
||||
beforeEach(function() {
|
||||
container = document.createElement('div');
|
||||
const getContainer = function() {
|
||||
@@ -1429,21 +1446,10 @@ describe('HtmlReporter', function() {
|
||||
reporter.initialize();
|
||||
|
||||
reporter.jasmineStarted({ totalSpecsDefined: 1 });
|
||||
const specStatus = {
|
||||
id: 123,
|
||||
description: 'with a spec',
|
||||
fullName: 'A Suite with a spec',
|
||||
status: 'pending',
|
||||
passedExpectations: [],
|
||||
failedExpectations: [],
|
||||
pendingReason: 'my custom pending reason'
|
||||
};
|
||||
reporter.specStarted(specStatus);
|
||||
reporter.specDone(specStatus);
|
||||
reporter.jasmineDone({});
|
||||
});
|
||||
|
||||
it('reports the pending specs count', function() {
|
||||
reportWithSpecStatus(pendingSpecStatus());
|
||||
const alertBar = container.querySelector('.jasmine-alert .jasmine-bar');
|
||||
|
||||
expect(alertBar.innerHTML).toMatch(
|
||||
@@ -1452,17 +1458,36 @@ describe('HtmlReporter', function() {
|
||||
});
|
||||
|
||||
it('reports no failure details', function() {
|
||||
reportWithSpecStatus(pendingSpecStatus());
|
||||
const specFailure = container.querySelector('.jasmine-failures');
|
||||
|
||||
expect(specFailure.childNodes.length).toEqual(0);
|
||||
});
|
||||
|
||||
it('displays the custom pending reason', function() {
|
||||
reportWithSpecStatus({
|
||||
...pendingSpecStatus(),
|
||||
pendingReason: 'my custom pending reason'
|
||||
});
|
||||
const pendingDetails = container.querySelector(
|
||||
'.jasmine-summary .jasmine-pending'
|
||||
);
|
||||
|
||||
expect(pendingDetails.innerHTML).toContain('my custom pending reason');
|
||||
expect(pendingDetails.innerHTML).toContain(
|
||||
'PENDING WITH MESSAGE: my custom pending reason'
|
||||
);
|
||||
});
|
||||
|
||||
it('indicates that the spec is pending even if there is no reason', function() {
|
||||
reportWithSpecStatus({
|
||||
...pendingSpecStatus(),
|
||||
pendingReason: ''
|
||||
});
|
||||
const pendingDetails = container.querySelector(
|
||||
'.jasmine-summary .jasmine-pending'
|
||||
);
|
||||
|
||||
expect(pendingDetails.innerHTML).toContain('PENDING');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ describe('PrettyPrinter (HTML Dependent)', function() {
|
||||
});
|
||||
|
||||
it("should print Firefox's wrapped native objects correctly", function() {
|
||||
if (jasmine.getEnv().firefoxVersion) {
|
||||
if (specHelpers.firefoxVersion) {
|
||||
const pp = jasmineUnderTest.makePrettyPrinter();
|
||||
let err;
|
||||
try {
|
||||
|
||||
@@ -78,15 +78,10 @@ describe('npm package', function() {
|
||||
|
||||
it('has bootFiles', function() {
|
||||
expect(this.packagedCore.files.bootFiles).toEqual(['boot0.js', 'boot1.js']);
|
||||
expect(this.packagedCore.files.nodeBootFiles).toEqual(['node_boot.js']);
|
||||
|
||||
for (const fileName of this.packagedCore.files.bootFiles) {
|
||||
expect(fileName).toExistInPath(this.packagedCore.files.bootDir);
|
||||
}
|
||||
|
||||
for (const fileName of this.packagedCore.files.nodeBootFiles) {
|
||||
expect(fileName).toExistInPath(this.packagedCore.files.bootDir);
|
||||
}
|
||||
});
|
||||
|
||||
it('has an imagesDir', function() {
|
||||
@@ -118,7 +113,7 @@ describe('npm package', function() {
|
||||
const files = fs.readdirSync(path.resolve(this.tmpDir, 'package'));
|
||||
files.sort();
|
||||
expect(files).toEqual([
|
||||
'MIT.LICENSE',
|
||||
'LICENSE',
|
||||
'README.md',
|
||||
'images',
|
||||
'lib',
|
||||
|
||||
@@ -3,7 +3,7 @@ const path = require('path'),
|
||||
jasmineBrowser = require('jasmine-browser-runner'),
|
||||
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.jasmineCore = jasmineCore;
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ module.exports = {
|
||||
specDir: 'spec',
|
||||
specFiles: ['**/*[Ss]pec.js', '!npmPackage/**/*'],
|
||||
helpers: [
|
||||
'helpers/init.js',
|
||||
'helpers/generator.js',
|
||||
'helpers/BrowserFlags.js',
|
||||
'helpers/domHelpers.js',
|
||||
@@ -28,16 +29,19 @@ module.exports = {
|
||||
random: true,
|
||||
browser: {
|
||||
name: process.env.JASMINE_BROWSER || 'firefox',
|
||||
useSauce: process.env.USE_SAUCE === 'true',
|
||||
sauce: {
|
||||
name: `jasmine-core ${new Date().toISOString()}`,
|
||||
os: process.env.SAUCE_OS,
|
||||
useRemoteSeleniumGrid: process.env.USE_SAUCE === 'true',
|
||||
remoteSeleniumGrid: {
|
||||
url: 'https://ondemand.saucelabs.com/wd/hub',
|
||||
browserVersion: process.env.SAUCE_BROWSER_VERSION,
|
||||
build: `Core ${process.env.TRAVIS_BUILD_NUMBER || 'Ran locally'}`,
|
||||
tags: ['Jasmine-Core'],
|
||||
tunnelIdentifier: process.env.SAUCE_TUNNEL_IDENTIFIER,
|
||||
username: process.env.SAUCE_USERNAME,
|
||||
accessKey: process.env.SAUCE_ACCESS_KEY
|
||||
platformName: process.env.SAUCE_OS,
|
||||
'sauce:options': {
|
||||
name: `jasmine-core ${new Date().toISOString()}`,
|
||||
build: `Core ${process.env.CIRCLE_BUILD_NUM || 'Ran locally'}`,
|
||||
tags: ['Jasmine-Core'],
|
||||
tunnelIdentifier: process.env.SAUCE_TUNNEL_IDENTIFIER,
|
||||
username: process.env.SAUCE_USERNAME,
|
||||
accessKey: process.env.SAUCE_ACCESS_KEY
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
"npmPackage/**/*[Ss]pec.js"
|
||||
],
|
||||
"helpers": [
|
||||
"helpers/init.js",
|
||||
"helpers/domHelpers.js",
|
||||
"helpers/integrationMatchers.js",
|
||||
"helpers/overrideConsoleLogForCircleCi.js",
|
||||
|
||||
@@ -5,14 +5,14 @@
|
||||
source files or spec files are loaded.
|
||||
*/
|
||||
(function() {
|
||||
var jasmineRequire = window.jasmineRequire || require('./jasmine.js');
|
||||
const jasmineRequire = window.jasmineRequire || require('./jasmine.js');
|
||||
|
||||
/**
|
||||
* ## Require & Instantiate
|
||||
*
|
||||
* 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 = jasmine;
|
||||
|
||||
@@ -24,19 +24,19 @@
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
* 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`.
|
||||
*/
|
||||
for (var property in jasmineInterface) {
|
||||
for (const property in jasmineInterface) {
|
||||
global[property] = jasmineInterface[property];
|
||||
}
|
||||
})();
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
*/
|
||||
|
||||
(function() {
|
||||
var env = jasmine.getEnv();
|
||||
const env = jasmine.getEnv();
|
||||
|
||||
/**
|
||||
* ## 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.
|
||||
*/
|
||||
|
||||
var queryString = new jasmine.QueryString({
|
||||
const queryString = new jasmine.QueryString({
|
||||
getWindowLocation: function() {
|
||||
return window.location;
|
||||
}
|
||||
});
|
||||
|
||||
var filterSpecs = !!queryString.getParam('spec');
|
||||
const filterSpecs = !!queryString.getParam('spec');
|
||||
|
||||
var config = {
|
||||
const config = {
|
||||
stopOnSpecFailure: queryString.getParam('stopOnSpecFailure'),
|
||||
stopSpecOnExpectationFailure: queryString.getParam(
|
||||
'stopSpecOnExpectationFailure'
|
||||
@@ -36,13 +36,13 @@
|
||||
hideDisabled: queryString.getParam('hideDisabled')
|
||||
};
|
||||
|
||||
var random = queryString.getParam('random');
|
||||
const random = queryString.getParam('random');
|
||||
|
||||
if (random !== undefined && random !== '') {
|
||||
config.random = random;
|
||||
}
|
||||
|
||||
var seed = queryString.getParam('seed');
|
||||
const seed = queryString.getParam('seed');
|
||||
if (seed) {
|
||||
config.seed = seed;
|
||||
}
|
||||
@@ -51,7 +51,7 @@
|
||||
* ## 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).
|
||||
*/
|
||||
var htmlReporter = new jasmine.HtmlReporter({
|
||||
const htmlReporter = new jasmine.HtmlReporter({
|
||||
env: env,
|
||||
navigateWithNewParam: function(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.
|
||||
*/
|
||||
var specFilter = new jasmine.HtmlSpecFilter({
|
||||
const specFilter = new jasmine.HtmlSpecFilter({
|
||||
filterString: function() {
|
||||
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.
|
||||
*/
|
||||
var currentWindowOnload = window.onload;
|
||||
const currentWindowOnload = window.onload;
|
||||
|
||||
window.onload = function() {
|
||||
if (currentWindowOnload) {
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
module.exports = function(jasmineRequire) {
|
||||
var jasmine = jasmineRequire.core(jasmineRequire);
|
||||
|
||||
var env = jasmine.getEnv({ suppressLoadErrors: true });
|
||||
|
||||
var jasmineInterface = jasmineRequire.interface(jasmine, env);
|
||||
|
||||
extend(global, jasmineInterface);
|
||||
|
||||
function extend(destination, source) {
|
||||
for (var property in source) destination[property] = source[property];
|
||||
return destination;
|
||||
}
|
||||
|
||||
return jasmine;
|
||||
};
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user