-
-
Notifications
You must be signed in to change notification settings - Fork 318
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: migrate logger tests to vitest #6220
Conversation
import {expose} from "@chainsafe/threads/worker"; | ||
|
||
const parentPort = worker.parentPort; | ||
const workerData = worker.workerData as {logFilepath: string}; | ||
const workerData = worker.workerData; |
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.
Have to convert this TS file to JS as Worker
can only load the JS files. Earlier this was handled by runtime compilation with global node loader.
logger.restoreStubs(); | ||
expect(logger.getLogs()).deep.equals([output[format]]); | ||
|
||
expect((console as TestConsole)._stdout.write).toHaveBeenNthCalledWith(1, `${output[format]}\n`); |
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 last \n
added in expectation, which was earlier removed by stubLoggerForProcessStd
.
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## unstable #6220 +/- ##
=========================================
Coverage 84.46% 84.46%
=========================================
Files 177 177
Lines 14913 14913
Branches 909 909
=========================================
Hits 12596 12596
Misses 2294 2294
Partials 23 23 |
Performance Report✔️ no performance regression detected Full benchmark results
|
@@ -27,13 +25,13 @@ describe("Json helper", () => { | |||
|
|||
// Functions | |||
// eslint-disable-next-line @typescript-eslint/no-empty-function | |||
{id: "function", arg: function () {}, json: "function () { }"}, | |||
{id: "function", arg: function () {}, json: "function() {\n }"}, |
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 really get from where the line breaks are coming
Function toString() does not seem to add them
lodestar/packages/logger/src/utils/json.ts
Lines 25 to 26 in 2530fae
case "function": | |
return arg.toString(); |
See output
> (function() {}).toString()
'function() {}'
Or is this related to what you mentioned here #6220 (comment)?
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.
Yes, the stub earlier was removing the new line break from the output. As no source code is changed related to encoding, so reset assure it behaves it had been before.
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.
But I still don't get why there would be a new line in the middle of the function, what's adding that?
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.
When vitest
transpile the TS code to JS the esbuild/rollup
add a new line at the function definition, that translates to new line when we do the function.string()
.
const arg = function () {
};
console.log(arg.toString());
I could not find the direct fix tin the Rollup config for it, and fixing the test fixture is not destructive in this case, so left it like that.
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 also don't think it is worth to try and find a fix for it, just good to know why these new lines are there
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.
should this file be renamed now?
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.
Will remove it completely when migrate all the tests.
🎉 This PR is included in v1.14.0 🎉 |
* Migrate logger tests to vitest * Remove lint comment
Motivation
Consolidate the testing frameworks and migrate to vitest.
Description
Migrate
logger
tests to vitest.Steps to test or reproduce