Skip to content
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

The function check does some internal assertions using the assert function it receives as parameter #13

Open
gerardo-lima-moonfare opened this issue Jun 4, 2024 · 1 comment

Comments

@gerardo-lima-moonfare
Copy link

The enclosed function check uses the same assert function it receives as parameter to do some internal checks on time, pid and hostname. It is unnecessary to use default assert function (deepStrictEqual) to check on these values and this behaviour also makes it hard to create assessments on properties -- ie: when chunkCopy must contain some property foo, we also have to account for the time, pid and hostname.

function check (chunk, expected, assert) {

My suggestion is to to use standard strictEqual on the internal checks and only use the assert function parameter on the payload (chunkCopy), itself. This is a suggestion of implementation:

function check (chunk, expected, assert) {
  const { time, pid, hostname, ...chunkCopy } = chunk

  // internal assertions (*)
  nodeAssert.strictEqual(new Date(time) <= new Date(), true, 'time is greater than Date.now()')
  nodeAssert.strictEqual(pid, process.pid)
  nodeAssert.strictEqual(hostname, os.hostname())

  // "consumer" assertion
  assert(chunkCopy, expected)
}

PS: on a side note, I'm not sure whether it's actually useful to run these internal assertions each time a consumer asserts on their logs, but maybe I'm missing something here

@mcollina
Copy link
Member

mcollina commented Jun 9, 2024

Thanks for reporting! Would you like to send a Pull Request to address this issue? Remember to add unit tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants