-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
refactor: replace mocha
with node:test
#1697
Conversation
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.
good job! tests are failing
Codecov ReportPatch coverage has no change and project coverage change:
Additional details and impacted files@@ Coverage Diff @@
## main #1697 +/- ##
==========================================
+ Coverage 81.00% 81.03% +0.03%
==========================================
Files 21 21
Lines 1369 1366 -3
Branches 324 323 -1
==========================================
- Hits 1109 1107 -2
+ Misses 183 182 -1
Partials 77 77 ☔ View full report in Codecov by Sentry. |
@mcollina Tests are working now BTW them are much slower then before A possible way to improve this would be to enable parallel tests. Problem is that abstract_client tests is used in multiple test files and it setup some servers that listen on a port (so this will end up with port conflict). I would like to know if there is a way using process.pid or else to shift ports so there are no conflicts. Otherwise we should use a package to get the first free open port every time listen is called |
Indeed. Avoiding reusing those broker instances will fix a lot of the flakyness. It's expected that the tests will take longer. As you said, the solution is to enable parallel testing and use different ports. |
@mcollina Curious thing, seems the internal types of Expected (based on types): beforeEach((done) => {
build((err, _store) => {
store = _store
done(err)
})
}) Correct: // eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
beforeEach((_ctx, done) => {
build((err, _store) => {
store = _store
done(err)
})
}) same for |
@mcollina I tried multiple approaches when running tests. The first was by using import { readdirSync } from 'node:fs'
import { run } from 'node:test'
import process from 'node:process'
import { tap } from 'node:test/reporters'
import { basename } from 'node:path'
const files = readdirSync(__dirname)
.filter((f) => f.endsWith('.ts') && f !== basename(__filename))
.map((f) => `${__dirname}/${f}`)
run({ files, timeout: 60 * 1000, concurrency: true })
.compose(tap)
.pipe(process.stdout) This runs the test concurrently but what I don't like is that if some test fail this is not reported at all, the test passes anyway as I think the exit code is 0 always, I'm not sure how to fix this, maybe by using a custom reporter? I also tried to use At the end I used another way to run test using It takes 37 seconds on my PC but in actions it still takes more then 2 minutes, dunno if you have any suggestion, it's now working with parallel test without any problem on my end but seems not enabling concurrency on github actions. Apart from this the PR is ready for review. |
I have been able to cut down time to ~2min. Don't know if we can do better here. |
mocha
with node:test
testStream.on('test:fail', (data) => { | ||
exitCode = 1 | ||
const error = data.details.error | ||
|
||
summary.push( | ||
`${data.file} - "${data.name}" (${Math.round( | ||
data.details.duration_ms, | ||
)}ms)\n${error.toString()} `, | ||
) | ||
}) | ||
|
||
testStream.on('test:stderr', (data) => { | ||
summary.push(`${data.file} - Error:\n${data.message} `) | ||
}) |
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.
Dunno why but the summary is missed when running tests using run
function. It is printed only when running test file directly with node or with --test
. Maybe it's a bug or I'm missing something, anyway I created my custom summary in this way, this is needed also to correct the exit code in case there are errors
* @param i Index to shift the ports by | ||
* @returns | ||
*/ | ||
export default function getPorts(i = 0) { |
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.
trick to be sure ports doesn't overlap, each file must use a different i
in order to work
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-expect-error | ||
beforeEach((_ctx, done) => { |
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 is the type error I mentioned above, use @ts-expect-error so in case this get fixed typescript will tell us
Ping @mcollina |
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
Fixes #1694
/cc @mcollina