-
Notifications
You must be signed in to change notification settings - Fork 1.8k
chore: migrate test runner from mocha to jest #2567
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
base: master
Are you sure you want to change the base?
Conversation
4e45ba7
to
dead87b
Compare
Appreciate the effort but this is not the direction the project is interested in going. Similar PRs that consider tap or the built-in node.js test runner would be considered. Thanks! |
Philosophically I am a minimalist w.r.t. software design patterns & API surfaces (see: Robustness principal, also known as "Postel's law"). This philosophy is deeply embedded into the history & design of Node.js itself. That said, those values must be balanced carefully with those that value volunteers like yourself @maverick1872 who step up to help in Keeping Important Code Alive, [SeattleJS 2015] Before tools like I realized this morning that This would have taken weeks if not months in the past. All of this taken together has leads me to retract my previous objections @maverick1872 as long as we have a shared understanding as maintainers that we may revisit this decision in the future as it is now relatively trivial to accomplish. |
6a4aac7
to
10dcb6d
Compare
@indexzero @DABH do either of you know if coveralls can inform you as to where the coverage decrease occurred? Looks like it's most likely a byproduct of the consolidation of the File Transport tests. Happy to just undo the refactor but figured consolidation would ease some maintenance and clarity of what the tests are doing. |
@maverick1872 Yeah just click the three dots next to the coverage/coveralls line in the little PR check area on this page and then click View Details. It should take you to the Coveralls site which lists individual files and their coverage changes you can look at. Thank you so much for the attention to detail here. Feel free to @ me when the PR is ready for review :) |
jest intercepts stderr and pipes it to stdout. As such this test needed to make it's assertions on that of console.error invocations instead. Practically speaking these tests shouldn't even be necessary as this repo no longer maintains the transport implementations.
Previously the exception handler tests were written in a way that a child node process was spawned by invoking a script that would throw an unhandled exception. This exception would invoke the exception handler and result in an invocation of `process.exit()`. Because of this these lines weren't being included in the coverage report resulting in what appeared to be a coverage regression. I opted to refactor the implementation to hopefully clarify what is being tested and how. The helpers while useful for the implementation, added a level of obfuscation that did not make it immediately obvious what the test did exactly.
… node version or not
6d550d8
to
926ec37
Compare
@DABH @indexzero feel free to review when/if desired. I know it's large so I would advocate looking to the summary in the PR description which should hopefully make it clear what all has been done. Happy to have a more involved discussion/provide reasoning on any of my choices if desired. |
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.
Pull Request Overview
This PR migrates Winston's test suite from Mocha to Jest, modernizing the testing infrastructure to provide enhanced testing capabilities and improved developer experience.
- Converted all test files from Mocha syntax (
before
,after
,this.timeout()
) to Jest equivalents (beforeAll
,afterAll
,jest.setTimeout()
) - Consolidated redundant file transport tests into a single comprehensive test file with improved organization
- Updated CI configuration and documentation to reflect the new Jest-based testing approach
Reviewed Changes
Copilot reviewed 36 out of 38 changed files in this pull request and generated 4 comments.
Show a summary per file
File | Description |
---|---|
test/unit/winston/winston.test.js |
New comprehensive test file moved from integration, testing Winston's public API |
test/unit/winston/transports/file.test.js |
Consolidated and modernized file transport tests with comprehensive coverage |
test/unit/winston/transports/http.test.js |
Updated timeout syntax for Jest compatibility |
test/unit/winston/logger.test.js |
Enhanced with new test cases and Jest-compatible error handling |
test/unit/winston/log-exception.test.js |
Modernized exception handling tests with async/await patterns |
package.json |
Updated dependencies and scripts to use Jest instead of Mocha |
.github/workflows/ci.yml |
Updated CI pipeline for Jest-based testing workflow |
Comments suppressed due to low confidence (4)
test/unit/winston/winston.test.js:24
- [nitpick] The parameter name 'opts' is ambiguous. Consider renaming to 'options' for better clarity.
});
npm run test:test # Runs all integration tests | ||
npm run test:test # Runs all integration tests |
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.
The command 'npm run test:test' appears to be incorrect. Based on the package.json scripts, it should be 'npm run test:integration'.
npm run test:test # Runs all integration tests | |
npm run test:test # Runs all integration tests | |
npm run test:integration # Runs all integration tests | |
npm run test:integration # Runs all integration tests |
Copilot uses AI. Check for mistakes.
npm test # Runs all tests | ||
npm run test:unit # Runs all Unit tests with coverage | ||
npm run test:test # Runs all integration tests | ||
npm run test:test # Runs all integration tests |
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.
This line is duplicated and contains the same incorrect command as the previous line.
npm run test:test # Runs all integration tests |
Copilot uses AI. Check for mistakes.
npm run test:unit # Runs all Unit tests with coverage | ||
npm run test:test # Runs all integration tests | ||
npm run test:test # Runs all integration tests | ||
npm run typescript:test # Runs tests verifying Typescript types |
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.
The command 'npm run typescript:test' is incorrect. Based on the package.json scripts, it should be 'npm run test:typescript'.
npm run typescript:test # Runs tests verifying Typescript types | |
npm run test:typescript # Runs tests verifying Typescript types |
Copilot uses AI. Check for mistakes.
``` | ||
|
||
All of the winston tests are written with [`jest`][jest]. Assertions use a mix of [`assume`][assume] and the built-in jest assertion library. |
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.
The documentation references a '[jest]' link that is not defined at the bottom of the document, unlike the other reference links.
Copilot uses AI. Check for mistakes.
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'm ok with this once you've appeased Copilot's comments. Thanks again for your efforts here!
[Chris Alderson]: https://github.com/chrisalderson |
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.
Feel free to add yourself ;)
Migrate Winston Test Suite from Mocha to Jest
This PR fully migrates Winston's test suite from Mocha to Jest to provide a more fully featured testing framework
Warning
The File Transport tests while passing in their current form, illustrate in my opinion
some potential issues in how it currently functions.
FIX:
comments on a couple of assertions that I presume are correct but are currently failing.maxsize
andlazy
options result in behavior I found unexpected. e.g. If the rotation is not lazy, it will drop a log file resulting in 1 less populated log file than I would expectSummary
before()
,after()
,this.timeout()
tobeforeAll()
,afterAll()
, andjest.setTimeout()
winston.test.js
fromintegration
tounit
. This felt more appropriate given the contents of the test.console.error
integration
suite given they're actually writing files to the FS.Test Plan