Skip to content

Commit ebc204d

Browse files
committed
Refactor .npmrc
1 parent 182d90a commit ebc204d

File tree

3 files changed

+80
-70
lines changed

3 files changed

+80
-70
lines changed

.npmrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
package-lock=false
21
ignore-scripts=true
2+
package-lock=false

lib/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
2-
* @typedef {import('mdast').Nodes} Nodes
32
* @typedef {import('mdast').Definition} Definition
3+
* @typedef {import('mdast').Nodes} Nodes
44
*/
55

66
/**
@@ -35,7 +35,7 @@ export function definitions(tree) {
3535
throw new Error('mdast-util-definitions expected node')
3636
}
3737

38-
visit(tree, 'definition', (definition) => {
38+
visit(tree, 'definition', function (definition) {
3939
const id = clean(definition.identifier)
4040
if (id && !own.call(cache, id)) {
4141
cache[id] = definition

test.js

+77-67
Original file line numberDiff line numberDiff line change
@@ -8,88 +8,98 @@ import {fromMarkdown} from 'mdast-util-from-markdown'
88
import {definitions} from './index.js'
99
import * as mod from './index.js'
1010

11-
test('definitions', () => {
12-
assert.deepEqual(
13-
Object.keys(mod).sort(),
14-
['definitions'],
15-
'should expose the public api'
16-
)
11+
test('definitions', async function (t) {
12+
await t.test('should expose the public api', async function () {
13+
assert.deepEqual(Object.keys(mod).sort(), ['definitions'])
14+
})
1715

18-
assert.throws(
19-
() => {
16+
await t.test('should fail without node', async function () {
17+
assert.throws(function () {
2018
// @ts-expect-error runtime
2119
definitions()
22-
},
23-
/mdast-util-definitions expected node/,
24-
'should fail without node'
25-
)
20+
}, /mdast-util-definitions expected node/)
21+
})
2622

27-
assert.deepEqual(
28-
definitions(from('[example]: https://example.com "Example"'))('example'),
29-
{
30-
type: 'definition',
31-
identifier: 'example',
32-
label: 'example',
33-
title: 'Example',
34-
url: 'https://example.com',
35-
position: {
36-
start: {line: 1, column: 1, offset: 0},
37-
end: {line: 1, column: 41, offset: 40}
23+
await t.test('should return a definition', async function () {
24+
assert.deepEqual(
25+
definitions(from('[example]: https://example.com "Example"'))('example'),
26+
{
27+
type: 'definition',
28+
identifier: 'example',
29+
label: 'example',
30+
title: 'Example',
31+
url: 'https://example.com',
32+
position: {
33+
start: {line: 1, column: 1, offset: 0},
34+
end: {line: 1, column: 41, offset: 40}
35+
}
3836
}
39-
},
40-
'should return a definition'
41-
)
37+
)
38+
})
4239

43-
assert.equal(
44-
definitions(from('[example]: https://example.com "Example"'))('foo'),
45-
null,
46-
'should return null when not found'
47-
)
40+
await t.test('should return null when not found', async function () {
41+
assert.equal(
42+
definitions(from('[example]: https://example.com "Example"'))('foo'),
43+
null
44+
)
45+
})
4846

49-
assert.deepEqual(
50-
definitions(from('[__proto__]: https://proto.com "Proto"'))('__proto__'),
51-
{
52-
type: 'definition',
53-
identifier: '__proto__',
54-
label: '__proto__',
55-
title: 'Proto',
56-
url: 'https://proto.com',
57-
position: {
58-
start: {line: 1, column: 1, offset: 0},
59-
end: {line: 1, column: 39, offset: 38}
47+
await t.test('should work on weird identifiers', async function () {
48+
assert.deepEqual(
49+
definitions(from('[__proto__]: https://proto.com "Proto"'))('__proto__'),
50+
{
51+
type: 'definition',
52+
identifier: '__proto__',
53+
label: '__proto__',
54+
title: 'Proto',
55+
url: 'https://proto.com',
56+
position: {
57+
start: {line: 1, column: 1, offset: 0},
58+
end: {line: 1, column: 39, offset: 38}
59+
}
6060
}
61-
},
62-
'should work on weird identifiers'
63-
)
61+
)
62+
})
6463

65-
/* eslint-disable no-use-extend-native/no-use-extend-native */
66-
// @ts-expect-error: yes.
67-
// type-coverage:ignore-next-line
68-
assert.equal({}.type, undefined, 'should not polute the prototype')
69-
/* eslint-enable no-use-extend-native/no-use-extend-native */
64+
await t.test('should not polute the prototype', async function () {
65+
/* eslint-disable no-use-extend-native/no-use-extend-native */
66+
// @ts-expect-error: yes.
67+
// type-coverage:ignore-next-line
68+
assert.equal({}.type, undefined)
69+
/* eslint-enable no-use-extend-native/no-use-extend-native */
70+
})
7071

71-
assert.deepEqual(
72-
definitions(from('[__proto__]: https://proto.com "Proto"'))('toString'),
73-
null,
74-
'should work on weird identifiers when not found'
72+
await t.test(
73+
'should work on weird identifiers when not found',
74+
async function () {
75+
assert.deepEqual(
76+
definitions(from('[__proto__]: https://proto.com "Proto"'))('toString'),
77+
null
78+
)
79+
}
7580
)
7681

77-
const example = definitions(
78-
from('[example]: https://one.com\n[example]: https://two.com')
79-
)('example')
82+
await t.test(
83+
'should prefer the first of duplicate definitions',
84+
async function () {
85+
const example = definitions(
86+
from('[example]: https://one.com\n[example]: https://two.com')
87+
)('example')
8088

81-
assert.deepEqual(
82-
example && example.url,
83-
'https://one.com',
84-
'should prefer the first of duplicate definitions'
89+
assert.deepEqual(example && example.url, 'https://one.com')
90+
}
8591
)
8692

87-
assert.deepEqual(
88-
definitions(from('[example]: https://one.com\n[example]: https://two.com'))(
89-
''
90-
),
91-
null,
92-
'should not return something for a missing identifier'
93+
await t.test(
94+
'should not return something for a missing identifier',
95+
async function () {
96+
assert.deepEqual(
97+
definitions(
98+
from('[example]: https://one.com\n[example]: https://two.com')
99+
)(''),
100+
null
101+
)
102+
}
93103
)
94104
})
95105

0 commit comments

Comments
 (0)