-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Expand file tree
/
Copy pathtest-descriptions.test.js
More file actions
153 lines (134 loc) · 4.29 KB
/
test-descriptions.test.js
File metadata and controls
153 lines (134 loc) · 4.29 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
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/* This file is a part of @mdn/browser-compat-data
* See LICENSE file for more information. */
/** @import {CompatStatement} from '../../types/types.js' */
/** @import {DescriptionError} from './test-descriptions.js' */
import assert from 'node:assert/strict';
import { processData } from './test-descriptions.js';
describe('test-descriptions', () => {
describe('API data', () => {
it('should ignore anything that is not an interface subfeature', () => {
const path = 'api.Interface.feature.subfeature';
/** @type {CompatStatement} */
const data = {
support: {},
};
const errors = processData(data, 'api', path);
assert.equal(errors.length, 0);
});
it('should check description for constructor', () => {
const path = 'api.Interface.Interface';
/** @type {CompatStatement} */
const data = {
description: '',
support: {},
};
const errors = processData(data, 'api', path);
assert.equal(errors.length, 1);
assert.equal(
/** @type {DescriptionError} */ (errors[0]).ruleName,
'constructor',
);
});
it('should check description for event', () => {
const path = 'api.Interface.click_event';
/** @type {CompatStatement} */
const data = {
description: '',
support: {},
};
const errors = processData(data, 'api', path);
assert.equal(errors.length, 1);
assert.equal(
/** @type {DescriptionError} */ (errors[0]).ruleName,
'event',
);
});
it('should check description for permission', () => {
const path = 'api.Interface.geolocation_permission';
/** @type {CompatStatement} */
const data = {
description: '',
support: {},
};
const errors = processData(data, 'api', path);
assert.equal(errors.length, 1);
assert.equal(
/** @type {DescriptionError} */ (errors[0]).ruleName,
'permission',
);
});
it('should check description for secure context required', () => {
const path = 'api.Interface.secure_context_required';
/** @type {CompatStatement} */
const data = {
description: '',
support: {},
};
const errors = processData(data, 'api', path);
assert.equal(errors.length, 1);
assert.equal(
/** @type {DescriptionError} */ (errors[0]).ruleName,
'secure context required',
);
});
it('should check description for worker support', () => {
const path = 'api.Interface.worker_support';
/** @type {CompatStatement} */
const data = {
description: '',
support: {},
};
const errors = processData(data, 'api', path);
assert.equal(errors.length, 1);
assert.equal(
/** @type {DescriptionError} */ (errors[0]).ruleName,
'worker',
);
});
it('should check for redundant description', () => {
const path = 'css.properties.width.auto';
/** @type {CompatStatement} */
const data = {
description: '`auto`',
support: {},
};
const errors = processData(data, 'css', path);
assert.equal(errors.length, 1);
});
});
describe('HTML in descriptions', () => {
it('flags <code> tags as no_code_tag_in_description', () => {
/** @type {CompatStatement} */
const data = {
description: '<code>transient_attachment</code> usage',
support: {},
};
const errors = processData(data, 'api', 'api.Foo.bar');
const err = /** @type {DescriptionError} */ (
errors.find(
(e) =>
typeof e !== 'string' &&
e.ruleName === 'no_code_tag_in_description',
)
);
assert.ok(err);
assert.equal(err.actual, '<code>transient_attachment</code> usage');
assert.equal(err.expected, '`transient_attachment` usage');
});
it('does not flag descriptions without HTML', () => {
/** @type {CompatStatement} */
const data = {
description: '`transient_attachment` usage',
support: {},
};
const errors = processData(data, 'api', 'api.Foo.bar');
assert.ok(
!errors.some(
(e) =>
typeof e !== 'string' &&
e.ruleName === 'no_code_tag_in_description',
),
);
});
});
});