2021-02-13 02:41:45 +07:00
|
|
|
import * as util from "util"
|
2021-02-01 23:06:49 +07:00
|
|
|
import * as wtfnode from "wtfnode"
|
|
|
|
|
2021-02-13 02:41:45 +07:00
|
|
|
// Jest seems to hijack console.log in a way that makes the output difficult to
|
|
|
|
// read. So we'll write directly to process.stderr instead.
|
|
|
|
const write = (...args: [any, ...any]) => {
|
|
|
|
if (args.length > 0) {
|
|
|
|
process.stderr.write(util.format(...args) + "\n")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
wtfnode.setLogger("info", write)
|
|
|
|
wtfnode.setLogger("warn", write)
|
|
|
|
wtfnode.setLogger("error", write)
|
|
|
|
|
2021-02-01 23:06:49 +07:00
|
|
|
let active = false
|
|
|
|
|
2021-02-13 02:41:45 +07:00
|
|
|
/**
|
|
|
|
* Start logging open handles periodically. This can be used to see what is
|
|
|
|
* hanging open if anything.
|
|
|
|
*/
|
2021-02-01 23:06:49 +07:00
|
|
|
export function setup(): void {
|
|
|
|
if (active) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
active = true
|
|
|
|
|
|
|
|
const interval = 5000
|
|
|
|
const wtfnodeDump = () => {
|
|
|
|
wtfnode.dump()
|
|
|
|
const t = setTimeout(wtfnodeDump, interval)
|
|
|
|
t.unref()
|
|
|
|
}
|
|
|
|
const t = setTimeout(wtfnodeDump, interval)
|
|
|
|
t.unref()
|
|
|
|
}
|