Security News
pnpm 10.0.0 Blocks Lifecycle Scripts by Default
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
icedfrisby
Advanced tools
IcedFrisby is a Node.js library that makes testing API endpoints easy, fast and fun.
The IcedFrisby API Docs are located in API.md.
The IcedFrisby Changelog is located in CHANGELOG.md.
expectJSONTypes
, add @hapi/joi
to devDependencies
.globalConfig()
and reset()
with calls to .config()
.
If necessary, create a helper function which invokes
frisby.create().config()
.async run()
instead of toss()
if it
improves your workflow.The full set of changes is documented in the changelog.
expectJSON(...)
is strict. Undefined/null fields are not ignored and missing fields are considered errorsexpectContainsJSON(...)
tests JSON responses without knowing every field.Install IcedFrisby and Mocha from NPM:
npm install mocha icedfrisby --save-dev
If you are using expectJSONTypes
, install Joi too:
npm install @hapi/joi --save-dev
IcedFrisby is built and tested against Node 8 and 10.
IcedFrisby tests start with frisby.create()
with a description of the test followed by one of get()
, put()
, post()
, delete()
, or head()
, and ending with toss()
to generate the resulting Mocha test. There is a expectStatus()
method built in to more easily test HTTP status codes. Any other Mocha expect
tests should be done inside the after()
or afterJSON()
callback.
Each set of unique sequences or API endpoint tests should be started with new frisby.toss
method calls instead of trying to chain multiple HTTP requests together.
const frisby = require('icedfrisby')
const Joi = require('@hapi/joi')
const URL = 'http://localhost:3000/'
const URL_AUTH = 'http://username:password@localhost:3000/'
frisby
.create('GET user johndoe')
.get(URL + '/users/3.json')
.addHeader('X-Auth-Token', 'fa8426a0-8eaf-4d22-8e13-7c1b16a9370c')
.expectStatus(200)
.expectJSONTypes({
id: Joi.number(),
username: Joi.string(),
is_admin: Joi.boolean(),
})
.expectJSON({
id: 3,
username: 'johndoe',
is_admin: false,
})
// 'afterJSON' automatically parses response body as JSON and passes it as an argument
.afterJSON(user => {
// You can use any normal assertions here
expect(1 + 1).to.equal(2)
// Use data from previous result in next test
frisby
.create('Update user')
.put(URL_AUTH + '/users/' + user.id + '.json', { tags: ['mocha', 'bdd'] })
.expectStatus(200)
.toss()
})
.toss()
Any Mocha/Chai/whatever tests can be used inside the after
and afterJSON
callbacks to perform additional or custom tests on the response data.
Run tests as you normally would with Mocha.
For example:
cd your/project
mocha tests/someTest.js --reporter nyan
Plugins can provide custom assertions, setup and teardown logic, and additional functionality. Plugins can be implemented in an application's test code or as a library.
To use a plugin, compose IcedFrisby with it:
const frisby = require('./icedfrisby-nock')(require('icedfrisby'))
or, more semantically, using the delightful mixwith:
const { mix } = require('mixwith')
const frisby = mix(require('icedfrisby')).with(require('./icedfrisby-nock'))
Writing your own plugin is easy. For more details see [CONTRIBUTING.md].
Contributions are awesome! If you have an idea or code that you want to contribute, feel free to open an issue or a pull request and we will gladly review it. For more details see [CONTRIBUTING.md]
You can assess code coverage by running npm run coverage
.
Contributions are awesome! If you have an idea or code that you want to contribute, feel free to open an issue or a pull request and we will gladly review it.
The library is post-1.0 now, so there is backward compatibility and future maintainability to consider. If you are adding functionality, you can also write a plugin and add a link here.
IcedFrisby is maintained by:
IcedFrisby was originally based on the Frisby project.
4.0.0
FAQs
API testing made easy, fast, and fun
We found that icedfrisby demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers 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
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.