Pete Bacon Darwin f440bd1793 build(docs-infra): fix CLI command github links (#30889)
The "view" links were broken because the version used to
compute the git tag for the GitHub URL included a build SHA.
Now we clean that off before using it in the URL.

The links are to the JSON schema that defines the documentation for
the command. This is accurate but confusing because the content for the
long description is stored in a separate markdown file referenced from this
schema file.
This commit adds a second set of links for the long description, if it exists,
which links directly to the markdown file.

Closes #30700

PR Close #30889
2019-06-06 08:49:37 -07:00

136 lines
4.0 KiB
JavaScript

const cliCommandReaderFactory = require('./cli-command');
const reader = cliCommandReaderFactory();
const content = `
{
"name": "add",
"description": "Add support for a library to your project.",
"longDescription": "Add support for a library in your project, for example adding \`@angular/pwa\` which would configure\\nyour project for PWA support.\\n",
"hidden": false,
"type": "custom",
"options": [
{
"name": "collection",
"description": "The package to be added.",
"type": "string",
"required": false,
"aliases": [],
"hidden": false,
"positional": 0
},
{
"name": "help",
"description": "Shows a help message.",
"type": "boolean",
"required": false,
"aliases": [],
"hidden": false
},
{
"name": "helpJson",
"description": "Shows the metadata associated with each flags, in JSON format.",
"type": "boolean",
"required": false,
"aliases": [],
"hidden": false
}
],
"aliases": ['a'],
"scope": "in"
}
`;
const fileInfo = {
content,
baseName: 'add',
relativePath: 'add.json',
basePath: __dirname + '/mocks/help',
};
describe('cli-command reader', () => {
describe('getDocs', () => {
it('should return an array containing a single doc', () => {
const docs = reader.getDocs(fileInfo);
expect(docs.length).toEqual(1);
});
it('should return a cli-command doc', () => {
const docs = reader.getDocs(fileInfo);
expect(docs[0]).toEqual(jasmine.objectContaining({
id: 'cli-add',
docType: 'cli-command',
}));
});
it('should extract the name from the fileInfo', () => {
const docs = reader.getDocs(fileInfo);
expect(docs[0].name).toEqual('add');
});
it('should compute the id and aliases', () => {
const docs = reader.getDocs(fileInfo);
expect(docs[0].id).toEqual('cli-add');
expect(docs[0].aliases).toEqual(['cli-add', 'cli-a']);
});
it('should compute the path and outputPath', () => {
const docs = reader.getDocs(fileInfo);
expect(docs[0].path).toEqual('cli/add');
expect(docs[0].outputPath).toEqual('cli/add.json');
});
it('should compute the bread crumbs', () => {
const docs = reader.getDocs(fileInfo);
expect(docs[0].breadCrumbs).toEqual([
{text: 'CLI', path: 'cli'},
{text: 'add', path: 'cli/add'},
]);
});
it('should extract the short description into the content', () => {
const docs = reader.getDocs(fileInfo);
expect(docs[0].content).toEqual('Add support for a library to your project.');
});
it('should extract the long description', () => {
const docs = reader.getDocs(fileInfo);
expect(docs[0].longDescription)
.toEqual(
'Add support for a library in your project, for example adding `@angular/pwa` which would configure\nyour project for PWA support.\n');
});
it('should extract the command type', () => {
const docs = reader.getDocs(fileInfo);
expect(docs[0].type).toEqual('custom');
});
it('should extract the command scope', () => {
const docs = reader.getDocs(fileInfo);
expect(docs[0].scope).toEqual('in');
});
it('should extract the command aliases', () => {
const docs = reader.getDocs(fileInfo);
expect(docs[0].commandAliases).toEqual(['a']);
});
it('should extract the options', () => {
const docs = reader.getDocs(fileInfo);
expect(docs[0].options).toEqual([
jasmine.objectContaining({name: 'collection'}),
jasmine.objectContaining({name: 'help'}),
jasmine.objectContaining({name: 'helpJson'}),
]);
});
it('should extract file info for the long description', () => {
const [doc] = reader.getDocs(fileInfo);
expect(doc.longDescriptionDoc).toEqual({
docType: 'content',
startingLine: 0,
fileInfo: {realProjectRelativePath: 'packages/angular/cli/commands/add-long.md'}
});
});
});
});