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

test(logger): simplify unit tests structure #2942

Merged
merged 7 commits into from
Aug 19, 2024
Merged

Conversation

dreamorosi
Copy link
Contributor

@dreamorosi dreamorosi commented Aug 16, 2024

Summary

Changes

Please provide a summary of what's being changed

This PR aims at improving maintainability and lower the barrier of entry for working on the unit tests for the Logger feature.

Before working on this PR we had 310 unit test cases, many of which redundant, and most importantly the majority of the tests were organised in a single big file (Logger.test.ts) which after 3 yrs of work had grown to over 3K LOC.

As primary objective, the PR breaks down the big test file in smaller and more focused files. As a secondary objective, the PR also in many cases changed the test strategy to prioritize observing side effects (i.e. the log output) versus testing the internals of the Logger or its implementation details.

The result of this work is a new test suite with ~130 test cases and the same coverage level that is instead more interested in asserting that the logger actually logs things in the expect way rather than how its internals work.

With this new testing strategy, we are also enabling POWERTOOLS_DEV by default for all tests except one, which allows us to put spies on the global console object, and remove the behavior described in #2821.

In future PRs, once we have migrated this module to Vitest, I'll continue investing some time in further improving the tests by creating custom assertions that will allow us to cut even more boilerplate from the tests.

Please add the issue number below, if no issue is present the PR might get blocked and not be reviewed

Issue number: #2821


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

@dreamorosi dreamorosi self-assigned this Aug 16, 2024
@dreamorosi dreamorosi requested review from a team as code owners August 16, 2024 14:29
@boring-cyborg boring-cyborg bot added logger This item relates to the Logger Utility tests PRs that add or change tests labels Aug 16, 2024
@pull-request-size pull-request-size bot added the size/XXL PRs with 1K+ LOC, largely documentation related label Aug 16, 2024
@dreamorosi dreamorosi changed the title tests(logger): simplify unit tests structure test(logger): simplify unit tests structure Aug 16, 2024
Copy link
Contributor

@leandrodamascena leandrodamascena left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @dreamorosi! Just a few comments that don't impact the tests, but make it easier to read and understand.

APPROVED!

packages/logger/tests/unit/configFromEnv.test.ts Outdated Show resolved Hide resolved
packages/logger/tests/unit/injectLambdaContext.test.ts Outdated Show resolved Hide resolved
packages/logger/tests/unit/logEvent.test.ts Show resolved Hide resolved
packages/logger/tests/unit/logEvent.test.ts Show resolved Hide resolved
Copy link

@leandrodamascena leandrodamascena self-requested a review August 19, 2024 16:31
Copy link
Contributor

@leandrodamascena leandrodamascena left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

APPROVED!

@dreamorosi dreamorosi merged commit 28e7a67 into main Aug 19, 2024
11 checks passed
@dreamorosi dreamorosi deleted the tests/logger_simplify branch August 19, 2024 16:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
logger This item relates to the Logger Utility size/XXL PRs with 1K+ LOC, largely documentation related tests PRs that add or change tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Maintenance: refactor tests (or implementation) so that we can remove usage of literal keys in some tests
2 participants