feat: add prettier-ignore to output (#74)

This commit is contained in:
Kent C. Dodds 2017-11-22 11:24:01 -07:00 committed by GitHub
parent 482a8ab956
commit ba248a99d8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 92 additions and 77 deletions

View file

@ -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:
<!-- ALL-CONTRIBUTORS-LIST:START -->
<!-- prettier-ignore -->
| Kent C. Dodds is awesome! | Divjot Singh is awesome! | Jeroen Engels is awesome! |
| :---: | :---: | :---: |
<!-- ALL-CONTRIBUTORS-LIST:END -->
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:
<!-- ALL-CONTRIBUTORS-LIST:START -->
<!-- prettier-ignore -->
| 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! |
<!-- ALL-CONTRIBUTORS-LIST:END -->
Thanks a lot everyone!"
`;

View file

@ -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:',
'<!-- ALL-CONTRIBUTORS-LIST:START -->',
'| Kent C. Dodds is awesome! | Divjot Singh is awesome! | Jeroen Engels is awesome! |',
'| :---: | :---: | :---: |',
'<!-- ALL-CONTRIBUTORS-LIST:END -->',
'',
'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:',
'<!-- ALL-CONTRIBUTORS-LIST:START -->',
'| 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! |',
'<!-- ALL-CONTRIBUTORS-LIST:END -->',
'',
'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:',
'<!-- ALL-CONTRIBUTORS-LIST:START -->',
'<!-- prettier-ignore -->',
'<!-- ALL-CONTRIBUTORS-LIST:END -->',
'',
'Thanks a lot everyone!',

View file

@ -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<!-- prettier-ignore -->',
newContent,
previousContent.slice(startOfClosingTagIndex),
].join('')
}
}

View file

@ -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)):
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
<!-- prettier-ignore -->
<!-- ALL-CONTRIBUTORS-LIST:END -->
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)):
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
<!-- prettier-ignore -->
<!-- ALL-CONTRIBUTORS-LIST:END -->
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
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
<!-- prettier-ignore -->
<!-- ALL-CONTRIBUTORS-LIST:END -->"
`;

View file

@ -9,55 +9,21 @@ test('insert list under contributors section', () => {
'## Contributors',
'',
].join('\n')
const expected = [
'# project',
'',
'Description',
'',
'## Contributors',
'',
'<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --><!-- ALL-CONTRIBUTORS-LIST:END -->',
].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)):',
'',
'<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --><!-- ALL-CONTRIBUTORS-LIST:END -->',
'',
'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)):',
'',
'<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --><!-- ALL-CONTRIBUTORS-LIST:END -->',
'',
'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()
})

View file

@ -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 =
'<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --><!-- ALL-CONTRIBUTORS-LIST:END -->'
const listContent = [
'<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->',
'<!-- prettier-ignore -->',
'<!-- ALL-CONTRIBUTORS-LIST:END -->',
].join('\n')
const footerContent =
'This project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification. Contributions of any kind welcome!'