Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Install with npm:
$ npm install ava-nock --save-dev
Install with Yarn:
$ yarn add ava-nock --dev
There are generally two approaches for mocking HTTP requests when we don’t control or can’t manually mock the code that makes the request: either use a proxy to fulfill the requests (this requires starting a server and being able to change your request code to point to it), or intercept the host language’s underlying code for sending a request. Libraries like yakbak use the former, while libraries like VCR, Nock, and Sepia use the latter. As the name implies, ava-nock uses Nock.
Likewise, there are multiple levels of granularity at which to capture requests. One approach is to generate a hash for each request and serve the same response any time a matching request is made throughout the entire test suite. Another approach is to isolate the specific requests made in each test. This library currently supports the latter approach (although it was designed with the former approach in mind – maybe someday).
Import and run the setupTests()
function in any test files that make network
requests. This function will add beforeEach
, afterEach
, and
afterEach.always
hooks that manage Nock fixtures for you.
import test from 'ava'
import fetch from 'isomorphic-fetch'
import { setupTests } from 'ava-nock'
setupTests()
test('using fetch to get JSON', t => {
return fetch(
'https://musicbrainz.org/ws/2/artist/c8da2e40-bd28-4d4e-813a-bd2f51958ba8?fmt=json'
)
.then(response => response.json())
.then(data => {
t.is(data.name, 'Lures')
})
})
Fixtures behave similarly to AVA snapshots: they are stored in a .nock
file
alongside the test file that generated them. Within each fixture, each test’s
requests and responses are stored for later playback.
Note that due to the way Nock works by globally intercepting requests to the
http
and https
modules, each test using ava-nock will effectively be run
serially – otherwise there is no way to isolate requests per-test. The
beforeEach
hook will enforce this for you automatically. (Running tests in
parallel in multiple processes is fine.)
You can control ava-nock’s behavior using the NOCK_MODE
environment variable.
NOCK_MODE | Network requests? | Read fixtures? | Write fixtures? |
---|---|---|---|
live | :ballot_box_with_check: | ||
preview | :ballot_box_with_check: | :ballot_box_with_check: | |
record | :ballot_box_with_check: | :ballot_box_with_check: | |
cache | :ballot_box_with_check: | :ballot_box_with_check: | :ballot_box_with_check: |
play | :ballot_box_with_check: |
FAQs
Drop-in, zero-config HTTP record & reply for [AVA](https://github.com/avajs/ava)!
The npm package ava-nock receives a total of 57 weekly downloads. As such, ava-nock popularity was classified as not popular.
We found that ava-nock demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.