Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #774: Adding support to location array #843

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 28 additions & 0 deletions loaders/__tests__/styleguide-loader.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,34 @@ it('should return correct component paths: function returning absolute paths', (
expect(result).not.toMatch(`'filepath': 'components/RandomButton/RandomButton.js'`);
});

it('should return correct component paths: function returning absolute paths', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

function returning absolute paths → array of component absolute paths.

You can also add a test for relative paths.

const result = styleguideLoader.pitch.call(
{
request: file,
_styleguidist: {
sections: [
{
components: [
`${__dirname}/components/Button/Button.js`,
`${__dirname}/components/Placeholder/Placeholder.js`,
],
},
],
configDir: __dirname,
getExampleFilename: () => 'Readme.md',
getComponentPathLine: filepath => filepath,
},
addContextDependency: () => {},
},
readFileSync(file, 'utf8')
);
expect(result).toBeTruthy();
expect(() => new vm.Script(result)).not.toThrow();
expect(result).toMatch(`'filepath': 'components/Button/Button.js'`);
expect(result).toMatch(`'filepath': 'components/Placeholder/Placeholder.js'`);
expect(result).not.toMatch(`'filepath': 'components/RandomButton/RandomButton.js'`);
});

it('should return correct component paths: function returning relative paths', () => {
const result = styleguideLoader.pitch.call(
{
Expand Down
2 changes: 2 additions & 0 deletions loaders/utils/getComponentFiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ module.exports = function getComponentFiles(components, rootDir, ignore) {
let componentFiles;
if (isFunction(components)) {
componentFiles = components();
} else if (Array.isArray(components)) {
componentFiles = components;
} else if (isString(components)) {
componentFiles = glob.sync(path.resolve(rootDir, components), { ignore });
} else {
Expand Down
2 changes: 1 addition & 1 deletion scripts/__tests__/config.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ it('should throw if config has errors', () => {
getConfig({
components: 42,
});
expect(fn).toThrowError('should be string or function');
expect(fn).toThrowError('should be string, function, or array');
});

it('should change the config using the update callback', () => {
Expand Down
2 changes: 1 addition & 1 deletion scripts/schemas/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ module.exports = {
},
// `components` is a shortcut for { sections: [{ components }] }, see `sections` below
components: {
type: ['string', 'function'],
type: ['string', 'function', 'array'],
example: 'components/**/[A-Z]*.js',
},
configDir: {
Expand Down