node/deps/npm/test/lib/utils/explain-eresolve.js
npm CLI robot 8c8e7e9e2c
deps: upgrade npm to 9.7.1
PR-URL: https://github.com/nodejs/node/pull/48378
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Luke Karrys <luke@lukekarrys.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
2023-06-08 12:24:49 +00:00

31 lines
1.2 KiB
JavaScript

const t = require('tap')
const { explain, report } = require('../../../lib/utils/explain-eresolve.js')
const cases = require('../../fixtures/eresolve-explanations.js')
t.test('basic', async t => {
const { Chalk } = await import('chalk')
const color = new Chalk({ level: 3 })
const noColor = new Chalk({ level: 0 })
for (const [name, expl] of Object.entries(cases)) {
// no sense storing the whole contents of each object in the snapshot
// we can trust that JSON.stringify still works just fine.
expl.toJSON = () => ({ name, json: true })
t.test(name, t => {
const colorReport = report(expl, color, noColor)
t.matchSnapshot(colorReport.explanation, 'report with color')
t.matchSnapshot(colorReport.file, 'report from color')
const noColorReport = report(expl, noColor, noColor)
t.matchSnapshot(noColorReport.explanation, 'report with no color')
t.equal(noColorReport.file, colorReport.file, 'same report written for object')
t.matchSnapshot(explain(expl, color, 2), 'explain with color, depth of 2')
t.matchSnapshot(explain(expl, noColor, 6), 'explain with no color, depth of 6')
t.end()
})
}
})