MCPcopy Index your code
hub / github.com/nodejs/node / loadLogFile

Function loadLogFile

deps/npm/test/lib/utils/log-file.js:43–79  ·  view source on GitHub ↗
(t, { buffer = [], mocks, testdir = {}, ...options } = {})

Source from the content-addressed store, hash-verified

41}
42
43const loadLogFile = async (t, { buffer = [], mocks, testdir = {}, ...options } = {}) => {
44 const root = t.testdir(testdir)
45
46 const MockLogFile = tmock(t, '{LIB}/utils/log-file.js', mocks)
47 const logFile = new MockLogFile(Object.keys(options).length ? options : undefined)
48
49 // Create a fake public method since there is not one on logFile anymore
50 logFile.log = (...b) => process.emit('log', ...b)
51 buffer.forEach((b) => logFile.log(...b))
52
53 const id = getId()
54 await logFile.load({ path: path.join(root, `${id}-`), ...options })
55
56 t.teardown(() => logFile.off())
57 return {
58 root,
59 logFile,
60 LogFile,
61 readLogs: async () => {
62 const logDir = await fs.readdir(root, { withFileTypes: true })
63 const logFiles = logDir
64 .filter(f => f.isFile())
65 .map((f) => path.join(root, f.name))
66 .filter((f) => _fs.existsSync(f))
67 return Promise.all(logFiles.map(async (f) => {
68 const content = await fs.readFile(f, 'utf8')
69 const rawLogs = content.split(os.EOL)
70 return {
71 filename: f,
72 content,
73 rawLogs,
74 logs: rawLogs.filter(Boolean),
75 }
76 }))
77 },
78 }
79}
80
81t.test('init', async t => {
82 const maxLogsPerFile = 10

Callers 1

log-file.jsFile · 0.85

Calls 15

tmockFunction · 0.85
getIdFunction · 0.85
allMethod · 0.80
keysMethod · 0.65
forEachMethod · 0.65
filterMethod · 0.65
mapMethod · 0.65
emitMethod · 0.45
logMethod · 0.45
loadMethod · 0.45
joinMethod · 0.45
offMethod · 0.45

Tested by

no test coverage detected