diff --git a/src/generate/__tests__/__snapshots__/index.js.snap b/src/generate/__tests__/__snapshots__/index.js.snap new file mode 100644 index 0000000..69ab374 --- /dev/null +++ b/src/generate/__tests__/__snapshots__/index.js.snap @@ -0,0 +1,34 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`replace the content between the ALL-CONTRIBUTORS-LIST tags by a table of contributors 1`] = ` +"# project + +Description + +## Contributors +These people contributed to the project: + + +| Kent C. Dodds is awesome! | Divjot Singh is awesome! | Jeroen Engels is awesome! | +| :---: | :---: | :---: | + + +Thanks a lot everyone!" +`; + +exports[`split contributors into multiples lines when there are too many 1`] = ` +"# project + +Description + +## Contributors +These people contributed to the project: + + +| Kent C. Dodds is awesome! | Kent C. Dodds is awesome! | Kent C. Dodds is awesome! | Kent C. Dodds is awesome! | Kent C. Dodds is awesome! | +| :---: | :---: | :---: | :---: | :---: | +| Kent C. Dodds is awesome! | Kent C. Dodds is awesome! | + + +Thanks a lot everyone!" +`; diff --git a/src/generate/__tests__/index.js b/src/generate/__tests__/index.js index 0e843fa..abe5f04 100644 --- a/src/generate/__tests__/index.js +++ b/src/generate/__tests__/index.js @@ -38,24 +38,9 @@ test('replace the content between the ALL-CONTRIBUTORS-LIST tags by a table of c const {kentcdodds, bogas04} = contributors const {options, jfmengels, content} = fixtures() const contributorList = [kentcdodds, bogas04, jfmengels] - const expected = [ - '# project', - '', - 'Description', - '', - '## Contributors', - 'These people contributed to the project:', - '', - '| Kent C. Dodds is awesome! | Divjot Singh is awesome! | Jeroen Engels is awesome! |', - '| :---: | :---: | :---: |', - '', - '', - 'Thanks a lot everyone!', - ].join('\n') - const result = generate(options, contributorList, content) - expect(result).toBe(expected) + expect(result).toMatchSnapshot() }) test('split contributors into multiples lines when there are too many', () => { @@ -70,25 +55,9 @@ test('split contributors into multiples lines when there are too many', () => { kentcdodds, kentcdodds, ] - const expected = [ - '# project', - '', - 'Description', - '', - '## Contributors', - 'These people contributed to the project:', - '', - '| Kent C. Dodds is awesome! | Kent C. Dodds is awesome! | Kent C. Dodds is awesome! | Kent C. Dodds is awesome! | Kent C. Dodds is awesome! |', - '| :---: | :---: | :---: | :---: | :---: |', - '| Kent C. Dodds is awesome! | Kent C. Dodds is awesome! |', - '', - '', - 'Thanks a lot everyone!', - ].join('\n') - const result = generate(options, contributorList, content) - expect(result).toBe(expected) + expect(result).toMatchSnapshot() }) test('not inject anything if there is no tags to inject content in', () => { @@ -150,6 +119,7 @@ test('inject nothing if there are no contributors', () => { '## Contributors', 'These people contributed to the project:', '', + '', '', '', 'Thanks a lot everyone!', diff --git a/src/generate/index.js b/src/generate/index.js index 7d7b9c5..c749889 100644 --- a/src/generate/index.js +++ b/src/generate/index.js @@ -27,11 +27,12 @@ function injectListBetweenTags(newContent) { ) { return previousContent } - return ( - previousContent.slice(0, endOfOpeningTagIndex + closingTag.length) + - newContent + - previousContent.slice(startOfClosingTagIndex) - ) + return [ + previousContent.slice(0, endOfOpeningTagIndex + closingTag.length), + '\n', + newContent, + previousContent.slice(startOfClosingTagIndex), + ].join('') } } diff --git a/src/init/__tests__/__snapshots__/add-contributors-list.js.snap b/src/init/__tests__/__snapshots__/add-contributors-list.js.snap new file mode 100644 index 0000000..65d9ce9 --- /dev/null +++ b/src/init/__tests__/__snapshots__/add-contributors-list.js.snap @@ -0,0 +1,41 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`create contributors section if content is empty 1`] = ` +" +## Contributors + +Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds/all-contributors#emoji-key)): + + + + + +This project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification. Contributions of any kind welcome!" +`; + +exports[`create contributors section if it is absent 1`] = ` +"# project + +Description +## Contributors + +Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds/all-contributors#emoji-key)): + + + + + +This project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification. Contributions of any kind welcome!" +`; + +exports[`insert list under contributors section 1`] = ` +"# project + +Description + +## Contributors + + + +" +`; diff --git a/src/init/__tests__/add-contributors-list.js b/src/init/__tests__/add-contributors-list.js index 6acc585..a6f05a6 100644 --- a/src/init/__tests__/add-contributors-list.js +++ b/src/init/__tests__/add-contributors-list.js @@ -9,55 +9,21 @@ test('insert list under contributors section', () => { '## Contributors', '', ].join('\n') - const expected = [ - '# project', - '', - 'Description', - '', - '## Contributors', - '', - '', - ].join('\n') - const result = addContributorsList(content) - expect(result).toBe(expected) + expect(result).toMatchSnapshot() }) test('create contributors section if it is absent', () => { const content = ['# project', '', 'Description'].join('\n') - const expected = [ - '# project', - '', - 'Description', - '## Contributors', - '', - 'Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds/all-contributors#emoji-key)):', - '', - '', - '', - 'This project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification. Contributions of any kind welcome!', - ].join('\n') - const result = addContributorsList(content) - expect(result).toBe(expected) + expect(result).toMatchSnapshot() }) test('create contributors section if content is empty', () => { const content = '' - const expected = [ - '', - '## Contributors', - '', - 'Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds/all-contributors#emoji-key)):', - '', - '', - '', - 'This project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification. Contributions of any kind welcome!', - ].join('\n') - const result = addContributorsList(content) - expect(result).toBe(expected) + expect(result).toMatchSnapshot() }) diff --git a/src/init/init-content.js b/src/init/init-content.js index 376d1bc..56ea862 100644 --- a/src/init/init-content.js +++ b/src/init/init-content.js @@ -5,8 +5,11 @@ const badgeContent = '[![All Contributors](https://img.shields.io/badge/all_contributors-0-orange.svg?style=flat-square)](#contributors)' const headerContent = 'Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds/all-contributors#emoji-key)):' -const listContent = - '' +const listContent = [ + '', + '', + '', +].join('\n') const footerContent = 'This project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification. Contributions of any kind welcome!'