build(docs-infra): throw error if using title
on code snippets (#26514)
Since #26396, the `title` property is ignored and `header` should be used instead for specifying a code snippet's header. This commit ensures that we don't accidentally set `title` have it be silently ignored. PR Close #26514
This commit is contained in:

committed by
Miško Hevery

parent
d557f1d9de
commit
0add00a743
@ -84,10 +84,10 @@ describe('renderExamples processor', () => {
|
||||
|
||||
it('should cope with spaces and double quotes inside attribute values', () => {
|
||||
const docs = [
|
||||
{ renderedContent: `<${CODE_TAG} title='a "quoted" value' path="test/url"></${CODE_TAG}>`}
|
||||
{ renderedContent: `<${CODE_TAG} header='a "quoted" value' path="test/url"></${CODE_TAG}>`}
|
||||
];
|
||||
processor.$process(docs);
|
||||
expect(docs[0].renderedContent).toEqual(`<${CODE_TAG} title="a "quoted" value" path="test/url">\nwhole file\n</${CODE_TAG}>`);
|
||||
expect(docs[0].renderedContent).toEqual(`<${CODE_TAG} header="a "quoted" value" path="test/url">\nwhole file\n</${CODE_TAG}>`);
|
||||
});
|
||||
|
||||
it('should throw an exception if the code-example tag is not closed correctly', () => {
|
||||
@ -117,6 +117,55 @@ describe('renderExamples processor', () => {
|
||||
'Missing example file... relativePath: "missing/url". - doc\n' +
|
||||
'Example files can be found in the following relative paths: "examples" - doc');
|
||||
});
|
||||
|
||||
it('should throw an exception if any code-example tag has a `title` attribute', () => {
|
||||
const docs = [
|
||||
{
|
||||
name: 'Document A',
|
||||
renderedContent: `
|
||||
Example 1: <${CODE_TAG} path="test/url" header="This is a header "></${CODE_TAG}>
|
||||
Example 2: <${CODE_TAG} path="test/url" title="This is a title 2"></${CODE_TAG}>
|
||||
`,
|
||||
},
|
||||
{
|
||||
name: 'Document B',
|
||||
renderedContent: `
|
||||
Example 3: <${CODE_TAG} path="test/url" title="This is a title 3"></${CODE_TAG}>
|
||||
Example 4: <${CODE_TAG} path="test/url" header="This is a header 4"></${CODE_TAG}>
|
||||
`,
|
||||
},
|
||||
];
|
||||
|
||||
expect(() => processor.$process(docs)).toThrowError(
|
||||
'Some code snippets use the `title` attribute instead of `header`.');
|
||||
|
||||
expect(log.error).toHaveBeenCalledTimes(2);
|
||||
expect(log.error).toHaveBeenCalledWith(
|
||||
`Using the "title" attribute for specifying a ${CODE_TAG} header is no longer supported. ` +
|
||||
'Use the "header" attribute instead.\n' +
|
||||
`<${CODE_TAG} path="test/url" title="This is a title 2"> - doc "Document A"`);
|
||||
expect(log.error).toHaveBeenCalledWith(
|
||||
`Using the "title" attribute for specifying a ${CODE_TAG} header is no longer supported. ` +
|
||||
'Use the "header" attribute instead.\n' +
|
||||
`<${CODE_TAG} path="test/url" title="This is a title 3"> - doc "Document B"`);
|
||||
});
|
||||
|
||||
it('should throw an exception for `title` attribute even if `ignoreBrokenExamples` is set to true', () => {
|
||||
processor.ignoreBrokenExamples = true;
|
||||
const docs = [
|
||||
{ renderedContent: `<${CODE_TAG} path="test/url" title="This is a title"></${CODE_TAG}>` },
|
||||
];
|
||||
expect(() => processor.$process(docs)).toThrowError(
|
||||
'Some code snippets use the `title` attribute instead of `header`.');
|
||||
});
|
||||
|
||||
it('should throw an exception for `title` attribute even if there is no `path` attribute', () => {
|
||||
const docs = [
|
||||
{ renderedContent: `<${CODE_TAG} title="This is a title">Hard-coded contents.</${CODE_TAG}>` },
|
||||
];
|
||||
expect(() => processor.$process(docs)).toThrowError(
|
||||
'Some code snippets use the `title` attribute instead of `header`.');
|
||||
});
|
||||
})
|
||||
);
|
||||
});
|
||||
|
Reference in New Issue
Block a user