forked from adamlaska/browser-compat-data
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-compare-features.js
More file actions
67 lines (61 loc) · 1.51 KB
/
test-compare-features.js
File metadata and controls
67 lines (61 loc) · 1.51 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
#!/usr/bin/env node
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
'use strict';
const fs = require('fs');
const path = require('path');
const chalk = require('chalk');
const compareFeatures = require('../scripts/compare-features');
/**
* A unit test for the compareFeatures() function, to ensure that features are sorted as expected.
* @returns {boolean} If the sorter isn't functioning properly
*/
const testFeatureOrder = () => {
const input = [
'foobar',
'Foo',
'__compat',
'toString',
'secure_context_required',
'protocol-r30',
'$0',
'Bar',
'_updated_spec',
'43',
'--variable',
'ZOO_Pals',
'2-factor-auth',
];
const actual = input.sort(compareFeatures);
const expected = [
'__compat',
'Bar',
'Foo',
'ZOO_Pals',
'foobar',
'protocol-r30',
'secure_context_required',
'toString',
'_updated_spec',
'--variable',
'$0',
'2-factor-auth',
'43',
];
let errors = false;
for (let i = actual.length; i--; ) {
if (actual[i] !== expected[i]) {
errors = true;
break;
}
}
if (errors) {
console.error(chalk`{red compareFeatures() – {bold 1} error:}`);
console.error(chalk`{red → Actual and expected orders do not match}`);
console.error(chalk`{yellow Actual: {bold ${actual}}}`);
console.error(chalk`{green Expected: {bold ${expected}}}`);
return true;
}
return false;
};
module.exports = testFeatureOrder;