Skip to content

Commit 4d29f66

Browse files
committed
Add stats unit test, update jsdoc comments, update arguments so addon option will be listed in --help.
1 parent 856d6e7 commit 4d29f66

File tree

3 files changed

+45
-8
lines changed

3 files changed

+45
-8
lines changed

lib/arguments.js

+4
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ module.exports = {
5454
default: false,
5555
describe: 'throw errors when unused components are found',
5656
})
57+
.option('include-addons', {
58+
alias: 'a',
59+
describe: 'include addons matching wildcard or boolean',
60+
})
5761
.locale('en').argv;
5862

5963
return this.argv;

lib/stats.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module.exports = {
44
/**
55
* Counts using `component "component-name"` usage in templates
66
*
7-
* @param {object} stats
7+
* @param {object} components
88
* @returns {number}
99
*/
1010
countComponentHelpers(components) {
@@ -21,7 +21,7 @@ module.exports = {
2121
* Counts components invocations in JS files.
2222
* That could happen through `import` or by referring by name in configuration of an script or so.
2323
*
24-
* @param {object} stats
24+
* @param {object} components
2525
* @returns {number}
2626
*/
2727
countJsUsage(components) {
@@ -37,7 +37,7 @@ module.exports = {
3737
/**
3838
* Counts components that were used just once.
3939
*
40-
* @param {object} stats
40+
* @param {object} components
4141
* @returns {number}
4242
*/
4343
countUsedJustOnce(components) {
@@ -55,7 +55,7 @@ module.exports = {
5555
/**
5656
* Creates a breakdown between {{curly-braces}} and <AngleBrackets> components syntax usage.
5757
*
58-
* @param {object} stats
58+
* @param {object} components
5959
* @returns {{curly: number, angle: number, curlyPercentage: number, anglePercentage: number}}
6060
*/
6161
curlyVsAngle(components) {
@@ -83,18 +83,18 @@ module.exports = {
8383
*
8484
* In case of the same number of occurrences for multiple component, the first on the list is returned.
8585
*
86-
* @param {object} stats
86+
* @param {object} components
8787
* @returns {object|null}
8888
*/
8989
getTheMostCommon(components) {
9090
let max = null;
9191

9292
for (const key of Object.keys(components)) {
93-
if (!max || max.count < components[key].count) {
94-
max = components[key].key;
93+
if (!max || max.stats.count < components[key].stats.count) {
94+
max = components[key];
9595
}
9696
}
9797

98-
return components[max];
98+
return max;
9999
},
100100
};

tests/unit/stats-test.js

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import test from 'ava';
2+
const utils = require('../../lib/utils');
3+
const analyser = require('../../lib/analyser');
4+
const stats = require('../../lib/stats');
5+
6+
function setup() {
7+
let commandOptions = { path: '/test-apps/ember_lts_3_4_with_addons/', includeAddons: true };
8+
let config = utils.getConfig(commandOptions);
9+
analyser.mapComponents(config);
10+
analyser.scanProject(config);
11+
analyser.respectWhitelist(config.whitelist);
12+
13+
return analyser.components;
14+
}
15+
16+
test('it calculates most common component', t => {
17+
let components = setup();
18+
let common = stats.getTheMostCommon(components);
19+
t.is(common.key, 'y-button');
20+
t.is(common.stats.count, 7);
21+
});
22+
23+
test('it calculates most curly vs bracket breakdown', t => {
24+
let components = setup();
25+
26+
let breakdown = stats.curlyVsAngle(components);
27+
t.deepEqual(breakdown, {
28+
curly: 10,
29+
curlyPercentage: 45.45454545454545,
30+
angle: 12,
31+
anglePercentage: 54.54545454545454,
32+
});
33+
});

0 commit comments

Comments
 (0)