-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.js
80 lines (69 loc) · 3.13 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
import assert from 'node:assert/strict'
import test from 'node:test'
import {toVFile} from 'to-vfile'
import {is} from 'vfile-is'
test('is', async function () {
assert.deepEqual(
Object.keys(await import('vfile-is')).sort(),
['convert', 'is'],
'should expose the public api'
)
const empty = null
const file = toVFile()
const index = toVFile('index.js')
const gitignore = toVFile('.gitignore')
const readme = toVFile('readme.md')
assert.ok(is(file), 'should support a missing test on a file')
assert.ok(!is(empty), 'should support a missing test with nothing')
assert.ok(is(index, 'index.js'), 'should support a basename (#1)')
assert.ok(!is(file, 'index.js'), 'should support a basename (#2)')
assert.ok(is(index, '.js'), 'should support a extname (#1)')
assert.ok(!is(index, '.md'), 'should support a extname (#2)')
assert.ok(is(gitignore, '.gitignore'), 'should support a dotfile (#1)')
assert.ok(
!is(toVFile('.gitignore'), '.npmrc'),
'should support a dotfile (#2)'
)
assert.ok(is(index, '*.js'), 'should support a glob (#1)')
assert.ok(!is(index, '*.md'), 'should support a glob (#2)')
assert.ok(is(index, '*.{js,jsx}'), 'should support a glob (#3)')
assert.ok(!is(readme, '*.{js,jsx}'), 'should support a glob (#4)')
assert.ok(is(index, isIndex), 'should support a function (#1)')
assert.ok(!is(empty, isIndex), 'should support a function (#2)')
assert.ok(!is(readme, isIndex), 'should support a function (#3)')
assert.ok(is(index, {stem: 'index'}), 'should support a spec (#1)')
assert.ok(!is(empty, {stem: 'index'}), 'should support a spec (#2)')
assert.ok(!is(readme, {stem: 'index'}), 'should support a spec (#3)')
assert.ok(is(readme, {stem: {prefix: 're'}}), 'should support a spec (#4)')
assert.ok(is(readme, {stem: {suffix: 'me'}}), 'should support a spec (#5)')
assert.ok(!is(readme, {stem: {prefix: 'in'}}), 'should support a spec (#6)')
assert.ok(!is(readme, {stem: {suffix: 'ex'}}), 'should support a spec (#7)')
assert.ok(!is(readme, {missing: true}), 'should support a spec (#8)')
assert.ok(is(readme, {stem: true}), 'should support a spec (#9)')
assert.ok(is(readme, {missing: false}), 'should support a spec (#10)')
assert.ok(!is(readme, {stem: false}), 'should support a spec (#11)')
assert.ok(is(readme, {stem: null}), 'should ignore nullish specs')
assert.throws(
function () {
// @ts-expect-error check that this is an error at runtime.
is(readme, {stem: 1})
},
/^Error: Invalid spec `1`, expected `boolean`, `string`, or `object`/,
'should throw on invalid specs'
)
assert.ok(!is(null, ['.js', 'index.js']), 'should support a list (#1)')
assert.ok(is(index, ['.js', 'index.js']), 'should support a list (#2)')
assert.ok(!is(readme, ['.js', 'index.js']), 'should support a list (#3)')
assert.throws(
function () {
// @ts-expect-error check that this is an error at runtime.
is(readme, 1)
},
/^Error: Expected function, string, array, or object as test/,
'should throw on invalid specs'
)
/** @type {import('./index.js').CheckFile} */
function isIndex(file) {
return file.stem === 'index'
}
})