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 faefeb3
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 11 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"@types/indent-string": "^3.0.0",
"@types/lodash": "^4.14.116",
"@types/mocha": "^5.2.5",
"@types/node": "^10.9.2",
"@types/node": "^10.9.4",
"@types/wrap-ansi": "^3.0.0",
"chai": "^4.1.2",
"fancy-test": "^1.3.0",
Expand All @@ -26,7 +26,7 @@
"mocha": "^5.2.0",
"ts-node": "^7.0.1",
"tslint": "^5.11.0",
"typescript": "^3.0.1"
"typescript": "^3.0.3"
},
"engines": {
"node": ">=8.0.0"
Expand Down
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'])
})
})
12 changes: 6 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@
version "10.7.1"
resolved "https://registry.yarnpkg.com/@types/node/-/node-10.7.1.tgz#b704d7c259aa40ee052eec678758a68d07132a2e"

"@types/node@^10.9.2":
version "10.9.2"
resolved "https://registry.yarnpkg.com/@types/node/-/node-10.9.2.tgz#f0ab8dced5cd6c56b26765e1c0d9e4fdcc9f2a00"
"@types/node@^10.9.4":
version "10.9.4"
resolved "https://registry.yarnpkg.com/@types/node/-/node-10.9.4.tgz#0f4cb2dc7c1de6096055357f70179043c33e9897"

"@types/sinon@^5.0.1":
version "5.0.1"
Expand Down Expand Up @@ -1229,9 +1229,9 @@ type-detect@^4.0.0:
version "4.0.8"
resolved "https://registry.yarnpkg.com/type-detect/-/type-detect-4.0.8.tgz#7646fb5f18871cfbb7749e69bd39a6388eb7450c"

typescript@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.0.1.tgz#43738f29585d3a87575520a4b93ab6026ef11fdb"
typescript@^3.0.3:
version "3.0.3"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.0.3.tgz#4853b3e275ecdaa27f78fda46dc273a7eb7fc1c8"

union-value@^1.0.0:
version "1.0.0"
Expand Down

0 comments on commit faefeb3

Please sign in to comment.