Gathering detailed insights and metrics for @tapjs/nock
Gathering detailed insights and metrics for @tapjs/nock
Gathering detailed insights and metrics for @tapjs/nock
Gathering detailed insights and metrics for @tapjs/nock
npm install @tapjs/nock
Typescript
Module System
Min. Node Version
Node Version
NPM Version
58.9
Supply Chain
92
Quality
84.8
Maintenance
100
Vulnerability
99.3
License
JavaScript (84.11%)
TypeScript (15.52%)
CSS (0.19%)
Mustache (0.08%)
Nunjucks (0.05%)
HTML (0.03%)
Shell (0.02%)
Total Downloads
49,128
Last Day
76
Last Week
317
Last Month
1,270
Last Year
38,543
2,375 Stars
3,818 Commits
274 Forks
23 Watching
102 Branches
92 Contributors
Minified
Minified + Gzipped
Latest Version
6.0.0
Package Id
@tapjs/nock@6.0.0
Unpacked Size
94.28 kB
Size
15.79 kB
File Count
29
NPM Version
10.7.0
Node Version
20.13.1
Publised On
08 Jul 2024
Cumulative downloads
Total Downloads
Last day
-35.6%
76
Compared to previous day
Last week
27.8%
317
Compared to previous week
Last month
-11.4%
1,270
Compared to previous month
Last year
264.1%
38,543
Compared to previous year
3
1
@tapjs/nock
A tap extension that integrates nock.
t.nock()
nock.disableNetConnect()
nock
, and the result from
nock
returnednock.enableNetConnect()
in teardownt.nock.snapshot()
nock
scopes for youLoad the @tapjs/nock
plugin in your tap config.
For example, in .taprc
:
1plugins: 2 - @tapjs/nock
Or in package.json
:
1{ 2 "tap": { 3 "plugins": ["@tapjs/nock"] 4 } 5}
Then use it in your tests like so:
1import t from 'tap' 2 3t.test('sends a request', async t => { 4 t.nock('https://registry.npmjs.org') 5 .get('/') 6 .reply(200, { hello: 'world' }) 7 8 const res = await fetch('https://registry.npmjs.org') 9 t.equal(res.status, 200) 10 const body = await res.json() 11 t.same(body, { hello: 'world' }) 12}) 13 14// when snapshots are enabled, this test will send a real request 15// and record the response 16// when they are disabled, the recorded response will be 17// automatically loaded into a nock scope, and the test will 18// receive that response 19// This requires that the @tapjs/snapshot plugin is enabled. 20t.test('snapshots a request', async t => { 21 t.nock.snapshot() 22 23 const res = await fetch('https://registry.npmjs.org') 24 t.equal(res.status, 200) 25 const body = await res.json() 26 t.match(body, { db_name: 'registry' }) 27})
You may use it directly, though that is a bit more clunky,
because it won't be automatically applied to child tests, but it
can be good if you only need nock
in a small number of tests.
1import { plugin as tapNock } from '@tapjs/nock' 2import t from 'tap' 3 4t.test('sends a request', async t => { 5 const tn = tapNock(t) 6 tn.nock('https://registry.npmjs.org') 7 .get('/') 8 .reply(200, { hello: 'world' }) 9 10 const res = await fetch('https://registry.npmjs.org') 11 t.equal(res.status, 200) 12 const body = await res.json() 13 t.same(body, { hello: 'world' }) 14}) 15 16// when snapshots are enabled, this test will send a real request 17// and record the response 18// when they are disabled, the recorded response will be 19// automatically loaded into a nock scope, and the test will 20// receive that response 21// This requires that the @tapjs/snapshot plugin is enabled. 22t.test('snapshots a request', async t => { 23 const tn = tapNock(t) 24 tn.nock.snapshot() 25 26 const res = await fetch('https://registry.npmjs.org') 27 t.equal(res.status, 200) 28 const body = await res.json() 29 t.match(body, { db_name: 'registry' }) 30})
This plugin was originally developed by nlf as the standalone extension @npmcli/tap-nock, and the use case was a major inspiration for tap's plugin eventual architecture.
No vulnerabilities found.
No security vulnerabilities found.