-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Expand file tree
/
Copy pathmirror.test.js
More file actions
477 lines (434 loc) · 13.5 KB
/
mirror.test.js
File metadata and controls
477 lines (434 loc) · 13.5 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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
/* This file is a part of @mdn/browser-compat-data
* See LICENSE file for more information. */
/**
* @import { BrowserName } from '../../types/types.js'
* @import { InternalSupportBlock } from '../../types/index.js'
*/
import assert from 'node:assert/strict';
import bcd from '../../index.js';
import mirrorSupport, { isOSLimitation, updateNotes } from './mirror.js';
describe('mirror', () => {
describe('isOSLimitation', () => {
it('returns true for OS limitation notes', () => {
assert.equal(
isOSLimitation('Supported on ChromeOS, macOS, and Windows only.'),
true,
);
assert.equal(isOSLimitation('Supported on macOS only.'), true);
assert.equal(isOSLimitation('Not supported on Windows.'), true);
});
it('returns false for non-OS-limitation notes', () => {
assert.equal(
isOSLimitation('This feature requires a flag to be enabled.'),
false,
);
assert.equal(
isOSLimitation('Before version 70, this method always returned true.'),
false,
);
assert.equal(
isOSLimitation('Firefox 73 added support for this thing.'),
false,
);
});
it('returns false for empty string', () => {
assert.equal(isOSLimitation(''), false);
});
});
describe('default export', () => {
describe('version numbers match expected values', () => {
/** @type {{ [index in BrowserName]?: [string, string | boolean][] }} */
const mappings = {
chrome_android: [
['1', '18'],
['2', '18'],
['17', '18'],
['18', '18'],
['19', '25'],
['24', '25'],
['25', '25'],
['26', '26'],
],
edge: [
['1', '79'],
['27', '79'],
['28', '79'],
['78', '79'],
['79', '79'],
['80', '80'],
['90', '90'],
],
firefox_android: [
['1', '4'],
['2', '4'],
['3', '4'],
['4', '4'],
['68', '68'],
['69', '79'],
['79', '79'],
['80', '80'],
],
opera: [
['1', '15'],
['27', '15'],
['28', '15'],
['29', '16'],
['30', '17'],
],
opera_android: [
['18', '14'],
['26', '14'],
['27', '15'],
['28', '15'],
['29', '16'],
['30', '18'],
],
safari_ios: [
['1', '1'],
['1.1', '1'],
['1.2', '1'],
['1.3', '1'],
['2', '1'],
['3', '2'],
['3.1', '2'],
['4', '3.2'],
['5', '4.2'],
['5.1', '5'],
['6', '6'],
['7', '7'],
['8', '8'],
['9', '9'],
['9.1', '9.3'],
['10', '10'],
['10.1', '10.3'],
['11', '11'],
['11.1', '11.3'],
['12', '12'],
['12.1', '12.2'],
['13', '13'],
['13.1', '13.4'],
['14', '14'],
['14.1', '14.5'],
['15', '15'],
['15.1', '15.1'],
['15.2', '15.2'],
['15.3', '15.3'],
['15.4', '15.4'],
],
samsunginternet_android: [
['18', '1.0'],
['25', '1.5'],
['28', '1.5'],
['29', '2.0'],
['33', '2.0'],
['34', '2.0'],
['35', '3.0'],
['95', '17.0'],
],
webview_android: [
['18', '4.4'],
['25', '4.4'],
['26', '4.4'],
['27', '4.4'],
['28', '4.4'],
['29', '4.4'],
['30', '4.4'],
['31', '4.4.3'],
['32', '4.4.3'],
['33', '4.4.3'],
['34', '37'],
['35', '37'],
['36', '37'],
['37', '37'],
],
};
for (const [browser, versionMap] of Object.entries(mappings)) {
describe(browser, () => {
const upstream = bcd.browsers[browser].upstream;
for (const pair of versionMap) {
it(`${pair[0]} => ${pair[1]}`, () => {
const support = {
[upstream]: {
version_added: pair[0],
},
};
const mirrored = mirrorSupport(
/** @type {BrowserName} */ (browser),
support,
);
assert.deepEqual(mirrored, { version_added: pair[1] });
});
}
});
}
});
describe('updateNotes', () => {
/** @type {(string) => (string | false)} */
const versionMapper = (v) => (v === '99' ? false : String(Number(v) + 1));
const regex = /\bChrome\b/g;
it('notes with unmapped versions are filtered out', () => {
assert.equal(
updateNotes(
'Supported since Chrome 99.',
regex,
'Opera',
versionMapper,
),
null,
);
});
it('notes without version references are kept unchanged', () => {
assert.equal(
updateNotes(
'Supported on ChromeOS, macOS, and Windows.',
regex,
'Opera',
versionMapper,
),
'Supported on ChromeOS, macOS, and Windows.',
);
});
it('notes with mapped versions are updated', () => {
assert.equal(
updateNotes(
'Supported since Chrome 70.',
regex,
'Opera',
versionMapper,
),
'Supported since Opera 71.',
);
});
it('in an array, only notes with unmapped versions are filtered out', () => {
assert.deepEqual(
updateNotes(
[
'Supported on ChromeOS, macOS, and Windows.',
'Supported since Chrome 99.',
],
regex,
'Opera',
versionMapper,
),
'Supported on ChromeOS, macOS, and Windows.',
);
});
it('returns null when all array notes are filtered out', () => {
assert.equal(
updateNotes(
['Supported since Chrome 99.', 'Available since Chrome 99.'],
regex,
'Opera',
versionMapper,
),
null,
);
});
});
describe('Notes', () => {
it('version numbers in notes are mapped', () => {
/** @type {InternalSupportBlock} */
const support = {
chrome: {
version_added: '65',
notes: [
'Before Chrome 70, this method always returned `true` even if the webcam was not connected. Since version 70, this method correctly returns the webcam state.',
'Google Chrome will always use the default webcam.',
],
},
};
const mirrored = mirrorSupport('opera', support);
assert.deepEqual(mirrored, {
version_added: '52',
notes: [
'Before Opera 57, this method always returned `true` even if the webcam was not connected. Since version 57, this method correctly returns the webcam state.',
'Opera will always use the default webcam.',
],
});
});
it('Firefox -> Firefox Android', () => {
const support = {
firefox: {
version_added: '70',
notes: 'Firefox 73 added support for this thing.',
},
};
const mirrored = mirrorSupport('firefox_android', support);
assert.deepEqual(mirrored, {
version_added: '79',
notes: 'Firefox for Android 79 added support for this thing.',
});
});
it('ChromeOS is not renamed to EdgeOS, OperaOS, etc.', () => {
const support = {
chrome: {
version_added: '65',
notes:
'This feature is only supported in ChromeOS, macOS and Linux.',
},
};
const mirrored = mirrorSupport('opera', support);
assert.deepEqual(mirrored, {
version_added: '52',
notes: 'This feature is only supported in ChromeOS, macOS and Linux.',
});
});
it('OS-specific partial_implementation and notes are not mirrored', () => {
/** @type {InternalSupportBlock} */
const support = {
chrome: {
version_added: '134',
partial_implementation: true,
notes: 'Supported on ChromeOS, macOS, and Windows only.',
},
};
const mirrored = mirrorSupport('chrome_android', support);
assert.deepEqual(mirrored, {
version_added: '134',
});
});
it('Non-OS-specific partial_implementation and notes are still mirrored', () => {
/** @type {InternalSupportBlock} */
const support = {
chrome: {
version_added: '70',
partial_implementation: true,
notes: 'This feature is incomplete and may not work as expected.',
},
};
const mirrored = mirrorSupport('chrome_android', support);
assert.deepEqual(mirrored, {
version_added: '70',
partial_implementation: true,
notes: 'This feature is incomplete and may not work as expected.',
});
});
});
describe('Validations', () => {
it('mirror target must have upstream browser', () => {
assert.throws(
() => mirrorSupport(/** @type {BrowserName} */ ('chrome'), {}),
Error,
'Upstream is not defined for chrome, cannot mirror!',
);
});
it('throw error if upstream data is not defined', () => {
assert.throws(
() =>
mirrorSupport(/** @type {BrowserName} */ ('chrome_android'), {}),
Error,
'The data for chrome is not defined for mirroring to chrome_android, cannot mirror!',
);
});
});
describe('Edge Cases', () => {
it('mirror from a mirrored value', () => {
/** @type {InternalSupportBlock} */
const support = {
chrome: {
version_added: '40',
},
chrome_android: 'mirror',
};
const mirrored = mirrorSupport('opera_android', support);
assert.deepEqual(mirrored, { version_added: '27' });
});
it('version_added is false if resulting version_added == version_removed', () => {
const support = {
firefox: {
version_added: '70',
version_removed: '72',
},
};
const mirrored = mirrorSupport('firefox_android', support);
assert.deepEqual(mirrored, { version_added: false });
});
describe('destination browser does not support flags', () => {
it('only flag statement', () => {
/** @type {InternalSupportBlock} */
const support = {
chrome_android: {
version_added: '50',
flags: [
{
name: '#enable-experimental-web-platform-features',
type: 'preference',
},
],
notes: 'This feature is only available on Google Pixel devices.',
},
};
const mirrored = mirrorSupport('samsunginternet_android', support);
assert.deepEqual(mirrored, { version_added: false });
});
it('flag and non-flag statement', () => {
/** @type {InternalSupportBlock} */
const support = {
chrome_android: [
{
version_added: '90',
},
{
version_added: '50',
flags: [
{
name: '#enable-experimental-web-platform-features',
type: 'preference',
},
],
},
],
};
const mirrored = mirrorSupport('samsunginternet_android', support);
assert.deepEqual(mirrored, { version_added: '15.0' });
});
});
it('feature removed before Chromium Edge', () => {
const support = {
chrome: {
version_added: '10',
version_removed: '38',
prefix: 'webkit',
},
};
const mirrored = mirrorSupport('edge', support);
assert.deepEqual(mirrored, { version_added: false });
});
it('link with Chrome in hash', () => {
const support = {
chrome: {
version_added: '35',
notes:
'[Non-standard exceptions in Chrome](https://developer.mozilla.org/docs/Web/API/AudioContext/AudioContext#Non-standard_exceptions_in_Chrome)',
},
};
const mirrored = mirrorSupport('chrome_android', support);
assert.deepEqual(mirrored, {
version_added: '35',
notes:
'[Non-standard exceptions in Chrome Android](https://developer.mozilla.org/docs/Web/API/AudioContext/AudioContext#Non-standard_exceptions_in_Chrome)',
});
});
});
describe('ranges are preserved', () => {
it('direct', () => {
const support = {
chrome: {
version_added: '≤80',
},
};
const mirrored = mirrorSupport('edge', support);
assert.deepEqual(mirrored, { version_added: '≤80' });
});
it('range is before first version of downstream browser', () => {
const support = {
chrome: {
version_added: '≤24',
},
};
const mirrored = mirrorSupport('edge', support);
assert.deepEqual(mirrored, { version_added: '79' });
});
});
});
});