get function name change
This commit is contained in:
3
node_modules/nock/.eslintignore
generated
vendored
Normal file
3
node_modules/nock/.eslintignore
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
/coverage
|
||||
/tests/browserify-public/browserify-bundle.js
|
||||
node_modules
|
||||
22
node_modules/nock/.eslintrc.yml
generated
vendored
Normal file
22
node_modules/nock/.eslintrc.yml
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
env:
|
||||
node: true
|
||||
es6: true
|
||||
|
||||
extends:
|
||||
- "eslint:recommended"
|
||||
|
||||
rules:
|
||||
# Override some recommended rules.
|
||||
no-unused-vars: ["error", {"args": "none"}]
|
||||
no-empty: ["error", { "allowEmptyCatch": true }]
|
||||
|
||||
strict: ["error", "safe"]
|
||||
no-loop-func: "error"
|
||||
no-trailing-spaces: "error"
|
||||
eol-last: "error"
|
||||
|
||||
# For future use.
|
||||
# indent: ["error", 2, {SwitchCase: 1}]
|
||||
# semi: ["error", always]
|
||||
# comma-style: ["error", "last"]
|
||||
# max-len: ["error", { code: 120, ignoreComments: true }]
|
||||
26
node_modules/nock/.github/ISSUE_TEMPLATE/01_bug_report.md
generated
vendored
Normal file
26
node_modules/nock/.github/ISSUE_TEMPLATE/01_bug_report.md
generated
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
---
|
||||
name: 🐛 Bug report
|
||||
about: If something isn't working 🤕
|
||||
|
||||
---
|
||||
|
||||
**What is the expected behavior?**
|
||||
|
||||
**What is the actual behavior?**
|
||||
|
||||
**Possible solution**
|
||||
|
||||
**How to reproduce the issue**
|
||||
|
||||
Runkit: *[Example link](https://runkit.com/gr2m/node-nock-nock-768)*
|
||||
|
||||
_Having problem producing a test case? Try and ask the community for help. If the test case cannot be reproduced, the Nock community might not be able to help you._
|
||||
|
||||
**Does the bug have a test case?**
|
||||
|
||||
**Versions**
|
||||
|
||||
| Software | Version(s) |
|
||||
|----------|------------|
|
||||
| Nock | |
|
||||
| Node | |
|
||||
21
node_modules/nock/.github/ISSUE_TEMPLATE/02_feature_request.md
generated
vendored
Normal file
21
node_modules/nock/.github/ISSUE_TEMPLATE/02_feature_request.md
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
---
|
||||
name: 🚀 Feature request
|
||||
about: Let us know if you have a feature request 💡
|
||||
|
||||
---
|
||||
|
||||
**Context**
|
||||
|
||||
What are you trying to do and how would you want to do it differently? Is it something you currently you cannot do? Is this related to an issue/problem?
|
||||
|
||||
**Alternatives**
|
||||
|
||||
Can you achieve the same result doing it in an alternative way? Is the alternative considerable?
|
||||
|
||||
**Has the feature been requested before?**
|
||||
|
||||
Please provide a link to the issue.
|
||||
|
||||
**If the feature request is accepted, would you be willing to submit a PR?**
|
||||
|
||||
Yes / No _(Help can be provided if you need assistance submitting a PR)_
|
||||
24
node_modules/nock/.github/ISSUE_TEMPLATE/03_support.md
generated
vendored
Normal file
24
node_modules/nock/.github/ISSUE_TEMPLATE/03_support.md
generated
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
---
|
||||
name: ❓ Support
|
||||
about: If you need support, check out Nock on StackOverflow
|
||||
|
||||
---
|
||||
|
||||
<!-- 👆 Click "Preview" for a nicer view! -->
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
We primarily use GitHub as an issue tracker; for usage and support questions we primairly use StackOverflow. Please tag the questions with `nock` so the community can easily find it. [Go to StackOverflow](https://stackoverflow.com/questions/tagged/nock).
|
||||
|
||||
If you want to submit a feature request you can do that [here](https://github.com/nock/nock/issues/new?template=feature_request.md) or bug reports [here](https://github.com/nock/nock/issues/new?template=bug_report.md).
|
||||
21
node_modules/nock/.github/ISSUE_TEMPLATE/04_thanks.md
generated
vendored
Normal file
21
node_modules/nock/.github/ISSUE_TEMPLATE/04_thanks.md
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
---
|
||||
name: ❤️ Say thank you
|
||||
about: Tell us how you use nock & support our efforts in maintaining Nock
|
||||
|
||||
---
|
||||
|
||||
# ❤️ I'm using Nock
|
||||
|
||||
If you (or your company) are using Nock - please let us know. We'd love to hear from you!
|
||||
|
||||
Nock is a community driven project, which means it's not maintained by a company. If you would like to help Nock - any of the following is greatly appreciated.
|
||||
|
||||
- [ ] Give the repository a star ⭐️
|
||||
- [ ] Help out with issues
|
||||
- [ ] Review pull requests
|
||||
- [ ] Blog about Nock
|
||||
- [ ] Make tutorials
|
||||
- [ ] Give talks
|
||||
- [ ] Support us on [https://opencollective.com/nock](https://opencollective.com/nock)
|
||||
|
||||
Thank you! 💐
|
||||
19
node_modules/nock/.github/lock.yml
generated
vendored
Normal file
19
node_modules/nock/.github/lock.yml
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
# Configuration for lock-threads - https://github.com/dessant/lock-threads
|
||||
|
||||
# Number of days of inactivity before a closed issue or pull request is locked
|
||||
daysUntilLock: 14
|
||||
|
||||
# Issues and pull requests with these labels will not be locked. Set to `[]` to disable
|
||||
exemptLabels: []
|
||||
|
||||
# Label to add before locking, such as `outdated`. Set to `false` to disable
|
||||
lockLabel: false
|
||||
|
||||
# Comment to post before locking. Set to `false` to disable
|
||||
lockComment: >
|
||||
This thread has been automatically locked since there has not been
|
||||
any recent activity after it was closed. Please open a new issue and
|
||||
add a reference to this one if it’s related. Thank you!
|
||||
|
||||
# Assign `resolved` as the reason for locking. Set to `false` to disable
|
||||
setLockReason: true
|
||||
25
node_modules/nock/.github/stale.yml
generated
vendored
Normal file
25
node_modules/nock/.github/stale.yml
generated
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
# Configuration for probot-stale - https://github.com/probot/stale
|
||||
|
||||
# Number of days of inactivity before an Issue or Pull Request becomes stale
|
||||
daysUntilStale: 90
|
||||
|
||||
# Number of days of inactivity before an Issue or Pull Request with the stale label is closed.
|
||||
# Set to false to disable. If disabled, issues still need to be closed manually, but will remain marked as stale.
|
||||
daysUntilClose: 7
|
||||
|
||||
# Issues or Pull Requests with these labels will never be considered stale. Set to `[]` to disable
|
||||
exemptLabels:
|
||||
- pinned
|
||||
|
||||
# Label to use when marking as stale
|
||||
staleLabel: stale
|
||||
|
||||
# Comment to post when marking as stale. Set to `false` to disable
|
||||
markComment: >
|
||||
This issue has been automatically marked as stale because it has not had
|
||||
recent activity. It will be closed if no further activity occurs. We try to
|
||||
do our best, but nock is maintained by volunteers and there is only so much
|
||||
we can do at a time. Thank you for your contributions.
|
||||
|
||||
# Limit the number of actions per hour, from 1-30. Default is 30
|
||||
limitPerRun: 30
|
||||
5
node_modules/nock/.istanbul.yml
generated
vendored
Normal file
5
node_modules/nock/.istanbul.yml
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
instrumentation:
|
||||
excludes: ['tests/**/*.js', 'examples/**/*.js', 'lib/recorder.js']
|
||||
check:
|
||||
global:
|
||||
lines: 90
|
||||
43
node_modules/nock/.travis.yml
generated
vendored
Normal file
43
node_modules/nock/.travis.yml
generated
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
language: node_js
|
||||
cache:
|
||||
directories:
|
||||
- ~/.npm
|
||||
|
||||
# Trigger a push build on master and greenkeeper branches + PRs build on every branches
|
||||
# Avoid double build on PRs (See https://github.com/travis-ci/travis-ci/issues/1147)
|
||||
branches:
|
||||
only:
|
||||
- master
|
||||
- /^greenkeeper.*$/
|
||||
- beta # semantic-release preview releases
|
||||
- next # semantic-release @next releases
|
||||
- /^\d+\.x$/ # semantic-release maintenance releases
|
||||
|
||||
stages:
|
||||
- lint
|
||||
- test
|
||||
- name: release
|
||||
if: branch =~ /^(\d+\.x|master|next|beta)$/ AND type IN (push)
|
||||
|
||||
jobs:
|
||||
include:
|
||||
- stage: lint
|
||||
node_js: lts/*
|
||||
env: linting
|
||||
script: npm run lint
|
||||
- stage: test
|
||||
node_js: 10
|
||||
script: npm run unit
|
||||
- node_js: 8
|
||||
script: npm run unit
|
||||
- node_js: 6
|
||||
script: npm run unit
|
||||
- stage: release
|
||||
node_js: lts/*
|
||||
env: semantic-release
|
||||
script: npm run semantic-release
|
||||
- node_js: lts/*
|
||||
env: coverage
|
||||
script:
|
||||
- npm run test
|
||||
- npm run coverage:upload
|
||||
3
node_modules/nock/CHANGELOG.md
generated
vendored
Normal file
3
node_modules/nock/CHANGELOG.md
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
# Changelog
|
||||
|
||||
Nock’s changelog can be found directly in the [GitHub release notes](https://github.com/nock/nock/releases). These are automatically created by [semantic-release](https://github.com/semantic-release/semantic-release) based on their [commit message conventions](https://semantic-release.gitbook.io/semantic-release#commit-message-format).
|
||||
46
node_modules/nock/CODE_OF_CONDUCT.md
generated
vendored
Normal file
46
node_modules/nock/CODE_OF_CONDUCT.md
generated
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
# Contributor Covenant Code of Conduct
|
||||
|
||||
## Our Pledge
|
||||
|
||||
In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
||||
|
||||
## Our Standards
|
||||
|
||||
Examples of behavior that contributes to creating a positive environment include:
|
||||
|
||||
* Using welcoming and inclusive language
|
||||
* Being respectful of differing viewpoints and experiences
|
||||
* Gracefully accepting constructive criticism
|
||||
* Focusing on what is best for the community
|
||||
* Showing empathy towards other community members
|
||||
|
||||
Examples of unacceptable behavior by participants include:
|
||||
|
||||
* The use of sexualized language or imagery and unwelcome sexual attention or advances
|
||||
* Trolling, insulting/derogatory comments, and personal or political attacks
|
||||
* Public or private harassment
|
||||
* Publishing others' private information, such as a physical or electronic address, without explicit permission
|
||||
* Other conduct which could reasonably be considered inappropriate in a professional setting
|
||||
|
||||
## Our Responsibilities
|
||||
|
||||
Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
|
||||
|
||||
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
|
||||
|
||||
## Scope
|
||||
|
||||
This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
|
||||
|
||||
## Enforcement
|
||||
|
||||
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at nock+coc@martynus.net or coc+nock@maintainer.io. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
|
||||
|
||||
Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
|
||||
|
||||
## Attribution
|
||||
|
||||
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
|
||||
|
||||
[homepage]: http://contributor-covenant.org
|
||||
[version]: http://contributor-covenant.org/version/1/4/
|
||||
138
node_modules/nock/CONTRIBUTING.md
generated
vendored
Normal file
138
node_modules/nock/CONTRIBUTING.md
generated
vendored
Normal file
@@ -0,0 +1,138 @@
|
||||
# Contribute
|
||||
|
||||
👋 Thanks for thinking about contributing to nock! We, the maintainers, are glad you're here and will be excited to help you get started if you have any questions. For now, here are some basic instructions for how we manage this project.
|
||||
|
||||
Please note that this project is released with a [Contributor Code of Conduct](./CODE_OF_CONDUCT.md). By participating in this project you agree to abide by its terms.
|
||||
|
||||
**Table of Contents**
|
||||
|
||||
<!-- toc -->
|
||||
|
||||
- [Commit Message conventions](#commit-message-conventions)
|
||||
- [Beta / Next / Maintenance releases](#beta--next--maintenance-releases)
|
||||
* [Backport a fix / feature to a previous version](#backport-a-fix--feature-to-a-previous-version)
|
||||
* [Submit a Beta / Next release](#submit-a-beta--next-release)
|
||||
- [Generate README TOC](#generate-readme-toc)
|
||||
- [Running tests](#running-tests)
|
||||
* [Airplane mode](#airplane-mode)
|
||||
- [Release Process](#release-process)
|
||||
- [GitHub Apps](#github-apps)
|
||||
- [Becoming a maintainer](#becoming-a-maintainer)
|
||||
- [Generating the CONTRIBUTORS.md file](#generating-the-contributorsmd-file)
|
||||
|
||||
<!-- tocstop -->
|
||||
|
||||
## Commit Message conventions
|
||||
|
||||
`nock` releases are automated using [semantic-release](https://github.com/semantic-release/semantic-release).
|
||||
To automatically calculate the correct version number as well as changelogs,
|
||||
three commit message conventions need to be followed
|
||||
|
||||
- Commit bug fixes with `fix: ...` or `fix(scope): ...` prefix in commit subject
|
||||
- Commit new features with `feat: ...` or `feat(scope): ...` prefix in commit subject
|
||||
- Commit breaking changes by adding `BREAKING CHANGE: ` in the commit body
|
||||
(not the subject line)
|
||||
|
||||
Other helpful conventions are
|
||||
|
||||
- Commit test files with `test: ...` or `test(scope): ...` prefix
|
||||
- Commit changes to `package.json`, `.gitignore` and other meta files with
|
||||
`chore(filename-without-ext): ...`
|
||||
- Commit changes to README files or comments with `docs: ...`
|
||||
- Code style changes with `style: standard`
|
||||
|
||||
The commit message(s) of a pull request can be fixed using the `squash & merge` button.
|
||||
|
||||
## Beta / Next / Maintenance releases
|
||||
|
||||
We use [semantic-release](https://github.com/semantic-release/semantic-release) to automate the release of new versions based on semantic commit messages as described above. Depending on the branch that a new pull request is merged into, it is published to different versions using different [npm dist-tags](https://docs.npmjs.com/cli/dist-tag).
|
||||
|
||||
- `master`: Publish with `@latest`, or if the commits have been merged into `next` branch before, update the `@latest` dist-tag to point at the new version
|
||||
- `next`: Publish with `@next`
|
||||
- `beta`: Publish to `X.0.0-beta.Y`, where `X` is the next breaking version and `Y` is number that gets increased with each release.
|
||||
- `[Version].x`: For example `10.x`, where `10` is the major release number. No breaking changes are allowed on this branch. Publishes fix/feature versions to `[Version]` using a `@release-@[version].x` release tag
|
||||
|
||||
### Backport a fix / feature to a previous version
|
||||
|
||||
If you want to **backport a fix** to version 10, and the last version released on version 10 is `10.0.4`, then you have to follow these steps
|
||||
|
||||
1. Create the `[Version].x` branch unless it already exists. If you don’t have write access, ask one of the maintainers to do it for you. In this example, then command is `git checkout -b 10.x v10.0.4`.
|
||||
2. Push the branch to GitHub: `git push -u origin $(git symbolic-ref --short HEAD)`
|
||||
3. Create a new branch based on `10.x`
|
||||
4. Make your changes
|
||||
5. Submit the pull request against the `10.x` branch
|
||||
|
||||
### Submit a Beta / Next release
|
||||
|
||||
Create a new branch based off `beta` or `next`, depending on what you want. Make your changes and submit them to the same branches. If either `beta` or `next` is outdated, ask a maintainer to re-create them from `master`
|
||||
|
||||
## Generate README TOC
|
||||
|
||||
Make sure to update the README's table of contents whenever you update the README using the following npm script.
|
||||
|
||||
```
|
||||
$ npm run toc
|
||||
```
|
||||
|
||||
## Running tests
|
||||
|
||||
```
|
||||
$ npm test
|
||||
```
|
||||
|
||||
### Airplane mode
|
||||
|
||||
Some of the tests depend on online connectivity. To skip them, set the `AIRPLANE` environment variable to some value.
|
||||
|
||||
```
|
||||
$ export AIRPLANE=true
|
||||
$ npm test
|
||||
```
|
||||
|
||||
## Release Process
|
||||
|
||||
All of our releases are automated using [semantic-release](https://github.com/semantic-release/semantic-release). The commit messages pushed to the master branch trigger new releases. Semantic-release requires that commits follow certain conventions, [described above](#commit-message-conventions). semantic-release creates a GitHub release, adds release notes and publishes the new version to npm. This is why we do not store release notes in the [`CHANGELOG`](CHANGELOG.md) file - they're already on GitHub.
|
||||
|
||||
We use @nockbot as a separate account for releases, because npm tokens cannot be scoped to a single package. This improves our security model in case of a data breach involving npm tokens. @nockbot's credentials were set up by @gr2m; contact him if for any reason you need to change this in the future.
|
||||
|
||||
## GitHub Apps
|
||||
|
||||
We use several GitHub apps to help maintain this repository. While we would like to address every issue and while we would like to be on hand to support every person, Nock is pretty much entirely volunteer run, and we simply don't have the time to do everything. Please don't be offended if an automated app posts in your issue! We're doing what we can with with we have.
|
||||
|
||||
Currently, we use the [Stale](https://github.com/apps/stale) and [Lock](https://github.com/apps/lock) apps to mark old issues as stale, and to lock issues which have been closed to stop drive-by comments. You can see the configuration files for these in [.github/](.github).
|
||||
|
||||
## Becoming a maintainer
|
||||
|
||||
So you want to do more than file a bug or submit a PR? Awesome!
|
||||
|
||||
Nock is actively interested in having more maintainers. That means that we would love to have you (yes, you) get more involved if you want to! We don't have strict tests that you need to pass to become a maintainer. Instead, all we want is to find people who are frequent contributors, understand what Nock does, and are eager to help make this tool better.
|
||||
|
||||
Here are some things you can do today to actively show the Nock team that you're interested in helping out in the long term:
|
||||
|
||||
* **Triage issues!** We have more issues than we have bandwidth to deal with. For some of these issues, there are no labels, no comments suggesting how the issue could be resolved, and no follow-up after months or years of silence. It would be great if the issues actively reflected the state of the project. Go through old issues and suggesting labels in comments, ask for more information, and generally help out with the resolution process. This would be a great help!
|
||||
* **Review PRs.** We have a lot of open PRs! Some of these are probably ready to merge, and some of them probably need more work. Any extra eyes on PRs are encouraged. Comment on code patterns you think need work, suggest extra tests, and let us know if a PR 'LGTM' ("looks good to me"). The more reviewers we have, the faster we can merge issues, the better this project becomes.
|
||||
* **Help out!** If someone files a bug and no one has responded yet, see if you can resolve it! Suggest PRs, or file them yourself. While most contributors are going to only be interested in their own bugs, great maintainers help out with other people's bugs. This is one of the best ways to become an expert at Nock (and Node.js, JavaScript, or pretty much any project) - helping others.
|
||||
* **Write docs.** Are our docs missing something important? Are they not clear? Could they be better? Open a PR!
|
||||
* **Suggest examples.** Right now, we have a few examples, but we could always have more. Submit small example files and tutorials. At some point, we'll have to work on a better way to display these - for now, it's great to show others how to solve difficult mocking problems easily with Nock.
|
||||
* **Refactor.** This is one of the hardest things to do, but one of the most useful. Go through the code, and find examples where it could be written better - with better variable names, more useful abstractions, and more elegant patterns. Taking away ten lines of code that are unnecessary is more valuable than submitting a hundred new lines, sometimes. Open a PR or a comment and defend your position; ask for feedback.
|
||||
|
||||
Once you've been around for a bit, ask a current Maintainer - one of [the team members](https://github.com/orgs/nock/people) - whether you can be elevated to Maintainer status and given permissions to close issues and merge PRs. We're interested in how well you know what Nock is about, and how involved you are in the community - not where you're from, how good your English is, or whether or not you can pass a whiteboard test blindfolded. If you think that you've been helpful, let us know. We're friendly, promise. :)
|
||||
|
||||
## Generating the CONTRIBUTORS.md file
|
||||
|
||||
We use [`name-your-contributors`](https://github.com/mntnr/name-your-contributors) to generate the CONTRIBUTORS file, which contains the names of everyone who have submitted code to the Nock codebase, or commented on an issue, or opened a pull request, or reviewed anyone else's code. After all, all contributions are welcome, and anyone who works with Nock is part of our community.
|
||||
|
||||
To generate this file, download `name-your-contributors` and set up a GitHub authorization token.
|
||||
|
||||
```sh
|
||||
# Generate a JSON file of the members. This may take a while.
|
||||
$ name-your-contributors -r nock -u nock > contributors.json
|
||||
```
|
||||
|
||||
To parse that file, we suggest using [`jq`](https://stedolan.github.io/jq/), although other options are clearly possible:
|
||||
|
||||
```sh
|
||||
cat contribs.json | jq '.[][]' | jq '"\(if (.name | length) > 0 then .name else null end) @\(.login) \(.url)"' | jq '. | tostring' | jq -s . | jq unique | jq .[] > CONTRIBUTORS.md
|
||||
```
|
||||
|
||||
Note: This is a convoluted and time-intensive process, and could be updated in several ways. For one, `name-your-contributors` accepts a date flag, which could be used to only catch recent entries. Another way would be to use a bot to automate this at some regular interval. Any help on this would be appreciated.
|
||||
21
node_modules/nock/LICENSE
generated
vendored
Normal file
21
node_modules/nock/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2011-2018 Pedro Teixeira and other contributors
|
||||
|
||||
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.
|
||||
1456
node_modules/nock/README.md
generated
vendored
Normal file
1456
node_modules/nock/README.md
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
1
node_modules/nock/assets/reply_file_1.txt
generated
vendored
Normal file
1
node_modules/nock/assets/reply_file_1.txt
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
Hello from the file!
|
||||
BIN
node_modules/nock/assets/reply_file_2.txt.gz
generated
vendored
Normal file
BIN
node_modules/nock/assets/reply_file_2.txt.gz
generated
vendored
Normal file
Binary file not shown.
3
node_modules/nock/examples/.eslintrc.yml
generated
vendored
Normal file
3
node_modules/nock/examples/.eslintrc.yml
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
rules:
|
||||
no-console: "off"
|
||||
strict: "off"
|
||||
12
node_modules/nock/examples/_log.js
generated
vendored
Normal file
12
node_modules/nock/examples/_log.js
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
module.exports = log;
|
||||
|
||||
var start = Date.now();
|
||||
|
||||
function log(emitter, name) {
|
||||
return function(event) {
|
||||
emitter.on(event, function() {
|
||||
var lag = '' + (Math.round((Date.now() - start) / 100) / 10) + ' sec';
|
||||
console.log('[%s] %s => %s', lag, name, event);
|
||||
});
|
||||
}
|
||||
}
|
||||
15
node_modules/nock/examples/delay-connection.js
generated
vendored
Normal file
15
node_modules/nock/examples/delay-connection.js
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
var http = require('http');
|
||||
var nock = require('../');
|
||||
var log = require('./_log');
|
||||
var events = ['socket', 'response', 'end', 'data'];
|
||||
|
||||
nock('http://delayconnection.com').
|
||||
get('/').
|
||||
delayConnection(1000).
|
||||
reply(200, 'hey');
|
||||
|
||||
var req = http.get('http://delayconnection.com', function(res) {
|
||||
events.forEach(log(res, 'res'));
|
||||
});
|
||||
|
||||
events.forEach(log(req, 'req'));
|
||||
15
node_modules/nock/examples/delay-response.js
generated
vendored
Normal file
15
node_modules/nock/examples/delay-response.js
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
var http = require('http');
|
||||
var nock = require('../');
|
||||
var log = require('./_log');
|
||||
var events = ['socket', 'response', 'end', 'data'];
|
||||
|
||||
nock('http://delayconnection.com').
|
||||
get('/').
|
||||
delay(1000).
|
||||
reply(200, 'hey');
|
||||
|
||||
var req = http.get('http://delayconnection.com', function(res) {
|
||||
events.forEach(log(res, 'res'));
|
||||
});
|
||||
|
||||
events.forEach(log(req, 'req'));
|
||||
18
node_modules/nock/examples/net-connect-default-no-mock.js
generated
vendored
Normal file
18
node_modules/nock/examples/net-connect-default-no-mock.js
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
Default net connect.
|
||||
No mock.
|
||||
Result: Nock allows request to proceed.
|
||||
*/
|
||||
|
||||
var log = require('./_log');
|
||||
|
||||
var events = ['socket', 'response', 'end', 'data', 'error'];
|
||||
|
||||
var http = require('http');
|
||||
console.log('making request...')
|
||||
var req = http.get('http://www.google.com/', function(res) {
|
||||
console.log('request result: res.statusCode = %j', res.statusCode);
|
||||
events.forEach(log(res, 'res'));
|
||||
});
|
||||
|
||||
events.forEach(log(req, 'req'));
|
||||
21
node_modules/nock/examples/net-connect-default-other-mock.js
generated
vendored
Normal file
21
node_modules/nock/examples/net-connect-default-other-mock.js
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
Default net connect.
|
||||
Mock the different hostname:port.
|
||||
Result: Nock allows request to proceed.
|
||||
*/
|
||||
|
||||
var log = require('./_log');
|
||||
|
||||
var events = ['socket', 'response', 'end', 'data', 'error'];
|
||||
|
||||
var nock = require('../');
|
||||
|
||||
nock('http://someotherservice.com').get('/').reply(200, 'whaaa');
|
||||
|
||||
var http = require('http');
|
||||
var req = http.get('http://www.google.com/', function(res) {
|
||||
console.log('request result: res.statusCode = %j', res.statusCode);
|
||||
events.forEach(log(res, 'res'));
|
||||
});
|
||||
|
||||
events.forEach(log(req, 'req'));
|
||||
24
node_modules/nock/examples/net-connect-disabled-different-host.js
generated
vendored
Normal file
24
node_modules/nock/examples/net-connect-disabled-different-host.js
generated
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
Disabled net connect.
|
||||
Mock the different hostname:port.
|
||||
Result: Nock does not allow request to proceed.
|
||||
*/
|
||||
|
||||
var log = require('./_log');
|
||||
|
||||
var events = ['socket', 'response', 'end', 'data', 'error'];
|
||||
|
||||
var nock = require('../');
|
||||
|
||||
nock.disableNetConnect();
|
||||
|
||||
nock('http://someotherservice.com').get('/').reply(200, 'whaaa');
|
||||
|
||||
var http = require('http');
|
||||
var req = http.get('http://www.google.com/');
|
||||
|
||||
req.once('error', function(err) {
|
||||
console.log(err.stack);
|
||||
});
|
||||
|
||||
events.forEach(log(req, 'req'));
|
||||
22
node_modules/nock/examples/net-connect-mock-same-host-different-path.js
generated
vendored
Normal file
22
node_modules/nock/examples/net-connect-mock-same-host-different-path.js
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
Default net connect.
|
||||
Mock the same hostname:port, different path.
|
||||
Result: Nock does not allow request to proceed.
|
||||
*/
|
||||
|
||||
var log = require('./_log');
|
||||
|
||||
var events = ['socket', 'response', 'end', 'data', 'error'];
|
||||
|
||||
var nock = require('../');
|
||||
|
||||
nock('http://example.com').get('/path').reply(200, 'whaaa');
|
||||
|
||||
var http = require('http');
|
||||
var req = http.get('http://example.com/other-path');
|
||||
|
||||
req.once('error', function(err) {
|
||||
console.log(err.stack);
|
||||
});
|
||||
|
||||
events.forEach(log(req, 'req'));
|
||||
19
node_modules/nock/examples/socket-delay-abort.js
generated
vendored
Normal file
19
node_modules/nock/examples/socket-delay-abort.js
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
var http = require('http');
|
||||
var nock = require('../');
|
||||
var log = require('./_log');
|
||||
var events = ['socket', 'response', 'end', 'data', 'timeout', 'error'];
|
||||
|
||||
nock('http://delayconnection.com').
|
||||
get('/').
|
||||
socketDelay(2000).
|
||||
reply(200, 'hey');
|
||||
|
||||
var req = http.get('http://delayconnection.com', function(res) {
|
||||
events.forEach(log(res, 'res'));
|
||||
});
|
||||
|
||||
req.setTimeout(1000, function() {
|
||||
req.abort();
|
||||
});
|
||||
|
||||
events.forEach(log(req, 'req'));
|
||||
15
node_modules/nock/examples/socket-delay-no-abort.js
generated
vendored
Normal file
15
node_modules/nock/examples/socket-delay-no-abort.js
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
var http = require('http');
|
||||
var nock = require('../');
|
||||
var log = require('./_log');
|
||||
var events = ['socket', 'response', 'end', 'data', 'timeout', 'error'];
|
||||
|
||||
nock('http://delayconnection.com').
|
||||
get('/').
|
||||
socketDelay(2000).
|
||||
reply(200, 'hey');
|
||||
|
||||
var req = http.get('http://delayconnection.com', function(res) {
|
||||
events.forEach(log(res, 'res'));
|
||||
});
|
||||
|
||||
events.forEach(log(req, 'req'));
|
||||
13
node_modules/nock/index.js
generated
vendored
Normal file
13
node_modules/nock/index.js
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
'use strict';
|
||||
|
||||
var recorder = require('./lib/recorder');
|
||||
module.exports = require('./lib/scope');
|
||||
|
||||
module.exports.recorder = {
|
||||
rec : recorder.record
|
||||
, clear : recorder.clear
|
||||
, play : recorder.outputs
|
||||
};
|
||||
|
||||
module.exports.back = require('./lib/back');
|
||||
module.exports.restore = recorder.restore;
|
||||
338
node_modules/nock/lib/back.js
generated
vendored
Normal file
338
node_modules/nock/lib/back.js
generated
vendored
Normal file
@@ -0,0 +1,338 @@
|
||||
'use strict';
|
||||
|
||||
/* global Promise */
|
||||
|
||||
var _ = require('lodash');
|
||||
var nock = require('./scope');
|
||||
var recorder = require('./recorder');
|
||||
|
||||
var format = require('util').format;
|
||||
var path = require('path');
|
||||
var expect = require('chai').expect;
|
||||
var debug = require('debug')('nock.back');
|
||||
|
||||
var _mode = null;
|
||||
|
||||
var fs;
|
||||
|
||||
try {
|
||||
fs = require('fs');
|
||||
} catch(err) {
|
||||
// do nothing, probably in browser
|
||||
}
|
||||
|
||||
var mkdirp;
|
||||
try {
|
||||
mkdirp = require('mkdirp');
|
||||
} catch(err) {
|
||||
// do nothing, probably in browser
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* nock the current function with the fixture given
|
||||
*
|
||||
* @param {string} fixtureName - the name of the fixture, e.x. 'foo.json'
|
||||
* @param {object} options - [optional] extra options for nock with, e.x. `{ assert: true }`
|
||||
* @param {function} nockedFn - [optional] callback function to be executed with the given fixture being loaded;
|
||||
* if defined the function will be called with context `{ scopes: loaded_nocks || [] }`
|
||||
* set as `this` and `nockDone` callback function as first and only parameter;
|
||||
* if not defined a promise resolving to `{nockDone, context}` where `context` is
|
||||
* aforementioned `{ scopes: loaded_nocks || [] }`
|
||||
*
|
||||
* List of options:
|
||||
*
|
||||
* @param {function} before - a preprocessing function, gets called before nock.define
|
||||
* @param {function} after - a postprocessing function, gets called after nock.define
|
||||
* @param {function} afterRecord - a postprocessing function, gets called after recording. Is passed the array
|
||||
* of scopes recorded and should return the array scopes to save to the fixture
|
||||
* @param {function} recorder - custom options to pass to the recorder
|
||||
*
|
||||
*/
|
||||
function Back (fixtureName, options, nockedFn) {
|
||||
if(!Back.fixtures) {
|
||||
throw new Error( 'Back requires nock.back.fixtures to be set\n' +
|
||||
'Ex:\n' +
|
||||
'\trequire(nock).back.fixtures = \'/path/to/fixures/\'');
|
||||
}
|
||||
|
||||
if (!_.isString(fixtureName)) {
|
||||
throw new Error('Parameter fixtureName must be a string');
|
||||
}
|
||||
|
||||
if( arguments.length === 1 ) {
|
||||
options = {};
|
||||
} else if( arguments.length === 2 ) {
|
||||
// If 2nd parameter is a function then `options` has been omitted
|
||||
// otherwise `options` haven't been omitted but `nockedFn` was.
|
||||
if (_.isFunction(options)) {
|
||||
nockedFn = options;
|
||||
options = {};
|
||||
}
|
||||
}
|
||||
|
||||
_mode.setup();
|
||||
|
||||
var fixture = path.join(Back.fixtures, fixtureName)
|
||||
, context = _mode.start(fixture, options);
|
||||
|
||||
|
||||
var nockDone = function () {
|
||||
_mode.finish(fixture, options, context);
|
||||
};
|
||||
|
||||
debug('context:', context);
|
||||
|
||||
// If nockedFn is a function then invoke it, otherwise return a promise resolving to nockDone.
|
||||
if (_.isFunction(nockedFn)) {
|
||||
nockedFn.call(context, nockDone);
|
||||
} else {
|
||||
return Promise.resolve({nockDone: nockDone, context: context});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
* Modes *
|
||||
*******************************************************************************/
|
||||
|
||||
|
||||
var wild = {
|
||||
|
||||
|
||||
setup: function () {
|
||||
nock.cleanAll();
|
||||
recorder.restore();
|
||||
nock.activate();
|
||||
nock.enableNetConnect();
|
||||
},
|
||||
|
||||
|
||||
start: function () {
|
||||
return load(); //don't load anything but get correct context
|
||||
},
|
||||
|
||||
|
||||
finish: function () {
|
||||
//nothing to do
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
var dryrun = {
|
||||
|
||||
|
||||
setup: function () {
|
||||
recorder.restore();
|
||||
nock.cleanAll();
|
||||
nock.activate();
|
||||
// We have to explicitly enable net connectivity as by default it's off.
|
||||
nock.enableNetConnect();
|
||||
},
|
||||
|
||||
|
||||
start: function (fixture, options) {
|
||||
var contexts = load(fixture, options);
|
||||
|
||||
nock.enableNetConnect();
|
||||
return contexts;
|
||||
},
|
||||
|
||||
|
||||
finish: function () {
|
||||
//nothing to do
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
var record = {
|
||||
|
||||
|
||||
setup: function () {
|
||||
recorder.restore();
|
||||
recorder.clear();
|
||||
nock.cleanAll();
|
||||
nock.activate();
|
||||
nock.disableNetConnect();
|
||||
},
|
||||
|
||||
|
||||
start: function (fixture, options) {
|
||||
if (! fs) {
|
||||
throw new Error('no fs');
|
||||
}
|
||||
var context = load(fixture, options);
|
||||
|
||||
if( !context.isLoaded ) {
|
||||
recorder.record(_.assign({
|
||||
dont_print: true,
|
||||
output_objects: true
|
||||
}, options && options.recorder));
|
||||
|
||||
context.isRecording = true;
|
||||
}
|
||||
|
||||
return context;
|
||||
},
|
||||
|
||||
|
||||
finish: function (fixture, options, context) {
|
||||
if( context.isRecording ) {
|
||||
var outputs = recorder.outputs();
|
||||
|
||||
if( typeof options.afterRecord === 'function' ) {
|
||||
outputs = options.afterRecord(outputs);
|
||||
}
|
||||
|
||||
outputs = JSON.stringify(outputs, null, 4);
|
||||
debug('recorder outputs:', outputs);
|
||||
|
||||
mkdirp.sync(path.dirname(fixture));
|
||||
fs.writeFileSync(fixture, outputs);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
var lockdown = {
|
||||
|
||||
|
||||
setup: function () {
|
||||
recorder.restore();
|
||||
recorder.clear();
|
||||
nock.cleanAll();
|
||||
nock.activate();
|
||||
nock.disableNetConnect();
|
||||
},
|
||||
|
||||
|
||||
start: function (fixture, options) {
|
||||
return load(fixture, options);
|
||||
},
|
||||
|
||||
|
||||
finish: function () {
|
||||
//nothing to do
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
function load (fixture, options) {
|
||||
var context = {
|
||||
scopes : [],
|
||||
assertScopesFinished: function () {
|
||||
assertScopes(this.scopes, fixture);
|
||||
}
|
||||
};
|
||||
|
||||
if( fixture && fixtureExists(fixture) ) {
|
||||
var scopes = nock.loadDefs(fixture);
|
||||
applyHook(scopes, options.before);
|
||||
|
||||
scopes = nock.define(scopes);
|
||||
applyHook(scopes, options.after);
|
||||
|
||||
context.scopes = scopes;
|
||||
context.isLoaded = true;
|
||||
}
|
||||
|
||||
|
||||
return context;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
function applyHook(scopes, fn) {
|
||||
if( !fn ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if( typeof fn !== 'function' ) {
|
||||
throw new Error ('processing hooks must be a function');
|
||||
}
|
||||
|
||||
scopes.forEach(fn);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
function fixtureExists(fixture) {
|
||||
if (! fs) {
|
||||
throw new Error('no fs');
|
||||
}
|
||||
|
||||
return fs.existsSync(fixture);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
function assertScopes (scopes, fixture) {
|
||||
scopes.forEach(function (scope) {
|
||||
expect( scope.isDone() )
|
||||
.to.be.equal(
|
||||
true,
|
||||
format('%j was not used, consider removing %s to rerecord fixture', scope.pendingMocks(), fixture)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
var Modes = {
|
||||
|
||||
wild: wild, //all requests go out to the internet, dont replay anything, doesnt record anything
|
||||
|
||||
dryrun: dryrun, //use recorded nocks, allow http calls, doesnt record anything, useful for writing new tests (default)
|
||||
|
||||
record: record, //use recorded nocks, record new nocks
|
||||
|
||||
lockdown: lockdown, //use recorded nocks, disables all http calls even when not nocked, doesnt record
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Back.setMode = function(mode) {
|
||||
if( !Modes.hasOwnProperty(mode) ) {
|
||||
throw new Error ('Unknown mode: ' + mode);
|
||||
}
|
||||
|
||||
Back.currentMode = mode;
|
||||
debug('New nock back mode:', Back.currentMode);
|
||||
|
||||
_mode = Modes[mode];
|
||||
_mode.setup();
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
Back.fixtures = null;
|
||||
Back.currentMode = null;
|
||||
Back.setMode(process.env.NOCK_BACK_MODE || 'dryrun');
|
||||
|
||||
module.exports = exports = Back;
|
||||
402
node_modules/nock/lib/common.js
generated
vendored
Normal file
402
node_modules/nock/lib/common.js
generated
vendored
Normal file
@@ -0,0 +1,402 @@
|
||||
'use strict';
|
||||
|
||||
var _ = require('lodash');
|
||||
var debug = require('debug')('nock.common');
|
||||
var semver = require('semver')
|
||||
|
||||
/**
|
||||
* Normalizes the request options so that it always has `host` property.
|
||||
*
|
||||
* @param {Object} options - a parsed options object of the request
|
||||
*/
|
||||
var normalizeRequestOptions = function(options) {
|
||||
options.proto = options.proto || (options._https_ ? 'https': 'http');
|
||||
options.port = options.port || ((options.proto === 'http') ? 80 : 443);
|
||||
if (options.host) {
|
||||
debug('options.host:', options.host);
|
||||
if (! options.hostname) {
|
||||
if (options.host.split(':').length == 2) {
|
||||
options.hostname = options.host.split(':')[0];
|
||||
} else {
|
||||
options.hostname = options.host;
|
||||
}
|
||||
}
|
||||
}
|
||||
debug('options.hostname in the end: %j', options.hostname);
|
||||
options.host = (options.hostname || 'localhost') + ':' + options.port;
|
||||
debug('options.host in the end: %j', options.host);
|
||||
|
||||
/// lowercase host names
|
||||
['hostname', 'host'].forEach(function(attr) {
|
||||
if (options[attr]) {
|
||||
options[attr] = options[attr].toLowerCase();
|
||||
}
|
||||
});
|
||||
|
||||
return options;
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns true if the data contained in buffer is binary which in this case means
|
||||
* that it cannot be reconstructed from its utf8 representation.
|
||||
*
|
||||
* @param {Object} buffer - a Buffer object
|
||||
*/
|
||||
var isBinaryBuffer = function(buffer) {
|
||||
|
||||
if(!Buffer.isBuffer(buffer)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Test if the buffer can be reconstructed verbatim from its utf8 encoding.
|
||||
var utfEncodedBuffer = buffer.toString('utf8');
|
||||
var reconstructedBuffer = Buffer.from(utfEncodedBuffer, 'utf8');
|
||||
var compareBuffers = function(lhs, rhs) {
|
||||
if(lhs.length !== rhs.length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for(var i = 0; i < lhs.length; ++i) {
|
||||
if(lhs[i] !== rhs[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
// If the buffers are *not* equal then this is a "binary buffer"
|
||||
// meaning that it cannot be faitfully represented in utf8.
|
||||
return !compareBuffers(buffer, reconstructedBuffer);
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* If the chunks are Buffer objects then it returns a single Buffer object with the data from all the chunks.
|
||||
* If the chunks are strings then it returns a single string value with data from all the chunks.
|
||||
*
|
||||
* @param {Array} chunks - an array of Buffer objects or strings
|
||||
*/
|
||||
var mergeChunks = function(chunks) {
|
||||
|
||||
if(_.isEmpty(chunks)) {
|
||||
return Buffer.alloc(0);
|
||||
}
|
||||
|
||||
// We assume that all chunks are Buffer objects if the first is buffer object.
|
||||
var areBuffers = Buffer.isBuffer(_.first(chunks));
|
||||
|
||||
if(!areBuffers) {
|
||||
// When the chunks are not buffers we assume that they are strings.
|
||||
return chunks.join('');
|
||||
}
|
||||
|
||||
// Merge all the buffers into a single Buffer object.
|
||||
return Buffer.concat(chunks);
|
||||
|
||||
};
|
||||
|
||||
// Array where all information about all the overridden requests are held.
|
||||
var requestOverride = [];
|
||||
|
||||
/**
|
||||
* Overrides the current `request` function of `http` and `https` modules with
|
||||
* our own version which intercepts issues HTTP/HTTPS requests and forwards them
|
||||
* to the given `newRequest` function.
|
||||
*
|
||||
* @param {Function} newRequest - a function handling requests; it accepts four arguments:
|
||||
* - proto - a string with the overridden module's protocol name (either `http` or `https`)
|
||||
* - overriddenRequest - the overridden module's request function already bound to module's object
|
||||
* - options - the options of the issued request
|
||||
* - callback - the callback of the issued request
|
||||
*/
|
||||
var overrideRequests = function(newRequest) {
|
||||
debug('overriding requests');
|
||||
|
||||
['http', 'https'].forEach(function(proto) {
|
||||
debug('- overriding request for', proto);
|
||||
|
||||
var moduleName = proto, // 1 to 1 match of protocol and module is fortunate :)
|
||||
module = {
|
||||
http: require('http'),
|
||||
https: require('https')
|
||||
}[moduleName],
|
||||
overriddenRequest = module.request,
|
||||
overriddenGet = module.get;
|
||||
|
||||
if(requestOverride[moduleName]) {
|
||||
throw new Error('Module\'s request already overridden for ' + moduleName + ' protocol.');
|
||||
}
|
||||
|
||||
// Store the properties of the overridden request so that it can be restored later on.
|
||||
requestOverride[moduleName] = {
|
||||
module: module,
|
||||
request: overriddenRequest,
|
||||
get: overriddenGet
|
||||
};
|
||||
|
||||
module.request = function(options, callback) {
|
||||
// debug('request options:', options);
|
||||
return newRequest(proto, overriddenRequest.bind(module), options, callback);
|
||||
};
|
||||
|
||||
if (semver.satisfies(process.version, '>=8')) {
|
||||
module.get = function(options, callback) {
|
||||
var req = newRequest(proto, overriddenRequest.bind(module), options, callback);
|
||||
req.end();
|
||||
return req;
|
||||
}
|
||||
}
|
||||
|
||||
debug('- overridden request for', proto);
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Restores `request` function of `http` and `https` modules to values they
|
||||
* held before they were overridden by us.
|
||||
*/
|
||||
var restoreOverriddenRequests = function() {
|
||||
debug('restoring requests');
|
||||
|
||||
// Restore any overridden requests.
|
||||
_(requestOverride).keys().each(function(proto) {
|
||||
debug('- restoring request for', proto);
|
||||
|
||||
var override = requestOverride[proto];
|
||||
if(override) {
|
||||
override.module.request = override.request;
|
||||
override.module.get = override.get;
|
||||
debug('- restored request for', proto);
|
||||
}
|
||||
});
|
||||
requestOverride = [];
|
||||
};
|
||||
|
||||
/**
|
||||
* Get high level information about request as string
|
||||
* @param {Object} options
|
||||
* @param {string} options.method
|
||||
* @param {string} options.port
|
||||
* @param {string} options.proto
|
||||
* @param {string} options.hostname
|
||||
* @param {string} options.path
|
||||
* @param {Object} options.headers
|
||||
* @param {string|object} body
|
||||
* @return {string}
|
||||
*/
|
||||
function stringifyRequest(options, body) {
|
||||
var method = options.method || 'GET';
|
||||
|
||||
var port = options.port;
|
||||
if (! port) port = (options.proto == 'https' ? '443' : '80');
|
||||
|
||||
if (options.proto == 'https' && port == '443' ||
|
||||
options.proto == 'http' && port == '80') {
|
||||
port = '';
|
||||
}
|
||||
|
||||
if (port) port = ':' + port;
|
||||
|
||||
var path = options.path ? options.path : '';
|
||||
|
||||
var log = {
|
||||
method: method,
|
||||
url: options.proto + '://' + options.hostname + port + path,
|
||||
headers: options.headers
|
||||
};
|
||||
|
||||
if (body) {
|
||||
log.body = body;
|
||||
}
|
||||
|
||||
return JSON.stringify(log, null, 2);
|
||||
}
|
||||
|
||||
function isContentEncoded(headers) {
|
||||
var contentEncoding = _.get(headers, 'content-encoding');
|
||||
return _.isString(contentEncoding) && contentEncoding !== '';
|
||||
}
|
||||
|
||||
function contentEncoding(headers, encoder) {
|
||||
var contentEncoding = _.get(headers, 'content-encoding');
|
||||
return contentEncoding === encoder;
|
||||
}
|
||||
|
||||
function isJSONContent(headers) {
|
||||
var contentType = _.get(headers, 'content-type');
|
||||
if (Array.isArray(contentType)) {
|
||||
contentType = contentType[0];
|
||||
}
|
||||
contentType = (contentType || '').toLocaleLowerCase();
|
||||
|
||||
return contentType === 'application/json';
|
||||
}
|
||||
|
||||
var headersFieldNamesToLowerCase = function(headers) {
|
||||
if(!_.isObject(headers)) {
|
||||
return headers;
|
||||
}
|
||||
|
||||
// For each key in the headers, delete its value and reinsert it with lower-case key.
|
||||
// Keys represent headers field names.
|
||||
var lowerCaseHeaders = {};
|
||||
_.forOwn(headers, function(fieldVal, fieldName) {
|
||||
var lowerCaseFieldName = fieldName.toLowerCase();
|
||||
if(!_.isUndefined(lowerCaseHeaders[lowerCaseFieldName])) {
|
||||
throw new Error('Failed to convert header keys to lower case due to field name conflict: ' + lowerCaseFieldName);
|
||||
}
|
||||
lowerCaseHeaders[lowerCaseFieldName] = fieldVal;
|
||||
});
|
||||
|
||||
return lowerCaseHeaders;
|
||||
};
|
||||
|
||||
var headersFieldsArrayToLowerCase = function (headers) {
|
||||
return _.uniq(_.map(headers, function (fieldName) {
|
||||
return fieldName.toLowerCase();
|
||||
}));
|
||||
};
|
||||
|
||||
var headersArrayToObject = function (rawHeaders) {
|
||||
if(!_.isArray(rawHeaders)) {
|
||||
return rawHeaders;
|
||||
}
|
||||
|
||||
var headers = {};
|
||||
|
||||
for (var i=0, len=rawHeaders.length; i<len; i=i+2) {
|
||||
var key = rawHeaders[i].toLowerCase();
|
||||
var value = rawHeaders[i+1];
|
||||
|
||||
if (headers[key]) {
|
||||
headers[key] = _.isArray(headers[key]) ? headers[key] : [headers[key]];
|
||||
headers[key].push(value);
|
||||
} else {
|
||||
headers[key] = value;
|
||||
}
|
||||
}
|
||||
|
||||
return headers;
|
||||
};
|
||||
|
||||
/**
|
||||
* Deletes the given `fieldName` property from `headers` object by performing
|
||||
* case-insensitive search through keys.
|
||||
*
|
||||
* @headers {Object} headers - object of header field names and values
|
||||
* @fieldName {String} field name - string with the case-insensitive field name
|
||||
*/
|
||||
var deleteHeadersField = function(headers, fieldNameToDelete) {
|
||||
|
||||
if(!_.isObject(headers) || !_.isString(fieldNameToDelete)) {
|
||||
return;
|
||||
}
|
||||
|
||||
var lowerCaseFieldNameToDelete = fieldNameToDelete.toLowerCase();
|
||||
|
||||
// Search through the headers and delete all values whose field name matches the given field name.
|
||||
_(headers).keys().each(function(fieldName) {
|
||||
var lowerCaseFieldName = fieldName.toLowerCase();
|
||||
if(lowerCaseFieldName === lowerCaseFieldNameToDelete) {
|
||||
delete headers[fieldName];
|
||||
// We don't stop here but continue in order to remove *all* matching field names
|
||||
// (even though if seen regorously there shouldn't be any)
|
||||
}
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
function percentDecode (str) {
|
||||
try {
|
||||
return decodeURIComponent(str.replace(/\+/g, ' '));
|
||||
} catch (e) {
|
||||
return str;
|
||||
}
|
||||
}
|
||||
|
||||
function percentEncode(str) {
|
||||
return encodeURIComponent(str).replace(/[!'()*]/g, function(c) {
|
||||
return '%' + c.charCodeAt(0).toString(16).toUpperCase();
|
||||
});
|
||||
}
|
||||
|
||||
function matchStringOrRegexp(target, pattern) {
|
||||
var str = (!_.isUndefined(target) && target.toString && target.toString()) || '';
|
||||
|
||||
return pattern instanceof RegExp ? str.match(pattern) : str === String(pattern);
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats a query parameter.
|
||||
*
|
||||
* @param key The key of the query parameter to format.
|
||||
* @param value The value of the query parameter to format.
|
||||
* @param stringFormattingFn The function used to format string values. Can
|
||||
* be used to encode or decode the query value.
|
||||
*
|
||||
* @returns the formatted [key, value] pair.
|
||||
*/
|
||||
function formatQueryValue(key, value, stringFormattingFn) {
|
||||
switch (true) {
|
||||
case _.isNumber(value): // fall-through
|
||||
case _.isBoolean(value):
|
||||
value = value.toString();
|
||||
break;
|
||||
case _.isUndefined(value): // fall-through
|
||||
case _.isNull(value):
|
||||
value = '';
|
||||
break;
|
||||
case _.isString(value):
|
||||
if(stringFormattingFn) {
|
||||
value = stringFormattingFn(value);
|
||||
}
|
||||
break;
|
||||
case (value instanceof RegExp):
|
||||
break;
|
||||
case _.isArray(value):
|
||||
var tmpArray = new Array(value.length);
|
||||
for (var i = 0; i < value.length; ++i) {
|
||||
tmpArray[i] = formatQueryValue(i, value[i], stringFormattingFn)[1];
|
||||
}
|
||||
value = tmpArray;
|
||||
break;
|
||||
case _.isObject(value):
|
||||
var tmpObj = {};
|
||||
_.forOwn(value, function(subVal, subKey){
|
||||
var subPair = formatQueryValue(subKey, subVal, stringFormattingFn);
|
||||
tmpObj[subPair[0]] = subPair[1];
|
||||
});
|
||||
value = tmpObj;
|
||||
break;
|
||||
}
|
||||
|
||||
if (stringFormattingFn) key = stringFormattingFn(key);
|
||||
return [key, value];
|
||||
}
|
||||
|
||||
function isStream(obj) {
|
||||
return obj &&
|
||||
(typeof a !== 'string') &&
|
||||
(! Buffer.isBuffer(obj)) &&
|
||||
_.isFunction(obj.setEncoding);
|
||||
}
|
||||
|
||||
exports.normalizeRequestOptions = normalizeRequestOptions;
|
||||
exports.isBinaryBuffer = isBinaryBuffer;
|
||||
exports.mergeChunks = mergeChunks;
|
||||
exports.overrideRequests = overrideRequests;
|
||||
exports.restoreOverriddenRequests = restoreOverriddenRequests;
|
||||
exports.stringifyRequest = stringifyRequest;
|
||||
exports.isContentEncoded = isContentEncoded;
|
||||
exports.contentEncoding = contentEncoding;
|
||||
exports.isJSONContent = isJSONContent;
|
||||
exports.headersFieldNamesToLowerCase = headersFieldNamesToLowerCase;
|
||||
exports.headersFieldsArrayToLowerCase = headersFieldsArrayToLowerCase;
|
||||
exports.headersArrayToObject = headersArrayToObject;
|
||||
exports.deleteHeadersField = deleteHeadersField;
|
||||
exports.percentEncode = percentEncode;
|
||||
exports.percentDecode = percentDecode;
|
||||
exports.matchStringOrRegexp = matchStringOrRegexp;
|
||||
exports.formatQueryValue = formatQueryValue;
|
||||
exports.isStream = isStream;
|
||||
81
node_modules/nock/lib/delayed_body.js
generated
vendored
Normal file
81
node_modules/nock/lib/delayed_body.js
generated
vendored
Normal file
@@ -0,0 +1,81 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Creates a stream which becomes the response body of the interceptor when a
|
||||
* delay is set. The stream outputs the intended body and EOF after the delay.
|
||||
*
|
||||
* @param {String|Buffer|Stream} body - the body to write/pipe out
|
||||
* @param {Integer} ms - The delay in milliseconds
|
||||
* @constructor
|
||||
*/
|
||||
module.exports = DelayedBody;
|
||||
|
||||
var Transform = require('stream').Transform;
|
||||
var EventEmitter = require('events').EventEmitter;
|
||||
var noop = function () {};
|
||||
var util = require('util');
|
||||
var common = require('./common');
|
||||
|
||||
if (!Transform) {
|
||||
// for barebones compatibility for node < 0.10
|
||||
var FakeTransformStream = function () {
|
||||
EventEmitter.call(this);
|
||||
};
|
||||
util.inherits(FakeTransformStream, EventEmitter);
|
||||
FakeTransformStream.prototype.pause = noop;
|
||||
FakeTransformStream.prototype.resume = noop;
|
||||
FakeTransformStream.prototype.setEncoding = noop;
|
||||
FakeTransformStream.prototype.write = function (chunk, encoding) {
|
||||
var self = this;
|
||||
process.nextTick(function () {
|
||||
self.emit('data', chunk, encoding);
|
||||
});
|
||||
};
|
||||
FakeTransformStream.prototype.end = function (chunk) {
|
||||
var self = this;
|
||||
if (chunk) {
|
||||
self.write(chunk);
|
||||
}
|
||||
process.nextTick(function () {
|
||||
self.emit('end');
|
||||
});
|
||||
};
|
||||
|
||||
Transform = FakeTransformStream;
|
||||
}
|
||||
|
||||
function DelayedBody(ms, body) {
|
||||
Transform.call(this);
|
||||
|
||||
var self = this;
|
||||
var data = '';
|
||||
var ended = false;
|
||||
|
||||
if (common.isStream(body)) {
|
||||
body.on('data', function (chunk) {
|
||||
data += Buffer.isBuffer(chunk) ? chunk.toString() : chunk;
|
||||
});
|
||||
|
||||
body.once('end', function () {
|
||||
ended = true;
|
||||
});
|
||||
|
||||
body.resume();
|
||||
}
|
||||
|
||||
setTimeout(function () {
|
||||
if (common.isStream(body) && !ended) {
|
||||
body.once('end', function () {
|
||||
self.end(data);
|
||||
});
|
||||
} else {
|
||||
self.end(data || body);
|
||||
}
|
||||
}, ms);
|
||||
}
|
||||
util.inherits(DelayedBody, Transform);
|
||||
|
||||
DelayedBody.prototype._transform = function (chunk, encoding, cb) {
|
||||
this.push(chunk);
|
||||
process.nextTick(cb);
|
||||
};
|
||||
5
node_modules/nock/lib/global_emitter.js
generated
vendored
Normal file
5
node_modules/nock/lib/global_emitter.js
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
var EventEmitter = require('events').EventEmitter
|
||||
|
||||
module.exports = new EventEmitter();
|
||||
429
node_modules/nock/lib/intercept.js
generated
vendored
Normal file
429
node_modules/nock/lib/intercept.js
generated
vendored
Normal file
@@ -0,0 +1,429 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* @module nock/intercepts
|
||||
*/
|
||||
|
||||
var RequestOverrider = require('./request_overrider'),
|
||||
common = require('./common'),
|
||||
inherits = require('util').inherits,
|
||||
Interceptor = require('./interceptor'),
|
||||
http = require('http'),
|
||||
parse = require('url').parse,
|
||||
URL = require('url').URL,
|
||||
_ = require('lodash'),
|
||||
debug = require('debug')('nock.intercept'),
|
||||
EventEmitter = require('events').EventEmitter,
|
||||
globalEmitter = require('./global_emitter'),
|
||||
timers = require('timers');
|
||||
|
||||
|
||||
/**
|
||||
* @name NetConnectNotAllowedError
|
||||
* @private
|
||||
* @desc Error trying to make a connection when disabled external access.
|
||||
* @class
|
||||
* @example
|
||||
* nock.disableNetConnect();
|
||||
* http.get('http://zombo.com');
|
||||
* // throw NetConnectNotAllowedError
|
||||
*/
|
||||
function NetConnectNotAllowedError(host, path) {
|
||||
Error.call(this);
|
||||
|
||||
this.name = 'NetConnectNotAllowedError';
|
||||
this.code = 'ENETUNREACH'
|
||||
this.message = 'Nock: Disallowed net connect for "' + host + path + '"';
|
||||
|
||||
Error.captureStackTrace(this, this.constructor);
|
||||
}
|
||||
|
||||
inherits(NetConnectNotAllowedError, Error);
|
||||
|
||||
var allInterceptors = {},
|
||||
allowNetConnect;
|
||||
|
||||
/**
|
||||
* Enabled real request.
|
||||
* @public
|
||||
* @param {String|RegExp} matcher=RegExp.new('.*') Expression to match
|
||||
* @example
|
||||
* // Enables all real requests
|
||||
* nock.enableNetConnect();
|
||||
* @example
|
||||
* // Enables real requests for url that matches google
|
||||
* nock.enableNetConnect('google');
|
||||
* @example
|
||||
* // Enables real requests for url that matches google and amazon
|
||||
* nock.enableNetConnect(/(google|amazon)/);
|
||||
*/
|
||||
function enableNetConnect(matcher) {
|
||||
if (_.isString(matcher)) {
|
||||
allowNetConnect = new RegExp(matcher);
|
||||
} else if (_.isObject(matcher) && _.isFunction(matcher.test)) {
|
||||
allowNetConnect = matcher;
|
||||
} else {
|
||||
allowNetConnect = /.*/;
|
||||
}
|
||||
}
|
||||
|
||||
function isEnabledForNetConnect(options) {
|
||||
common.normalizeRequestOptions(options);
|
||||
|
||||
var enabled = allowNetConnect && allowNetConnect.test(options.host);
|
||||
debug('Net connect', enabled ? '' : 'not', 'enabled for', options.host);
|
||||
return enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable all real requests.
|
||||
* @public
|
||||
* @param {String|RegExp} matcher=RegExp.new('.*') Expression to match
|
||||
* @example
|
||||
* nock.disableNetConnect();
|
||||
*/
|
||||
function disableNetConnect() {
|
||||
allowNetConnect = undefined;
|
||||
}
|
||||
|
||||
function isOn() {
|
||||
return !isOff();
|
||||
}
|
||||
|
||||
function isOff() {
|
||||
return process.env.NOCK_OFF === 'true';
|
||||
}
|
||||
|
||||
function add(key, interceptor, scope, scopeOptions, host) {
|
||||
if (! allInterceptors.hasOwnProperty(key)) {
|
||||
allInterceptors[key] = { key: key, scopes: [] };
|
||||
}
|
||||
interceptor.__nock_scope = scope;
|
||||
|
||||
// We need scope's key and scope options for scope filtering function (if defined)
|
||||
interceptor.__nock_scopeKey = key;
|
||||
interceptor.__nock_scopeOptions = scopeOptions;
|
||||
// We need scope's host for setting correct request headers for filtered scopes.
|
||||
interceptor.__nock_scopeHost = host;
|
||||
interceptor.interceptionCounter = 0;
|
||||
|
||||
if (scopeOptions.allowUnmocked)
|
||||
allInterceptors[key].allowUnmocked = true;
|
||||
|
||||
allInterceptors[key].scopes.push(interceptor);
|
||||
}
|
||||
|
||||
function remove(interceptor) {
|
||||
if (interceptor.__nock_scope.shouldPersist() || --interceptor.counter > 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
var basePath = interceptor.basePath;
|
||||
var interceptors = allInterceptors[basePath] && allInterceptors[basePath].scopes || [];
|
||||
|
||||
interceptors.some(function (thisInterceptor, i) {
|
||||
return (thisInterceptor === interceptor) ? interceptors.splice(i, 1) : false;
|
||||
});
|
||||
}
|
||||
|
||||
function removeAll() {
|
||||
Object.keys(allInterceptors).forEach(function(key) {
|
||||
allInterceptors[key].scopes.forEach(function(interceptor) {
|
||||
interceptor.scope.keyedInterceptors = {};
|
||||
});
|
||||
});
|
||||
allInterceptors = {};
|
||||
}
|
||||
|
||||
function interceptorsFor(options) {
|
||||
var basePath,
|
||||
matchingInterceptor;
|
||||
|
||||
common.normalizeRequestOptions(options);
|
||||
|
||||
debug('interceptors for %j', options.host);
|
||||
|
||||
basePath = options.proto + '://' + options.host;
|
||||
|
||||
debug('filtering interceptors for basepath', basePath);
|
||||
|
||||
// First try to use filteringScope if any of the interceptors has it defined.
|
||||
_.each(allInterceptors, function(interceptor, k) {
|
||||
_.each(interceptor.scopes, function(scope) {
|
||||
var filteringScope = scope.__nock_scopeOptions.filteringScope;
|
||||
|
||||
// If scope filtering function is defined and returns a truthy value
|
||||
// then we have to treat this as a match.
|
||||
if(filteringScope && filteringScope(basePath)) {
|
||||
debug('found matching scope interceptor');
|
||||
|
||||
// Keep the filtered scope (its key) to signal the rest of the module
|
||||
// that this wasn't an exact but filtered match.
|
||||
scope.__nock_filteredScope = scope.__nock_scopeKey;
|
||||
matchingInterceptor = interceptor.scopes;
|
||||
// Break out of _.each for scopes.
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
if (!matchingInterceptor && common.matchStringOrRegexp(basePath, interceptor.key)) {
|
||||
if (interceptor.scopes.length === 0 && interceptor.allowUnmocked) {
|
||||
matchingInterceptor = [
|
||||
{
|
||||
options: { allowUnmocked: true },
|
||||
matchIndependentOfBody: function() { return false }
|
||||
}
|
||||
];
|
||||
} else {
|
||||
matchingInterceptor = interceptor.scopes;
|
||||
}
|
||||
// false to short circuit the .each
|
||||
return false;
|
||||
}
|
||||
|
||||
// Returning falsy value here (which will happen if we have found our matching interceptor)
|
||||
// will break out of _.each for all interceptors.
|
||||
return !matchingInterceptor;
|
||||
});
|
||||
|
||||
return matchingInterceptor;
|
||||
}
|
||||
|
||||
function removeInterceptor(options) {
|
||||
var baseUrl, key, method, proto;
|
||||
if (options instanceof Interceptor) {
|
||||
baseUrl = options.basePath;
|
||||
key = options._key;
|
||||
} else {
|
||||
proto = options.proto ? options.proto : 'http';
|
||||
|
||||
common.normalizeRequestOptions(options);
|
||||
baseUrl = proto + '://' + options.host;
|
||||
method = options.method && options.method.toUpperCase() || 'GET';
|
||||
key = method + ' ' + baseUrl + (options.path || '/');
|
||||
}
|
||||
|
||||
if (allInterceptors[baseUrl] && allInterceptors[baseUrl].scopes.length > 0) {
|
||||
if (key) {
|
||||
for (var i = 0; i < allInterceptors[baseUrl].scopes.length; i++) {
|
||||
var interceptor = allInterceptors[baseUrl].scopes[i];
|
||||
if (interceptor._key === key) {
|
||||
allInterceptors[baseUrl].scopes.splice(i, 1);
|
||||
interceptor.scope.remove(key, interceptor);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
allInterceptors[baseUrl].scopes.length = 0;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
// Variable where we keep the ClientRequest we have overridden
|
||||
// (which might or might not be node's original http.ClientRequest)
|
||||
var originalClientRequest;
|
||||
|
||||
function ErroringClientRequest(error) {
|
||||
if (http.OutgoingMessage) http.OutgoingMessage.call(this);
|
||||
process.nextTick(function() {
|
||||
this.emit('error', error);
|
||||
}.bind(this));
|
||||
}
|
||||
|
||||
if (http.ClientRequest) {
|
||||
inherits(ErroringClientRequest, http.ClientRequest);
|
||||
}
|
||||
|
||||
function overrideClientRequest() {
|
||||
debug('Overriding ClientRequest');
|
||||
|
||||
if(originalClientRequest) {
|
||||
throw new Error('Nock already overrode http.ClientRequest');
|
||||
}
|
||||
|
||||
// ----- Extending http.ClientRequest
|
||||
|
||||
// Define the overriding client request that nock uses internally.
|
||||
function OverriddenClientRequest(options, cb) {
|
||||
if (http.OutgoingMessage) http.OutgoingMessage.call(this);
|
||||
|
||||
// Filter the interceptors per request options.
|
||||
var interceptors = interceptorsFor(options);
|
||||
|
||||
if (isOn() && interceptors) {
|
||||
debug('using', interceptors.length, 'interceptors');
|
||||
|
||||
// Use filtered interceptors to intercept requests.
|
||||
var overrider = RequestOverrider(this, options, interceptors, remove, cb);
|
||||
for(var propName in overrider) {
|
||||
if (overrider.hasOwnProperty(propName)) {
|
||||
this[propName] = overrider[propName];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
debug('falling back to original ClientRequest');
|
||||
|
||||
// Fallback to original ClientRequest if nock is off or the net connection is enabled.
|
||||
if(isOff() || isEnabledForNetConnect(options)) {
|
||||
originalClientRequest.apply(this, arguments);
|
||||
} else {
|
||||
timers.setImmediate(function () {
|
||||
var error = new NetConnectNotAllowedError(options.host, options.path);
|
||||
this.emit('error', error);
|
||||
}.bind(this));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (http.ClientRequest) {
|
||||
inherits(OverriddenClientRequest, http.ClientRequest);
|
||||
} else {
|
||||
inherits(OverriddenClientRequest, EventEmitter);
|
||||
}
|
||||
|
||||
// Override the http module's request but keep the original so that we can use it and later restore it.
|
||||
// NOTE: We only override http.ClientRequest as https module also uses it.
|
||||
originalClientRequest = http.ClientRequest;
|
||||
http.ClientRequest = OverriddenClientRequest;
|
||||
|
||||
debug('ClientRequest overridden');
|
||||
}
|
||||
|
||||
function restoreOverriddenClientRequest() {
|
||||
debug('restoring overridden ClientRequest');
|
||||
|
||||
// Restore the ClientRequest we have overridden.
|
||||
if(!originalClientRequest) {
|
||||
debug('- ClientRequest was not overridden');
|
||||
} else {
|
||||
http.ClientRequest = originalClientRequest;
|
||||
originalClientRequest = undefined;
|
||||
|
||||
debug('- ClientRequest restored');
|
||||
}
|
||||
}
|
||||
|
||||
function isActive() {
|
||||
|
||||
// If ClientRequest has been overwritten by Nock then originalClientRequest is not undefined.
|
||||
// This means that Nock has been activated.
|
||||
return !_.isUndefined(originalClientRequest);
|
||||
|
||||
}
|
||||
|
||||
function interceptorScopes() {
|
||||
return _.reduce(allInterceptors, function(result, interceptors) {
|
||||
for (var interceptor in interceptors.scopes) {
|
||||
result = result.concat(interceptors.scopes[interceptor].__nock_scope);
|
||||
}
|
||||
|
||||
return result;
|
||||
}, []);
|
||||
}
|
||||
|
||||
function isDone() {
|
||||
return _.every(interceptorScopes(), function(scope) {
|
||||
return scope.isDone();
|
||||
});
|
||||
}
|
||||
|
||||
function pendingMocks() {
|
||||
return _.flatten(_.map(interceptorScopes(), function(scope) {
|
||||
return scope.pendingMocks();
|
||||
}));
|
||||
}
|
||||
|
||||
function activeMocks() {
|
||||
return _.flatten(_.map(interceptorScopes(), function(scope) {
|
||||
return scope.activeMocks();
|
||||
}));
|
||||
}
|
||||
|
||||
function activate() {
|
||||
|
||||
if(originalClientRequest) {
|
||||
throw new Error('Nock already active');
|
||||
}
|
||||
|
||||
overrideClientRequest();
|
||||
|
||||
// ----- Overriding http.request and https.request:
|
||||
|
||||
common.overrideRequests(function(proto, overriddenRequest, options, callback) {
|
||||
// NOTE: overriddenRequest is already bound to its module.
|
||||
var req,
|
||||
res;
|
||||
|
||||
if (typeof options === 'string') {
|
||||
options = parse(options);
|
||||
} else if (URL && options instanceof URL) {
|
||||
options = parse(options.toString());
|
||||
}
|
||||
options.proto = proto;
|
||||
|
||||
var interceptors = interceptorsFor(options)
|
||||
|
||||
if (isOn() && interceptors) {
|
||||
var matches = false,
|
||||
allowUnmocked = false;
|
||||
|
||||
matches = !! _.find(interceptors, function(interceptor) {
|
||||
return interceptor.matchIndependentOfBody(options);
|
||||
});
|
||||
|
||||
allowUnmocked = !! _.find(interceptors, function(interceptor) {
|
||||
return interceptor.options.allowUnmocked;
|
||||
});
|
||||
|
||||
if (! matches && allowUnmocked) {
|
||||
if (proto === 'https') {
|
||||
var ClientRequest = http.ClientRequest;
|
||||
http.ClientRequest = originalClientRequest;
|
||||
req = overriddenRequest(options, callback);
|
||||
http.ClientRequest = ClientRequest;
|
||||
} else {
|
||||
req = overriddenRequest(options, callback);
|
||||
}
|
||||
globalEmitter.emit('no match', req);
|
||||
return req;
|
||||
}
|
||||
|
||||
// NOTE: Since we already overrode the http.ClientRequest we are in fact constructing
|
||||
// our own OverriddenClientRequest.
|
||||
req = new http.ClientRequest(options);
|
||||
|
||||
res = RequestOverrider(req, options, interceptors, remove);
|
||||
if (callback) {
|
||||
res.on('response', callback);
|
||||
}
|
||||
return req;
|
||||
} else {
|
||||
globalEmitter.emit('no match', options);
|
||||
if (isOff() || isEnabledForNetConnect(options)) {
|
||||
return overriddenRequest(options, callback);
|
||||
} else {
|
||||
var error = new NetConnectNotAllowedError(options.host, options.path);
|
||||
return new ErroringClientRequest(error);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
activate();
|
||||
|
||||
module.exports = add;
|
||||
module.exports.removeAll = removeAll;
|
||||
module.exports.removeInterceptor = removeInterceptor;
|
||||
module.exports.isOn = isOn;
|
||||
module.exports.activate = activate;
|
||||
module.exports.isActive = isActive;
|
||||
module.exports.isDone = isDone;
|
||||
module.exports.pendingMocks = pendingMocks;
|
||||
module.exports.activeMocks = activeMocks;
|
||||
module.exports.enableNetConnect = enableNetConnect;
|
||||
module.exports.disableNetConnect = disableNetConnect;
|
||||
module.exports.overrideClientRequest = overrideClientRequest;
|
||||
module.exports.restoreOverriddenClientRequest = restoreOverriddenClientRequest;
|
||||
569
node_modules/nock/lib/interceptor.js
generated
vendored
Normal file
569
node_modules/nock/lib/interceptor.js
generated
vendored
Normal file
@@ -0,0 +1,569 @@
|
||||
'use strict';
|
||||
|
||||
var mixin = require('./mixin')
|
||||
, matchBody = require('./match_body')
|
||||
, common = require('./common')
|
||||
, _ = require('lodash')
|
||||
, debug = require('debug')('nock.interceptor')
|
||||
, stringify = require('json-stringify-safe')
|
||||
, qs = require('qs');
|
||||
|
||||
var fs;
|
||||
|
||||
try {
|
||||
fs = require('fs');
|
||||
} catch (err) {
|
||||
// do nothing, we're in the browser
|
||||
}
|
||||
|
||||
module.exports = Interceptor;
|
||||
|
||||
function Interceptor(scope, uri, method, requestBody, interceptorOptions) {
|
||||
this.scope = scope;
|
||||
this.interceptorMatchHeaders = [];
|
||||
|
||||
if (typeof method === 'undefined' || !method) {
|
||||
throw new Error('The "method" parameter is required for an intercept call.');
|
||||
}
|
||||
this.method = method.toUpperCase();
|
||||
this.uri = uri;
|
||||
this._key = this.method + ' ' + scope.basePath + scope.basePathname + (typeof uri === 'string' ? '' : '/') + uri;
|
||||
this.basePath = this.scope.basePath;
|
||||
this.path = (typeof uri === 'string') ? scope.basePathname + uri : uri;
|
||||
|
||||
this.baseUri = this.method + ' ' + scope.basePath + scope.basePathname;
|
||||
this.options = interceptorOptions || {};
|
||||
this.counter = 1;
|
||||
this._requestBody = requestBody;
|
||||
|
||||
// We use lower-case header field names throughout Nock.
|
||||
this.reqheaders = common.headersFieldNamesToLowerCase((scope.scopeOptions && scope.scopeOptions.reqheaders) || {});
|
||||
this.badheaders = common.headersFieldsArrayToLowerCase((scope.scopeOptions && scope.scopeOptions.badheaders) || []);
|
||||
|
||||
|
||||
this.delayInMs = 0;
|
||||
this.delayConnectionInMs = 0;
|
||||
|
||||
this.optional = false;
|
||||
}
|
||||
|
||||
Interceptor.prototype.optionally = function optionally(value) {
|
||||
// The default behaviour of optionally() with no arguments is to make the mock optional.
|
||||
value = (typeof value === 'undefined') ? true : value;
|
||||
|
||||
this.optional = value;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
Interceptor.prototype.replyWithError = function replyWithError(errorMessage) {
|
||||
this.errorMessage = errorMessage;
|
||||
|
||||
_.defaults(this.options, this.scope.scopeOptions);
|
||||
|
||||
this.scope.add(this._key, this, this.scope, this.scopeOptions);
|
||||
return this.scope;
|
||||
};
|
||||
|
||||
Interceptor.prototype.reply = function reply(statusCode, body, rawHeaders) {
|
||||
if (arguments.length <= 2 && _.isFunction(statusCode)) {
|
||||
body = statusCode;
|
||||
statusCode = 200;
|
||||
}
|
||||
|
||||
this.statusCode = statusCode;
|
||||
|
||||
_.defaults(this.options, this.scope.scopeOptions);
|
||||
|
||||
// convert rawHeaders from Array to Object
|
||||
var headers = common.headersArrayToObject(rawHeaders);
|
||||
|
||||
if (this.scope._defaultReplyHeaders) {
|
||||
headers = headers || {};
|
||||
headers = common.headersFieldNamesToLowerCase(headers);
|
||||
headers = mixin(this.scope._defaultReplyHeaders, headers);
|
||||
}
|
||||
|
||||
if (this.scope.date) {
|
||||
headers = headers || {};
|
||||
headers['date'] = this.scope.date.toUTCString();
|
||||
}
|
||||
|
||||
if (headers !== undefined) {
|
||||
this.rawHeaders = [];
|
||||
|
||||
// makes sure all keys in headers are in lower case
|
||||
for (var key in headers) {
|
||||
if (headers.hasOwnProperty(key)) {
|
||||
this.rawHeaders.push(key);
|
||||
this.rawHeaders.push(headers[key]);
|
||||
}
|
||||
}
|
||||
|
||||
// We use lower-case headers throughout Nock.
|
||||
this.headers = common.headersFieldNamesToLowerCase(headers);
|
||||
|
||||
debug('reply.headers:', this.headers);
|
||||
debug('reply.rawHeaders:', this.rawHeaders);
|
||||
}
|
||||
|
||||
// If the content is not encoded we may need to transform the response body.
|
||||
// Otherwise we leave it as it is.
|
||||
if (!common.isContentEncoded(this.headers)) {
|
||||
if (body && typeof (body) !== 'string' &&
|
||||
typeof (body) !== 'function' &&
|
||||
!Buffer.isBuffer(body) &&
|
||||
!common.isStream(body)) {
|
||||
try {
|
||||
body = stringify(body);
|
||||
if (!this.headers) {
|
||||
this.headers = {};
|
||||
}
|
||||
if (!this.headers['content-type']) {
|
||||
this.headers['content-type'] = 'application/json';
|
||||
}
|
||||
if (this.scope.contentLen) {
|
||||
this.headers['content-length'] = body.length;
|
||||
}
|
||||
} catch (err) {
|
||||
throw new Error('Error encoding response body into JSON');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.body = body;
|
||||
|
||||
this.scope.add(this._key, this, this.scope, this.scopeOptions);
|
||||
return this.scope;
|
||||
};
|
||||
|
||||
Interceptor.prototype.replyWithFile = function replyWithFile(statusCode, filePath, headers) {
|
||||
if (!fs) {
|
||||
throw new Error('No fs');
|
||||
}
|
||||
var readStream = fs.createReadStream(filePath);
|
||||
readStream.pause();
|
||||
this.filePath = filePath;
|
||||
return this.reply(statusCode, readStream, headers);
|
||||
};
|
||||
|
||||
// Also match request headers
|
||||
// https://github.com/pgte/nock/issues/163
|
||||
Interceptor.prototype.reqheaderMatches = function reqheaderMatches(options, key) {
|
||||
// We don't try to match request headers if these weren't even specified in the request.
|
||||
if (!options.headers) {
|
||||
return true;
|
||||
}
|
||||
|
||||
var reqHeader = this.reqheaders[key];
|
||||
var header = options.headers[key];
|
||||
if (header && (typeof header !== 'string') && header.toString) {
|
||||
header = header.toString();
|
||||
}
|
||||
|
||||
// We skip 'host' header comparison unless it's available in both mock and actual request.
|
||||
// This because 'host' may get inserted by Nock itself and then get recorder.
|
||||
// NOTE: We use lower-case header field names throughout Nock.
|
||||
if (key === 'host' &&
|
||||
(_.isUndefined(header) ||
|
||||
_.isUndefined(reqHeader))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!_.isUndefined(reqHeader) && !_.isUndefined(header)) {
|
||||
if (_.isFunction(reqHeader)) {
|
||||
return reqHeader(header);
|
||||
} else if (common.matchStringOrRegexp(header, reqHeader)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
debug('request header field doesn\'t match:', key, header, reqHeader);
|
||||
return false;
|
||||
};
|
||||
|
||||
Interceptor.prototype.match = function match(options, body, hostNameOnly) {
|
||||
if (debug.enabled) {
|
||||
debug('match %s, body = %s', stringify(options), stringify(body));
|
||||
}
|
||||
|
||||
if (hostNameOnly) {
|
||||
return options.hostname === this.scope.urlParts.hostname;
|
||||
}
|
||||
|
||||
var method = (options.method || 'GET').toUpperCase()
|
||||
, path = options.path
|
||||
, matches
|
||||
, matchKey
|
||||
, proto = options.proto;
|
||||
|
||||
if (this.scope.transformPathFunction) {
|
||||
path = this.scope.transformPathFunction(path);
|
||||
}
|
||||
if (typeof (body) !== 'string') {
|
||||
body = body.toString();
|
||||
}
|
||||
if (this.scope.transformRequestBodyFunction) {
|
||||
body = this.scope.transformRequestBodyFunction(body, this._requestBody);
|
||||
}
|
||||
|
||||
var checkHeaders = function (header) {
|
||||
if (_.isFunction(header.value)) {
|
||||
return header.value(options.getHeader(header.name));
|
||||
}
|
||||
return common.matchStringOrRegexp(options.getHeader(header.name), header.value);
|
||||
};
|
||||
|
||||
if (!this.scope.matchHeaders.every(checkHeaders) ||
|
||||
!this.interceptorMatchHeaders.every(checkHeaders)) {
|
||||
this.scope.logger('headers don\'t match');
|
||||
return false;
|
||||
}
|
||||
|
||||
var reqHeadersMatch =
|
||||
!this.reqheaders ||
|
||||
Object.keys(this.reqheaders).every(this.reqheaderMatches.bind(this, options));
|
||||
|
||||
if (!reqHeadersMatch) {
|
||||
return false;
|
||||
}
|
||||
|
||||
function reqheaderContains(header) {
|
||||
return _.has(options.headers, header);
|
||||
}
|
||||
|
||||
var reqContainsBadHeaders =
|
||||
this.badheaders &&
|
||||
_.some(this.badheaders, reqheaderContains);
|
||||
|
||||
if (reqContainsBadHeaders) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// If we have a filtered scope then we use it instead reconstructing
|
||||
// the scope from the request options (proto, host and port) as these
|
||||
// two won't necessarily match and we have to remove the scope that was
|
||||
// matched (vs. that was defined).
|
||||
if (this.__nock_filteredScope) {
|
||||
matchKey = this.__nock_filteredScope;
|
||||
} else {
|
||||
matchKey = proto + '://' + options.host;
|
||||
if (
|
||||
options.port && options.host.indexOf(':') < 0 &&
|
||||
(options.port !== 80 || options.proto !== 'http') &&
|
||||
(options.port !== 443 || options.proto !== 'https')
|
||||
) {
|
||||
matchKey += ":" + options.port;
|
||||
}
|
||||
}
|
||||
|
||||
// Match query strings when using query()
|
||||
var matchQueries = true;
|
||||
var queryIndex = -1;
|
||||
var queryString;
|
||||
var queries;
|
||||
|
||||
if (this.queries) {
|
||||
queryIndex = path.indexOf('?');
|
||||
queryString = (queryIndex !== -1) ? path.slice(queryIndex + 1) : '';
|
||||
queries = qs.parse(queryString);
|
||||
|
||||
// Only check for query string matches if this.queries is an object
|
||||
if (_.isObject(this.queries)) {
|
||||
|
||||
if (_.isFunction(this.queries)) {
|
||||
matchQueries = this.queries(queries);
|
||||
} else {
|
||||
// Make sure that you have an equal number of keys. We are
|
||||
// looping through the passed query params and not the expected values
|
||||
// if the user passes fewer query params than expected but all values
|
||||
// match this will throw a false positive. Testing that the length of the
|
||||
// passed query params is equal to the length of expected keys will prevent
|
||||
// us from doing any value checking BEFORE we know if they have all the proper
|
||||
// params
|
||||
debug('this.queries: %j', this.queries);
|
||||
debug('queries: %j', queries);
|
||||
if (_.size(this.queries) !== _.size(queries)) {
|
||||
matchQueries = false;
|
||||
} else {
|
||||
var self = this;
|
||||
_.forOwn(queries, function matchOneKeyVal(val, key) {
|
||||
var expVal = self.queries[key];
|
||||
var isMatch = true;
|
||||
if (val === undefined || expVal === undefined) {
|
||||
isMatch = false;
|
||||
} else if (expVal instanceof RegExp) {
|
||||
isMatch = common.matchStringOrRegexp(val, expVal);
|
||||
} else if (_.isArray(expVal) || _.isObject(expVal)) {
|
||||
isMatch = _.isEqual(val, expVal);
|
||||
} else {
|
||||
isMatch = common.matchStringOrRegexp(val, expVal);
|
||||
}
|
||||
matchQueries = matchQueries && !!isMatch;
|
||||
});
|
||||
}
|
||||
debug('matchQueries: %j', matchQueries);
|
||||
}
|
||||
}
|
||||
|
||||
// Remove the query string from the path
|
||||
if (queryIndex !== -1) {
|
||||
path = path.substr(0, queryIndex);
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof this.uri === 'function') {
|
||||
matches = matchQueries &&
|
||||
method === this.method &&
|
||||
common.matchStringOrRegexp(matchKey, this.basePath) &&
|
||||
this.uri.call(this, path);
|
||||
} else {
|
||||
matches = method === this.method &&
|
||||
common.matchStringOrRegexp(matchKey, this.basePath) &&
|
||||
common.matchStringOrRegexp(path, this.path) &&
|
||||
matchQueries;
|
||||
}
|
||||
|
||||
// special logger for query()
|
||||
if (queryIndex !== -1) {
|
||||
this.scope.logger('matching ' + matchKey + path + '?' + queryString + ' to ' + this._key +
|
||||
' with query(' + stringify(this.queries) + '): ' + matches);
|
||||
} else {
|
||||
this.scope.logger('matching ' + matchKey + path + ' to ' + this._key + ': ' + matches);
|
||||
}
|
||||
|
||||
if (matches) {
|
||||
matches = (matchBody.call(options, this._requestBody, body));
|
||||
if (!matches) {
|
||||
this.scope.logger('bodies don\'t match: \n', this._requestBody, '\n', body);
|
||||
}
|
||||
}
|
||||
|
||||
return matches;
|
||||
};
|
||||
|
||||
Interceptor.prototype.matchIndependentOfBody = function matchIndependentOfBody(options) {
|
||||
var isRegex = _.isRegExp(this.path);
|
||||
var isRegexBasePath = _.isRegExp(this.scope.basePath);
|
||||
|
||||
var method = (options.method || 'GET').toUpperCase()
|
||||
, path = options.path
|
||||
, proto = options.proto;
|
||||
|
||||
// NOTE: Do not split off the query params as the regex could use them
|
||||
if (!isRegex) {
|
||||
path = path ? path.split('?')[0] : '';
|
||||
}
|
||||
|
||||
if (this.scope.transformPathFunction) {
|
||||
path = this.scope.transformPathFunction(path);
|
||||
}
|
||||
|
||||
var checkHeaders = function (header) {
|
||||
return options.getHeader && common.matchStringOrRegexp(options.getHeader(header.name), header.value);
|
||||
};
|
||||
|
||||
if (!this.scope.matchHeaders.every(checkHeaders) ||
|
||||
!this.interceptorMatchHeaders.every(checkHeaders)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var comparisonKey = isRegex ? this.__nock_scopeKey : this._key;
|
||||
var matchKey = method + ' ' + proto + '://' + options.host + path;
|
||||
|
||||
if (isRegex && !isRegexBasePath) {
|
||||
return !!matchKey.match(comparisonKey) && !!path.match(this.path);
|
||||
}
|
||||
|
||||
if(isRegexBasePath) {
|
||||
return !!matchKey.match(this.scope.basePath) && !!path.match(this.path);
|
||||
}
|
||||
|
||||
return comparisonKey === matchKey;
|
||||
};
|
||||
|
||||
Interceptor.prototype.filteringPath = function filteringPath() {
|
||||
if (_.isFunction(arguments[0])) {
|
||||
this.scope.transformFunction = arguments[0];
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
Interceptor.prototype.discard = function discard() {
|
||||
if ((this.scope.shouldPersist() || this.counter > 0) && this.filePath) {
|
||||
this.body = fs.createReadStream(this.filePath);
|
||||
this.body.pause();
|
||||
}
|
||||
|
||||
if (!this.scope.shouldPersist() && this.counter < 1) {
|
||||
this.scope.remove(this._key, this);
|
||||
}
|
||||
};
|
||||
|
||||
Interceptor.prototype.matchHeader = function matchHeader(name, value) {
|
||||
this.interceptorMatchHeaders.push({ name: name, value: value });
|
||||
return this;
|
||||
};
|
||||
|
||||
Interceptor.prototype.basicAuth = function basicAuth(options) {
|
||||
var username = options['user'];
|
||||
var password = options['pass'] || '';
|
||||
var name = 'authorization';
|
||||
var value = 'Basic ' + Buffer.from(username + ':' + password).toString('base64');
|
||||
this.interceptorMatchHeaders.push({ name: name, value: value });
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Set query strings for the interceptor
|
||||
* @name query
|
||||
* @param Object Object of query string name,values (accepts regexp values)
|
||||
* @public
|
||||
* @example
|
||||
* // Will match 'http://zombo.com/?q=t'
|
||||
* nock('http://zombo.com').get('/').query({q: 't'});
|
||||
*/
|
||||
Interceptor.prototype.query = function query(queries) {
|
||||
this.queries = this.queries || {};
|
||||
|
||||
// Allow all query strings to match this route
|
||||
if (queries === true) {
|
||||
this.queries = queries;
|
||||
return this;
|
||||
}
|
||||
|
||||
if (_.isFunction(queries)) {
|
||||
this.queries = queries;
|
||||
return this;
|
||||
}
|
||||
|
||||
var stringFormattingFn;
|
||||
if (this.scope.scopeOptions.encodedQueryParams) {
|
||||
stringFormattingFn = common.percentDecode;
|
||||
}
|
||||
|
||||
for (var key in queries) {
|
||||
if (_.isUndefined(this.queries[key])) {
|
||||
var formattedPair = common.formatQueryValue(key, queries[key], stringFormattingFn);
|
||||
this.queries[formattedPair[0]] = formattedPair[1];
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Set number of times will repeat the interceptor
|
||||
* @name times
|
||||
* @param Integer Number of times to repeat (should be > 0)
|
||||
* @public
|
||||
* @example
|
||||
* // Will repeat mock 5 times for same king of request
|
||||
* nock('http://zombo.com).get('/').times(5).reply(200, 'Ok');
|
||||
*/
|
||||
Interceptor.prototype.times = function times(newCounter) {
|
||||
if (newCounter < 1) {
|
||||
return this;
|
||||
}
|
||||
|
||||
this.counter = newCounter;
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* An sugar syntax for times(1)
|
||||
* @name once
|
||||
* @see {@link times}
|
||||
* @public
|
||||
* @example
|
||||
* nock('http://zombo.com).get('/').once.reply(200, 'Ok');
|
||||
*/
|
||||
Interceptor.prototype.once = function once() {
|
||||
return this.times(1);
|
||||
};
|
||||
|
||||
/**
|
||||
* An sugar syntax for times(2)
|
||||
* @name twice
|
||||
* @see {@link times}
|
||||
* @public
|
||||
* @example
|
||||
* nock('http://zombo.com).get('/').twice.reply(200, 'Ok');
|
||||
*/
|
||||
Interceptor.prototype.twice = function twice() {
|
||||
return this.times(2);
|
||||
};
|
||||
|
||||
/**
|
||||
* An sugar syntax for times(3).
|
||||
* @name thrice
|
||||
* @see {@link times}
|
||||
* @public
|
||||
* @example
|
||||
* nock('http://zombo.com).get('/').thrice.reply(200, 'Ok');
|
||||
*/
|
||||
Interceptor.prototype.thrice = function thrice() {
|
||||
return this.times(3);
|
||||
};
|
||||
|
||||
/**
|
||||
* Delay the response by a certain number of ms.
|
||||
*
|
||||
* @param {(integer|object)} opts - Number of milliseconds to wait, or an object
|
||||
* @param {integer} [opts.head] - Number of milliseconds to wait before response is sent
|
||||
* @param {integer} [opts.body] - Number of milliseconds to wait before response body is sent
|
||||
* @return {interceptor} - the current interceptor for chaining
|
||||
*/
|
||||
Interceptor.prototype.delay = function delay(opts) {
|
||||
var headDelay = 0;
|
||||
var bodyDelay = 0;
|
||||
if (_.isNumber(opts)) {
|
||||
headDelay = opts;
|
||||
} else if (_.isObject(opts)) {
|
||||
headDelay = opts.head || 0;
|
||||
bodyDelay = opts.body || 0;
|
||||
} else {
|
||||
throw new Error("Unexpected input opts" + opts);
|
||||
}
|
||||
|
||||
return this.delayConnection(headDelay)
|
||||
.delayBody(bodyDelay);
|
||||
};
|
||||
|
||||
/**
|
||||
* Delay the response body by a certain number of ms.
|
||||
*
|
||||
* @param {integer} ms - Number of milliseconds to wait before response is sent
|
||||
* @return {interceptor} - the current interceptor for chaining
|
||||
*/
|
||||
Interceptor.prototype.delayBody = function delayBody(ms) {
|
||||
this.delayInMs += ms;
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Delay the connection by a certain number of ms.
|
||||
*
|
||||
* @param {integer} ms - Number of milliseconds to wait
|
||||
* @return {interceptor} - the current interceptor for chaining
|
||||
*/
|
||||
Interceptor.prototype.delayConnection = function delayConnection(ms) {
|
||||
this.delayConnectionInMs += ms;
|
||||
return this;
|
||||
};
|
||||
|
||||
Interceptor.prototype.getTotalDelay = function getTotalDelay() {
|
||||
return this.delayInMs + this.delayConnectionInMs;
|
||||
};
|
||||
|
||||
/**
|
||||
* Make the socket idle for a certain number of ms (simulated).
|
||||
*
|
||||
* @param {integer} ms - Number of milliseconds to wait
|
||||
* @return {interceptor} - the current interceptor for chaining
|
||||
*/
|
||||
Interceptor.prototype.socketDelay = function socketDelay(ms) {
|
||||
this.socketDelayInMs = ms;
|
||||
return this;
|
||||
};
|
||||
117
node_modules/nock/lib/match_body.js
generated
vendored
Normal file
117
node_modules/nock/lib/match_body.js
generated
vendored
Normal file
@@ -0,0 +1,117 @@
|
||||
'use strict';
|
||||
|
||||
var deepEqual = require('deep-equal');
|
||||
var qs = require('qs');
|
||||
var _ = require('lodash')
|
||||
var common = require('./common');
|
||||
|
||||
module.exports =
|
||||
function matchBody(spec, body) {
|
||||
if (typeof spec === 'undefined') {
|
||||
return true;
|
||||
}
|
||||
|
||||
var options = this || {};
|
||||
|
||||
if (Buffer.isBuffer(body)) {
|
||||
body = body.toString();
|
||||
}
|
||||
|
||||
if (spec instanceof RegExp) {
|
||||
if (typeof body === "string") {
|
||||
return body.match(spec);
|
||||
}
|
||||
}
|
||||
|
||||
if (Buffer.isBuffer(spec)) {
|
||||
if (common.isBinaryBuffer(spec)) {
|
||||
spec = spec.toString('hex');
|
||||
} else {
|
||||
spec = spec.toString('utf8');
|
||||
}
|
||||
}
|
||||
|
||||
var contentType = (
|
||||
options.headers &&
|
||||
(options.headers['Content-Type'] || options.headers['content-type']) ||
|
||||
''
|
||||
).toString();
|
||||
|
||||
var isMultipart = contentType.indexOf('multipart') >= 0;
|
||||
var isUrlencoded = contentType.indexOf('application/x-www-form-urlencoded') >= 0;
|
||||
|
||||
// try to transform body to json
|
||||
var json;
|
||||
if (typeof spec === 'object' || typeof spec === 'function') {
|
||||
try { json = JSON.parse(body);} catch(err) {}
|
||||
if (json !== undefined) {
|
||||
body = json;
|
||||
} else if (isUrlencoded) {
|
||||
body = qs.parse(body, { allowDots: true });
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof spec === "function") {
|
||||
return spec.call(this, body);
|
||||
}
|
||||
|
||||
//strip line endings from both so that we get a match no matter what OS we are running on
|
||||
//if Content-Type does not contains 'multipart'
|
||||
if (!isMultipart && typeof body === "string") {
|
||||
body = body.replace(/\r?\n|\r/g, '');
|
||||
}
|
||||
|
||||
if (!isMultipart && typeof spec === "string") {
|
||||
spec = spec.replace(/\r?\n|\r/g, '');
|
||||
}
|
||||
|
||||
if (isUrlencoded) {
|
||||
spec = mapValuesDeep(spec, function(val) {
|
||||
if (_.isRegExp(val)) {
|
||||
return val
|
||||
}
|
||||
return val + ''
|
||||
})
|
||||
}
|
||||
|
||||
return deepEqualExtended(spec, body);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Based on lodash issue discussion
|
||||
* https://github.com/lodash/lodash/issues/1244
|
||||
*/
|
||||
function mapValuesDeep(obj, cb) {
|
||||
if (_.isArray(obj)) {
|
||||
return obj.map(function(v) {
|
||||
return mapValuesDeep(v, cb)
|
||||
})
|
||||
}
|
||||
if (_.isPlainObject(obj)) {
|
||||
return _.mapValues(obj, function(v) {
|
||||
return mapValuesDeep(v, cb)
|
||||
})
|
||||
}
|
||||
return cb(obj)
|
||||
}
|
||||
|
||||
function deepEqualExtended(spec, body) {
|
||||
if (spec && spec.constructor === RegExp) {
|
||||
return spec.test(body);
|
||||
}
|
||||
if (spec && (spec.constructor === Object || spec.constructor === Array) && body) {
|
||||
var keys = Object.keys(spec);
|
||||
var bodyKeys = Object.keys(body);
|
||||
if (keys.length !== bodyKeys.length) {
|
||||
return false;
|
||||
}
|
||||
for (var i = 0; i < keys.length; i++) {
|
||||
if (!deepEqualExtended(spec[keys[i]], body[keys[i]])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return deepEqual(spec, body, { strict: true });
|
||||
}
|
||||
14
node_modules/nock/lib/mixin.js
generated
vendored
Normal file
14
node_modules/nock/lib/mixin.js
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
'use strict';
|
||||
var _ = require("lodash");
|
||||
|
||||
function mixin(a, b) {
|
||||
if (! a) { a = {}; }
|
||||
if (! b) {b = {}; }
|
||||
a = _.cloneDeep(a);
|
||||
for(var prop in b) {
|
||||
a[prop] = b[prop];
|
||||
}
|
||||
return a;
|
||||
}
|
||||
|
||||
module.exports = mixin;
|
||||
406
node_modules/nock/lib/recorder.js
generated
vendored
Normal file
406
node_modules/nock/lib/recorder.js
generated
vendored
Normal file
@@ -0,0 +1,406 @@
|
||||
'use strict';
|
||||
|
||||
var inspect = require('util').inspect;
|
||||
var parse = require('url').parse;
|
||||
var common = require('./common');
|
||||
var intercept = require('./intercept');
|
||||
var debug = require('debug')('nock.recorder');
|
||||
var _ = require('lodash');
|
||||
var URL = require('url');
|
||||
var semver = require('semver')
|
||||
var qs = require('qs');
|
||||
|
||||
var SEPARATOR = '\n<<<<<<-- cut here -->>>>>>\n';
|
||||
var recordingInProgress = false;
|
||||
var outputs = [];
|
||||
|
||||
function getScope(options) {
|
||||
|
||||
common.normalizeRequestOptions(options);
|
||||
|
||||
var scope = [];
|
||||
if (options._https_) {
|
||||
scope.push('https://');
|
||||
} else {
|
||||
scope.push('http://');
|
||||
}
|
||||
|
||||
scope.push(options.host);
|
||||
|
||||
// If a non-standard port wasn't specified in options.host, include it from options.port.
|
||||
if(options.host.indexOf(':') === -1 &&
|
||||
options.port &&
|
||||
((options._https_ && options.port.toString() !== '443') ||
|
||||
(!options._https_ && options.port.toString() !== '80'))) {
|
||||
scope.push(':');
|
||||
scope.push(options.port);
|
||||
}
|
||||
|
||||
return scope.join('');
|
||||
|
||||
}
|
||||
|
||||
function getMethod(options) {
|
||||
|
||||
return (options.method || 'GET');
|
||||
|
||||
}
|
||||
|
||||
var getBodyFromChunks = function(chunks, headers) {
|
||||
|
||||
// If we have headers and there is content-encoding it means that
|
||||
// the body shouldn't be merged but instead persisted as an array
|
||||
// of hex strings so that the responses can be mocked one by one.
|
||||
if(common.isContentEncoded(headers)) {
|
||||
return {
|
||||
body: _.map(chunks, function(chunk) {
|
||||
if(!Buffer.isBuffer(chunk)) {
|
||||
if (typeof chunk === 'string') {
|
||||
chunk = Buffer.from(chunk);
|
||||
} else {
|
||||
throw new Error('content-encoded responses must all be binary buffers');
|
||||
}
|
||||
}
|
||||
|
||||
return chunk.toString('hex');
|
||||
})
|
||||
};
|
||||
}
|
||||
|
||||
var mergedBuffer = common.mergeChunks(chunks);
|
||||
|
||||
// The merged buffer can be one of three things:
|
||||
// 1. A binary buffer which then has to be recorded as a hex string.
|
||||
// 2. A string buffer which represents a JSON object.
|
||||
// 3. A string buffer which doesn't represent a JSON object.
|
||||
|
||||
var isBinary = common.isBinaryBuffer(mergedBuffer);
|
||||
if(isBinary) {
|
||||
return {
|
||||
body: mergedBuffer.toString('hex'),
|
||||
isBinary: true
|
||||
}
|
||||
} else {
|
||||
var maybeStringifiedJson = mergedBuffer.toString('utf8');
|
||||
try {
|
||||
return {
|
||||
body: JSON.parse(maybeStringifiedJson),
|
||||
isBinary: false
|
||||
};
|
||||
} catch(err) {
|
||||
return {
|
||||
body: maybeStringifiedJson,
|
||||
isBinary: false
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
function generateRequestAndResponseObject(req, bodyChunks, options, res, dataChunks) {
|
||||
|
||||
var response = getBodyFromChunks(dataChunks, res.headers)
|
||||
options.path = req.path;
|
||||
|
||||
var nockDef = {
|
||||
scope: getScope(options),
|
||||
method: getMethod(options),
|
||||
path: options.path,
|
||||
body: getBodyFromChunks(bodyChunks).body,
|
||||
status: res.statusCode,
|
||||
response: response.body,
|
||||
rawHeaders: res.rawHeaders || res.headers,
|
||||
reqheaders: req._headers
|
||||
};
|
||||
|
||||
if (response.isBinary) {
|
||||
nockDef.responseIsBinary = true
|
||||
}
|
||||
|
||||
return nockDef;
|
||||
}
|
||||
|
||||
function generateRequestAndResponse(req, bodyChunks, options, res, dataChunks) {
|
||||
|
||||
var requestBody = getBodyFromChunks(bodyChunks).body;
|
||||
var responseBody = getBodyFromChunks(dataChunks, res.headers).body;
|
||||
|
||||
// Remove any query params from options.path so they can be added in the query() function
|
||||
var path = options.path;
|
||||
var queryIndex = 0;
|
||||
var queryObj = {};
|
||||
if ((queryIndex = req.path.indexOf('?')) !== -1) {
|
||||
// Remove the query from the path
|
||||
path = path.substring(0, queryIndex);
|
||||
|
||||
// Create the query() object
|
||||
var queryStr = req.path.slice(queryIndex + 1);
|
||||
queryObj = qs.parse(queryStr);
|
||||
}
|
||||
// Always encoding the query parameters when recording.
|
||||
var encodedQueryObj = {};
|
||||
for (var key in queryObj) {
|
||||
var formattedPair = common.formatQueryValue(key, queryObj[key], common.percentEncode);
|
||||
encodedQueryObj[formattedPair[0]] = formattedPair[1];
|
||||
}
|
||||
|
||||
var ret = [];
|
||||
ret.push('\nnock(\'');
|
||||
ret.push(getScope(options));
|
||||
ret.push('\', ');
|
||||
ret.push(JSON.stringify({ encodedQueryParams: true }));
|
||||
ret.push(')\n');
|
||||
ret.push(' .');
|
||||
ret.push(getMethod(options).toLowerCase());
|
||||
ret.push('(\'');
|
||||
ret.push(path);
|
||||
ret.push("'");
|
||||
if (requestBody) {
|
||||
ret.push(', ');
|
||||
ret.push(JSON.stringify(requestBody));
|
||||
}
|
||||
ret.push(")\n");
|
||||
if (req.headers) {
|
||||
for (var k in req.headers) {
|
||||
ret.push(' .matchHeader(' + JSON.stringify(k) + ', ' + JSON.stringify(req.headers[k]) + ')\n');
|
||||
}
|
||||
}
|
||||
|
||||
if (queryIndex !== -1) {
|
||||
ret.push(' .query(');
|
||||
ret.push(JSON.stringify(encodedQueryObj));
|
||||
ret.push(')\n');
|
||||
}
|
||||
|
||||
ret.push(' .reply(');
|
||||
ret.push(res.statusCode.toString());
|
||||
ret.push(', ');
|
||||
ret.push(JSON.stringify(responseBody));
|
||||
if (res.rawHeaders) {
|
||||
ret.push(', ');
|
||||
ret.push(inspect(res.rawHeaders));
|
||||
} else if (res.headers) {
|
||||
ret.push(', ');
|
||||
ret.push(inspect(res.headers));
|
||||
}
|
||||
ret.push(');\n');
|
||||
|
||||
return ret.join('');
|
||||
}
|
||||
|
||||
// This module variable is used to identify a unique recording ID in order to skip
|
||||
// spurious requests that sometimes happen. This problem has been, so far,
|
||||
// exclusively detected in nock's unit testing where 'checks if callback is specified'
|
||||
// interferes with other tests as its t.end() is invoked without waiting for request
|
||||
// to finish (which is the point of the test).
|
||||
var currentRecordingId = 0;
|
||||
|
||||
function record(rec_options) {
|
||||
|
||||
// Set the new current recording ID and capture its value in this instance of record().
|
||||
currentRecordingId = currentRecordingId + 1;
|
||||
var thisRecordingId = currentRecordingId;
|
||||
|
||||
debug('start recording', thisRecordingId, JSON.stringify(rec_options));
|
||||
|
||||
// Trying to start recording with recording already in progress implies an error
|
||||
// in the recording configuration (double recording makes no sense and used to lead
|
||||
// to duplicates in output)
|
||||
if(recordingInProgress) {
|
||||
throw new Error('Nock recording already in progress');
|
||||
}
|
||||
|
||||
recordingInProgress = true;
|
||||
|
||||
// Originaly the parameters was a dont_print boolean flag.
|
||||
// To keep the existing code compatible we take that case into account.
|
||||
var optionsIsObject = typeof rec_options === 'object';
|
||||
var dont_print = (typeof rec_options === 'boolean' && rec_options) ||
|
||||
(optionsIsObject && rec_options.dont_print);
|
||||
var output_objects = optionsIsObject && rec_options.output_objects;
|
||||
var enable_reqheaders_recording = optionsIsObject && rec_options.enable_reqheaders_recording;
|
||||
// eslint-disable-next-line no-console
|
||||
var logging = (optionsIsObject && rec_options.logging) || console.log;
|
||||
var use_separator = true;
|
||||
if (optionsIsObject && _.has(rec_options, 'use_separator')) {
|
||||
use_separator = rec_options.use_separator;
|
||||
}
|
||||
|
||||
debug(thisRecordingId, 'restoring overridden requests before new overrides');
|
||||
// To preserve backward compatibility (starting recording wasn't throwing if nock was already active)
|
||||
// we restore any requests that may have been overridden by other parts of nock (e.g. intercept)
|
||||
// NOTE: This is hacky as hell but it keeps the backward compatibility *and* allows correct
|
||||
// behavior in the face of other modules also overriding ClientRequest.
|
||||
common.restoreOverriddenRequests();
|
||||
// We restore ClientRequest as it messes with recording of modules that also override ClientRequest (e.g. xhr2)
|
||||
intercept.restoreOverriddenClientRequest();
|
||||
|
||||
// We override the requests so that we can save information on them before executing.
|
||||
common.overrideRequests(function(proto, overriddenRequest, options, callback) {
|
||||
|
||||
var bodyChunks = [];
|
||||
|
||||
if (typeof options == 'string') {
|
||||
var url = URL.parse(options);
|
||||
options = {
|
||||
hostname: url.hostname,
|
||||
method: 'GET',
|
||||
port: url.port,
|
||||
path: url.path
|
||||
};
|
||||
}
|
||||
|
||||
// Node 0.11 https.request calls http.request -- don't want to record things
|
||||
// twice.
|
||||
if (options._recording) {
|
||||
return overriddenRequest(options, callback);
|
||||
}
|
||||
options._recording = true;
|
||||
|
||||
var req = overriddenRequest(options, function(res) {
|
||||
|
||||
debug(thisRecordingId, 'intercepting', proto, 'request to record');
|
||||
|
||||
if (typeof options === 'string') {
|
||||
options = parse(options);
|
||||
}
|
||||
|
||||
// We put our 'end' listener to the front of the listener array.
|
||||
res.once('end', function() {
|
||||
debug(thisRecordingId, proto, 'intercepted request ended');
|
||||
|
||||
var out;
|
||||
if(output_objects) {
|
||||
out = generateRequestAndResponseObject(req, bodyChunks, options, res, dataChunks);
|
||||
if(out.reqheaders) {
|
||||
// We never record user-agent headers as they are worse than useless -
|
||||
// they actually make testing more difficult without providing any benefit (see README)
|
||||
common.deleteHeadersField(out.reqheaders, 'user-agent');
|
||||
|
||||
// Remove request headers completely unless it was explicitly enabled by the user (see README)
|
||||
if(!enable_reqheaders_recording) {
|
||||
delete out.reqheaders;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
out = generateRequestAndResponse(req, bodyChunks, options, res, dataChunks);
|
||||
}
|
||||
|
||||
debug('out:', out);
|
||||
|
||||
// Check that the request was made during the current recording.
|
||||
// If it hasn't then skip it. There is no other simple way to handle
|
||||
// this as it depends on the timing of requests and responses. Throwing
|
||||
// will make some recordings/unit tests faily randomly depending on how
|
||||
// fast/slow the response arrived.
|
||||
// If you are seeing this error then you need to make sure that all
|
||||
// the requests made during a single recording session finish before
|
||||
// ending the same recording session.
|
||||
if(thisRecordingId !== currentRecordingId) {
|
||||
debug('skipping recording of an out-of-order request', out);
|
||||
return;
|
||||
}
|
||||
|
||||
outputs.push(out);
|
||||
|
||||
if (!dont_print) {
|
||||
if (use_separator) {
|
||||
if (typeof out !== 'string') {
|
||||
out = JSON.stringify(out, null, 2);
|
||||
}
|
||||
logging(SEPARATOR + out + SEPARATOR);
|
||||
} else {
|
||||
logging(out);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
var dataChunks = [];
|
||||
var encoding;
|
||||
|
||||
// We need to be aware of changes to the stream's encoding so that we
|
||||
// don't accidentally mangle the data.
|
||||
var setEncoding = res.setEncoding;
|
||||
res.setEncoding = function (newEncoding) {
|
||||
encoding = newEncoding;
|
||||
return setEncoding.apply(this, arguments);
|
||||
};
|
||||
|
||||
// Replace res.push with our own implementation that stores chunks
|
||||
var origResPush = res.push;
|
||||
res.push = function(data) {
|
||||
if (data) {
|
||||
if (encoding) {
|
||||
data = Buffer.from(data, encoding);
|
||||
}
|
||||
dataChunks.push(data);
|
||||
}
|
||||
|
||||
return origResPush.call(res, data);
|
||||
}
|
||||
|
||||
if (callback) {
|
||||
callback(res, options, callback);
|
||||
} else {
|
||||
res.resume();
|
||||
}
|
||||
|
||||
debug('finished setting up intercepting');
|
||||
|
||||
if (proto === 'https') {
|
||||
options._https_ = true;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
var oldWrite = req.write;
|
||||
req.write = function(data, encoding) {
|
||||
if ('undefined' !== typeof(data)) {
|
||||
if (data) {
|
||||
debug(thisRecordingId, 'new', proto, 'body chunk');
|
||||
if (! Buffer.isBuffer(data)) {
|
||||
data = Buffer.from(data, encoding);
|
||||
}
|
||||
bodyChunks.push(data);
|
||||
}
|
||||
oldWrite.apply(req, arguments);
|
||||
}
|
||||
};
|
||||
|
||||
// in Node 8, res.end() does not call res.write() directly
|
||||
if (semver.satisfies(process.version, '>=8')) {
|
||||
var oldEnd = req.end;
|
||||
req.end = function(data, encoding) {
|
||||
if (data) {
|
||||
debug(thisRecordingId, 'new', proto, 'body chunk');
|
||||
if (! Buffer.isBuffer(data)) {
|
||||
data = Buffer.from(data, encoding);
|
||||
}
|
||||
bodyChunks.push(data);
|
||||
}
|
||||
oldEnd.apply(req, arguments);
|
||||
};
|
||||
}
|
||||
|
||||
return req;
|
||||
});
|
||||
}
|
||||
|
||||
// Restores *all* the overridden http/https modules' properties.
|
||||
function restore() {
|
||||
debug(currentRecordingId, 'restoring all the overridden http/https properties');
|
||||
|
||||
common.restoreOverriddenRequests();
|
||||
intercept.restoreOverriddenClientRequest();
|
||||
recordingInProgress = false;
|
||||
}
|
||||
|
||||
function clear() {
|
||||
outputs = [];
|
||||
}
|
||||
|
||||
exports.record = record;
|
||||
exports.outputs = function() {
|
||||
return outputs;
|
||||
};
|
||||
exports.restore = restore;
|
||||
exports.clear = clear;
|
||||
563
node_modules/nock/lib/request_overrider.js
generated
vendored
Normal file
563
node_modules/nock/lib/request_overrider.js
generated
vendored
Normal file
@@ -0,0 +1,563 @@
|
||||
'use strict';
|
||||
|
||||
var EventEmitter = require('events').EventEmitter,
|
||||
http = require('http'),
|
||||
propagate = require('propagate'),
|
||||
DelayedBody = require('./delayed_body'),
|
||||
IncomingMessage = http.IncomingMessage,
|
||||
ClientRequest = http.ClientRequest,
|
||||
common = require('./common'),
|
||||
Socket = require('./socket'),
|
||||
_ = require('lodash'),
|
||||
debug = require('debug')('nock.request_overrider'),
|
||||
ReadableStream = require('stream').Readable,
|
||||
globalEmitter = require('./global_emitter'),
|
||||
zlib = require('zlib'),
|
||||
timers = require('timers');
|
||||
|
||||
function getHeader(request, name) {
|
||||
if (!request._headers) {
|
||||
return;
|
||||
}
|
||||
|
||||
var key = name.toLowerCase();
|
||||
|
||||
return request.getHeader ? request.getHeader(key) : request._headers[key];
|
||||
}
|
||||
|
||||
function setHeader(request, name, value) {
|
||||
debug('setHeader', name, value);
|
||||
|
||||
var key = name.toLowerCase();
|
||||
|
||||
request._headers = request._headers || {};
|
||||
request._headerNames = request._headerNames || {};
|
||||
request._removedHeader = request._removedHeader || {};
|
||||
|
||||
if (request.setHeader) {
|
||||
request.setHeader(key, value);
|
||||
} else {
|
||||
request._headers[key] = value;
|
||||
request._headerNames[key] = name;
|
||||
}
|
||||
|
||||
if (name == 'expect' && value == '100-continue') {
|
||||
timers.setImmediate(function() {
|
||||
debug('continue');
|
||||
request.emit('continue');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Sets request headers of the given request. This is needed during both matching phase
|
||||
// (in case header filters were specified) and mocking phase (to correctly pass mocked
|
||||
// request headers).
|
||||
function setRequestHeaders(req, options, interceptor) {
|
||||
// If a filtered scope is being used we have to use scope's host
|
||||
// in the header, otherwise 'host' header won't match.
|
||||
// NOTE: We use lower-case header field names throught Nock.
|
||||
var HOST_HEADER = 'host';
|
||||
if(interceptor.__nock_filteredScope && interceptor.__nock_scopeHost) {
|
||||
if(options && options.headers) {
|
||||
options.headers[HOST_HEADER] = interceptor.__nock_scopeHost;
|
||||
}
|
||||
setHeader(req, HOST_HEADER, interceptor.__nock_scopeHost);
|
||||
} else {
|
||||
// For all other cases, we always add host header equal to the
|
||||
// requested host unless it was already defined.
|
||||
if (options.host && !getHeader(req, HOST_HEADER)) {
|
||||
var hostHeader = options.host;
|
||||
|
||||
if (options.port === 80 || options.port === 443) {
|
||||
hostHeader = hostHeader.split(':')[0];
|
||||
}
|
||||
|
||||
setHeader(req, HOST_HEADER, hostHeader);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function RequestOverrider(req, options, interceptors, remove, cb) {
|
||||
var response;
|
||||
if (IncomingMessage) {
|
||||
response = new IncomingMessage(new EventEmitter());
|
||||
} else {
|
||||
response = new ReadableStream();
|
||||
response._read = function() {};
|
||||
}
|
||||
|
||||
var requestBodyBuffers = [],
|
||||
emitError,
|
||||
end,
|
||||
ended,
|
||||
headers;
|
||||
|
||||
// We may be changing the options object and we don't want those
|
||||
// changes affecting the user so we use a clone of the object.
|
||||
options = _.clone(options) || {};
|
||||
|
||||
response.req = req;
|
||||
|
||||
if (options.headers) {
|
||||
// We use lower-case header field names throught Nock.
|
||||
options.headers = common.headersFieldNamesToLowerCase(options.headers);
|
||||
|
||||
headers = options.headers;
|
||||
_.forOwn(headers, function(val, key) {
|
||||
setHeader(req, key, val);
|
||||
});
|
||||
}
|
||||
|
||||
/// options.auth
|
||||
if (options.auth && (! options.headers || ! options.headers.authorization)) {
|
||||
setHeader(req, 'Authorization', 'Basic ' + (Buffer.from(options.auth)).toString('base64'));
|
||||
}
|
||||
|
||||
if (! req.connection) {
|
||||
req.connection = new EventEmitter();
|
||||
}
|
||||
|
||||
req.path = options.path;
|
||||
|
||||
options.getHeader = function(name) {
|
||||
return getHeader(req, name);
|
||||
};
|
||||
|
||||
req.socket = response.socket = Socket({ proto: options.proto });
|
||||
|
||||
req.write = function(buffer, encoding, callback) {
|
||||
debug('write', arguments);
|
||||
if (!req.aborted) {
|
||||
if (buffer) {
|
||||
if (!Buffer.isBuffer(buffer)) {
|
||||
buffer = Buffer.from(buffer, encoding);
|
||||
}
|
||||
requestBodyBuffers.push(buffer);
|
||||
}
|
||||
if (typeof callback === 'function') {
|
||||
callback();
|
||||
}
|
||||
}
|
||||
else {
|
||||
emitError(new Error('Request aborted'));
|
||||
}
|
||||
|
||||
timers.setImmediate(function() {
|
||||
req.emit('drain');
|
||||
});
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
req.end = function(buffer, encoding, callback) {
|
||||
debug('req.end');
|
||||
if (!req.aborted && !ended) {
|
||||
req.write(buffer, encoding, function () {
|
||||
if (typeof callback === 'function') {
|
||||
callback();
|
||||
}
|
||||
end(cb);
|
||||
req.emit('finish');
|
||||
req.emit('end');
|
||||
});
|
||||
}
|
||||
if (req.aborted) {
|
||||
emitError(new Error('Request aborted'));
|
||||
}
|
||||
};
|
||||
|
||||
req.flushHeaders = function() {
|
||||
debug('req.flushHeaders');
|
||||
if (!req.aborted && !ended) {
|
||||
end(cb);
|
||||
}
|
||||
if (req.aborted) {
|
||||
emitError(new Error('Request aborted'));
|
||||
}
|
||||
};
|
||||
|
||||
req.abort = function() {
|
||||
if (req.aborted) {
|
||||
return;
|
||||
}
|
||||
debug('req.abort');
|
||||
req.aborted = Date.now();
|
||||
if (!ended) {
|
||||
end();
|
||||
}
|
||||
var err = new Error();
|
||||
err.code = 'aborted';
|
||||
response.emit('close', err);
|
||||
|
||||
req.socket.destroy();
|
||||
|
||||
req.emit('abort');
|
||||
|
||||
var connResetError = new Error('socket hang up');
|
||||
connResetError.code = 'ECONNRESET';
|
||||
emitError(connResetError);
|
||||
};
|
||||
|
||||
// restify listens for a 'socket' event to
|
||||
// be emitted before calling end(), which causes
|
||||
// nock to hang with restify. The following logic
|
||||
// fakes the socket behavior for restify,
|
||||
// Fixes: https://github.com/pgte/nock/issues/79
|
||||
req.once = req.on = function(event, listener) {
|
||||
// emit a fake socket.
|
||||
if (event == 'socket') {
|
||||
listener.call(req, req.socket);
|
||||
req.socket.emit('connect', req.socket);
|
||||
req.socket.emit('secureConnect', req.socket);
|
||||
}
|
||||
|
||||
EventEmitter.prototype.on.call(this, event, listener);
|
||||
return this;
|
||||
};
|
||||
|
||||
emitError = function(error) {
|
||||
process.nextTick(function () {
|
||||
req.emit('error', error);
|
||||
});
|
||||
};
|
||||
|
||||
end = function(cb) {
|
||||
debug('ending');
|
||||
ended = true;
|
||||
var requestBody,
|
||||
responseBody,
|
||||
responseBuffers,
|
||||
interceptor;
|
||||
|
||||
var continued = false;
|
||||
|
||||
// When request body is a binary buffer we internally use in its hexadecimal representation.
|
||||
var requestBodyBuffer = common.mergeChunks(requestBodyBuffers);
|
||||
var isBinaryRequestBodyBuffer = common.isBinaryBuffer(requestBodyBuffer);
|
||||
if(isBinaryRequestBodyBuffer) {
|
||||
requestBody = requestBodyBuffer.toString('hex');
|
||||
} else {
|
||||
requestBody = requestBodyBuffer.toString('utf8');
|
||||
}
|
||||
|
||||
/// put back the path into options
|
||||
/// because bad behaving agents like superagent
|
||||
/// like to change request.path in mid-flight.
|
||||
options.path = req.path;
|
||||
|
||||
// fixes #976
|
||||
options.protocol = options.proto + ':';
|
||||
|
||||
interceptors.forEach(function(interceptor) {
|
||||
// For correct matching we need to have correct request headers - if these were specified.
|
||||
setRequestHeaders(req, options, interceptor);
|
||||
});
|
||||
|
||||
interceptor = _.find(interceptors, function(interceptor) {
|
||||
return interceptor.match(options, requestBody);
|
||||
});
|
||||
|
||||
if (!interceptor) {
|
||||
globalEmitter.emit('no match', req, options, requestBody);
|
||||
// Try to find a hostname match
|
||||
interceptor = _.find(interceptors, function(interceptor) {
|
||||
return interceptor.match(options, requestBody, true);
|
||||
});
|
||||
if (interceptor && req instanceof ClientRequest) {
|
||||
if (interceptor.options.allowUnmocked) {
|
||||
var newReq = new ClientRequest(options, cb);
|
||||
propagate(newReq, req);
|
||||
// We send the raw buffer as we received it, not as we interpreted it.
|
||||
newReq.end(requestBodyBuffer);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
var err = new Error("Nock: No match for request " + common.stringifyRequest(options, requestBody));
|
||||
err.statusCode = err.status = 404;
|
||||
emitError(err);
|
||||
return;
|
||||
}
|
||||
|
||||
debug('interceptor identified, starting mocking');
|
||||
|
||||
// We again set request headers, now for our matched interceptor.
|
||||
setRequestHeaders(req, options, interceptor);
|
||||
interceptor.req = req;
|
||||
req.headers = req.getHeaders ? req.getHeaders() : req._headers;
|
||||
|
||||
interceptor.scope.emit('request', req, interceptor, requestBody);
|
||||
|
||||
if (typeof interceptor.errorMessage !== 'undefined') {
|
||||
interceptor.interceptionCounter++;
|
||||
remove(interceptor);
|
||||
interceptor.discard();
|
||||
|
||||
var error;
|
||||
if (_.isObject(interceptor.errorMessage)) {
|
||||
error = interceptor.errorMessage;
|
||||
} else {
|
||||
error = new Error(interceptor.errorMessage);
|
||||
}
|
||||
timers.setTimeout(emitError, interceptor.getTotalDelay(), error);
|
||||
return;
|
||||
}
|
||||
response.statusCode = Number(interceptor.statusCode) || 200;
|
||||
|
||||
// Clone headers/rawHeaders to not override them when evaluating later
|
||||
response.headers = _.extend({}, interceptor.headers);
|
||||
response.rawHeaders = (interceptor.rawHeaders || []).slice();
|
||||
debug('response.rawHeaders:', response.rawHeaders);
|
||||
|
||||
|
||||
if (typeof interceptor.body === 'function') {
|
||||
if (requestBody && common.isJSONContent(req.headers)) {
|
||||
if (requestBody && common.contentEncoding(req.headers, 'gzip')) {
|
||||
if (typeof zlib.gunzipSync !== 'function') {
|
||||
emitError(new Error('Gzip encoding is currently not supported in this version of Node.'));
|
||||
return;
|
||||
}
|
||||
requestBody = String(zlib.gunzipSync(Buffer.from(requestBody, 'hex')), 'hex')
|
||||
} else if (requestBody && common.contentEncoding(req.headers, 'deflate')) {
|
||||
if (typeof zlib.deflateSync !== 'function') {
|
||||
emitError(new Error('Deflate encoding is currently not supported in this version of Node.'));
|
||||
return;
|
||||
}
|
||||
requestBody = String(zlib.inflateSync(Buffer.from(requestBody, 'hex')), 'hex')
|
||||
}
|
||||
|
||||
requestBody = JSON.parse(requestBody);
|
||||
}
|
||||
|
||||
// In case we are waiting for a callback
|
||||
if (interceptor.body.length === 3) {
|
||||
return interceptor.body(options.path, requestBody || '', continueWithResponseBody);
|
||||
}
|
||||
|
||||
responseBody = interceptor.body(options.path, requestBody) || '';
|
||||
|
||||
} else {
|
||||
|
||||
// If the content is encoded we know that the response body *must* be an array
|
||||
// of response buffers which should be mocked one by one.
|
||||
// (otherwise decompressions after the first one fails as unzip expects to receive
|
||||
// buffer by buffer and not one single merged buffer)
|
||||
if(common.isContentEncoded(response.headers) && ! common.isStream(interceptor.body)) {
|
||||
|
||||
if (interceptor.delayInMs) {
|
||||
emitError(new Error('Response delay is currently not supported with content-encoded responses.'));
|
||||
return;
|
||||
}
|
||||
|
||||
var buffers = interceptor.body;
|
||||
if(!_.isArray(buffers)) {
|
||||
buffers = [buffers];
|
||||
}
|
||||
|
||||
responseBuffers = _.map(buffers, function(buffer) {
|
||||
return Buffer.from(buffer, 'hex');
|
||||
});
|
||||
|
||||
} else {
|
||||
|
||||
responseBody = interceptor.body;
|
||||
|
||||
// If the request was binary then we assume that the response will be binary as well.
|
||||
// In that case we send the response as a Buffer object as that's what the client will expect.
|
||||
if(isBinaryRequestBodyBuffer && typeof(responseBody) === 'string') {
|
||||
// Try to create the buffer from the interceptor's body response as hex.
|
||||
try {
|
||||
responseBody = Buffer.from(responseBody, 'hex');
|
||||
} catch(err) {
|
||||
debug('exception during Buffer construction from hex data:', responseBody, '-', err);
|
||||
}
|
||||
|
||||
// Creating buffers does not necessarily throw errors, check for difference in size
|
||||
if (!responseBody || (interceptor.body.length > 0 && responseBody.length === 0)) {
|
||||
// We fallback on constructing buffer from utf8 representation of the body.
|
||||
responseBody = Buffer.from(interceptor.body, 'utf8');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return continueWithResponseBody(null, responseBody);
|
||||
|
||||
function continueWithResponseBody(err, responseBody) {
|
||||
|
||||
if (continued) {
|
||||
return;
|
||||
}
|
||||
continued = true;
|
||||
|
||||
if (err) {
|
||||
response.statusCode = 500;
|
||||
responseBody = err.stack;
|
||||
}
|
||||
|
||||
// Transform the response body if it exists (it may not exist
|
||||
// if we have `responseBuffers` instead)
|
||||
|
||||
if (responseBody) {
|
||||
debug('transform the response body');
|
||||
|
||||
if (Array.isArray(responseBody)) {
|
||||
debug('response body is array: %j', responseBody);
|
||||
|
||||
if (!isNaN(Number(responseBody[0])))
|
||||
{
|
||||
response.statusCode = Number(responseBody[0]);
|
||||
}
|
||||
|
||||
if (responseBody.length >= 2 && responseBody.length <= 3)
|
||||
{
|
||||
debug('new headers: %j', responseBody[2]);
|
||||
if (!response.headers) response.headers = {};
|
||||
_.assign(response.headers, responseBody[2] || {});
|
||||
debug('response.headers after: %j', response.headers);
|
||||
responseBody = responseBody[1];
|
||||
|
||||
response.rawHeaders = response.rawHeaders || [];
|
||||
Object.keys(response.headers).forEach(function(key) {
|
||||
response.rawHeaders.push(key, response.headers[key]);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (interceptor.delayInMs) {
|
||||
debug('delaying the response for', interceptor.delayInMs, 'milliseconds');
|
||||
// Because setTimeout is called immediately in DelayedBody(), so we
|
||||
// need count in the delayConnectionInMs.
|
||||
responseBody = new DelayedBody(interceptor.getTotalDelay(), responseBody);
|
||||
}
|
||||
|
||||
if (common.isStream(responseBody)) {
|
||||
debug('response body is a stream');
|
||||
responseBody.pause();
|
||||
responseBody.on('data', function(d) {
|
||||
response.push(d);
|
||||
});
|
||||
responseBody.on('end', function() {
|
||||
response.push(null);
|
||||
});
|
||||
responseBody.on('error', function(err) {
|
||||
response.emit('error', err);
|
||||
});
|
||||
} else if (responseBody && !Buffer.isBuffer(responseBody)) {
|
||||
if (typeof responseBody === 'string') {
|
||||
responseBody = Buffer.from(responseBody);
|
||||
} else {
|
||||
responseBody = JSON.stringify(responseBody);
|
||||
response.headers['content-type'] = 'application/json';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
interceptor.interceptionCounter++;
|
||||
remove(interceptor);
|
||||
interceptor.discard();
|
||||
|
||||
if (req.aborted) { return; }
|
||||
|
||||
/// response.client.authorized = true
|
||||
/// fixes https://github.com/pgte/nock/issues/158
|
||||
response.client = _.extend(response.client || {}, {
|
||||
authorized: true
|
||||
});
|
||||
|
||||
// Account for updates to Node.js response interface
|
||||
// cf https://github.com/request/request/pull/1615
|
||||
response.socket = _.extend(response.socket || {}, {
|
||||
authorized: true
|
||||
});
|
||||
|
||||
// Evaluate functional headers.
|
||||
var evaluatedHeaders = {}
|
||||
Object.keys(response.headers).forEach(function (key) {
|
||||
var value = response.headers[key];
|
||||
|
||||
if (typeof value === "function") {
|
||||
response.headers[key] = evaluatedHeaders[key] = value(req, response, responseBody);
|
||||
}
|
||||
});
|
||||
|
||||
for(var rawHeaderIndex = 0 ; rawHeaderIndex < response.rawHeaders.length ; rawHeaderIndex += 2) {
|
||||
var key = response.rawHeaders[rawHeaderIndex];
|
||||
var value = response.rawHeaders[rawHeaderIndex + 1];
|
||||
if (typeof value === "function") {
|
||||
response.rawHeaders[rawHeaderIndex + 1] = evaluatedHeaders[key.toLowerCase()];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
process.nextTick(respond);
|
||||
|
||||
function respond() {
|
||||
|
||||
if (req.aborted) { return; }
|
||||
|
||||
if (interceptor.socketDelayInMs && interceptor.socketDelayInMs > 0) {
|
||||
req.socket.applyDelay(interceptor.socketDelayInMs);
|
||||
}
|
||||
|
||||
if (interceptor.delayConnectionInMs && interceptor.delayConnectionInMs > 0) {
|
||||
req.socket.applyDelay(interceptor.delayConnectionInMs);
|
||||
setTimeout(_respond, interceptor.delayConnectionInMs);
|
||||
} else {
|
||||
_respond();
|
||||
}
|
||||
|
||||
function _respond() {
|
||||
if (req.aborted) { return; }
|
||||
|
||||
debug('emitting response');
|
||||
|
||||
if (typeof cb === 'function') {
|
||||
debug('callback with response');
|
||||
cb(response);
|
||||
}
|
||||
|
||||
if (req.aborted) {
|
||||
emitError(new Error('Request aborted'));
|
||||
}
|
||||
else {
|
||||
req.emit('response', response);
|
||||
}
|
||||
|
||||
if (common.isStream(responseBody)) {
|
||||
debug('resuming response stream');
|
||||
responseBody.resume();
|
||||
}
|
||||
else {
|
||||
responseBuffers = responseBuffers || [];
|
||||
if (typeof responseBody !== "undefined") {
|
||||
debug('adding body to buffer list');
|
||||
responseBuffers.push(responseBody);
|
||||
}
|
||||
|
||||
// Stream the response chunks one at a time.
|
||||
timers.setImmediate(function emitChunk() {
|
||||
var chunk = responseBuffers.shift();
|
||||
|
||||
if (chunk) {
|
||||
debug('emitting response chunk');
|
||||
response.push(chunk);
|
||||
timers.setImmediate(emitChunk);
|
||||
}
|
||||
else {
|
||||
debug('ending response stream');
|
||||
response.push(null);
|
||||
interceptor.scope.emit('replied', req, interceptor);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return req;
|
||||
}
|
||||
|
||||
module.exports = RequestOverrider;
|
||||
365
node_modules/nock/lib/scope.js
generated
vendored
Normal file
365
node_modules/nock/lib/scope.js
generated
vendored
Normal file
@@ -0,0 +1,365 @@
|
||||
/* eslint-disable strict */
|
||||
/**
|
||||
* @module nock/scope
|
||||
*/
|
||||
var globalIntercept = require('./intercept')
|
||||
, common = require('./common')
|
||||
, assert = require('assert')
|
||||
, url = require('url')
|
||||
, _ = require('lodash')
|
||||
, debug = require('debug')('nock.scope')
|
||||
, EventEmitter = require('events').EventEmitter
|
||||
, globalEmitter = require('./global_emitter')
|
||||
, util = require('util')
|
||||
, Interceptor = require('./interceptor') ;
|
||||
|
||||
var fs;
|
||||
|
||||
try {
|
||||
fs = require('fs');
|
||||
} catch(err) {
|
||||
// do nothing, we're in the browser
|
||||
}
|
||||
|
||||
function startScope(basePath, options) {
|
||||
return new Scope(basePath, options);
|
||||
}
|
||||
|
||||
function Scope(basePath, options) {
|
||||
if (!(this instanceof Scope)) {
|
||||
return new Scope(basePath, options);
|
||||
}
|
||||
|
||||
EventEmitter.apply(this);
|
||||
this.keyedInterceptors = {};
|
||||
this.interceptors = [];
|
||||
this.transformPathFunction = null;
|
||||
this.transformRequestBodyFunction = null;
|
||||
this.matchHeaders = [];
|
||||
this.logger = debug;
|
||||
this.scopeOptions = options || {};
|
||||
this.urlParts = {};
|
||||
this._persist = false;
|
||||
this.contentLen = false;
|
||||
this.date = null;
|
||||
this.basePath = basePath;
|
||||
this.basePathname = '';
|
||||
this.port = null;
|
||||
|
||||
if (!(basePath instanceof RegExp)) {
|
||||
this.urlParts = url.parse(basePath);
|
||||
this.port = this.urlParts.port || ((this.urlParts.protocol === 'http:') ? 80 : 443);
|
||||
this.basePathname = this.urlParts.pathname.replace(/\/$/, '');
|
||||
this.basePath = this.urlParts.protocol + '//' + this.urlParts.hostname + ':' + this.port;
|
||||
}
|
||||
}
|
||||
|
||||
util.inherits(Scope, EventEmitter);
|
||||
|
||||
Scope.prototype.add = function add(key, interceptor, scope) {
|
||||
if (! this.keyedInterceptors.hasOwnProperty(key)) {
|
||||
this.keyedInterceptors[key] = [];
|
||||
}
|
||||
this.keyedInterceptors[key].push(interceptor);
|
||||
globalIntercept(this.basePath,
|
||||
interceptor,
|
||||
this,
|
||||
this.scopeOptions,
|
||||
this.urlParts.hostname);
|
||||
};
|
||||
|
||||
Scope.prototype.remove = function remove(key, interceptor) {
|
||||
if (this._persist) {
|
||||
return;
|
||||
}
|
||||
var arr = this.keyedInterceptors[key];
|
||||
if (arr) {
|
||||
arr.splice(arr.indexOf(interceptor), 1);
|
||||
if (arr.length === 0) {
|
||||
delete this.keyedInterceptors[key];
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Scope.prototype.intercept = function intercept(uri, method, requestBody, interceptorOptions) {
|
||||
var ic = new Interceptor(this, uri, method, requestBody, interceptorOptions);
|
||||
|
||||
this.interceptors.push(ic);
|
||||
return ic;
|
||||
};
|
||||
|
||||
Scope.prototype.get = function get(uri, requestBody, options) {
|
||||
return this.intercept(uri, 'GET', requestBody, options);
|
||||
};
|
||||
|
||||
Scope.prototype.post = function post(uri, requestBody, options) {
|
||||
return this.intercept(uri, 'POST', requestBody, options);
|
||||
};
|
||||
|
||||
Scope.prototype.put = function put(uri, requestBody, options) {
|
||||
return this.intercept(uri, 'PUT', requestBody, options);
|
||||
};
|
||||
|
||||
Scope.prototype.head = function head(uri, requestBody, options) {
|
||||
return this.intercept(uri, 'HEAD', requestBody, options);
|
||||
};
|
||||
|
||||
Scope.prototype.patch = function patch(uri, requestBody, options) {
|
||||
return this.intercept(uri, 'PATCH', requestBody, options);
|
||||
};
|
||||
|
||||
Scope.prototype.merge = function merge(uri, requestBody, options) {
|
||||
return this.intercept(uri, 'MERGE', requestBody, options);
|
||||
};
|
||||
|
||||
Scope.prototype.delete = function _delete(uri, requestBody, options) {
|
||||
return this.intercept(uri, 'DELETE', requestBody, options);
|
||||
};
|
||||
|
||||
Scope.prototype.options = function _options(uri, requestBody, options) {
|
||||
return this.intercept(uri, 'OPTIONS', requestBody, options);
|
||||
};
|
||||
|
||||
Scope.prototype.pendingMocks = function pendingMocks() {
|
||||
var self = this;
|
||||
|
||||
var pendingInterceptorKeys = Object.keys(this.keyedInterceptors).filter(function (key) {
|
||||
var interceptorList = self.keyedInterceptors[key];
|
||||
var pendingInterceptors = interceptorList.filter(function (interceptor) {
|
||||
// TODO: This assumes that completed mocks are removed from the keyedInterceptors list
|
||||
// (when persistence is off). We should change that (and this) in future.
|
||||
var persistedAndUsed = self._persist && interceptor.interceptionCounter > 0;
|
||||
return !persistedAndUsed && !interceptor.optional;
|
||||
});
|
||||
return pendingInterceptors.length > 0;
|
||||
});
|
||||
|
||||
return pendingInterceptorKeys;
|
||||
};
|
||||
|
||||
// Returns all keyedInterceptors that are active.
|
||||
// This incomplete interceptors, persisted but complete interceptors, and
|
||||
// optional interceptors, but not non-persisted and completed interceptors.
|
||||
Scope.prototype.activeMocks = function activeMocks() {
|
||||
return Object.keys(this.keyedInterceptors);
|
||||
}
|
||||
|
||||
Scope.prototype.isDone = function isDone() {
|
||||
// if nock is turned off, it always says it's done
|
||||
if (! globalIntercept.isOn()) { return true; }
|
||||
|
||||
return this.pendingMocks().length === 0;
|
||||
};
|
||||
|
||||
Scope.prototype.done = function done() {
|
||||
assert.ok(this.isDone(), "Mocks not yet satisfied:\n" + this.pendingMocks().join("\n"));
|
||||
};
|
||||
|
||||
Scope.prototype.buildFilter = function buildFilter() {
|
||||
var filteringArguments = arguments;
|
||||
|
||||
if (arguments[0] instanceof RegExp) {
|
||||
return function(candidate) {
|
||||
if (candidate) {
|
||||
candidate = candidate.replace(filteringArguments[0], filteringArguments[1]);
|
||||
}
|
||||
return candidate;
|
||||
};
|
||||
} else if (_.isFunction(arguments[0])) {
|
||||
return arguments[0];
|
||||
}
|
||||
};
|
||||
|
||||
Scope.prototype.filteringPath = function filteringPath() {
|
||||
this.transformPathFunction = this.buildFilter.apply(this, arguments);
|
||||
if (!this.transformPathFunction) {
|
||||
throw new Error('Invalid arguments: filtering path should be a function or a regular expression');
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
Scope.prototype.filteringRequestBody = function filteringRequestBody() {
|
||||
this.transformRequestBodyFunction = this.buildFilter.apply(this, arguments);
|
||||
if (!this.transformRequestBodyFunction) {
|
||||
throw new Error('Invalid arguments: filtering request body should be a function or a regular expression');
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
Scope.prototype.matchHeader = function matchHeader(name, value) {
|
||||
// We use lower-case header field names throughout Nock.
|
||||
this.matchHeaders.push({ name: name.toLowerCase(), value: value });
|
||||
return this;
|
||||
};
|
||||
|
||||
Scope.prototype.defaultReplyHeaders = function defaultReplyHeaders(headers) {
|
||||
this._defaultReplyHeaders = common.headersFieldNamesToLowerCase(headers);
|
||||
return this;
|
||||
};
|
||||
|
||||
Scope.prototype.log = function log(newLogger) {
|
||||
this.logger = newLogger;
|
||||
return this;
|
||||
};
|
||||
|
||||
Scope.prototype.persist = function persist(flag) {
|
||||
this._persist = flag == null ? true : flag;
|
||||
if (typeof this._persist !== 'boolean') {
|
||||
throw new Error('Invalid arguments: argument should be a boolean');
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
Scope.prototype.shouldPersist = function shouldPersist() {
|
||||
return this._persist;
|
||||
};
|
||||
|
||||
Scope.prototype.replyContentLength = function replyContentLength() {
|
||||
this.contentLen = true;
|
||||
return this;
|
||||
};
|
||||
|
||||
Scope.prototype.replyDate = function replyDate(d) {
|
||||
this.date = d || new Date();
|
||||
return this;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
function cleanAll() {
|
||||
globalIntercept.removeAll();
|
||||
return module.exports;
|
||||
}
|
||||
|
||||
function loadDefs(path) {
|
||||
if (! fs) {
|
||||
throw new Error('No fs');
|
||||
}
|
||||
|
||||
var contents = fs.readFileSync(path);
|
||||
return JSON.parse(contents);
|
||||
}
|
||||
|
||||
function load(path) {
|
||||
return define(loadDefs(path));
|
||||
}
|
||||
|
||||
function getStatusFromDefinition(nockDef) {
|
||||
// Backward compatibility for when `status` was encoded as string in `reply`.
|
||||
if (!_.isUndefined(nockDef.reply)) {
|
||||
// Try parsing `reply` property.
|
||||
var parsedReply = parseInt(nockDef.reply, 10);
|
||||
if (_.isNumber(parsedReply)) {
|
||||
return parsedReply;
|
||||
}
|
||||
}
|
||||
|
||||
var DEFAULT_STATUS_OK = 200;
|
||||
return nockDef.status || DEFAULT_STATUS_OK;
|
||||
}
|
||||
|
||||
function getScopeFromDefinition(nockDef) {
|
||||
|
||||
// Backward compatibility for when `port` was part of definition.
|
||||
if (!_.isUndefined(nockDef.port)) {
|
||||
// Include `port` into scope if it doesn't exist.
|
||||
var options = url.parse(nockDef.scope);
|
||||
if (_.isNull(options.port)) {
|
||||
return nockDef.scope + ':' + nockDef.port;
|
||||
} else {
|
||||
if (parseInt(options.port) !== parseInt(nockDef.port)) {
|
||||
throw new Error('Mismatched port numbers in scope and port properties of nock definition.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nockDef.scope;
|
||||
}
|
||||
|
||||
function tryJsonParse(string) {
|
||||
try {
|
||||
return JSON.parse(string);
|
||||
} catch(err) {
|
||||
return string;
|
||||
}
|
||||
}
|
||||
|
||||
function define(nockDefs) {
|
||||
|
||||
var nocks = [];
|
||||
|
||||
nockDefs.forEach(function(nockDef) {
|
||||
|
||||
var nscope = getScopeFromDefinition(nockDef)
|
||||
, npath = nockDef.path
|
||||
, method = nockDef.method.toLowerCase() || "get"
|
||||
, status = getStatusFromDefinition(nockDef)
|
||||
, rawHeaders = nockDef.rawHeaders || []
|
||||
, reqheaders = nockDef.reqheaders || {}
|
||||
, badheaders = nockDef.badheaders || []
|
||||
, body = nockDef.body || ''
|
||||
, options = nockDef.options || {};
|
||||
|
||||
// We use request headers for both filtering (see below) and mocking.
|
||||
// Here we are setting up mocked request headers but we don't want to
|
||||
// be changing the user's options object so we clone it first.
|
||||
options = _.clone(options) || {};
|
||||
options.reqheaders = reqheaders;
|
||||
options.badheaders = badheaders;
|
||||
|
||||
// Response is not always JSON as it could be a string or binary data or
|
||||
// even an array of binary buffers (e.g. when content is enconded)
|
||||
var response;
|
||||
if (!nockDef.response) {
|
||||
response = '';
|
||||
} else if (nockDef.responseIsBinary) {
|
||||
response = Buffer.from(nockDef.response, 'hex')
|
||||
} else {
|
||||
response = _.isString(nockDef.response) ? tryJsonParse(nockDef.response) : nockDef.response;
|
||||
}
|
||||
|
||||
var nock;
|
||||
if (body==="*") {
|
||||
nock = startScope(nscope, options).filteringRequestBody(function() {
|
||||
return "*";
|
||||
})[method](npath, "*").reply(status, response, rawHeaders);
|
||||
} else {
|
||||
nock = startScope(nscope, options);
|
||||
// If request headers were specified filter by them.
|
||||
if (_.size(reqheaders) > 0) {
|
||||
for (var k in reqheaders) {
|
||||
nock.matchHeader(k, reqheaders[k]);
|
||||
}
|
||||
}
|
||||
var acceptableFilters = ['filteringRequestBody', 'filteringPath'];
|
||||
acceptableFilters.forEach((filter) => {
|
||||
if (nockDef[filter]) {
|
||||
nock[filter](nockDef[filter]);
|
||||
}
|
||||
});
|
||||
nock.intercept(npath, method, body).reply(status, response, rawHeaders);
|
||||
}
|
||||
|
||||
nocks.push(nock);
|
||||
|
||||
});
|
||||
|
||||
return nocks;
|
||||
}
|
||||
|
||||
module.exports = Object.assign(startScope, {
|
||||
cleanAll: cleanAll,
|
||||
activate: globalIntercept.activate,
|
||||
isActive: globalIntercept.isActive,
|
||||
isDone: globalIntercept.isDone,
|
||||
pendingMocks: globalIntercept.pendingMocks,
|
||||
activeMocks: globalIntercept.activeMocks,
|
||||
removeInterceptor: globalIntercept.removeInterceptor,
|
||||
disableNetConnect: globalIntercept.disableNetConnect,
|
||||
enableNetConnect: globalIntercept.enableNetConnect,
|
||||
load: load,
|
||||
loadDefs: loadDefs,
|
||||
define: define,
|
||||
emitter: globalEmitter,
|
||||
});
|
||||
70
node_modules/nock/lib/socket.js
generated
vendored
Normal file
70
node_modules/nock/lib/socket.js
generated
vendored
Normal file
@@ -0,0 +1,70 @@
|
||||
'use strict';
|
||||
|
||||
var EventEmitter = require('events').EventEmitter;
|
||||
var debug = require('debug')('nock.socket');
|
||||
var util = require('util');
|
||||
|
||||
module.exports = Socket;
|
||||
|
||||
function Socket(options) {
|
||||
if (!(this instanceof Socket)) {
|
||||
return new Socket(options);
|
||||
}
|
||||
|
||||
EventEmitter.apply(this);
|
||||
|
||||
options = options || {};
|
||||
|
||||
if (options.proto === 'https') {
|
||||
this.authorized = true;
|
||||
}
|
||||
|
||||
this.writable = true;
|
||||
this.readable = true;
|
||||
this.destroyed = false;
|
||||
this.connecting = false;
|
||||
|
||||
this.setNoDelay = noop;
|
||||
this.setKeepAlive = noop;
|
||||
this.resume = noop;
|
||||
|
||||
// totalDelay that has already been applied to the current
|
||||
// request/connection, timeout error will be generated if
|
||||
// it is timed-out.
|
||||
this.totalDelayMs = 0;
|
||||
// Maximum allowed delay. Null means unlimited.
|
||||
this.timeoutMs = null;
|
||||
}
|
||||
util.inherits(Socket, EventEmitter);
|
||||
|
||||
Socket.prototype.setTimeout = function setTimeout(timeoutMs, fn) {
|
||||
this.timeoutMs = timeoutMs;
|
||||
this.timeoutFunction = fn;
|
||||
};
|
||||
|
||||
Socket.prototype.applyDelay = function applyDelay(delayMs) {
|
||||
this.totalDelayMs += delayMs;
|
||||
|
||||
if (this.timeoutMs && this.totalDelayMs > this.timeoutMs) {
|
||||
debug('socket timeout');
|
||||
if (this.timeoutFunction) {
|
||||
this.timeoutFunction();
|
||||
}
|
||||
else {
|
||||
this.emit('timeout');
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
Socket.prototype.getPeerCertificate = function getPeerCertificate() {
|
||||
return Buffer.from((Math.random() * 10000 + Date.now()).toString()).toString('base64');
|
||||
};
|
||||
|
||||
Socket.prototype.destroy = function destroy() {
|
||||
this.destroyed = true;
|
||||
this.readable = this.writable = false;
|
||||
};
|
||||
|
||||
function noop() {}
|
||||
|
||||
395
node_modules/nock/node_modules/debug/CHANGELOG.md
generated
vendored
Normal file
395
node_modules/nock/node_modules/debug/CHANGELOG.md
generated
vendored
Normal file
@@ -0,0 +1,395 @@
|
||||
|
||||
3.1.0 / 2017-09-26
|
||||
==================
|
||||
|
||||
* Add `DEBUG_HIDE_DATE` env var (#486)
|
||||
* Remove ReDoS regexp in %o formatter (#504)
|
||||
* Remove "component" from package.json
|
||||
* Remove `component.json`
|
||||
* Ignore package-lock.json
|
||||
* Examples: fix colors printout
|
||||
* Fix: browser detection
|
||||
* Fix: spelling mistake (#496, @EdwardBetts)
|
||||
|
||||
3.0.1 / 2017-08-24
|
||||
==================
|
||||
|
||||
* Fix: Disable colors in Edge and Internet Explorer (#489)
|
||||
|
||||
3.0.0 / 2017-08-08
|
||||
==================
|
||||
|
||||
* Breaking: Remove DEBUG_FD (#406)
|
||||
* Breaking: Use `Date#toISOString()` instead to `Date#toUTCString()` when output is not a TTY (#418)
|
||||
* Breaking: Make millisecond timer namespace specific and allow 'always enabled' output (#408)
|
||||
* Addition: document `enabled` flag (#465)
|
||||
* Addition: add 256 colors mode (#481)
|
||||
* Addition: `enabled()` updates existing debug instances, add `destroy()` function (#440)
|
||||
* Update: component: update "ms" to v2.0.0
|
||||
* Update: separate the Node and Browser tests in Travis-CI
|
||||
* Update: refactor Readme, fixed documentation, added "Namespace Colors" section, redid screenshots
|
||||
* Update: separate Node.js and web browser examples for organization
|
||||
* Update: update "browserify" to v14.4.0
|
||||
* Fix: fix Readme typo (#473)
|
||||
|
||||
2.6.9 / 2017-09-22
|
||||
==================
|
||||
|
||||
* remove ReDoS regexp in %o formatter (#504)
|
||||
|
||||
2.6.8 / 2017-05-18
|
||||
==================
|
||||
|
||||
* Fix: Check for undefined on browser globals (#462, @marbemac)
|
||||
|
||||
2.6.7 / 2017-05-16
|
||||
==================
|
||||
|
||||
* Fix: Update ms to 2.0.0 to fix regular expression denial of service vulnerability (#458, @hubdotcom)
|
||||
* Fix: Inline extend function in node implementation (#452, @dougwilson)
|
||||
* Docs: Fix typo (#455, @msasad)
|
||||
|
||||
2.6.5 / 2017-04-27
|
||||
==================
|
||||
|
||||
* Fix: null reference check on window.documentElement.style.WebkitAppearance (#447, @thebigredgeek)
|
||||
* Misc: clean up browser reference checks (#447, @thebigredgeek)
|
||||
* Misc: add npm-debug.log to .gitignore (@thebigredgeek)
|
||||
|
||||
|
||||
2.6.4 / 2017-04-20
|
||||
==================
|
||||
|
||||
* Fix: bug that would occur if process.env.DEBUG is a non-string value. (#444, @LucianBuzzo)
|
||||
* Chore: ignore bower.json in npm installations. (#437, @joaovieira)
|
||||
* Misc: update "ms" to v0.7.3 (@tootallnate)
|
||||
|
||||
2.6.3 / 2017-03-13
|
||||
==================
|
||||
|
||||
* Fix: Electron reference to `process.env.DEBUG` (#431, @paulcbetts)
|
||||
* Docs: Changelog fix (@thebigredgeek)
|
||||
|
||||
2.6.2 / 2017-03-10
|
||||
==================
|
||||
|
||||
* Fix: DEBUG_MAX_ARRAY_LENGTH (#420, @slavaGanzin)
|
||||
* Docs: Add backers and sponsors from Open Collective (#422, @piamancini)
|
||||
* Docs: Add Slackin invite badge (@tootallnate)
|
||||
|
||||
2.6.1 / 2017-02-10
|
||||
==================
|
||||
|
||||
* Fix: Module's `export default` syntax fix for IE8 `Expected identifier` error
|
||||
* Fix: Whitelist DEBUG_FD for values 1 and 2 only (#415, @pi0)
|
||||
* Fix: IE8 "Expected identifier" error (#414, @vgoma)
|
||||
* Fix: Namespaces would not disable once enabled (#409, @musikov)
|
||||
|
||||
2.6.0 / 2016-12-28
|
||||
==================
|
||||
|
||||
* Fix: added better null pointer checks for browser useColors (@thebigredgeek)
|
||||
* Improvement: removed explicit `window.debug` export (#404, @tootallnate)
|
||||
* Improvement: deprecated `DEBUG_FD` environment variable (#405, @tootallnate)
|
||||
|
||||
2.5.2 / 2016-12-25
|
||||
==================
|
||||
|
||||
* Fix: reference error on window within webworkers (#393, @KlausTrainer)
|
||||
* Docs: fixed README typo (#391, @lurch)
|
||||
* Docs: added notice about v3 api discussion (@thebigredgeek)
|
||||
|
||||
2.5.1 / 2016-12-20
|
||||
==================
|
||||
|
||||
* Fix: babel-core compatibility
|
||||
|
||||
2.5.0 / 2016-12-20
|
||||
==================
|
||||
|
||||
* Fix: wrong reference in bower file (@thebigredgeek)
|
||||
* Fix: webworker compatibility (@thebigredgeek)
|
||||
* Fix: output formatting issue (#388, @kribblo)
|
||||
* Fix: babel-loader compatibility (#383, @escwald)
|
||||
* Misc: removed built asset from repo and publications (@thebigredgeek)
|
||||
* Misc: moved source files to /src (#378, @yamikuronue)
|
||||
* Test: added karma integration and replaced babel with browserify for browser tests (#378, @yamikuronue)
|
||||
* Test: coveralls integration (#378, @yamikuronue)
|
||||
* Docs: simplified language in the opening paragraph (#373, @yamikuronue)
|
||||
|
||||
2.4.5 / 2016-12-17
|
||||
==================
|
||||
|
||||
* Fix: `navigator` undefined in Rhino (#376, @jochenberger)
|
||||
* Fix: custom log function (#379, @hsiliev)
|
||||
* Improvement: bit of cleanup + linting fixes (@thebigredgeek)
|
||||
* Improvement: rm non-maintainted `dist/` dir (#375, @freewil)
|
||||
* Docs: simplified language in the opening paragraph. (#373, @yamikuronue)
|
||||
|
||||
2.4.4 / 2016-12-14
|
||||
==================
|
||||
|
||||
* Fix: work around debug being loaded in preload scripts for electron (#368, @paulcbetts)
|
||||
|
||||
2.4.3 / 2016-12-14
|
||||
==================
|
||||
|
||||
* Fix: navigation.userAgent error for react native (#364, @escwald)
|
||||
|
||||
2.4.2 / 2016-12-14
|
||||
==================
|
||||
|
||||
* Fix: browser colors (#367, @tootallnate)
|
||||
* Misc: travis ci integration (@thebigredgeek)
|
||||
* Misc: added linting and testing boilerplate with sanity check (@thebigredgeek)
|
||||
|
||||
2.4.1 / 2016-12-13
|
||||
==================
|
||||
|
||||
* Fix: typo that broke the package (#356)
|
||||
|
||||
2.4.0 / 2016-12-13
|
||||
==================
|
||||
|
||||
* Fix: bower.json references unbuilt src entry point (#342, @justmatt)
|
||||
* Fix: revert "handle regex special characters" (@tootallnate)
|
||||
* Feature: configurable util.inspect()`options for NodeJS (#327, @tootallnate)
|
||||
* Feature: %O`(big O) pretty-prints objects (#322, @tootallnate)
|
||||
* Improvement: allow colors in workers (#335, @botverse)
|
||||
* Improvement: use same color for same namespace. (#338, @lchenay)
|
||||
|
||||
2.3.3 / 2016-11-09
|
||||
==================
|
||||
|
||||
* Fix: Catch `JSON.stringify()` errors (#195, Jovan Alleyne)
|
||||
* Fix: Returning `localStorage` saved values (#331, Levi Thomason)
|
||||
* Improvement: Don't create an empty object when no `process` (Nathan Rajlich)
|
||||
|
||||
2.3.2 / 2016-11-09
|
||||
==================
|
||||
|
||||
* Fix: be super-safe in index.js as well (@TooTallNate)
|
||||
* Fix: should check whether process exists (Tom Newby)
|
||||
|
||||
2.3.1 / 2016-11-09
|
||||
==================
|
||||
|
||||
* Fix: Added electron compatibility (#324, @paulcbetts)
|
||||
* Improvement: Added performance optimizations (@tootallnate)
|
||||
* Readme: Corrected PowerShell environment variable example (#252, @gimre)
|
||||
* Misc: Removed yarn lock file from source control (#321, @fengmk2)
|
||||
|
||||
2.3.0 / 2016-11-07
|
||||
==================
|
||||
|
||||
* Fix: Consistent placement of ms diff at end of output (#215, @gorangajic)
|
||||
* Fix: Escaping of regex special characters in namespace strings (#250, @zacronos)
|
||||
* Fix: Fixed bug causing crash on react-native (#282, @vkarpov15)
|
||||
* Feature: Enabled ES6+ compatible import via default export (#212 @bucaran)
|
||||
* Feature: Added %O formatter to reflect Chrome's console.log capability (#279, @oncletom)
|
||||
* Package: Update "ms" to 0.7.2 (#315, @DevSide)
|
||||
* Package: removed superfluous version property from bower.json (#207 @kkirsche)
|
||||
* Readme: fix USE_COLORS to DEBUG_COLORS
|
||||
* Readme: Doc fixes for format string sugar (#269, @mlucool)
|
||||
* Readme: Updated docs for DEBUG_FD and DEBUG_COLORS environment variables (#232, @mattlyons0)
|
||||
* Readme: doc fixes for PowerShell (#271 #243, @exoticknight @unreadable)
|
||||
* Readme: better docs for browser support (#224, @matthewmueller)
|
||||
* Tooling: Added yarn integration for development (#317, @thebigredgeek)
|
||||
* Misc: Renamed History.md to CHANGELOG.md (@thebigredgeek)
|
||||
* Misc: Added license file (#226 #274, @CantemoInternal @sdaitzman)
|
||||
* Misc: Updated contributors (@thebigredgeek)
|
||||
|
||||
2.2.0 / 2015-05-09
|
||||
==================
|
||||
|
||||
* package: update "ms" to v0.7.1 (#202, @dougwilson)
|
||||
* README: add logging to file example (#193, @DanielOchoa)
|
||||
* README: fixed a typo (#191, @amir-s)
|
||||
* browser: expose `storage` (#190, @stephenmathieson)
|
||||
* Makefile: add a `distclean` target (#189, @stephenmathieson)
|
||||
|
||||
2.1.3 / 2015-03-13
|
||||
==================
|
||||
|
||||
* Updated stdout/stderr example (#186)
|
||||
* Updated example/stdout.js to match debug current behaviour
|
||||
* Renamed example/stderr.js to stdout.js
|
||||
* Update Readme.md (#184)
|
||||
* replace high intensity foreground color for bold (#182, #183)
|
||||
|
||||
2.1.2 / 2015-03-01
|
||||
==================
|
||||
|
||||
* dist: recompile
|
||||
* update "ms" to v0.7.0
|
||||
* package: update "browserify" to v9.0.3
|
||||
* component: fix "ms.js" repo location
|
||||
* changed bower package name
|
||||
* updated documentation about using debug in a browser
|
||||
* fix: security error on safari (#167, #168, @yields)
|
||||
|
||||
2.1.1 / 2014-12-29
|
||||
==================
|
||||
|
||||
* browser: use `typeof` to check for `console` existence
|
||||
* browser: check for `console.log` truthiness (fix IE 8/9)
|
||||
* browser: add support for Chrome apps
|
||||
* Readme: added Windows usage remarks
|
||||
* Add `bower.json` to properly support bower install
|
||||
|
||||
2.1.0 / 2014-10-15
|
||||
==================
|
||||
|
||||
* node: implement `DEBUG_FD` env variable support
|
||||
* package: update "browserify" to v6.1.0
|
||||
* package: add "license" field to package.json (#135, @panuhorsmalahti)
|
||||
|
||||
2.0.0 / 2014-09-01
|
||||
==================
|
||||
|
||||
* package: update "browserify" to v5.11.0
|
||||
* node: use stderr rather than stdout for logging (#29, @stephenmathieson)
|
||||
|
||||
1.0.4 / 2014-07-15
|
||||
==================
|
||||
|
||||
* dist: recompile
|
||||
* example: remove `console.info()` log usage
|
||||
* example: add "Content-Type" UTF-8 header to browser example
|
||||
* browser: place %c marker after the space character
|
||||
* browser: reset the "content" color via `color: inherit`
|
||||
* browser: add colors support for Firefox >= v31
|
||||
* debug: prefer an instance `log()` function over the global one (#119)
|
||||
* Readme: update documentation about styled console logs for FF v31 (#116, @wryk)
|
||||
|
||||
1.0.3 / 2014-07-09
|
||||
==================
|
||||
|
||||
* Add support for multiple wildcards in namespaces (#122, @seegno)
|
||||
* browser: fix lint
|
||||
|
||||
1.0.2 / 2014-06-10
|
||||
==================
|
||||
|
||||
* browser: update color palette (#113, @gscottolson)
|
||||
* common: make console logging function configurable (#108, @timoxley)
|
||||
* node: fix %o colors on old node <= 0.8.x
|
||||
* Makefile: find node path using shell/which (#109, @timoxley)
|
||||
|
||||
1.0.1 / 2014-06-06
|
||||
==================
|
||||
|
||||
* browser: use `removeItem()` to clear localStorage
|
||||
* browser, node: don't set DEBUG if namespaces is undefined (#107, @leedm777)
|
||||
* package: add "contributors" section
|
||||
* node: fix comment typo
|
||||
* README: list authors
|
||||
|
||||
1.0.0 / 2014-06-04
|
||||
==================
|
||||
|
||||
* make ms diff be global, not be scope
|
||||
* debug: ignore empty strings in enable()
|
||||
* node: make DEBUG_COLORS able to disable coloring
|
||||
* *: export the `colors` array
|
||||
* npmignore: don't publish the `dist` dir
|
||||
* Makefile: refactor to use browserify
|
||||
* package: add "browserify" as a dev dependency
|
||||
* Readme: add Web Inspector Colors section
|
||||
* node: reset terminal color for the debug content
|
||||
* node: map "%o" to `util.inspect()`
|
||||
* browser: map "%j" to `JSON.stringify()`
|
||||
* debug: add custom "formatters"
|
||||
* debug: use "ms" module for humanizing the diff
|
||||
* Readme: add "bash" syntax highlighting
|
||||
* browser: add Firebug color support
|
||||
* browser: add colors for WebKit browsers
|
||||
* node: apply log to `console`
|
||||
* rewrite: abstract common logic for Node & browsers
|
||||
* add .jshintrc file
|
||||
|
||||
0.8.1 / 2014-04-14
|
||||
==================
|
||||
|
||||
* package: re-add the "component" section
|
||||
|
||||
0.8.0 / 2014-03-30
|
||||
==================
|
||||
|
||||
* add `enable()` method for nodejs. Closes #27
|
||||
* change from stderr to stdout
|
||||
* remove unnecessary index.js file
|
||||
|
||||
0.7.4 / 2013-11-13
|
||||
==================
|
||||
|
||||
* remove "browserify" key from package.json (fixes something in browserify)
|
||||
|
||||
0.7.3 / 2013-10-30
|
||||
==================
|
||||
|
||||
* fix: catch localStorage security error when cookies are blocked (Chrome)
|
||||
* add debug(err) support. Closes #46
|
||||
* add .browser prop to package.json. Closes #42
|
||||
|
||||
0.7.2 / 2013-02-06
|
||||
==================
|
||||
|
||||
* fix package.json
|
||||
* fix: Mobile Safari (private mode) is broken with debug
|
||||
* fix: Use unicode to send escape character to shell instead of octal to work with strict mode javascript
|
||||
|
||||
0.7.1 / 2013-02-05
|
||||
==================
|
||||
|
||||
* add repository URL to package.json
|
||||
* add DEBUG_COLORED to force colored output
|
||||
* add browserify support
|
||||
* fix component. Closes #24
|
||||
|
||||
0.7.0 / 2012-05-04
|
||||
==================
|
||||
|
||||
* Added .component to package.json
|
||||
* Added debug.component.js build
|
||||
|
||||
0.6.0 / 2012-03-16
|
||||
==================
|
||||
|
||||
* Added support for "-" prefix in DEBUG [Vinay Pulim]
|
||||
* Added `.enabled` flag to the node version [TooTallNate]
|
||||
|
||||
0.5.0 / 2012-02-02
|
||||
==================
|
||||
|
||||
* Added: humanize diffs. Closes #8
|
||||
* Added `debug.disable()` to the CS variant
|
||||
* Removed padding. Closes #10
|
||||
* Fixed: persist client-side variant again. Closes #9
|
||||
|
||||
0.4.0 / 2012-02-01
|
||||
==================
|
||||
|
||||
* Added browser variant support for older browsers [TooTallNate]
|
||||
* Added `debug.enable('project:*')` to browser variant [TooTallNate]
|
||||
* Added padding to diff (moved it to the right)
|
||||
|
||||
0.3.0 / 2012-01-26
|
||||
==================
|
||||
|
||||
* Added millisecond diff when isatty, otherwise UTC string
|
||||
|
||||
0.2.0 / 2012-01-22
|
||||
==================
|
||||
|
||||
* Added wildcard support
|
||||
|
||||
0.1.0 / 2011-12-02
|
||||
==================
|
||||
|
||||
* Added: remove colors unless stderr isatty [TooTallNate]
|
||||
|
||||
0.0.1 / 2010-01-03
|
||||
==================
|
||||
|
||||
* Initial release
|
||||
19
node_modules/nock/node_modules/debug/LICENSE
generated
vendored
Normal file
19
node_modules/nock/node_modules/debug/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
(The MIT License)
|
||||
|
||||
Copyright (c) 2014 TJ Holowaychuk <tj@vision-media.ca>
|
||||
|
||||
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.
|
||||
|
||||
455
node_modules/nock/node_modules/debug/README.md
generated
vendored
Normal file
455
node_modules/nock/node_modules/debug/README.md
generated
vendored
Normal file
@@ -0,0 +1,455 @@
|
||||
# debug
|
||||
[](https://travis-ci.org/visionmedia/debug) [](https://coveralls.io/github/visionmedia/debug?branch=master) [](https://visionmedia-community-slackin.now.sh/) [](#backers)
|
||||
[](#sponsors)
|
||||
|
||||
<img width="647" src="https://user-images.githubusercontent.com/71256/29091486-fa38524c-7c37-11e7-895f-e7ec8e1039b6.png">
|
||||
|
||||
A tiny JavaScript debugging utility modelled after Node.js core's debugging
|
||||
technique. Works in Node.js and web browsers.
|
||||
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
$ npm install debug
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
`debug` exposes a function; simply pass this function the name of your module, and it will return a decorated version of `console.error` for you to pass debug statements to. This will allow you to toggle the debug output for different parts of your module as well as the module as a whole.
|
||||
|
||||
Example [_app.js_](./examples/node/app.js):
|
||||
|
||||
```js
|
||||
var debug = require('debug')('http')
|
||||
, http = require('http')
|
||||
, name = 'My App';
|
||||
|
||||
// fake app
|
||||
|
||||
debug('booting %o', name);
|
||||
|
||||
http.createServer(function(req, res){
|
||||
debug(req.method + ' ' + req.url);
|
||||
res.end('hello\n');
|
||||
}).listen(3000, function(){
|
||||
debug('listening');
|
||||
});
|
||||
|
||||
// fake worker of some kind
|
||||
|
||||
require('./worker');
|
||||
```
|
||||
|
||||
Example [_worker.js_](./examples/node/worker.js):
|
||||
|
||||
```js
|
||||
var a = require('debug')('worker:a')
|
||||
, b = require('debug')('worker:b');
|
||||
|
||||
function work() {
|
||||
a('doing lots of uninteresting work');
|
||||
setTimeout(work, Math.random() * 1000);
|
||||
}
|
||||
|
||||
work();
|
||||
|
||||
function workb() {
|
||||
b('doing some work');
|
||||
setTimeout(workb, Math.random() * 2000);
|
||||
}
|
||||
|
||||
workb();
|
||||
```
|
||||
|
||||
The `DEBUG` environment variable is then used to enable these based on space or
|
||||
comma-delimited names.
|
||||
|
||||
Here are some examples:
|
||||
|
||||
<img width="647" alt="screen shot 2017-08-08 at 12 53 04 pm" src="https://user-images.githubusercontent.com/71256/29091703-a6302cdc-7c38-11e7-8304-7c0b3bc600cd.png">
|
||||
<img width="647" alt="screen shot 2017-08-08 at 12 53 38 pm" src="https://user-images.githubusercontent.com/71256/29091700-a62a6888-7c38-11e7-800b-db911291ca2b.png">
|
||||
<img width="647" alt="screen shot 2017-08-08 at 12 53 25 pm" src="https://user-images.githubusercontent.com/71256/29091701-a62ea114-7c38-11e7-826a-2692bedca740.png">
|
||||
|
||||
#### Windows command prompt notes
|
||||
|
||||
##### CMD
|
||||
|
||||
On Windows the environment variable is set using the `set` command.
|
||||
|
||||
```cmd
|
||||
set DEBUG=*,-not_this
|
||||
```
|
||||
|
||||
Example:
|
||||
|
||||
```cmd
|
||||
set DEBUG=* & node app.js
|
||||
```
|
||||
|
||||
##### PowerShell (VS Code default)
|
||||
|
||||
PowerShell uses different syntax to set environment variables.
|
||||
|
||||
```cmd
|
||||
$env:DEBUG = "*,-not_this"
|
||||
```
|
||||
|
||||
Example:
|
||||
|
||||
```cmd
|
||||
$env:DEBUG='app';node app.js
|
||||
```
|
||||
|
||||
Then, run the program to be debugged as usual.
|
||||
|
||||
npm script example:
|
||||
```js
|
||||
"windowsDebug": "@powershell -Command $env:DEBUG='*';node app.js",
|
||||
```
|
||||
|
||||
## Namespace Colors
|
||||
|
||||
Every debug instance has a color generated for it based on its namespace name.
|
||||
This helps when visually parsing the debug output to identify which debug instance
|
||||
a debug line belongs to.
|
||||
|
||||
#### Node.js
|
||||
|
||||
In Node.js, colors are enabled when stderr is a TTY. You also _should_ install
|
||||
the [`supports-color`](https://npmjs.org/supports-color) module alongside debug,
|
||||
otherwise debug will only use a small handful of basic colors.
|
||||
|
||||
<img width="521" src="https://user-images.githubusercontent.com/71256/29092181-47f6a9e6-7c3a-11e7-9a14-1928d8a711cd.png">
|
||||
|
||||
#### Web Browser
|
||||
|
||||
Colors are also enabled on "Web Inspectors" that understand the `%c` formatting
|
||||
option. These are WebKit web inspectors, Firefox ([since version
|
||||
31](https://hacks.mozilla.org/2014/05/editable-box-model-multiple-selection-sublime-text-keys-much-more-firefox-developer-tools-episode-31/))
|
||||
and the Firebug plugin for Firefox (any version).
|
||||
|
||||
<img width="524" src="https://user-images.githubusercontent.com/71256/29092033-b65f9f2e-7c39-11e7-8e32-f6f0d8e865c1.png">
|
||||
|
||||
|
||||
## Millisecond diff
|
||||
|
||||
When actively developing an application it can be useful to see when the time spent between one `debug()` call and the next. Suppose for example you invoke `debug()` before requesting a resource, and after as well, the "+NNNms" will show you how much time was spent between calls.
|
||||
|
||||
<img width="647" src="https://user-images.githubusercontent.com/71256/29091486-fa38524c-7c37-11e7-895f-e7ec8e1039b6.png">
|
||||
|
||||
When stdout is not a TTY, `Date#toISOString()` is used, making it more useful for logging the debug information as shown below:
|
||||
|
||||
<img width="647" src="https://user-images.githubusercontent.com/71256/29091956-6bd78372-7c39-11e7-8c55-c948396d6edd.png">
|
||||
|
||||
|
||||
## Conventions
|
||||
|
||||
If you're using this in one or more of your libraries, you _should_ use the name of your library so that developers may toggle debugging as desired without guessing names. If you have more than one debuggers you _should_ prefix them with your library name and use ":" to separate features. For example "bodyParser" from Connect would then be "connect:bodyParser". If you append a "*" to the end of your name, it will always be enabled regardless of the setting of the DEBUG environment variable. You can then use it for normal output as well as debug output.
|
||||
|
||||
## Wildcards
|
||||
|
||||
The `*` character may be used as a wildcard. Suppose for example your library has
|
||||
debuggers named "connect:bodyParser", "connect:compress", "connect:session",
|
||||
instead of listing all three with
|
||||
`DEBUG=connect:bodyParser,connect:compress,connect:session`, you may simply do
|
||||
`DEBUG=connect:*`, or to run everything using this module simply use `DEBUG=*`.
|
||||
|
||||
You can also exclude specific debuggers by prefixing them with a "-" character.
|
||||
For example, `DEBUG=*,-connect:*` would include all debuggers except those
|
||||
starting with "connect:".
|
||||
|
||||
## Environment Variables
|
||||
|
||||
When running through Node.js, you can set a few environment variables that will
|
||||
change the behavior of the debug logging:
|
||||
|
||||
| Name | Purpose |
|
||||
|-----------|-------------------------------------------------|
|
||||
| `DEBUG` | Enables/disables specific debugging namespaces. |
|
||||
| `DEBUG_HIDE_DATE` | Hide date from debug output (non-TTY). |
|
||||
| `DEBUG_COLORS`| Whether or not to use colors in the debug output. |
|
||||
| `DEBUG_DEPTH` | Object inspection depth. |
|
||||
| `DEBUG_SHOW_HIDDEN` | Shows hidden properties on inspected objects. |
|
||||
|
||||
|
||||
__Note:__ The environment variables beginning with `DEBUG_` end up being
|
||||
converted into an Options object that gets used with `%o`/`%O` formatters.
|
||||
See the Node.js documentation for
|
||||
[`util.inspect()`](https://nodejs.org/api/util.html#util_util_inspect_object_options)
|
||||
for the complete list.
|
||||
|
||||
## Formatters
|
||||
|
||||
Debug uses [printf-style](https://wikipedia.org/wiki/Printf_format_string) formatting.
|
||||
Below are the officially supported formatters:
|
||||
|
||||
| Formatter | Representation |
|
||||
|-----------|----------------|
|
||||
| `%O` | Pretty-print an Object on multiple lines. |
|
||||
| `%o` | Pretty-print an Object all on a single line. |
|
||||
| `%s` | String. |
|
||||
| `%d` | Number (both integer and float). |
|
||||
| `%j` | JSON. Replaced with the string '[Circular]' if the argument contains circular references. |
|
||||
| `%%` | Single percent sign ('%'). This does not consume an argument. |
|
||||
|
||||
|
||||
### Custom formatters
|
||||
|
||||
You can add custom formatters by extending the `debug.formatters` object.
|
||||
For example, if you wanted to add support for rendering a Buffer as hex with
|
||||
`%h`, you could do something like:
|
||||
|
||||
```js
|
||||
const createDebug = require('debug')
|
||||
createDebug.formatters.h = (v) => {
|
||||
return v.toString('hex')
|
||||
}
|
||||
|
||||
// …elsewhere
|
||||
const debug = createDebug('foo')
|
||||
debug('this is hex: %h', new Buffer('hello world'))
|
||||
// foo this is hex: 68656c6c6f20776f726c6421 +0ms
|
||||
```
|
||||
|
||||
|
||||
## Browser Support
|
||||
|
||||
You can build a browser-ready script using [browserify](https://github.com/substack/node-browserify),
|
||||
or just use the [browserify-as-a-service](https://wzrd.in/) [build](https://wzrd.in/standalone/debug@latest),
|
||||
if you don't want to build it yourself.
|
||||
|
||||
Debug's enable state is currently persisted by `localStorage`.
|
||||
Consider the situation shown below where you have `worker:a` and `worker:b`,
|
||||
and wish to debug both. You can enable this using `localStorage.debug`:
|
||||
|
||||
```js
|
||||
localStorage.debug = 'worker:*'
|
||||
```
|
||||
|
||||
And then refresh the page.
|
||||
|
||||
```js
|
||||
a = debug('worker:a');
|
||||
b = debug('worker:b');
|
||||
|
||||
setInterval(function(){
|
||||
a('doing some work');
|
||||
}, 1000);
|
||||
|
||||
setInterval(function(){
|
||||
b('doing some work');
|
||||
}, 1200);
|
||||
```
|
||||
|
||||
|
||||
## Output streams
|
||||
|
||||
By default `debug` will log to stderr, however this can be configured per-namespace by overriding the `log` method:
|
||||
|
||||
Example [_stdout.js_](./examples/node/stdout.js):
|
||||
|
||||
```js
|
||||
var debug = require('debug');
|
||||
var error = debug('app:error');
|
||||
|
||||
// by default stderr is used
|
||||
error('goes to stderr!');
|
||||
|
||||
var log = debug('app:log');
|
||||
// set this namespace to log via console.log
|
||||
log.log = console.log.bind(console); // don't forget to bind to console!
|
||||
log('goes to stdout');
|
||||
error('still goes to stderr!');
|
||||
|
||||
// set all output to go via console.info
|
||||
// overrides all per-namespace log settings
|
||||
debug.log = console.info.bind(console);
|
||||
error('now goes to stdout via console.info');
|
||||
log('still goes to stdout, but via console.info now');
|
||||
```
|
||||
|
||||
## Extend
|
||||
You can simply extend debugger
|
||||
```js
|
||||
const log = require('debug')('auth');
|
||||
|
||||
//creates new debug instance with extended namespace
|
||||
const logSign = log.extend('sign');
|
||||
const logLogin = log.extend('login');
|
||||
|
||||
log('hello'); // auth hello
|
||||
logSign('hello'); //auth:sign hello
|
||||
logLogin('hello'); //auth:login hello
|
||||
```
|
||||
|
||||
## Set dynamically
|
||||
|
||||
You can also enable debug dynamically by calling the `enable()` method :
|
||||
|
||||
```js
|
||||
let debug = require('debug');
|
||||
|
||||
console.log(1, debug.enabled('test'));
|
||||
|
||||
debug.enable('test');
|
||||
console.log(2, debug.enabled('test'));
|
||||
|
||||
debug.disable();
|
||||
console.log(3, debug.enabled('test'));
|
||||
|
||||
```
|
||||
|
||||
print :
|
||||
```
|
||||
1 false
|
||||
2 true
|
||||
3 false
|
||||
```
|
||||
|
||||
Usage :
|
||||
`enable(namespaces)`
|
||||
`namespaces` can include modes separated by a colon and wildcards.
|
||||
|
||||
Note that calling `enable()` completely overrides previously set DEBUG variable :
|
||||
|
||||
```
|
||||
$ DEBUG=foo node -e 'var dbg = require("debug"); dbg.enable("bar"); console.log(dbg.enabled("foo"))'
|
||||
=> false
|
||||
```
|
||||
|
||||
`disable()`
|
||||
|
||||
Will disable all namespaces. The functions returns the namespaces currently
|
||||
enabled (and skipped). This can be useful if you want to disable debugging
|
||||
temporarily without knowing what was enabled to begin with.
|
||||
|
||||
For example:
|
||||
|
||||
```js
|
||||
let debug = require('debug');
|
||||
debug.enable('foo:*,-foo:bar');
|
||||
let namespaces = debug.disable();
|
||||
debug.enable(namespaces);
|
||||
```
|
||||
|
||||
Note: There is no guarantee that the string will be identical to the initial
|
||||
enable string, but semantically they will be identical.
|
||||
|
||||
## Checking whether a debug target is enabled
|
||||
|
||||
After you've created a debug instance, you can determine whether or not it is
|
||||
enabled by checking the `enabled` property:
|
||||
|
||||
```javascript
|
||||
const debug = require('debug')('http');
|
||||
|
||||
if (debug.enabled) {
|
||||
// do stuff...
|
||||
}
|
||||
```
|
||||
|
||||
You can also manually toggle this property to force the debug instance to be
|
||||
enabled or disabled.
|
||||
|
||||
|
||||
## Authors
|
||||
|
||||
- TJ Holowaychuk
|
||||
- Nathan Rajlich
|
||||
- Andrew Rhyne
|
||||
|
||||
## Backers
|
||||
|
||||
Support us with a monthly donation and help us continue our activities. [[Become a backer](https://opencollective.com/debug#backer)]
|
||||
|
||||
<a href="https://opencollective.com/debug/backer/0/website" target="_blank"><img src="https://opencollective.com/debug/backer/0/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/1/website" target="_blank"><img src="https://opencollective.com/debug/backer/1/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/2/website" target="_blank"><img src="https://opencollective.com/debug/backer/2/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/3/website" target="_blank"><img src="https://opencollective.com/debug/backer/3/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/4/website" target="_blank"><img src="https://opencollective.com/debug/backer/4/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/5/website" target="_blank"><img src="https://opencollective.com/debug/backer/5/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/6/website" target="_blank"><img src="https://opencollective.com/debug/backer/6/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/7/website" target="_blank"><img src="https://opencollective.com/debug/backer/7/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/8/website" target="_blank"><img src="https://opencollective.com/debug/backer/8/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/9/website" target="_blank"><img src="https://opencollective.com/debug/backer/9/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/10/website" target="_blank"><img src="https://opencollective.com/debug/backer/10/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/11/website" target="_blank"><img src="https://opencollective.com/debug/backer/11/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/12/website" target="_blank"><img src="https://opencollective.com/debug/backer/12/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/13/website" target="_blank"><img src="https://opencollective.com/debug/backer/13/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/14/website" target="_blank"><img src="https://opencollective.com/debug/backer/14/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/15/website" target="_blank"><img src="https://opencollective.com/debug/backer/15/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/16/website" target="_blank"><img src="https://opencollective.com/debug/backer/16/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/17/website" target="_blank"><img src="https://opencollective.com/debug/backer/17/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/18/website" target="_blank"><img src="https://opencollective.com/debug/backer/18/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/19/website" target="_blank"><img src="https://opencollective.com/debug/backer/19/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/20/website" target="_blank"><img src="https://opencollective.com/debug/backer/20/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/21/website" target="_blank"><img src="https://opencollective.com/debug/backer/21/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/22/website" target="_blank"><img src="https://opencollective.com/debug/backer/22/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/23/website" target="_blank"><img src="https://opencollective.com/debug/backer/23/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/24/website" target="_blank"><img src="https://opencollective.com/debug/backer/24/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/25/website" target="_blank"><img src="https://opencollective.com/debug/backer/25/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/26/website" target="_blank"><img src="https://opencollective.com/debug/backer/26/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/27/website" target="_blank"><img src="https://opencollective.com/debug/backer/27/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/28/website" target="_blank"><img src="https://opencollective.com/debug/backer/28/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/29/website" target="_blank"><img src="https://opencollective.com/debug/backer/29/avatar.svg"></a>
|
||||
|
||||
|
||||
## Sponsors
|
||||
|
||||
Become a sponsor and get your logo on our README on Github with a link to your site. [[Become a sponsor](https://opencollective.com/debug#sponsor)]
|
||||
|
||||
<a href="https://opencollective.com/debug/sponsor/0/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/0/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/1/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/1/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/2/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/2/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/3/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/3/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/4/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/4/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/5/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/5/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/6/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/6/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/7/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/7/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/8/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/8/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/9/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/9/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/10/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/10/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/11/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/11/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/12/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/12/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/13/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/13/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/14/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/14/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/15/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/15/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/16/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/16/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/17/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/17/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/18/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/18/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/19/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/19/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/20/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/20/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/21/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/21/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/22/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/22/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/23/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/23/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/24/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/24/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/25/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/25/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/26/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/26/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/27/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/27/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/28/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/28/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/29/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/29/avatar.svg"></a>
|
||||
|
||||
## License
|
||||
|
||||
(The MIT License)
|
||||
|
||||
Copyright (c) 2014-2017 TJ Holowaychuk <tj@vision-media.ca>
|
||||
|
||||
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.
|
||||
912
node_modules/nock/node_modules/debug/dist/debug.js
generated
vendored
Normal file
912
node_modules/nock/node_modules/debug/dist/debug.js
generated
vendored
Normal file
@@ -0,0 +1,912 @@
|
||||
"use strict";
|
||||
|
||||
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
|
||||
|
||||
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }
|
||||
|
||||
function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }
|
||||
|
||||
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }
|
||||
|
||||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
||||
|
||||
(function (f) {
|
||||
if ((typeof exports === "undefined" ? "undefined" : _typeof(exports)) === "object" && typeof module !== "undefined") {
|
||||
module.exports = f();
|
||||
} else if (typeof define === "function" && define.amd) {
|
||||
define([], f);
|
||||
} else {
|
||||
var g;
|
||||
|
||||
if (typeof window !== "undefined") {
|
||||
g = window;
|
||||
} else if (typeof global !== "undefined") {
|
||||
g = global;
|
||||
} else if (typeof self !== "undefined") {
|
||||
g = self;
|
||||
} else {
|
||||
g = this;
|
||||
}
|
||||
|
||||
g.debug = f();
|
||||
}
|
||||
})(function () {
|
||||
var define, module, exports;
|
||||
return function () {
|
||||
function r(e, n, t) {
|
||||
function o(i, f) {
|
||||
if (!n[i]) {
|
||||
if (!e[i]) {
|
||||
var c = "function" == typeof require && require;
|
||||
if (!f && c) return c(i, !0);
|
||||
if (u) return u(i, !0);
|
||||
var a = new Error("Cannot find module '" + i + "'");
|
||||
throw a.code = "MODULE_NOT_FOUND", a;
|
||||
}
|
||||
|
||||
var p = n[i] = {
|
||||
exports: {}
|
||||
};
|
||||
e[i][0].call(p.exports, function (r) {
|
||||
var n = e[i][1][r];
|
||||
return o(n || r);
|
||||
}, p, p.exports, r, e, n, t);
|
||||
}
|
||||
|
||||
return n[i].exports;
|
||||
}
|
||||
|
||||
for (var u = "function" == typeof require && require, i = 0; i < t.length; i++) {
|
||||
o(t[i]);
|
||||
}
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
return r;
|
||||
}()({
|
||||
1: [function (require, module, exports) {
|
||||
/**
|
||||
* Helpers.
|
||||
*/
|
||||
var s = 1000;
|
||||
var m = s * 60;
|
||||
var h = m * 60;
|
||||
var d = h * 24;
|
||||
var w = d * 7;
|
||||
var y = d * 365.25;
|
||||
/**
|
||||
* Parse or format the given `val`.
|
||||
*
|
||||
* Options:
|
||||
*
|
||||
* - `long` verbose formatting [false]
|
||||
*
|
||||
* @param {String|Number} val
|
||||
* @param {Object} [options]
|
||||
* @throws {Error} throw an error if val is not a non-empty string or a number
|
||||
* @return {String|Number}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
module.exports = function (val, options) {
|
||||
options = options || {};
|
||||
|
||||
var type = _typeof(val);
|
||||
|
||||
if (type === 'string' && val.length > 0) {
|
||||
return parse(val);
|
||||
} else if (type === 'number' && isNaN(val) === false) {
|
||||
return options.long ? fmtLong(val) : fmtShort(val);
|
||||
}
|
||||
|
||||
throw new Error('val is not a non-empty string or a valid number. val=' + JSON.stringify(val));
|
||||
};
|
||||
/**
|
||||
* Parse the given `str` and return milliseconds.
|
||||
*
|
||||
* @param {String} str
|
||||
* @return {Number}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
|
||||
function parse(str) {
|
||||
str = String(str);
|
||||
|
||||
if (str.length > 100) {
|
||||
return;
|
||||
}
|
||||
|
||||
var match = /^((?:\d+)?\-?\d?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(str);
|
||||
|
||||
if (!match) {
|
||||
return;
|
||||
}
|
||||
|
||||
var n = parseFloat(match[1]);
|
||||
var type = (match[2] || 'ms').toLowerCase();
|
||||
|
||||
switch (type) {
|
||||
case 'years':
|
||||
case 'year':
|
||||
case 'yrs':
|
||||
case 'yr':
|
||||
case 'y':
|
||||
return n * y;
|
||||
|
||||
case 'weeks':
|
||||
case 'week':
|
||||
case 'w':
|
||||
return n * w;
|
||||
|
||||
case 'days':
|
||||
case 'day':
|
||||
case 'd':
|
||||
return n * d;
|
||||
|
||||
case 'hours':
|
||||
case 'hour':
|
||||
case 'hrs':
|
||||
case 'hr':
|
||||
case 'h':
|
||||
return n * h;
|
||||
|
||||
case 'minutes':
|
||||
case 'minute':
|
||||
case 'mins':
|
||||
case 'min':
|
||||
case 'm':
|
||||
return n * m;
|
||||
|
||||
case 'seconds':
|
||||
case 'second':
|
||||
case 'secs':
|
||||
case 'sec':
|
||||
case 's':
|
||||
return n * s;
|
||||
|
||||
case 'milliseconds':
|
||||
case 'millisecond':
|
||||
case 'msecs':
|
||||
case 'msec':
|
||||
case 'ms':
|
||||
return n;
|
||||
|
||||
default:
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Short format for `ms`.
|
||||
*
|
||||
* @param {Number} ms
|
||||
* @return {String}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
|
||||
function fmtShort(ms) {
|
||||
var msAbs = Math.abs(ms);
|
||||
|
||||
if (msAbs >= d) {
|
||||
return Math.round(ms / d) + 'd';
|
||||
}
|
||||
|
||||
if (msAbs >= h) {
|
||||
return Math.round(ms / h) + 'h';
|
||||
}
|
||||
|
||||
if (msAbs >= m) {
|
||||
return Math.round(ms / m) + 'm';
|
||||
}
|
||||
|
||||
if (msAbs >= s) {
|
||||
return Math.round(ms / s) + 's';
|
||||
}
|
||||
|
||||
return ms + 'ms';
|
||||
}
|
||||
/**
|
||||
* Long format for `ms`.
|
||||
*
|
||||
* @param {Number} ms
|
||||
* @return {String}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
|
||||
function fmtLong(ms) {
|
||||
var msAbs = Math.abs(ms);
|
||||
|
||||
if (msAbs >= d) {
|
||||
return plural(ms, msAbs, d, 'day');
|
||||
}
|
||||
|
||||
if (msAbs >= h) {
|
||||
return plural(ms, msAbs, h, 'hour');
|
||||
}
|
||||
|
||||
if (msAbs >= m) {
|
||||
return plural(ms, msAbs, m, 'minute');
|
||||
}
|
||||
|
||||
if (msAbs >= s) {
|
||||
return plural(ms, msAbs, s, 'second');
|
||||
}
|
||||
|
||||
return ms + ' ms';
|
||||
}
|
||||
/**
|
||||
* Pluralization helper.
|
||||
*/
|
||||
|
||||
|
||||
function plural(ms, msAbs, n, name) {
|
||||
var isPlural = msAbs >= n * 1.5;
|
||||
return Math.round(ms / n) + ' ' + name + (isPlural ? 's' : '');
|
||||
}
|
||||
}, {}],
|
||||
2: [function (require, module, exports) {
|
||||
// shim for using process in browser
|
||||
var process = module.exports = {}; // cached from whatever global is present so that test runners that stub it
|
||||
// don't break things. But we need to wrap it in a try catch in case it is
|
||||
// wrapped in strict mode code which doesn't define any globals. It's inside a
|
||||
// function because try/catches deoptimize in certain engines.
|
||||
|
||||
var cachedSetTimeout;
|
||||
var cachedClearTimeout;
|
||||
|
||||
function defaultSetTimout() {
|
||||
throw new Error('setTimeout has not been defined');
|
||||
}
|
||||
|
||||
function defaultClearTimeout() {
|
||||
throw new Error('clearTimeout has not been defined');
|
||||
}
|
||||
|
||||
(function () {
|
||||
try {
|
||||
if (typeof setTimeout === 'function') {
|
||||
cachedSetTimeout = setTimeout;
|
||||
} else {
|
||||
cachedSetTimeout = defaultSetTimout;
|
||||
}
|
||||
} catch (e) {
|
||||
cachedSetTimeout = defaultSetTimout;
|
||||
}
|
||||
|
||||
try {
|
||||
if (typeof clearTimeout === 'function') {
|
||||
cachedClearTimeout = clearTimeout;
|
||||
} else {
|
||||
cachedClearTimeout = defaultClearTimeout;
|
||||
}
|
||||
} catch (e) {
|
||||
cachedClearTimeout = defaultClearTimeout;
|
||||
}
|
||||
})();
|
||||
|
||||
function runTimeout(fun) {
|
||||
if (cachedSetTimeout === setTimeout) {
|
||||
//normal enviroments in sane situations
|
||||
return setTimeout(fun, 0);
|
||||
} // if setTimeout wasn't available but was latter defined
|
||||
|
||||
|
||||
if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
|
||||
cachedSetTimeout = setTimeout;
|
||||
return setTimeout(fun, 0);
|
||||
}
|
||||
|
||||
try {
|
||||
// when when somebody has screwed with setTimeout but no I.E. maddness
|
||||
return cachedSetTimeout(fun, 0);
|
||||
} catch (e) {
|
||||
try {
|
||||
// When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
|
||||
return cachedSetTimeout.call(null, fun, 0);
|
||||
} catch (e) {
|
||||
// same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error
|
||||
return cachedSetTimeout.call(this, fun, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function runClearTimeout(marker) {
|
||||
if (cachedClearTimeout === clearTimeout) {
|
||||
//normal enviroments in sane situations
|
||||
return clearTimeout(marker);
|
||||
} // if clearTimeout wasn't available but was latter defined
|
||||
|
||||
|
||||
if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
|
||||
cachedClearTimeout = clearTimeout;
|
||||
return clearTimeout(marker);
|
||||
}
|
||||
|
||||
try {
|
||||
// when when somebody has screwed with setTimeout but no I.E. maddness
|
||||
return cachedClearTimeout(marker);
|
||||
} catch (e) {
|
||||
try {
|
||||
// When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
|
||||
return cachedClearTimeout.call(null, marker);
|
||||
} catch (e) {
|
||||
// same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error.
|
||||
// Some versions of I.E. have different rules for clearTimeout vs setTimeout
|
||||
return cachedClearTimeout.call(this, marker);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var queue = [];
|
||||
var draining = false;
|
||||
var currentQueue;
|
||||
var queueIndex = -1;
|
||||
|
||||
function cleanUpNextTick() {
|
||||
if (!draining || !currentQueue) {
|
||||
return;
|
||||
}
|
||||
|
||||
draining = false;
|
||||
|
||||
if (currentQueue.length) {
|
||||
queue = currentQueue.concat(queue);
|
||||
} else {
|
||||
queueIndex = -1;
|
||||
}
|
||||
|
||||
if (queue.length) {
|
||||
drainQueue();
|
||||
}
|
||||
}
|
||||
|
||||
function drainQueue() {
|
||||
if (draining) {
|
||||
return;
|
||||
}
|
||||
|
||||
var timeout = runTimeout(cleanUpNextTick);
|
||||
draining = true;
|
||||
var len = queue.length;
|
||||
|
||||
while (len) {
|
||||
currentQueue = queue;
|
||||
queue = [];
|
||||
|
||||
while (++queueIndex < len) {
|
||||
if (currentQueue) {
|
||||
currentQueue[queueIndex].run();
|
||||
}
|
||||
}
|
||||
|
||||
queueIndex = -1;
|
||||
len = queue.length;
|
||||
}
|
||||
|
||||
currentQueue = null;
|
||||
draining = false;
|
||||
runClearTimeout(timeout);
|
||||
}
|
||||
|
||||
process.nextTick = function (fun) {
|
||||
var args = new Array(arguments.length - 1);
|
||||
|
||||
if (arguments.length > 1) {
|
||||
for (var i = 1; i < arguments.length; i++) {
|
||||
args[i - 1] = arguments[i];
|
||||
}
|
||||
}
|
||||
|
||||
queue.push(new Item(fun, args));
|
||||
|
||||
if (queue.length === 1 && !draining) {
|
||||
runTimeout(drainQueue);
|
||||
}
|
||||
}; // v8 likes predictible objects
|
||||
|
||||
|
||||
function Item(fun, array) {
|
||||
this.fun = fun;
|
||||
this.array = array;
|
||||
}
|
||||
|
||||
Item.prototype.run = function () {
|
||||
this.fun.apply(null, this.array);
|
||||
};
|
||||
|
||||
process.title = 'browser';
|
||||
process.browser = true;
|
||||
process.env = {};
|
||||
process.argv = [];
|
||||
process.version = ''; // empty string to avoid regexp issues
|
||||
|
||||
process.versions = {};
|
||||
|
||||
function noop() {}
|
||||
|
||||
process.on = noop;
|
||||
process.addListener = noop;
|
||||
process.once = noop;
|
||||
process.off = noop;
|
||||
process.removeListener = noop;
|
||||
process.removeAllListeners = noop;
|
||||
process.emit = noop;
|
||||
process.prependListener = noop;
|
||||
process.prependOnceListener = noop;
|
||||
|
||||
process.listeners = function (name) {
|
||||
return [];
|
||||
};
|
||||
|
||||
process.binding = function (name) {
|
||||
throw new Error('process.binding is not supported');
|
||||
};
|
||||
|
||||
process.cwd = function () {
|
||||
return '/';
|
||||
};
|
||||
|
||||
process.chdir = function (dir) {
|
||||
throw new Error('process.chdir is not supported');
|
||||
};
|
||||
|
||||
process.umask = function () {
|
||||
return 0;
|
||||
};
|
||||
}, {}],
|
||||
3: [function (require, module, exports) {
|
||||
/**
|
||||
* This is the common logic for both the Node.js and web browser
|
||||
* implementations of `debug()`.
|
||||
*/
|
||||
function setup(env) {
|
||||
createDebug.debug = createDebug;
|
||||
createDebug.default = createDebug;
|
||||
createDebug.coerce = coerce;
|
||||
createDebug.disable = disable;
|
||||
createDebug.enable = enable;
|
||||
createDebug.enabled = enabled;
|
||||
createDebug.humanize = require('ms');
|
||||
Object.keys(env).forEach(function (key) {
|
||||
createDebug[key] = env[key];
|
||||
});
|
||||
/**
|
||||
* Active `debug` instances.
|
||||
*/
|
||||
|
||||
createDebug.instances = [];
|
||||
/**
|
||||
* The currently active debug mode names, and names to skip.
|
||||
*/
|
||||
|
||||
createDebug.names = [];
|
||||
createDebug.skips = [];
|
||||
/**
|
||||
* Map of special "%n" handling functions, for the debug "format" argument.
|
||||
*
|
||||
* Valid key names are a single, lower or upper-case letter, i.e. "n" and "N".
|
||||
*/
|
||||
|
||||
createDebug.formatters = {};
|
||||
/**
|
||||
* Selects a color for a debug namespace
|
||||
* @param {String} namespace The namespace string for the for the debug instance to be colored
|
||||
* @return {Number|String} An ANSI color code for the given namespace
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function selectColor(namespace) {
|
||||
var hash = 0;
|
||||
|
||||
for (var i = 0; i < namespace.length; i++) {
|
||||
hash = (hash << 5) - hash + namespace.charCodeAt(i);
|
||||
hash |= 0; // Convert to 32bit integer
|
||||
}
|
||||
|
||||
return createDebug.colors[Math.abs(hash) % createDebug.colors.length];
|
||||
}
|
||||
|
||||
createDebug.selectColor = selectColor;
|
||||
/**
|
||||
* Create a debugger with the given `namespace`.
|
||||
*
|
||||
* @param {String} namespace
|
||||
* @return {Function}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
function createDebug(namespace) {
|
||||
var prevTime;
|
||||
|
||||
function debug() {
|
||||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
||||
args[_key] = arguments[_key];
|
||||
}
|
||||
|
||||
// Disabled?
|
||||
if (!debug.enabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
var self = debug; // Set `diff` timestamp
|
||||
|
||||
var curr = Number(new Date());
|
||||
var ms = curr - (prevTime || curr);
|
||||
self.diff = ms;
|
||||
self.prev = prevTime;
|
||||
self.curr = curr;
|
||||
prevTime = curr;
|
||||
args[0] = createDebug.coerce(args[0]);
|
||||
|
||||
if (typeof args[0] !== 'string') {
|
||||
// Anything else let's inspect with %O
|
||||
args.unshift('%O');
|
||||
} // Apply any `formatters` transformations
|
||||
|
||||
|
||||
var index = 0;
|
||||
args[0] = args[0].replace(/%([a-zA-Z%])/g, function (match, format) {
|
||||
// If we encounter an escaped % then don't increase the array index
|
||||
if (match === '%%') {
|
||||
return match;
|
||||
}
|
||||
|
||||
index++;
|
||||
var formatter = createDebug.formatters[format];
|
||||
|
||||
if (typeof formatter === 'function') {
|
||||
var val = args[index];
|
||||
match = formatter.call(self, val); // Now we need to remove `args[index]` since it's inlined in the `format`
|
||||
|
||||
args.splice(index, 1);
|
||||
index--;
|
||||
}
|
||||
|
||||
return match;
|
||||
}); // Apply env-specific formatting (colors, etc.)
|
||||
|
||||
createDebug.formatArgs.call(self, args);
|
||||
var logFn = self.log || createDebug.log;
|
||||
logFn.apply(self, args);
|
||||
}
|
||||
|
||||
debug.namespace = namespace;
|
||||
debug.enabled = createDebug.enabled(namespace);
|
||||
debug.useColors = createDebug.useColors();
|
||||
debug.color = selectColor(namespace);
|
||||
debug.destroy = destroy;
|
||||
debug.extend = extend; // Debug.formatArgs = formatArgs;
|
||||
// debug.rawLog = rawLog;
|
||||
// env-specific initialization logic for debug instances
|
||||
|
||||
if (typeof createDebug.init === 'function') {
|
||||
createDebug.init(debug);
|
||||
}
|
||||
|
||||
createDebug.instances.push(debug);
|
||||
return debug;
|
||||
}
|
||||
|
||||
function destroy() {
|
||||
var index = createDebug.instances.indexOf(this);
|
||||
|
||||
if (index !== -1) {
|
||||
createDebug.instances.splice(index, 1);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function extend(namespace, delimiter) {
|
||||
var newDebug = createDebug(this.namespace + (typeof delimiter === 'undefined' ? ':' : delimiter) + namespace);
|
||||
newDebug.log = this.log;
|
||||
return newDebug;
|
||||
}
|
||||
/**
|
||||
* Enables a debug mode by namespaces. This can include modes
|
||||
* separated by a colon and wildcards.
|
||||
*
|
||||
* @param {String} namespaces
|
||||
* @api public
|
||||
*/
|
||||
|
||||
|
||||
function enable(namespaces) {
|
||||
createDebug.save(namespaces);
|
||||
createDebug.names = [];
|
||||
createDebug.skips = [];
|
||||
var i;
|
||||
var split = (typeof namespaces === 'string' ? namespaces : '').split(/[\s,]+/);
|
||||
var len = split.length;
|
||||
|
||||
for (i = 0; i < len; i++) {
|
||||
if (!split[i]) {
|
||||
// ignore empty strings
|
||||
continue;
|
||||
}
|
||||
|
||||
namespaces = split[i].replace(/\*/g, '.*?');
|
||||
|
||||
if (namespaces[0] === '-') {
|
||||
createDebug.skips.push(new RegExp('^' + namespaces.substr(1) + '$'));
|
||||
} else {
|
||||
createDebug.names.push(new RegExp('^' + namespaces + '$'));
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < createDebug.instances.length; i++) {
|
||||
var instance = createDebug.instances[i];
|
||||
instance.enabled = createDebug.enabled(instance.namespace);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Disable debug output.
|
||||
*
|
||||
* @return {String} namespaces
|
||||
* @api public
|
||||
*/
|
||||
|
||||
|
||||
function disable() {
|
||||
var namespaces = [].concat(_toConsumableArray(createDebug.names.map(toNamespace)), _toConsumableArray(createDebug.skips.map(toNamespace).map(function (namespace) {
|
||||
return '-' + namespace;
|
||||
}))).join(',');
|
||||
createDebug.enable('');
|
||||
return namespaces;
|
||||
}
|
||||
/**
|
||||
* Returns true if the given mode name is enabled, false otherwise.
|
||||
*
|
||||
* @param {String} name
|
||||
* @return {Boolean}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
|
||||
function enabled(name) {
|
||||
if (name[name.length - 1] === '*') {
|
||||
return true;
|
||||
}
|
||||
|
||||
var i;
|
||||
var len;
|
||||
|
||||
for (i = 0, len = createDebug.skips.length; i < len; i++) {
|
||||
if (createDebug.skips[i].test(name)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0, len = createDebug.names.length; i < len; i++) {
|
||||
if (createDebug.names[i].test(name)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Convert regexp to namespace
|
||||
*
|
||||
* @param {RegExp} regxep
|
||||
* @return {String} namespace
|
||||
* @api private
|
||||
*/
|
||||
|
||||
|
||||
function toNamespace(regexp) {
|
||||
return regexp.toString().substring(2, regexp.toString().length - 2).replace(/\.\*\?$/, '*');
|
||||
}
|
||||
/**
|
||||
* Coerce `val`.
|
||||
*
|
||||
* @param {Mixed} val
|
||||
* @return {Mixed}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
|
||||
function coerce(val) {
|
||||
if (val instanceof Error) {
|
||||
return val.stack || val.message;
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
createDebug.enable(createDebug.load());
|
||||
return createDebug;
|
||||
}
|
||||
|
||||
module.exports = setup;
|
||||
}, {
|
||||
"ms": 1
|
||||
}],
|
||||
4: [function (require, module, exports) {
|
||||
(function (process) {
|
||||
/* eslint-env browser */
|
||||
|
||||
/**
|
||||
* This is the web browser implementation of `debug()`.
|
||||
*/
|
||||
exports.log = log;
|
||||
exports.formatArgs = formatArgs;
|
||||
exports.save = save;
|
||||
exports.load = load;
|
||||
exports.useColors = useColors;
|
||||
exports.storage = localstorage();
|
||||
/**
|
||||
* Colors.
|
||||
*/
|
||||
|
||||
exports.colors = ['#0000CC', '#0000FF', '#0033CC', '#0033FF', '#0066CC', '#0066FF', '#0099CC', '#0099FF', '#00CC00', '#00CC33', '#00CC66', '#00CC99', '#00CCCC', '#00CCFF', '#3300CC', '#3300FF', '#3333CC', '#3333FF', '#3366CC', '#3366FF', '#3399CC', '#3399FF', '#33CC00', '#33CC33', '#33CC66', '#33CC99', '#33CCCC', '#33CCFF', '#6600CC', '#6600FF', '#6633CC', '#6633FF', '#66CC00', '#66CC33', '#9900CC', '#9900FF', '#9933CC', '#9933FF', '#99CC00', '#99CC33', '#CC0000', '#CC0033', '#CC0066', '#CC0099', '#CC00CC', '#CC00FF', '#CC3300', '#CC3333', '#CC3366', '#CC3399', '#CC33CC', '#CC33FF', '#CC6600', '#CC6633', '#CC9900', '#CC9933', '#CCCC00', '#CCCC33', '#FF0000', '#FF0033', '#FF0066', '#FF0099', '#FF00CC', '#FF00FF', '#FF3300', '#FF3333', '#FF3366', '#FF3399', '#FF33CC', '#FF33FF', '#FF6600', '#FF6633', '#FF9900', '#FF9933', '#FFCC00', '#FFCC33'];
|
||||
/**
|
||||
* Currently only WebKit-based Web Inspectors, Firefox >= v31,
|
||||
* and the Firebug extension (any Firefox version) are known
|
||||
* to support "%c" CSS customizations.
|
||||
*
|
||||
* TODO: add a `localStorage` variable to explicitly enable/disable colors
|
||||
*/
|
||||
// eslint-disable-next-line complexity
|
||||
|
||||
function useColors() {
|
||||
// NB: In an Electron preload script, document will be defined but not fully
|
||||
// initialized. Since we know we're in Chrome, we'll just detect this case
|
||||
// explicitly
|
||||
if (typeof window !== 'undefined' && window.process && (window.process.type === 'renderer' || window.process.__nwjs)) {
|
||||
return true;
|
||||
} // Internet Explorer and Edge do not support colors.
|
||||
|
||||
|
||||
if (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) {
|
||||
return false;
|
||||
} // Is webkit? http://stackoverflow.com/a/16459606/376773
|
||||
// document is undefined in react-native: https://github.com/facebook/react-native/pull/1632
|
||||
|
||||
|
||||
return typeof document !== 'undefined' && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance || // Is firebug? http://stackoverflow.com/a/398120/376773
|
||||
typeof window !== 'undefined' && window.console && (window.console.firebug || window.console.exception && window.console.table) || // Is firefox >= v31?
|
||||
// https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
|
||||
typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31 || // Double check webkit in userAgent just in case we are in a worker
|
||||
typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/);
|
||||
}
|
||||
/**
|
||||
* Colorize log arguments if enabled.
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
|
||||
function formatArgs(args) {
|
||||
args[0] = (this.useColors ? '%c' : '') + this.namespace + (this.useColors ? ' %c' : ' ') + args[0] + (this.useColors ? '%c ' : ' ') + '+' + module.exports.humanize(this.diff);
|
||||
|
||||
if (!this.useColors) {
|
||||
return;
|
||||
}
|
||||
|
||||
var c = 'color: ' + this.color;
|
||||
args.splice(1, 0, c, 'color: inherit'); // The final "%c" is somewhat tricky, because there could be other
|
||||
// arguments passed either before or after the %c, so we need to
|
||||
// figure out the correct index to insert the CSS into
|
||||
|
||||
var index = 0;
|
||||
var lastC = 0;
|
||||
args[0].replace(/%[a-zA-Z%]/g, function (match) {
|
||||
if (match === '%%') {
|
||||
return;
|
||||
}
|
||||
|
||||
index++;
|
||||
|
||||
if (match === '%c') {
|
||||
// We only are interested in the *last* %c
|
||||
// (the user may have provided their own)
|
||||
lastC = index;
|
||||
}
|
||||
});
|
||||
args.splice(lastC, 0, c);
|
||||
}
|
||||
/**
|
||||
* Invokes `console.log()` when available.
|
||||
* No-op when `console.log` is not a "function".
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
|
||||
function log() {
|
||||
var _console;
|
||||
|
||||
// This hackery is required for IE8/9, where
|
||||
// the `console.log` function doesn't have 'apply'
|
||||
return (typeof console === "undefined" ? "undefined" : _typeof(console)) === 'object' && console.log && (_console = console).log.apply(_console, arguments);
|
||||
}
|
||||
/**
|
||||
* Save `namespaces`.
|
||||
*
|
||||
* @param {String} namespaces
|
||||
* @api private
|
||||
*/
|
||||
|
||||
|
||||
function save(namespaces) {
|
||||
try {
|
||||
if (namespaces) {
|
||||
exports.storage.setItem('debug', namespaces);
|
||||
} else {
|
||||
exports.storage.removeItem('debug');
|
||||
}
|
||||
} catch (error) {// Swallow
|
||||
// XXX (@Qix-) should we be logging these?
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Load `namespaces`.
|
||||
*
|
||||
* @return {String} returns the previously persisted debug modes
|
||||
* @api private
|
||||
*/
|
||||
|
||||
|
||||
function load() {
|
||||
var r;
|
||||
|
||||
try {
|
||||
r = exports.storage.getItem('debug');
|
||||
} catch (error) {} // Swallow
|
||||
// XXX (@Qix-) should we be logging these?
|
||||
// If debug isn't set in LS, and we're in Electron, try to load $DEBUG
|
||||
|
||||
|
||||
if (!r && typeof process !== 'undefined' && 'env' in process) {
|
||||
r = process.env.DEBUG;
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
/**
|
||||
* Localstorage attempts to return the localstorage.
|
||||
*
|
||||
* This is necessary because safari throws
|
||||
* when a user disables cookies/localstorage
|
||||
* and you attempt to access it.
|
||||
*
|
||||
* @return {LocalStorage}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
|
||||
function localstorage() {
|
||||
try {
|
||||
// TVMLKit (Apple TV JS Runtime) does not have a window object, just localStorage in the global context
|
||||
// The Browser also has localStorage in the global context.
|
||||
return localStorage;
|
||||
} catch (error) {// Swallow
|
||||
// XXX (@Qix-) should we be logging these?
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = require('./common')(exports);
|
||||
var formatters = module.exports.formatters;
|
||||
/**
|
||||
* Map %j to `JSON.stringify()`, since no Web Inspectors do that by default.
|
||||
*/
|
||||
|
||||
formatters.j = function (v) {
|
||||
try {
|
||||
return JSON.stringify(v);
|
||||
} catch (error) {
|
||||
return '[UnexpectedJSONParseError]: ' + error.message;
|
||||
}
|
||||
};
|
||||
}).call(this, require('_process'));
|
||||
}, {
|
||||
"./common": 3,
|
||||
"_process": 2
|
||||
}]
|
||||
}, {}, [4])(4);
|
||||
});
|
||||
102
node_modules/nock/node_modules/debug/package.json
generated
vendored
Normal file
102
node_modules/nock/node_modules/debug/package.json
generated
vendored
Normal file
@@ -0,0 +1,102 @@
|
||||
{
|
||||
"_from": "debug@^4.1.0",
|
||||
"_id": "debug@4.1.1",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==",
|
||||
"_location": "/nock/debug",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "debug@^4.1.0",
|
||||
"name": "debug",
|
||||
"escapedName": "debug",
|
||||
"rawSpec": "^4.1.0",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "^4.1.0"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/nock"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz",
|
||||
"_shasum": "3b72260255109c6b589cee050f1d516139664791",
|
||||
"_spec": "debug@^4.1.0",
|
||||
"_where": "/Volumes/MacMini Disk/Project/Nodejs/flixinfo/node_modules/nock",
|
||||
"author": {
|
||||
"name": "TJ Holowaychuk",
|
||||
"email": "tj@vision-media.ca"
|
||||
},
|
||||
"browser": "./src/browser.js",
|
||||
"bugs": {
|
||||
"url": "https://github.com/visionmedia/debug/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"contributors": [
|
||||
{
|
||||
"name": "Nathan Rajlich",
|
||||
"email": "nathan@tootallnate.net",
|
||||
"url": "http://n8.io"
|
||||
},
|
||||
{
|
||||
"name": "Andrew Rhyne",
|
||||
"email": "rhyneandrew@gmail.com"
|
||||
}
|
||||
],
|
||||
"dependencies": {
|
||||
"ms": "^2.1.1"
|
||||
},
|
||||
"deprecated": false,
|
||||
"description": "small debugging utility",
|
||||
"devDependencies": {
|
||||
"@babel/cli": "^7.0.0",
|
||||
"@babel/core": "^7.0.0",
|
||||
"@babel/preset-env": "^7.0.0",
|
||||
"browserify": "14.4.0",
|
||||
"chai": "^3.5.0",
|
||||
"concurrently": "^3.1.0",
|
||||
"coveralls": "^3.0.2",
|
||||
"istanbul": "^0.4.5",
|
||||
"karma": "^3.0.0",
|
||||
"karma-chai": "^0.1.0",
|
||||
"karma-mocha": "^1.3.0",
|
||||
"karma-phantomjs-launcher": "^1.0.2",
|
||||
"mocha": "^5.2.0",
|
||||
"mocha-lcov-reporter": "^1.2.0",
|
||||
"rimraf": "^2.5.4",
|
||||
"xo": "^0.23.0"
|
||||
},
|
||||
"files": [
|
||||
"src",
|
||||
"dist/debug.js",
|
||||
"LICENSE",
|
||||
"README.md"
|
||||
],
|
||||
"homepage": "https://github.com/visionmedia/debug#readme",
|
||||
"keywords": [
|
||||
"debug",
|
||||
"log",
|
||||
"debugger"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "./src/index.js",
|
||||
"name": "debug",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/visionmedia/debug.git"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "npm run build:debug && npm run build:test",
|
||||
"build:debug": "babel -o dist/debug.js dist/debug.es6.js > dist/debug.js",
|
||||
"build:test": "babel -d dist test.js",
|
||||
"clean": "rimraf dist coverage",
|
||||
"lint": "xo",
|
||||
"prebuild:debug": "mkdir -p dist && browserify --standalone debug -o dist/debug.es6.js .",
|
||||
"pretest:browser": "npm run build",
|
||||
"test": "npm run test:node && npm run test:browser",
|
||||
"test:browser": "karma start --single-run",
|
||||
"test:coverage": "cat ./coverage/lcov.info | coveralls",
|
||||
"test:node": "istanbul cover _mocha -- test.js"
|
||||
},
|
||||
"unpkg": "./dist/debug.js",
|
||||
"version": "4.1.1"
|
||||
}
|
||||
264
node_modules/nock/node_modules/debug/src/browser.js
generated
vendored
Normal file
264
node_modules/nock/node_modules/debug/src/browser.js
generated
vendored
Normal file
@@ -0,0 +1,264 @@
|
||||
/* eslint-env browser */
|
||||
|
||||
/**
|
||||
* This is the web browser implementation of `debug()`.
|
||||
*/
|
||||
|
||||
exports.log = log;
|
||||
exports.formatArgs = formatArgs;
|
||||
exports.save = save;
|
||||
exports.load = load;
|
||||
exports.useColors = useColors;
|
||||
exports.storage = localstorage();
|
||||
|
||||
/**
|
||||
* Colors.
|
||||
*/
|
||||
|
||||
exports.colors = [
|
||||
'#0000CC',
|
||||
'#0000FF',
|
||||
'#0033CC',
|
||||
'#0033FF',
|
||||
'#0066CC',
|
||||
'#0066FF',
|
||||
'#0099CC',
|
||||
'#0099FF',
|
||||
'#00CC00',
|
||||
'#00CC33',
|
||||
'#00CC66',
|
||||
'#00CC99',
|
||||
'#00CCCC',
|
||||
'#00CCFF',
|
||||
'#3300CC',
|
||||
'#3300FF',
|
||||
'#3333CC',
|
||||
'#3333FF',
|
||||
'#3366CC',
|
||||
'#3366FF',
|
||||
'#3399CC',
|
||||
'#3399FF',
|
||||
'#33CC00',
|
||||
'#33CC33',
|
||||
'#33CC66',
|
||||
'#33CC99',
|
||||
'#33CCCC',
|
||||
'#33CCFF',
|
||||
'#6600CC',
|
||||
'#6600FF',
|
||||
'#6633CC',
|
||||
'#6633FF',
|
||||
'#66CC00',
|
||||
'#66CC33',
|
||||
'#9900CC',
|
||||
'#9900FF',
|
||||
'#9933CC',
|
||||
'#9933FF',
|
||||
'#99CC00',
|
||||
'#99CC33',
|
||||
'#CC0000',
|
||||
'#CC0033',
|
||||
'#CC0066',
|
||||
'#CC0099',
|
||||
'#CC00CC',
|
||||
'#CC00FF',
|
||||
'#CC3300',
|
||||
'#CC3333',
|
||||
'#CC3366',
|
||||
'#CC3399',
|
||||
'#CC33CC',
|
||||
'#CC33FF',
|
||||
'#CC6600',
|
||||
'#CC6633',
|
||||
'#CC9900',
|
||||
'#CC9933',
|
||||
'#CCCC00',
|
||||
'#CCCC33',
|
||||
'#FF0000',
|
||||
'#FF0033',
|
||||
'#FF0066',
|
||||
'#FF0099',
|
||||
'#FF00CC',
|
||||
'#FF00FF',
|
||||
'#FF3300',
|
||||
'#FF3333',
|
||||
'#FF3366',
|
||||
'#FF3399',
|
||||
'#FF33CC',
|
||||
'#FF33FF',
|
||||
'#FF6600',
|
||||
'#FF6633',
|
||||
'#FF9900',
|
||||
'#FF9933',
|
||||
'#FFCC00',
|
||||
'#FFCC33'
|
||||
];
|
||||
|
||||
/**
|
||||
* Currently only WebKit-based Web Inspectors, Firefox >= v31,
|
||||
* and the Firebug extension (any Firefox version) are known
|
||||
* to support "%c" CSS customizations.
|
||||
*
|
||||
* TODO: add a `localStorage` variable to explicitly enable/disable colors
|
||||
*/
|
||||
|
||||
// eslint-disable-next-line complexity
|
||||
function useColors() {
|
||||
// NB: In an Electron preload script, document will be defined but not fully
|
||||
// initialized. Since we know we're in Chrome, we'll just detect this case
|
||||
// explicitly
|
||||
if (typeof window !== 'undefined' && window.process && (window.process.type === 'renderer' || window.process.__nwjs)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Internet Explorer and Edge do not support colors.
|
||||
if (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Is webkit? http://stackoverflow.com/a/16459606/376773
|
||||
// document is undefined in react-native: https://github.com/facebook/react-native/pull/1632
|
||||
return (typeof document !== 'undefined' && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance) ||
|
||||
// Is firebug? http://stackoverflow.com/a/398120/376773
|
||||
(typeof window !== 'undefined' && window.console && (window.console.firebug || (window.console.exception && window.console.table))) ||
|
||||
// Is firefox >= v31?
|
||||
// https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
|
||||
(typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31) ||
|
||||
// Double check webkit in userAgent just in case we are in a worker
|
||||
(typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/));
|
||||
}
|
||||
|
||||
/**
|
||||
* Colorize log arguments if enabled.
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
function formatArgs(args) {
|
||||
args[0] = (this.useColors ? '%c' : '') +
|
||||
this.namespace +
|
||||
(this.useColors ? ' %c' : ' ') +
|
||||
args[0] +
|
||||
(this.useColors ? '%c ' : ' ') +
|
||||
'+' + module.exports.humanize(this.diff);
|
||||
|
||||
if (!this.useColors) {
|
||||
return;
|
||||
}
|
||||
|
||||
const c = 'color: ' + this.color;
|
||||
args.splice(1, 0, c, 'color: inherit');
|
||||
|
||||
// The final "%c" is somewhat tricky, because there could be other
|
||||
// arguments passed either before or after the %c, so we need to
|
||||
// figure out the correct index to insert the CSS into
|
||||
let index = 0;
|
||||
let lastC = 0;
|
||||
args[0].replace(/%[a-zA-Z%]/g, match => {
|
||||
if (match === '%%') {
|
||||
return;
|
||||
}
|
||||
index++;
|
||||
if (match === '%c') {
|
||||
// We only are interested in the *last* %c
|
||||
// (the user may have provided their own)
|
||||
lastC = index;
|
||||
}
|
||||
});
|
||||
|
||||
args.splice(lastC, 0, c);
|
||||
}
|
||||
|
||||
/**
|
||||
* Invokes `console.log()` when available.
|
||||
* No-op when `console.log` is not a "function".
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
function log(...args) {
|
||||
// This hackery is required for IE8/9, where
|
||||
// the `console.log` function doesn't have 'apply'
|
||||
return typeof console === 'object' &&
|
||||
console.log &&
|
||||
console.log(...args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Save `namespaces`.
|
||||
*
|
||||
* @param {String} namespaces
|
||||
* @api private
|
||||
*/
|
||||
function save(namespaces) {
|
||||
try {
|
||||
if (namespaces) {
|
||||
exports.storage.setItem('debug', namespaces);
|
||||
} else {
|
||||
exports.storage.removeItem('debug');
|
||||
}
|
||||
} catch (error) {
|
||||
// Swallow
|
||||
// XXX (@Qix-) should we be logging these?
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load `namespaces`.
|
||||
*
|
||||
* @return {String} returns the previously persisted debug modes
|
||||
* @api private
|
||||
*/
|
||||
function load() {
|
||||
let r;
|
||||
try {
|
||||
r = exports.storage.getItem('debug');
|
||||
} catch (error) {
|
||||
// Swallow
|
||||
// XXX (@Qix-) should we be logging these?
|
||||
}
|
||||
|
||||
// If debug isn't set in LS, and we're in Electron, try to load $DEBUG
|
||||
if (!r && typeof process !== 'undefined' && 'env' in process) {
|
||||
r = process.env.DEBUG;
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
* Localstorage attempts to return the localstorage.
|
||||
*
|
||||
* This is necessary because safari throws
|
||||
* when a user disables cookies/localstorage
|
||||
* and you attempt to access it.
|
||||
*
|
||||
* @return {LocalStorage}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function localstorage() {
|
||||
try {
|
||||
// TVMLKit (Apple TV JS Runtime) does not have a window object, just localStorage in the global context
|
||||
// The Browser also has localStorage in the global context.
|
||||
return localStorage;
|
||||
} catch (error) {
|
||||
// Swallow
|
||||
// XXX (@Qix-) should we be logging these?
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = require('./common')(exports);
|
||||
|
||||
const {formatters} = module.exports;
|
||||
|
||||
/**
|
||||
* Map %j to `JSON.stringify()`, since no Web Inspectors do that by default.
|
||||
*/
|
||||
|
||||
formatters.j = function (v) {
|
||||
try {
|
||||
return JSON.stringify(v);
|
||||
} catch (error) {
|
||||
return '[UnexpectedJSONParseError]: ' + error.message;
|
||||
}
|
||||
};
|
||||
266
node_modules/nock/node_modules/debug/src/common.js
generated
vendored
Normal file
266
node_modules/nock/node_modules/debug/src/common.js
generated
vendored
Normal file
@@ -0,0 +1,266 @@
|
||||
|
||||
/**
|
||||
* This is the common logic for both the Node.js and web browser
|
||||
* implementations of `debug()`.
|
||||
*/
|
||||
|
||||
function setup(env) {
|
||||
createDebug.debug = createDebug;
|
||||
createDebug.default = createDebug;
|
||||
createDebug.coerce = coerce;
|
||||
createDebug.disable = disable;
|
||||
createDebug.enable = enable;
|
||||
createDebug.enabled = enabled;
|
||||
createDebug.humanize = require('ms');
|
||||
|
||||
Object.keys(env).forEach(key => {
|
||||
createDebug[key] = env[key];
|
||||
});
|
||||
|
||||
/**
|
||||
* Active `debug` instances.
|
||||
*/
|
||||
createDebug.instances = [];
|
||||
|
||||
/**
|
||||
* The currently active debug mode names, and names to skip.
|
||||
*/
|
||||
|
||||
createDebug.names = [];
|
||||
createDebug.skips = [];
|
||||
|
||||
/**
|
||||
* Map of special "%n" handling functions, for the debug "format" argument.
|
||||
*
|
||||
* Valid key names are a single, lower or upper-case letter, i.e. "n" and "N".
|
||||
*/
|
||||
createDebug.formatters = {};
|
||||
|
||||
/**
|
||||
* Selects a color for a debug namespace
|
||||
* @param {String} namespace The namespace string for the for the debug instance to be colored
|
||||
* @return {Number|String} An ANSI color code for the given namespace
|
||||
* @api private
|
||||
*/
|
||||
function selectColor(namespace) {
|
||||
let hash = 0;
|
||||
|
||||
for (let i = 0; i < namespace.length; i++) {
|
||||
hash = ((hash << 5) - hash) + namespace.charCodeAt(i);
|
||||
hash |= 0; // Convert to 32bit integer
|
||||
}
|
||||
|
||||
return createDebug.colors[Math.abs(hash) % createDebug.colors.length];
|
||||
}
|
||||
createDebug.selectColor = selectColor;
|
||||
|
||||
/**
|
||||
* Create a debugger with the given `namespace`.
|
||||
*
|
||||
* @param {String} namespace
|
||||
* @return {Function}
|
||||
* @api public
|
||||
*/
|
||||
function createDebug(namespace) {
|
||||
let prevTime;
|
||||
|
||||
function debug(...args) {
|
||||
// Disabled?
|
||||
if (!debug.enabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
const self = debug;
|
||||
|
||||
// Set `diff` timestamp
|
||||
const curr = Number(new Date());
|
||||
const ms = curr - (prevTime || curr);
|
||||
self.diff = ms;
|
||||
self.prev = prevTime;
|
||||
self.curr = curr;
|
||||
prevTime = curr;
|
||||
|
||||
args[0] = createDebug.coerce(args[0]);
|
||||
|
||||
if (typeof args[0] !== 'string') {
|
||||
// Anything else let's inspect with %O
|
||||
args.unshift('%O');
|
||||
}
|
||||
|
||||
// Apply any `formatters` transformations
|
||||
let index = 0;
|
||||
args[0] = args[0].replace(/%([a-zA-Z%])/g, (match, format) => {
|
||||
// If we encounter an escaped % then don't increase the array index
|
||||
if (match === '%%') {
|
||||
return match;
|
||||
}
|
||||
index++;
|
||||
const formatter = createDebug.formatters[format];
|
||||
if (typeof formatter === 'function') {
|
||||
const val = args[index];
|
||||
match = formatter.call(self, val);
|
||||
|
||||
// Now we need to remove `args[index]` since it's inlined in the `format`
|
||||
args.splice(index, 1);
|
||||
index--;
|
||||
}
|
||||
return match;
|
||||
});
|
||||
|
||||
// Apply env-specific formatting (colors, etc.)
|
||||
createDebug.formatArgs.call(self, args);
|
||||
|
||||
const logFn = self.log || createDebug.log;
|
||||
logFn.apply(self, args);
|
||||
}
|
||||
|
||||
debug.namespace = namespace;
|
||||
debug.enabled = createDebug.enabled(namespace);
|
||||
debug.useColors = createDebug.useColors();
|
||||
debug.color = selectColor(namespace);
|
||||
debug.destroy = destroy;
|
||||
debug.extend = extend;
|
||||
// Debug.formatArgs = formatArgs;
|
||||
// debug.rawLog = rawLog;
|
||||
|
||||
// env-specific initialization logic for debug instances
|
||||
if (typeof createDebug.init === 'function') {
|
||||
createDebug.init(debug);
|
||||
}
|
||||
|
||||
createDebug.instances.push(debug);
|
||||
|
||||
return debug;
|
||||
}
|
||||
|
||||
function destroy() {
|
||||
const index = createDebug.instances.indexOf(this);
|
||||
if (index !== -1) {
|
||||
createDebug.instances.splice(index, 1);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function extend(namespace, delimiter) {
|
||||
const newDebug = createDebug(this.namespace + (typeof delimiter === 'undefined' ? ':' : delimiter) + namespace);
|
||||
newDebug.log = this.log;
|
||||
return newDebug;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables a debug mode by namespaces. This can include modes
|
||||
* separated by a colon and wildcards.
|
||||
*
|
||||
* @param {String} namespaces
|
||||
* @api public
|
||||
*/
|
||||
function enable(namespaces) {
|
||||
createDebug.save(namespaces);
|
||||
|
||||
createDebug.names = [];
|
||||
createDebug.skips = [];
|
||||
|
||||
let i;
|
||||
const split = (typeof namespaces === 'string' ? namespaces : '').split(/[\s,]+/);
|
||||
const len = split.length;
|
||||
|
||||
for (i = 0; i < len; i++) {
|
||||
if (!split[i]) {
|
||||
// ignore empty strings
|
||||
continue;
|
||||
}
|
||||
|
||||
namespaces = split[i].replace(/\*/g, '.*?');
|
||||
|
||||
if (namespaces[0] === '-') {
|
||||
createDebug.skips.push(new RegExp('^' + namespaces.substr(1) + '$'));
|
||||
} else {
|
||||
createDebug.names.push(new RegExp('^' + namespaces + '$'));
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < createDebug.instances.length; i++) {
|
||||
const instance = createDebug.instances[i];
|
||||
instance.enabled = createDebug.enabled(instance.namespace);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable debug output.
|
||||
*
|
||||
* @return {String} namespaces
|
||||
* @api public
|
||||
*/
|
||||
function disable() {
|
||||
const namespaces = [
|
||||
...createDebug.names.map(toNamespace),
|
||||
...createDebug.skips.map(toNamespace).map(namespace => '-' + namespace)
|
||||
].join(',');
|
||||
createDebug.enable('');
|
||||
return namespaces;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the given mode name is enabled, false otherwise.
|
||||
*
|
||||
* @param {String} name
|
||||
* @return {Boolean}
|
||||
* @api public
|
||||
*/
|
||||
function enabled(name) {
|
||||
if (name[name.length - 1] === '*') {
|
||||
return true;
|
||||
}
|
||||
|
||||
let i;
|
||||
let len;
|
||||
|
||||
for (i = 0, len = createDebug.skips.length; i < len; i++) {
|
||||
if (createDebug.skips[i].test(name)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0, len = createDebug.names.length; i < len; i++) {
|
||||
if (createDebug.names[i].test(name)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert regexp to namespace
|
||||
*
|
||||
* @param {RegExp} regxep
|
||||
* @return {String} namespace
|
||||
* @api private
|
||||
*/
|
||||
function toNamespace(regexp) {
|
||||
return regexp.toString()
|
||||
.substring(2, regexp.toString().length - 2)
|
||||
.replace(/\.\*\?$/, '*');
|
||||
}
|
||||
|
||||
/**
|
||||
* Coerce `val`.
|
||||
*
|
||||
* @param {Mixed} val
|
||||
* @return {Mixed}
|
||||
* @api private
|
||||
*/
|
||||
function coerce(val) {
|
||||
if (val instanceof Error) {
|
||||
return val.stack || val.message;
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
createDebug.enable(createDebug.load());
|
||||
|
||||
return createDebug;
|
||||
}
|
||||
|
||||
module.exports = setup;
|
||||
10
node_modules/nock/node_modules/debug/src/index.js
generated
vendored
Normal file
10
node_modules/nock/node_modules/debug/src/index.js
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
/**
|
||||
* Detect Electron renderer / nwjs process, which is node, but we should
|
||||
* treat as a browser.
|
||||
*/
|
||||
|
||||
if (typeof process === 'undefined' || process.type === 'renderer' || process.browser === true || process.__nwjs) {
|
||||
module.exports = require('./browser.js');
|
||||
} else {
|
||||
module.exports = require('./node.js');
|
||||
}
|
||||
257
node_modules/nock/node_modules/debug/src/node.js
generated
vendored
Normal file
257
node_modules/nock/node_modules/debug/src/node.js
generated
vendored
Normal file
@@ -0,0 +1,257 @@
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
const tty = require('tty');
|
||||
const util = require('util');
|
||||
|
||||
/**
|
||||
* This is the Node.js implementation of `debug()`.
|
||||
*/
|
||||
|
||||
exports.init = init;
|
||||
exports.log = log;
|
||||
exports.formatArgs = formatArgs;
|
||||
exports.save = save;
|
||||
exports.load = load;
|
||||
exports.useColors = useColors;
|
||||
|
||||
/**
|
||||
* Colors.
|
||||
*/
|
||||
|
||||
exports.colors = [6, 2, 3, 4, 5, 1];
|
||||
|
||||
try {
|
||||
// Optional dependency (as in, doesn't need to be installed, NOT like optionalDependencies in package.json)
|
||||
// eslint-disable-next-line import/no-extraneous-dependencies
|
||||
const supportsColor = require('supports-color');
|
||||
|
||||
if (supportsColor && (supportsColor.stderr || supportsColor).level >= 2) {
|
||||
exports.colors = [
|
||||
20,
|
||||
21,
|
||||
26,
|
||||
27,
|
||||
32,
|
||||
33,
|
||||
38,
|
||||
39,
|
||||
40,
|
||||
41,
|
||||
42,
|
||||
43,
|
||||
44,
|
||||
45,
|
||||
56,
|
||||
57,
|
||||
62,
|
||||
63,
|
||||
68,
|
||||
69,
|
||||
74,
|
||||
75,
|
||||
76,
|
||||
77,
|
||||
78,
|
||||
79,
|
||||
80,
|
||||
81,
|
||||
92,
|
||||
93,
|
||||
98,
|
||||
99,
|
||||
112,
|
||||
113,
|
||||
128,
|
||||
129,
|
||||
134,
|
||||
135,
|
||||
148,
|
||||
149,
|
||||
160,
|
||||
161,
|
||||
162,
|
||||
163,
|
||||
164,
|
||||
165,
|
||||
166,
|
||||
167,
|
||||
168,
|
||||
169,
|
||||
170,
|
||||
171,
|
||||
172,
|
||||
173,
|
||||
178,
|
||||
179,
|
||||
184,
|
||||
185,
|
||||
196,
|
||||
197,
|
||||
198,
|
||||
199,
|
||||
200,
|
||||
201,
|
||||
202,
|
||||
203,
|
||||
204,
|
||||
205,
|
||||
206,
|
||||
207,
|
||||
208,
|
||||
209,
|
||||
214,
|
||||
215,
|
||||
220,
|
||||
221
|
||||
];
|
||||
}
|
||||
} catch (error) {
|
||||
// Swallow - we only care if `supports-color` is available; it doesn't have to be.
|
||||
}
|
||||
|
||||
/**
|
||||
* Build up the default `inspectOpts` object from the environment variables.
|
||||
*
|
||||
* $ DEBUG_COLORS=no DEBUG_DEPTH=10 DEBUG_SHOW_HIDDEN=enabled node script.js
|
||||
*/
|
||||
|
||||
exports.inspectOpts = Object.keys(process.env).filter(key => {
|
||||
return /^debug_/i.test(key);
|
||||
}).reduce((obj, key) => {
|
||||
// Camel-case
|
||||
const prop = key
|
||||
.substring(6)
|
||||
.toLowerCase()
|
||||
.replace(/_([a-z])/g, (_, k) => {
|
||||
return k.toUpperCase();
|
||||
});
|
||||
|
||||
// Coerce string value into JS value
|
||||
let val = process.env[key];
|
||||
if (/^(yes|on|true|enabled)$/i.test(val)) {
|
||||
val = true;
|
||||
} else if (/^(no|off|false|disabled)$/i.test(val)) {
|
||||
val = false;
|
||||
} else if (val === 'null') {
|
||||
val = null;
|
||||
} else {
|
||||
val = Number(val);
|
||||
}
|
||||
|
||||
obj[prop] = val;
|
||||
return obj;
|
||||
}, {});
|
||||
|
||||
/**
|
||||
* Is stdout a TTY? Colored output is enabled when `true`.
|
||||
*/
|
||||
|
||||
function useColors() {
|
||||
return 'colors' in exports.inspectOpts ?
|
||||
Boolean(exports.inspectOpts.colors) :
|
||||
tty.isatty(process.stderr.fd);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds ANSI color escape codes if enabled.
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
function formatArgs(args) {
|
||||
const {namespace: name, useColors} = this;
|
||||
|
||||
if (useColors) {
|
||||
const c = this.color;
|
||||
const colorCode = '\u001B[3' + (c < 8 ? c : '8;5;' + c);
|
||||
const prefix = ` ${colorCode};1m${name} \u001B[0m`;
|
||||
|
||||
args[0] = prefix + args[0].split('\n').join('\n' + prefix);
|
||||
args.push(colorCode + 'm+' + module.exports.humanize(this.diff) + '\u001B[0m');
|
||||
} else {
|
||||
args[0] = getDate() + name + ' ' + args[0];
|
||||
}
|
||||
}
|
||||
|
||||
function getDate() {
|
||||
if (exports.inspectOpts.hideDate) {
|
||||
return '';
|
||||
}
|
||||
return new Date().toISOString() + ' ';
|
||||
}
|
||||
|
||||
/**
|
||||
* Invokes `util.format()` with the specified arguments and writes to stderr.
|
||||
*/
|
||||
|
||||
function log(...args) {
|
||||
return process.stderr.write(util.format(...args) + '\n');
|
||||
}
|
||||
|
||||
/**
|
||||
* Save `namespaces`.
|
||||
*
|
||||
* @param {String} namespaces
|
||||
* @api private
|
||||
*/
|
||||
function save(namespaces) {
|
||||
if (namespaces) {
|
||||
process.env.DEBUG = namespaces;
|
||||
} else {
|
||||
// If you set a process.env field to null or undefined, it gets cast to the
|
||||
// string 'null' or 'undefined'. Just delete instead.
|
||||
delete process.env.DEBUG;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load `namespaces`.
|
||||
*
|
||||
* @return {String} returns the previously persisted debug modes
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function load() {
|
||||
return process.env.DEBUG;
|
||||
}
|
||||
|
||||
/**
|
||||
* Init logic for `debug` instances.
|
||||
*
|
||||
* Create a new `inspectOpts` object in case `useColors` is set
|
||||
* differently for a particular `debug` instance.
|
||||
*/
|
||||
|
||||
function init(debug) {
|
||||
debug.inspectOpts = {};
|
||||
|
||||
const keys = Object.keys(exports.inspectOpts);
|
||||
for (let i = 0; i < keys.length; i++) {
|
||||
debug.inspectOpts[keys[i]] = exports.inspectOpts[keys[i]];
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = require('./common')(exports);
|
||||
|
||||
const {formatters} = module.exports;
|
||||
|
||||
/**
|
||||
* Map %o to `util.inspect()`, all on a single line.
|
||||
*/
|
||||
|
||||
formatters.o = function (v) {
|
||||
this.inspectOpts.colors = this.useColors;
|
||||
return util.inspect(v, this.inspectOpts)
|
||||
.replace(/\s*\n\s*/g, ' ');
|
||||
};
|
||||
|
||||
/**
|
||||
* Map %O to `util.inspect()`, allowing multiple lines if needed.
|
||||
*/
|
||||
|
||||
formatters.O = function (v) {
|
||||
this.inspectOpts.colors = this.useColors;
|
||||
return util.inspect(v, this.inspectOpts);
|
||||
};
|
||||
162
node_modules/nock/node_modules/ms/index.js
generated
vendored
Normal file
162
node_modules/nock/node_modules/ms/index.js
generated
vendored
Normal file
@@ -0,0 +1,162 @@
|
||||
/**
|
||||
* Helpers.
|
||||
*/
|
||||
|
||||
var s = 1000;
|
||||
var m = s * 60;
|
||||
var h = m * 60;
|
||||
var d = h * 24;
|
||||
var w = d * 7;
|
||||
var y = d * 365.25;
|
||||
|
||||
/**
|
||||
* Parse or format the given `val`.
|
||||
*
|
||||
* Options:
|
||||
*
|
||||
* - `long` verbose formatting [false]
|
||||
*
|
||||
* @param {String|Number} val
|
||||
* @param {Object} [options]
|
||||
* @throws {Error} throw an error if val is not a non-empty string or a number
|
||||
* @return {String|Number}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
module.exports = function(val, options) {
|
||||
options = options || {};
|
||||
var type = typeof val;
|
||||
if (type === 'string' && val.length > 0) {
|
||||
return parse(val);
|
||||
} else if (type === 'number' && isFinite(val)) {
|
||||
return options.long ? fmtLong(val) : fmtShort(val);
|
||||
}
|
||||
throw new Error(
|
||||
'val is not a non-empty string or a valid number. val=' +
|
||||
JSON.stringify(val)
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Parse the given `str` and return milliseconds.
|
||||
*
|
||||
* @param {String} str
|
||||
* @return {Number}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function parse(str) {
|
||||
str = String(str);
|
||||
if (str.length > 100) {
|
||||
return;
|
||||
}
|
||||
var match = /^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(
|
||||
str
|
||||
);
|
||||
if (!match) {
|
||||
return;
|
||||
}
|
||||
var n = parseFloat(match[1]);
|
||||
var type = (match[2] || 'ms').toLowerCase();
|
||||
switch (type) {
|
||||
case 'years':
|
||||
case 'year':
|
||||
case 'yrs':
|
||||
case 'yr':
|
||||
case 'y':
|
||||
return n * y;
|
||||
case 'weeks':
|
||||
case 'week':
|
||||
case 'w':
|
||||
return n * w;
|
||||
case 'days':
|
||||
case 'day':
|
||||
case 'd':
|
||||
return n * d;
|
||||
case 'hours':
|
||||
case 'hour':
|
||||
case 'hrs':
|
||||
case 'hr':
|
||||
case 'h':
|
||||
return n * h;
|
||||
case 'minutes':
|
||||
case 'minute':
|
||||
case 'mins':
|
||||
case 'min':
|
||||
case 'm':
|
||||
return n * m;
|
||||
case 'seconds':
|
||||
case 'second':
|
||||
case 'secs':
|
||||
case 'sec':
|
||||
case 's':
|
||||
return n * s;
|
||||
case 'milliseconds':
|
||||
case 'millisecond':
|
||||
case 'msecs':
|
||||
case 'msec':
|
||||
case 'ms':
|
||||
return n;
|
||||
default:
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Short format for `ms`.
|
||||
*
|
||||
* @param {Number} ms
|
||||
* @return {String}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function fmtShort(ms) {
|
||||
var msAbs = Math.abs(ms);
|
||||
if (msAbs >= d) {
|
||||
return Math.round(ms / d) + 'd';
|
||||
}
|
||||
if (msAbs >= h) {
|
||||
return Math.round(ms / h) + 'h';
|
||||
}
|
||||
if (msAbs >= m) {
|
||||
return Math.round(ms / m) + 'm';
|
||||
}
|
||||
if (msAbs >= s) {
|
||||
return Math.round(ms / s) + 's';
|
||||
}
|
||||
return ms + 'ms';
|
||||
}
|
||||
|
||||
/**
|
||||
* Long format for `ms`.
|
||||
*
|
||||
* @param {Number} ms
|
||||
* @return {String}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function fmtLong(ms) {
|
||||
var msAbs = Math.abs(ms);
|
||||
if (msAbs >= d) {
|
||||
return plural(ms, msAbs, d, 'day');
|
||||
}
|
||||
if (msAbs >= h) {
|
||||
return plural(ms, msAbs, h, 'hour');
|
||||
}
|
||||
if (msAbs >= m) {
|
||||
return plural(ms, msAbs, m, 'minute');
|
||||
}
|
||||
if (msAbs >= s) {
|
||||
return plural(ms, msAbs, s, 'second');
|
||||
}
|
||||
return ms + ' ms';
|
||||
}
|
||||
|
||||
/**
|
||||
* Pluralization helper.
|
||||
*/
|
||||
|
||||
function plural(ms, msAbs, n, name) {
|
||||
var isPlural = msAbs >= n * 1.5;
|
||||
return Math.round(ms / n) + ' ' + name + (isPlural ? 's' : '');
|
||||
}
|
||||
21
node_modules/nock/node_modules/ms/license.md
generated
vendored
Normal file
21
node_modules/nock/node_modules/ms/license.md
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2016 Zeit, Inc.
|
||||
|
||||
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.
|
||||
69
node_modules/nock/node_modules/ms/package.json
generated
vendored
Normal file
69
node_modules/nock/node_modules/ms/package.json
generated
vendored
Normal file
@@ -0,0 +1,69 @@
|
||||
{
|
||||
"_from": "ms@^2.1.1",
|
||||
"_id": "ms@2.1.2",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==",
|
||||
"_location": "/nock/ms",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "ms@^2.1.1",
|
||||
"name": "ms",
|
||||
"escapedName": "ms",
|
||||
"rawSpec": "^2.1.1",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "^2.1.1"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/nock/debug"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
|
||||
"_shasum": "d09d1f357b443f493382a8eb3ccd183872ae6009",
|
||||
"_spec": "ms@^2.1.1",
|
||||
"_where": "/Volumes/MacMini Disk/Project/Nodejs/flixinfo/node_modules/nock/node_modules/debug",
|
||||
"bugs": {
|
||||
"url": "https://github.com/zeit/ms/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"deprecated": false,
|
||||
"description": "Tiny millisecond conversion utility",
|
||||
"devDependencies": {
|
||||
"eslint": "4.12.1",
|
||||
"expect.js": "0.3.1",
|
||||
"husky": "0.14.3",
|
||||
"lint-staged": "5.0.0",
|
||||
"mocha": "4.0.1"
|
||||
},
|
||||
"eslintConfig": {
|
||||
"extends": "eslint:recommended",
|
||||
"env": {
|
||||
"node": true,
|
||||
"es6": true
|
||||
}
|
||||
},
|
||||
"files": [
|
||||
"index.js"
|
||||
],
|
||||
"homepage": "https://github.com/zeit/ms#readme",
|
||||
"license": "MIT",
|
||||
"lint-staged": {
|
||||
"*.js": [
|
||||
"npm run lint",
|
||||
"prettier --single-quote --write",
|
||||
"git add"
|
||||
]
|
||||
},
|
||||
"main": "./index",
|
||||
"name": "ms",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/zeit/ms.git"
|
||||
},
|
||||
"scripts": {
|
||||
"lint": "eslint lib/* bin/*",
|
||||
"precommit": "lint-staged",
|
||||
"test": "mocha tests.js"
|
||||
},
|
||||
"version": "2.1.2"
|
||||
}
|
||||
60
node_modules/nock/node_modules/ms/readme.md
generated
vendored
Normal file
60
node_modules/nock/node_modules/ms/readme.md
generated
vendored
Normal file
@@ -0,0 +1,60 @@
|
||||
# ms
|
||||
|
||||
[](https://travis-ci.org/zeit/ms)
|
||||
[](https://spectrum.chat/zeit)
|
||||
|
||||
Use this package to easily convert various time formats to milliseconds.
|
||||
|
||||
## Examples
|
||||
|
||||
```js
|
||||
ms('2 days') // 172800000
|
||||
ms('1d') // 86400000
|
||||
ms('10h') // 36000000
|
||||
ms('2.5 hrs') // 9000000
|
||||
ms('2h') // 7200000
|
||||
ms('1m') // 60000
|
||||
ms('5s') // 5000
|
||||
ms('1y') // 31557600000
|
||||
ms('100') // 100
|
||||
ms('-3 days') // -259200000
|
||||
ms('-1h') // -3600000
|
||||
ms('-200') // -200
|
||||
```
|
||||
|
||||
### Convert from Milliseconds
|
||||
|
||||
```js
|
||||
ms(60000) // "1m"
|
||||
ms(2 * 60000) // "2m"
|
||||
ms(-3 * 60000) // "-3m"
|
||||
ms(ms('10 hours')) // "10h"
|
||||
```
|
||||
|
||||
### Time Format Written-Out
|
||||
|
||||
```js
|
||||
ms(60000, { long: true }) // "1 minute"
|
||||
ms(2 * 60000, { long: true }) // "2 minutes"
|
||||
ms(-3 * 60000, { long: true }) // "-3 minutes"
|
||||
ms(ms('10 hours'), { long: true }) // "10 hours"
|
||||
```
|
||||
|
||||
## Features
|
||||
|
||||
- Works both in [Node.js](https://nodejs.org) and in the browser
|
||||
- If a number is supplied to `ms`, a string with a unit is returned
|
||||
- If a string that contains the number is supplied, it returns it as a number (e.g.: it returns `100` for `'100'`)
|
||||
- If you pass a string with a number and a valid unit, the number of equivalent milliseconds is returned
|
||||
|
||||
## Related Packages
|
||||
|
||||
- [ms.macro](https://github.com/knpwrs/ms.macro) - Run `ms` as a macro at build-time.
|
||||
|
||||
## Caught a Bug?
|
||||
|
||||
1. [Fork](https://help.github.com/articles/fork-a-repo/) this repository to your own GitHub account and then [clone](https://help.github.com/articles/cloning-a-repository/) it to your local device
|
||||
2. Link the package to the global module directory: `npm link`
|
||||
3. Within the module you want to test your local development instance of ms, just link it to the dependencies: `npm link ms`. Instead of the default one from npm, Node.js will now use your clone of ms!
|
||||
|
||||
As always, you can run the tests using: `npm test`
|
||||
103
node_modules/nock/package.json
generated
vendored
Normal file
103
node_modules/nock/package.json
generated
vendored
Normal file
@@ -0,0 +1,103 @@
|
||||
{
|
||||
"_from": "nock@^10.0.5",
|
||||
"_id": "nock@10.0.6",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-b47OWj1qf/LqSQYnmokNWM8D88KvUl2y7jT0567NB3ZBAZFz2bWp2PC81Xn7u8F2/vJxzkzNZybnemeFa7AZ2w==",
|
||||
"_location": "/nock",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "nock@^10.0.5",
|
||||
"name": "nock",
|
||||
"escapedName": "nock",
|
||||
"rawSpec": "^10.0.5",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "^10.0.5"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"#DEV:/"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/nock/-/nock-10.0.6.tgz",
|
||||
"_shasum": "e6d90ee7a68b8cfc2ab7f6127e7d99aa7d13d111",
|
||||
"_spec": "nock@^10.0.5",
|
||||
"_where": "/Volumes/MacMini Disk/Project/Nodejs/flixinfo",
|
||||
"author": {
|
||||
"name": "Pedro Teixeira",
|
||||
"email": "pedro.teixeira@gmail.com"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "http://github.com/nock/nock/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"dependencies": {
|
||||
"chai": "^4.1.2",
|
||||
"debug": "^4.1.0",
|
||||
"deep-equal": "^1.0.0",
|
||||
"json-stringify-safe": "^5.0.1",
|
||||
"lodash": "^4.17.5",
|
||||
"mkdirp": "^0.5.0",
|
||||
"propagate": "^1.0.0",
|
||||
"qs": "^6.5.1",
|
||||
"semver": "^5.5.0"
|
||||
},
|
||||
"deprecated": false,
|
||||
"description": "HTTP server mocking and expectations library for Node.js",
|
||||
"devDependencies": {
|
||||
"acorn": "^6.0.4",
|
||||
"async": "^2.6.0",
|
||||
"aws-sdk": "^2.202.0",
|
||||
"coveralls": "^3.0.0",
|
||||
"eslint": "^5.0.0",
|
||||
"hyperquest": "^2.1.3",
|
||||
"isomorphic-fetch": "^2.2.0",
|
||||
"lolex": "^3.0.0",
|
||||
"markdown-toc": "^1.2.0",
|
||||
"needle": "^2.2.2",
|
||||
"nyc": "^12.0.1",
|
||||
"request": "^2.83.0",
|
||||
"request-promise": "^4.2.2",
|
||||
"restify-clients": "^2.2.0",
|
||||
"rimraf": "^2.6.2",
|
||||
"semantic-release": "^16.0.0-beta.13",
|
||||
"superagent": "^4.0.0",
|
||||
"tap": "^12.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 6.0"
|
||||
},
|
||||
"homepage": "https://github.com/nock/nock#readme",
|
||||
"license": "MIT",
|
||||
"main": "./index",
|
||||
"name": "nock",
|
||||
"nyc": {
|
||||
"reporter": [
|
||||
"lcov",
|
||||
"text-summary"
|
||||
],
|
||||
"exclude": [
|
||||
"tests/"
|
||||
]
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/nock/nock.git"
|
||||
},
|
||||
"scripts": {
|
||||
"coverage": "tap --coverage-report=html && open coverage/lcov-report/index.html",
|
||||
"coverage:upload": "tap --coverage-report=text-lcov | coveralls",
|
||||
"lint": "eslint \"**/*.js\"",
|
||||
"pretest": "npm run -s lint",
|
||||
"semantic-release": "semantic-release",
|
||||
"test": "npm run -s unit",
|
||||
"toc": "markdown-toc -i README.md && markdown-toc -i CONTRIBUTING.md ",
|
||||
"unit": "tap --coverage ./tests/test_*.js"
|
||||
},
|
||||
"tags": [
|
||||
"Mock",
|
||||
"HTTP",
|
||||
"testing",
|
||||
"isolation"
|
||||
],
|
||||
"version": "10.0.6"
|
||||
}
|
||||
Reference in New Issue
Block a user