-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
proposal for a simpler check() API #1066
Comments
I think allowing grouping multiple checks is a nice API for some cases. let defaultReqChecks = {
"status is 200": (r) => r.status === 200,
"duration under 150ms": (r) => r.timings.duration <= 150
"duration under 200ms": (r) => r.timings.duration <= 200
}
.....
let r1 = http.post(`https://example.com/auth/login`, { username: 'user', password: 'pass!'});
check(r1, defaultReqChecks);
.....
let r2 = http.get(`https://example.com/account/items`);
check(r2, defaultReqChecks); But I think the current API could not be very intuitive for newcomers. For me, check(r.status === 200, "status is 200");
check(r.body.length === 1176, "body is 1176 bytes");
// even without check title
check(r.status === 200);
if (check(r.status === 200 && res.data)) {
// check the data here
} I would like |
I agree that the current I personally prefer Edit:
Glad to see we're on the same page 👍 😀 |
To take the assertion similarities one step further, it seems to me that there might be a very valid use case for Actually, AFAIK, I think that "assert"-like constructs frequently abort the program execution when their condition isn't satisfied, but not always. For example, the Go testify library we use in k6 has two main modules: assert and require. Both have the same helper check functions, but the I'm not sure what the best UX here is... Should |
Adding a note here for a minor technical detail that I don't think will be an issue, but it would be best if we benchmark, just in case... We'd be switching from a single |
I think we are discussing a few related issues and each one might deserve its own issue. 1 - Should the check API provide an additional syntax to use it? For this type of API changes that cannot be iterated without introducing breaking change, we have discussed that an option could be to provide different module/namespaces for the new API. From example: import check from `k6/check`
or
import { check } from `k6/latest` This could allow showing deprecation messages for the previous API until the new API becomes the standard. 2 - Should the check API provide an option to exit the iteration if the condition fails?
I think there is also a need of having an API to exit the iteration and the It's fine for me if
if (!res.status === 200) {
exit();
}
// or
if (check(res.status === 200)) {
...
} else {
exit();
} 3 - The conversion brought up the question if |
I think that would be needlessly very confusing...
As you've mentioned above, the current
But we already have that -
But |
I think the batch checks are unnecessarily confusing when the batch uses more than one response. See example. (note the first argument to const delRes = http.del("https://test-api.loadimpact.com/my/crocodiles/23/");
const getRes = http.get("https://test-api.loadimpact.com/my/crocodiles/23/");
const isSuccessfulDelete = check(null, {
'croc was deleted': () => delRes.status === 204,
"deleted croc can't be retrieved": () => getRes.status === 404,
}); I needed to use two different variables in this batch:
The proposed new check() function would not have this issue. |
I agree, and I fully support a new simpler function, we just have to agree on a name and semantics for it 😉 ... And why I see how your particular example can be a bit annoying, if it was a real Or in your case, as you didn't use a batch, you could have passed |
If we want to align with popular js testing frameworks, we could consider going for expect(someExpression).toEqual(someValue);
expect(someExpression).toBeTruthy();
expect(someInt).toBeGreaterThan(3);
expect(somethingVoid).not.toBeDefined(); Adding labels to this could be done using another function chain, like: expect(something).toBe(something).applyLabel('some string');
// or, as is common in js testing frameworks:
it('should something', () => {
expect(something).toBe(something);
expect(somethingElse).toBe(somethingElse);
}); |
The team discussed this during our backlog review, and we decided to close this issue in favor of a newer one once we have had the opportunity to reevaluate the product aspects of the checks API. Feel free to reopen this down the road if you stumble upon this and with have failed to do so ☝🏻 |
The current
check()
API seems to be unnecessarily complex and lengthy.Consider an example:
It seems unnecessary to require an object of arrow functions to make a simple check.
A simpler solution would be to write it this way:
Even for batch checks, this format is less readable for me. Example:
and alternative:
IMO multiple checks are more readable, than an object of arrow functions.
The text was updated successfully, but these errors were encountered: