From 50caa92ee85971309d4a4ca325c00ff2b7bc548a Mon Sep 17 00:00:00 2001 From: "Jake F - @samouri" Date: Thu, 5 Oct 2017 23:15:07 -0400 Subject: [PATCH] [jest-docblock] remove leading newlines from parswWithComments().comments --- .../jest-docblock/src/__tests__/index.test.js | 15 +++++++++++++++ packages/jest-docblock/src/index.js | 5 ++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/packages/jest-docblock/src/__tests__/index.test.js b/packages/jest-docblock/src/__tests__/index.test.js index 0a00ac6b2107..cd01de14dcf4 100644 --- a/packages/jest-docblock/src/__tests__/index.test.js +++ b/packages/jest-docblock/src/__tests__/index.test.js @@ -254,6 +254,21 @@ describe('docblock', () => { ); }); + it('removes leading newlines in multiline comments from docblock', () => { + const code = + '/**' + + os.EOL + + ' * @snailcode' + + os.EOL + + ' *' + + os.EOL + + ' * hello world' + + os.EOL + + ' */'; + + expect(docblock.parseWithComments(code).comments).toEqual(' hello world'); + }); + it('extracts comments from beginning and end of docblock', () => { const code = '/**' + diff --git a/packages/jest-docblock/src/index.js b/packages/jest-docblock/src/index.js index 771693acd332..cea91c629732 100644 --- a/packages/jest-docblock/src/index.js +++ b/packages/jest-docblock/src/index.js @@ -55,7 +55,10 @@ export function parseWithComments( docblock = docblock.replace(ltrimNewlineRe, '').replace(rtrimRe, ''); const result = Object.create(null); - const comments = docblock.replace(propertyRe, ''); + const comments = docblock + .replace(propertyRe, '') + .replace(ltrimNewlineRe, '') + .replace(rtrimRe, ''); let match; while ((match = propertyRe.exec(docblock))) {