![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
assert-responselike
Advanced tools
An ultra simple all-test-framework friendly utility, meant to be used with the test framework of your choice, decorates the built-in assert object with a new method responseLike(res,exp,msg)
This is an ultra simple all-test-framework friendly utility, meant to be used with the test framework of your choice, decorates the built-in assert object with a new method responseLike(res,exp,msg)
usage :
var assert = require("assert");
, request = require('your favorite http request lib')
, test = require('your favorite test function of your favorite framework')
;
require("assert-responselike");
test( "foo", function() {
request(url, function(response){
assert.responseLike( response
, { status : 200 //throws 'Invalid response code - expected ... got ...'
, statusCode : 200 //same like status, for the explicitness lovers..
, headers :
{ "Content-Type" : "text/plain" //throws 'response-header - expected ... got ...'
}
, body : "run vows for full spec" //throws 'Invalid response body - expected ... got ...'
}
);
});
});
using NPM
npm install assert-responselike
esample of output:
D:\work\mymodule>npm install assert-responselike
npm http GET https://registry.npmjs.org/assert-responselike
npm http 304 https://registry.npmjs.org/assert-responselike
assert-responselike@0.2.0 ./node_modules/assert-responselike
Do it yourself
download the zip from github, and extract it to your ./node_modules/ directory.
example of structure Either way - expect the following:
└───node_modules
└───assert-responselike
│ .npmignore
│ index.js
│ package.json
│ README.md
│
└───test
assert-response-test.js
after extracting first you have to :
npm install
esample of output:
D:\work\assert-responseLike>npm install
npm http GET https://registry.npmjs.org/vows
npm http 304 https://registry.npmjs.org/vows
npm http GET https://registry.npmjs.org/eyes
npm http 304 https://registry.npmjs.org/eyes
npm WARN eyes@0.1.7 dependencies field should be hash of <name>:<version-range> pairs
vows@0.6.3 ./node_modules/vows
└── eyes@0.1.7
and then vows --spec
node ./node_modules/vows/bin/vows --spec
? assert response
API
√ assert should be decorated with the method:
assert.responseLike ( oActualResponse, oExpectedDescr, sCustomMessage )
check status code with attribute 'status'
√ providing correct numner should work
√ providing wrong number should throw
check status code with attribute 'statusCode'
√ providing correct number should work
√ providing wrong number should throw
check response headers
√ providing existing headers should work - case insensitive
√ providing wrong headers throw on the first mismatch
√ providing missing headers throw on the first misfound
check response body
√ regexp body descriptor that matches should not throw
√ regexp body descriptor that does not match should throw
√ when descriptor is not a RegExp, and body is object - deep equal match should not throw
√ when descriptor is not a RegExp, and body is object - deep equal difference should throw
check response headers - provide expected content
√ equal string - should pass
√ different string - should throw
√ matching regexp - should pass
√ non-matching regexp - should throw
thrown errors - when providing a message
√ should trail status-code error messages
√ should trail response-header error messages
√ should trail response-body error messages
thrown errors - a status-code check error message
√ should start with 'Invalid response status code'
√ should contain the expected response code
√ should contain the actual response code
thrown errors - a missing response-header check error message
√ should start with 'response header'
√ should contain the expected response header name
√ should contain the expected response header value
√ should contain the actual response value
thrown errors - a mismatching response-header check error message
√ should start with 'response header'
√ should contain the expected response header name
√ should contain the expected response header value
√ should contain the actual response value
√ OK » 30 honored (0.183s)
It's not the most genious utility or anything, it is meant to be my first git hub project. I use it to test responses of web-requests to web projects, with vows.
The basis of the implementation is taken from from expresso, that did not work well for me on windows, and the implementation there is coupled with the request firing itself - and I did not like that. so now I can use the same assert description language with any test-framework i like, and use whatever request tools I want.
I don't know what i need to do to make it officual under whatever lisence is up there... I took from 'the community' so I give back. Take it, as is, I give no warantee. Do with it whatever you want on your own responsibility.
FAQs
An ultra simple all-test-framework friendly utility, meant to be used with the test framework of your choice, decorates the built-in assert object with a new method responseLike(res,exp,msg)
The npm package assert-responselike receives a total of 2 weekly downloads. As such, assert-responselike popularity was classified as not popular.
We found that assert-responselike demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 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
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.