Http Client include js file

I have some tests written in http client.

 

For example 

regression.http

GET {{ host }}/api/1.0/foo/bar

> foo/bar.js

foo/bar.js


var data = ...
var diffChecker = ...

client.test("Header", function () {
client.assert(response.status === 200, "Response status code should be 200");
client.assert(response.contentType.mimeType === "application/json", "Response content type should be application/json");
});

client.test("Whole response", function () {
var change = JSON.stringify(response.body) !== JSON.stringify(data);
if (change) {
var diff = diffChecker.map(response.body, data);
for (var key in diff) {
var value = diff[key];
if (value.hasOwnProperty('type') && value.type !== 'unchanged') {
client.log(value.path + ": " + "[" + value.values.new + "] should be [" + value.values.old + "]");
}
}
}
client.assert(!change, "different response");
});

The problem is that i have a lot of different endpoints stored in foo/*.js files but my code is exactly same except of data variable. 

 

Is there any way how to include some shared code ? or to inject data variable into > foo/bar.js

I have red documentation and tried Issue tracker as well but no luck so far.

Is anyone having same issue ? Did i get concept wrong ?

2 comments
Comment actions Permalink

You can use variables in requests, see https://www.jetbrains.com/help/phpstorm/http-client-in-product-code-editor.html#using_request_vars

If that doesn't work for you - please specify what part of your requests you would like to replace with a variable

 

0
Comment actions Permalink

Dmitry Tronin My problem is not a request but response validation. I am trying to validate response and for such purpose i am using object diffChecker and variable data

 

I have about 30 separated .js files which have almost the same content except for data variable.

 

I am looking fo a way how to cleanup these files in such a way that i have only one definition of diffChecker object in project 

0

Please sign in to leave a comment.