Skip to content
This repository has been archived by the owner on Aug 22, 2023. It is now read-only.

Commit

Permalink
fix: default subtopic names
Browse files Browse the repository at this point in the history
Fixes #48
  • Loading branch information
jdx committed Aug 30, 2018
1 parent c084703 commit e74a395
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`))
})
}
Expand Down
40 changes: 37 additions & 3 deletions test/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}) {
Expand Down Expand Up @@ -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'])
})
})

0 comments on commit e74a395

Please sign in to comment.