-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
test.js
90 lines (85 loc) · 2.96 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import assert from 'node:assert/strict'
import test from 'node:test'
import {fileURLToPath} from 'node:url'
import {VFile} from 'vfile'
import {VFileMessage} from 'vfile-message'
import {compareFile, compareMessage} from 'vfile-sort'
test('core', async function () {
assert.deepEqual(
Object.keys(await import('vfile-sort')).sort(),
['compareFile', 'compareMessage'],
'should expose the public api'
)
})
test('compareMessage', async function () {
assert.deepEqual(
[
new VFileMessage('Hotel', {line: 0, column: 0}),
new VFileMessage('Foxtrot'),
new VFileMessage('Alpha', {line: 3, column: 0}),
new VFileMessage('Bravo', {line: 3, column: 1}),
new VFileMessage('Charlie', {line: 3, column: 2}),
new VFileMessage('Delta', {line: 0, column: 1}),
new VFileMessage('Echo', {line: 0, column: 1}),
new VFileMessage('Golf', {line: 0, column: 0}),
new VFileMessage('Golf', {line: 0, column: 0})
]
.sort(compareMessage)
.map(String),
[
'1:1: Foxtrot',
'1:1: Golf',
'1:1: Golf',
'1:1: Hotel',
'1:1: Delta',
'1:1: Echo',
'3:1: Alpha',
'3:1: Bravo',
'3:2: Charlie'
],
'should compare on line/column, reason'
)
const one = new VFileMessage('One', {line: 2, column: 5})
const two = new VFileMessage('Two', {line: 2, column: 5})
const three = new VFileMessage('Three', {line: 2, column: 5})
two.fatal = false
three.fatal = true
assert.deepEqual(
[one, two, three].sort(compareMessage).map(String),
['2:5: Three', '2:5: Two', '2:5: One'],
'should compare on `fatal`'
)
})
test('compareFile', async function () {
assert.deepEqual(
[
new VFile(),
new VFile(new URL(import.meta.url)),
new VFile(new URL('.', import.meta.url)),
new VFile(new URL('readme.md', import.meta.url)),
new VFile(new URL('.github/', import.meta.url)),
new VFile(new URL('.github/workflows/', import.meta.url)),
new VFile(new URL('.github/workflows/main.yml', import.meta.url)),
new VFile(new URL('node_modules', import.meta.url)),
new VFile(new URL('node_modules/', import.meta.url)),
new VFile(new URL('lib/', import.meta.url)),
new VFile(new URL('lib/index.js', import.meta.url))
]
.sort(compareFile)
.map((d) => d.path),
[
undefined,
fileURLToPath(new URL('.', import.meta.url)),
fileURLToPath(new URL('.github/', import.meta.url)),
fileURLToPath(new URL('.github/workflows/', import.meta.url)),
fileURLToPath(new URL('.github/workflows/main.yml', import.meta.url)),
fileURLToPath(new URL('lib/', import.meta.url)),
fileURLToPath(new URL('lib/index.js', import.meta.url)),
fileURLToPath(new URL('node_modules', import.meta.url)),
fileURLToPath(new URL('node_modules/', import.meta.url)),
fileURLToPath(new URL('readme.md', import.meta.url)),
fileURLToPath(new URL(import.meta.url))
],
'should compare on `path`'
)
})