-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
test.js
66 lines (59 loc) · 1.72 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import assert from 'node:assert/strict'
import path from 'node:path'
import process from 'node:process'
import test from 'node:test'
import {VFile} from 'vfile'
import symbols from 'log-symbols'
import chalk from 'chalk'
import {reporterPretty} from 'vfile-reporter-pretty'
// https://github.com/sindresorhus/eslint-formatter-pretty/blob/159b30a/index.js#L90-L93
const cwd = process.env.CI ? '' : `\u001B]50;CurrentDir=${process.cwd()}\u0007`
test('reporterPretty', async function () {
assert.deepEqual(
Object.keys(await import('vfile-reporter-pretty')).sort(),
['default', 'reporterPretty'],
'should expose the public api'
)
const fp = path.join('~', 'example.md')
const file = new VFile({path: fp})
file.info('This is perfect', {line: 5, column: 3}, 'alpha:bravo')
file.message('This should be fixed', {
start: {line: 3, column: 5},
end: {line: 3, column: 7}
})
try {
file.fail('This is horrible', {
place: {
start: {line: 2, column: 1},
end: {line: 2, column: 8}
}
})
} catch {}
assert.equal(
reporterPretty([file]),
[
'',
cwd + ' ' + chalk.underline(fp) + chalk.hidden.dim.gray(':2:1'),
' ' +
symbols.warning +
' ' +
chalk.dim('3' + chalk.gray(':') + '5') +
' This should be fixed ',
' ' +
symbols.warning +
' ' +
chalk.dim('5' + chalk.gray(':') + '3') +
' This is perfect ' +
chalk.dim('alpha:bravo'),
' ' +
symbols.error +
' ' +
chalk.dim('2' + chalk.gray(':') + '1') +
' This is horrible ',
'',
' ' + chalk.yellow('2 warnings'),
' ' + chalk.red('1 error'),
''
].join('\n')
)
})