Skip to content

Commit db6b282

Browse files
committed
test: adding some unit tests
1 parent 6123518 commit db6b282

5 files changed

Lines changed: 2296 additions & 101 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55
/lib
66
/package-lock.json
77
/tmp
8+
/test/tmp
89
node_modules
910
oclif.manifest.json

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
"@oclif/plugin-help": "^2",
2121
"@oclif/test": "^1",
2222
"globby": "^8",
23-
"husky": "^1"
23+
"husky": "^1",
24+
"salesforcedx": "48.3.1"
2425
},
2526
"engines": {
2627
"node": ">=8.4.0"
@@ -47,7 +48,8 @@
4748
}
4849
},
4950
"devPlugins": [
50-
"@oclif/plugin-help"
51+
"@oclif/plugin-help",
52+
"salesforcedx"
5153
]
5254
},
5355
"repository": "salesforcecli/plugin-command-reference",

src/docs.ts

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -37,23 +37,13 @@ export class Docs {
3737
private topicMeta: JsonMap
3838
) {}
3939

40-
/**
41-
* Take CLI help json output and transform into dita map format
42-
* @param options - array of command line options (args)
43-
*/
4440
public async build(commands: JsonMap[]) {
4541
// Create if doesn't exist
4642
await fs.mkdirp(this.outputDir);
4743

4844
await this.populateTemplate(commands);
4945
}
5046

51-
/**
52-
* Create the descriptor xml file for the main level topic
53-
* @param namespace
54-
* @param results
55-
* @param rootOutputDir
56-
*/
5747
public async populateTopic(topic: string, subtopics: Dictionary<Dictionary | Dictionary[]>) {
5848
const topicMeta = ensureJsonMap(this.topicMeta[topic]);
5949
let description = asString(topicMeta.longDescription);
@@ -127,17 +117,14 @@ export class Docs {
127117
// The topic ditamap with all of the subtopic links.
128118
events.emit('subtopics', topic, subTopicNames);
129119
await new TopicDitamap(topic, subTopicNames, commandNames).write();
130-
131-
// TODO just include it in the upper loop?
132-
// await this.populateSubTopics(topic, subtopics)
133120
return subTopicNames;
134121
}
135122

136123
/**
137124
* Group all commands by the top level topic and then subtopic. e.g. force, analytics, evergreen, etc
138125
* then org, apex, etc within the force namespace.
139126
* @param commands - The entire set of command data.
140-
* @returns The commands grouped by namespace grouped by topics/commands.
127+
* @returns The commands grouped by topics/subtopic/commands.
141128
*/
142129
private groupTopicsAndSubtopics(commands: JsonMap[]) {
143130
const topLevelTopics: Dictionary<Dictionary<Dictionary | Dictionary[]>> = {};
@@ -192,12 +179,6 @@ export class Docs {
192179
return topLevelTopics;
193180
}
194181

195-
/**
196-
* Given help data in json convert it to ditamap format
197-
* @param outputdir - directory for ditamap format results
198-
* @param showhidden - include hidden parameters in converted help
199-
* @param parsedData - {object} containing CLI help
200-
*/
201182
private async populateTemplate(commands: JsonMap[]) {
202183
const topicsAndSubtopics = this.groupTopicsAndSubtopics(commands);
203184

test/endtoend.test.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright (c) 2018, salesforce.com, inc.
3+
* All rights reserved.
4+
* Licensed under the BSD 3-Clause license.
5+
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
6+
*/
7+
8+
import { fs } from '@salesforce/core';
9+
import { expect } from 'chai';
10+
import { readFileSync } from 'fs';
11+
import { join } from 'path';
12+
13+
/**
14+
* This plugin was primarily made to generate command reference docs for
15+
* salesforcedx. Generate actual docs and ensure some of the files are generated
16+
* correctly. If there is new code added to fix a new bug that relies on a new
17+
* version of salesforcedx, updated it in the package.json. To add test for other
18+
* plugins, it would probably be best to create a base test to generate the docs
19+
* for the test cases to reference.
20+
*/
21+
22+
const testFilesPath = './test/tmp';
23+
24+
function loadTestDitamapFile(path: string) {
25+
return readFileSync(join(testFilesPath, path), 'utf8');
26+
}
27+
28+
describe('salesforcedx', () => {
29+
before(async () => {
30+
await require('@oclif/command').run([
31+
'commandreference:generate',
32+
'--plugins',
33+
'salesforcedx',
34+
'--outputdir',
35+
testFilesPath
36+
]);
37+
});
38+
after(async () => {
39+
await fs.remove(testFilesPath);
40+
});
41+
42+
it('creates closed-pilot commands', async () => {
43+
const dita = loadTestDitamapFile(join('force', 'org', 'cli_reference_force_org_shape_create.xml'));
44+
expect(/invitation-only\s+pilot\s+program/.test(dita)).to.be.true;
45+
});
46+
it('creates beta commands', async () => {
47+
const dita = loadTestDitamapFile(join('force', 'org', 'cli_reference_force_org_clone.xml'));
48+
expect(/a\s+beta\s+version\s+of\s+the/.test(dita)).to.be.true;
49+
});
50+
it('creates open-pilot commands', async () => {
51+
const dita = loadTestDitamapFile(join('force', 'package', 'cli_reference_force_package_hammertest_run.xml'));
52+
expect(/through\s+a\s+pilot\s+program\s+that\s+requires/.test(dita)).to.be.true;
53+
});
54+
it('creates with long description', async () => {
55+
const dita = loadTestDitamapFile(join('force', 'source', 'cli_reference_force_source_push.xml'));
56+
expect(/shortdesc">Pushes changed/.test(dita)).to.be.true;
57+
});
58+
});

0 commit comments

Comments
 (0)