Skip to content

Commit 66c6945

Browse files
levithomasonkyleturco
authored andcommitted
add META.isPrivate(), allow private components
1 parent 34d8692 commit 66c6945

3 files changed

Lines changed: 26 additions & 2 deletions

File tree

src/utils/Meta.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,23 @@ const META = {
3838
!_.has(component, '_meta.parent') || _.get(component, '_meta.parent') === component._meta.name
3939
),
4040
isChild: component => !META.isParent(component),
41+
42+
// other
43+
/**
44+
* Components whose constructor begins with an "_" are private.
45+
* This helper handles strings, classes, and instances and returns true if the
46+
* name or class definition begins with an "_".
47+
* @param {string|class|object} component A class, an instance, or constructor name.
48+
* @returns {boolean}
49+
*/
50+
isPrivate: component => {
51+
// handle component names from a string, a class, or an instance
52+
const name = _.isString(component) && component
53+
|| _.get(component, '_meta.name')
54+
|| _.get(component, '.constructor._meta.name');
55+
56+
return _.startsWith(name, '_');
57+
},
4158
};
4259

4360
export default META;

test/specs/Conformance-test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ describe('Conformance', () => {
2929
});
3030

3131
it(`has the "${sdClass}" element as its first child (no wrapper elements)`, () => {
32+
// private components may be used as root elements and will not have the sd-* class
33+
// skip any assertions if the first child is a private component
34+
// TODO: this excludes private components from conformance, need to find a sane way to get conformance coverage
35+
if (META.isPrivate(firstChild)) {
36+
return;
37+
}
38+
3239
if (isDOMComponent(firstChild)) {
3340
expect(firstChild.getAttribute('class')).to.contain(sdClass);
3441
} else {

test/specs/index-test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import _ from 'lodash';
22
import path from 'path';
33
import stardust from 'stardust';
4+
import META from 'src/utils/Meta';
45

56
const componentCtx = require.context(
67
'src/',
@@ -14,10 +15,9 @@ const componentNames = _.map(componentCtx.keys(), key => {
1415

1516
describe('stardust (index.js)', () => {
1617
_.each(componentNames, name => {
17-
const isPrivate = _.startsWith(name, '_');
18+
const isPrivate = META.isPrivate(name);
1819
const isStardustProp = _.has(stardust, name); // => stardust.H1
1920
const isSubComponent = _.some(stardust, name); // => stardust.Header.H1
20-
// console.log(`${name} isStardustProp=${isStardustProp} isSubComponent=${isSubComponent}`);
2121

2222
if (isPrivate) {
2323
it(`does not expose private component "${name}"`, () => {

0 commit comments

Comments
 (0)