-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
Copy pathcoverage-test.js
118 lines (104 loc) · 4.55 KB
/
coverage-test.js
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
'use strict';
const path = require('path');
QUnit.module('Docs coverage', function (hooks) {
let docs, expected;
hooks.before(function () {
if (!process.env.REUSE_DOCS) {
buildDocs();
}
docs = require(path.join(__dirname, '../../docs/data.json'));
expected = require('./expected');
});
QUnit.module('classitems', function (hooks) {
let docsItems, expectedItems;
hooks.before(function () {
docsItems = new Set(docs.classitems.map((item) => item.name).filter(Boolean));
expectedItems = new Set(expected.classitems);
});
QUnit.test('No missing classitems', function (assert) {
let missing = setDifference(expectedItems, docsItems);
assert.emptySet(
missing,
'The following classitems are missing. If you intentionally removed a public API method, please update tests/docs/expected.js. Otherwise, documentation is missing, incorrectly formatted, or in a directory that is not watched by yuidoc. All files containing documentation must have a yuidoc class declaration.'
);
});
QUnit.test('No extraneous classitems', function (assert) {
let extraneous = setDifference(docsItems, expectedItems);
assert.emptySet(
extraneous,
'The following classitems are unexpected. If you have added new features, please update tests/docs/expected.js and confirm that any public properties are marked both @public and @static to be included in the Ember API Docs viewer.'
);
});
});
QUnit.module('classes', function (hooks) {
let docsItems, expectedItems;
hooks.before(function () {
docsItems = new Set(
Object.values(docs.classes)
.filter((item) => item?.access !== 'private' && !item.name.includes('@'))
.map((item) => item.name)
);
expectedItems = new Set(expected.classes);
});
QUnit.test('No missing classes', function (assert) {
let missing = setDifference(expectedItems, docsItems);
assert.emptySet(
missing,
'The following classes are missing. If you intentionally removed a public API class, please update tests/docs/expected.js. Otherwise, documentation is missing, incorrectly formatted, or in a directory that is not watched by yuidoc. All files containing documentation must have a yuidoc class declaration.'
);
});
QUnit.test('No extraneous classes', function (assert) {
let extraneous = setDifference(docsItems, expectedItems);
assert.emptySet(
extraneous,
'The following classes are unexpected. If you have added new classes, please update tests/docs/expected.js and confirm that any public properties are marked both @public and @static to be included in the Ember API Docs viewer.'
);
});
});
QUnit.module('modules (packages)', function (hooks) {
let docsItems, expectedItems;
hooks.before(function () {
docsItems = new Set(
Object.values(docs.modules)
.filter((item) => item?.access !== 'private')
.map((item) => item.name)
);
expectedItems = new Set(expected.modules);
});
QUnit.test('No missing modules (packages)', function (assert) {
let missing = setDifference(expectedItems, docsItems);
assert.emptySet(
missing,
'The following modules (packages) are missing. If you intentionally removed a public API module (package), please update tests/docs/expected.js. Otherwise, documentation is missing, incorrectly formatted, or in a directory that is not watched by yuidoc. All files containing documentation must have a yuidoc class declaration.'
);
});
QUnit.test('No extraneous modules (packages)', function (assert) {
let extraneous = setDifference(docsItems, expectedItems);
assert.emptySet(
extraneous,
'The following modules (packages) are unexpected. If you have added new modules (packages), please update tests/docs/expected.js and confirm that any public properties are marked both @public and @static to be included in the Ember API Docs viewer.'
);
});
});
});
function buildDocs() {
let child = require('child_process');
child.execFileSync('node', [require.resolve('ember-cli/bin/ember'), 'ember-cli-yuidoc'], {
stdio: 'pipe',
});
}
function setDifference(setA, setB) {
let difference = new Set(setA);
for (let elem of setB) {
difference.delete(elem);
}
return difference;
}
QUnit.assert.emptySet = function assertEmptySet(value, message) {
this.pushResult({
result: value.size === 0,
actual: Array.from(value).sort(),
expected: [],
message: message,
});
};