aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/src/main/js/apps/documentation
diff options
context:
space:
mode:
authorGrégoire Aubert <gregoire.aubert@sonarsource.com>2020-02-18 09:17:09 +0100
committerSonarTech <sonartech@sonarsource.com>2020-02-21 20:46:17 +0100
commitfd01cdec71067de25ea572e0462ff710e8f8ef22 (patch)
treee5d846779494dbac7dbe7c085fafcbbb287b078a /server/sonar-web/src/main/js/apps/documentation
parent1e1af62df661c8c43786bae8de2bf74f2d00d33d (diff)
downloadsonarqube-fd01cdec71067de25ea572e0462ff710e8f8ef22.tar.gz
sonarqube-fd01cdec71067de25ea572e0462ff710e8f8ef22.zip
SONAR-13103 Parsing errors break the whole documentation app
Diffstat (limited to 'server/sonar-web/src/main/js/apps/documentation')
-rw-r--r--server/sonar-web/src/main/js/apps/documentation/__tests__/pages-test.ts23
-rw-r--r--server/sonar-web/src/main/js/apps/documentation/pages.ts15
2 files changed, 35 insertions, 3 deletions
diff --git a/server/sonar-web/src/main/js/apps/documentation/__tests__/pages-test.ts b/server/sonar-web/src/main/js/apps/documentation/__tests__/pages-test.ts
index 2a7a6a07de9..822033a6e4a 100644
--- a/server/sonar-web/src/main/js/apps/documentation/__tests__/pages-test.ts
+++ b/server/sonar-web/src/main/js/apps/documentation/__tests__/pages-test.ts
@@ -17,7 +17,8 @@
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-import { ParsedContent } from '../../../helpers/markdown';
+/* eslint-disable no-console */
+import { filterContent, ParsedContent } from '../../../helpers/markdown';
import { mockDocumentationMarkdown } from '../../../helpers/testMocks';
jest.mock('remark', () => ({
@@ -32,6 +33,11 @@ jest.mock('unist-util-visit', () => ({
}
}));
+jest.mock('../../../helpers/markdown', () => {
+ const markdown = jest.requireActual('../../../helpers/markdown');
+ return { ...markdown, filterContent: jest.fn().mockImplementation(markdown.filterContent) };
+});
+
const lorem = {
url: 'analysis/languages/lorem',
title: 'toto doc',
@@ -99,6 +105,21 @@ it('should correctly handle overrides (replace & add)', () => {
expect(pages[2].title).toBe(newDoc.title);
});
+it('should not break the whole doc when one page cannot be parsed', () => {
+ const originalConsoleError = console.error;
+ console.error = jest.fn();
+
+ (filterContent as jest.Mock).mockImplementationOnce(() => {
+ throw Error('Parse page error');
+ });
+ const pages = getPages();
+ expect(pages.length).toBe(2);
+ expect(pages[0].content).toBe('');
+ expect(console.error).toBeCalledTimes(1);
+
+ console.error = originalConsoleError;
+});
+
function getPages(overrides: T.Dict<ParsedContent> = {}) {
// This allows the use of out-of-scope data inside jest.mock
// Usually, it is impossible as jest.mock'ed module is hoisted on the top of the file
diff --git a/server/sonar-web/src/main/js/apps/documentation/pages.ts b/server/sonar-web/src/main/js/apps/documentation/pages.ts
index 9ca8b4969d8..1d311ebd1bb 100644
--- a/server/sonar-web/src/main/js/apps/documentation/pages.ts
+++ b/server/sonar-web/src/main/js/apps/documentation/pages.ts
@@ -52,8 +52,19 @@ export default function getPages(
});
return pages.map(({ parsed, file }) => {
- const content = filterContent(parsed.content);
- const text = getText(content);
+ let content = '';
+ let text = '';
+ try {
+ content = filterContent(parsed.content);
+ text = getText(content);
+ } catch (e) {
+ /* eslint-disable-next-line no-console */
+ console.error(
+ `Documentation - an error occured while parsing page "${parsed.frontmatter.url ||
+ file.path}":`,
+ e
+ );
+ }
return {
relativeName: file.path,