-
Notifications
You must be signed in to change notification settings - Fork 1
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
fix: use native strictEqual for the internal asserts #16
Conversation
58fe3b6
to
2b999df
Compare
@mcollina can you please review it? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand the original issue. Why would this function use a different assertion library than the one provided?
Currently, if you want to use a custom assertion callback, you have to worry about the internals of the Let me show an example. // index.js
const crypto = require('node:crypto')
function businessLogic(loggerInstance) {
loggerInstance.info({
uuid: crypto.randomUUID(),
foo: 'bar',
baz: 'buz',
})
}
module.exports = businessLogic // test.js
const {test} = require('node:test')
const assert = require('node:assert')
const pino = require('pino')
const pinoTest = require('pino-test')
const businessLogic = require('./index')
test('should log a random generated uuid', async () => {
const stream = pinoTest.sink();
const loggerInstance = pino(stream);
businessLogic(loggerInstance);
const expected = {
foo: 'bar',
baz: 'buz',
}
await pinoTest.once(stream, expected, (actual, expected) => {
assert.ok(/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/.test(actual.uuid))
assert.strictEqual(actual.foo, expected.foo)
assert.strictEqual(actual.baz, expected.baz)
})
}) The test will fail because the custom callback will be called 4 times by the internal So if you want to do this kind of custom assert, you have to complicate the callback in an inappropriate way: await pinoTest.once(stream, expected, (actual, expected) => {
if (actual.uuid) {
assert.ok(/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/.test(actual.uuid))
assert.strictEqual(actual.foo, expected.foo)
assert.strictEqual(actual.baz, expected.baz)
}
}) |
I would say that is due to your "custom callback" not actually being an "assert" function as Lines 47 to 64 in c0bb52c
|
Yes, both the documentation and the type should be changed. In my opinion, it is a use case that should be allowed by the library, so I would rethink the |
I think that is a major change and that the library probably shouldn't have been released at v1.0.0. |
@jsumners My latest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
@jsumners PTAL |
(wrong button, sorry) |
Closes #13