From e74a39524a564bc33e92ed8c1bed420e9f67e99c Mon Sep 17 00:00:00 2001 From: Jeff Dickey <216188+jdxcode@users.noreply.github.com> Date: Thu, 30 Aug 2018 13:54:13 -0700 Subject: [PATCH] fix: default subtopic names Fixes #48 --- src/plugin.ts | 1 + test/config.test.ts | 40 +++++++++++++++++++++++++++++++++++++--- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/src/plugin.ts b/src/plugin.ts index 909eedad..f1796e0e 100644 --- a/src/plugin.ts +++ b/src/plugin.ts @@ -246,6 +246,7 @@ function topicsToArray(input: any, base?: string): Topic[] { return input.concat(flatMap(input, t => topicsToArray(t.subtopics, `${base}${t.name}`))) } return flatMap(Object.keys(input), k => { + input[k].name = k return [{...input[k], name: `${base}${k}`}].concat(topicsToArray(input[k].subtopics, `${base}${input[k].name}`)) }) } diff --git a/test/config.test.ts b/test/config.test.ts index 77aa92d8..7fc9a7ca 100644 --- a/test/config.test.ts +++ b/test/config.test.ts @@ -2,23 +2,28 @@ import * as os from 'os' import * as path from 'path' import {IConfig, load, PJSON} from '../src' +import * as util from '../src/util' import {expect, fancy} from './test' interface Options { + pjson?: any, homedir?: string, platform?: string, env?: {[k: string]: string}, } describe('Config', () => { - const testConfig = ({homedir = '/my/home', platform = 'darwin', env = {}}: Options = {}) => { - const test = fancy + const testConfig = ({pjson, homedir = '/my/home', platform = 'darwin', env = {}}: Options = {}) => { + let test = fancy .resetConfig() .env(env, {clear: true}) .stub(os, 'homedir', () => path.join(homedir)) .stub(os, 'platform', () => platform) - .add('config', () => load()) + + if (pjson) test = test.stub(util, 'loadJSON', () => Promise.resolve(pjson)) + + test = test.add('config', () => load()) return { hasS3Key(k: keyof PJSON.S3.Templates, expected: string, extra: any = {}) { @@ -108,4 +113,33 @@ describe('Config', () => { expect(config.s3Url('/b/c')).to.equal('https://bar.com/a/b/c') config.pjson.oclif.update.s3.host = orig }) + + testConfig({ + pjson: { + name: 'foo', + oclif: { + topics: { + t1: { + description: 'desc for t1', + subtopics: { + 't1-1': { + description: 'desc for t1-1', + subtopics: { + 't1-1-1': { + description: 'desc for t1-1-1' + }, + 't1-1-2': { + description: 'desc for t1-1-2' + } + } + } + } + } + } + } + } + }) + .it('has subtopics', config => { + expect(config.topics.map(t => t.name)).to.have.members(['t1', 't1:t1-1', 't1:t1-1:t1-1-1', 't1:t1-1:t1-1-2']) + }) })