-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathslugger.test.mjs
More file actions
63 lines (54 loc) · 2.03 KB
/
slugger.test.mjs
File metadata and controls
63 lines (54 loc) · 2.03 KB
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
'use strict';
import assert from 'node:assert/strict';
import { describe, it } from 'node:test';
import { createLegacySlugger } from '../slugger.mjs';
describe('createLegacySlugger', () => {
it('prefixes with api stem and uses underscores', () => {
const getLegacySlug = createLegacySlugger();
assert.strictEqual(getLegacySlug('File System', 'fs'), 'fs_file_system');
});
it('replaces special characters with underscores', () => {
const getLegacySlug = createLegacySlugger();
assert.strictEqual(
getLegacySlug('fs.readFile(path)', 'fs'),
'fs_fs_readfile_path'
);
});
it('strips leading and trailing underscores', () => {
const getLegacySlug = createLegacySlugger();
assert.strictEqual(getLegacySlug('Hello', 'fs'), 'fs_hello');
});
it('prefixes with underscore when result starts with non-alpha', () => {
const getLegacySlug = createLegacySlugger();
assert.strictEqual(getLegacySlug('123 test', '0num'), '_0num_123_test');
});
it('deduplicates with a counter for identical titles', () => {
const getLegacySlug = createLegacySlugger();
assert.strictEqual(getLegacySlug('Hello', 'fs'), 'fs_hello');
assert.strictEqual(getLegacySlug('Hello', 'fs'), 'fs_hello_1');
assert.strictEqual(getLegacySlug('Hello', 'fs'), 'fs_hello_2');
assert.strictEqual(getLegacySlug('World', 'fs'), 'fs_world');
});
describe('deprecation headings', () => {
it('returns the DEP code for a deprecation heading', () => {
const getLegacySlug = createLegacySlugger();
assert.strictEqual(
getLegacySlug(
'DEP0001: `http.OutgoingMessage.prototype.flush`',
'deprecations'
),
'DEP0001'
);
});
it('returns the DEP code regardless of the description text', () => {
const getLegacySlug = createLegacySlugger();
assert.strictEqual(
getLegacySlug(
'DEP0190: spawning .bat and .cmd files with child_process.spawn() with shell option',
'deprecations'
),
'DEP0190'
);
});
});
});