Skip to content

Commit

Permalink
refactor: add tbody to contributors table (#307)
Browse files Browse the repository at this point in the history
* refactor: add tbody to contributors table

* chore(node): bump version to lts

* fix(html): add correct indentation

* test(url): fix bind error message

Co-authored-by: Pierre Huyghe <[email protected]>
  • Loading branch information
hpierre74 and Pierre Huyghe authored Sep 7, 2022
1 parent 5dbb721 commit deb6be9
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 42 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: 2.1

docker_defaults: &docker_defaults
docker:
- image: circleci/node:12.14.0
- image: cimg/node:16.17.0

commands:
prep_env:
Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
12.14.0
16.17.0
36 changes: 20 additions & 16 deletions src/generate/__tests__/__snapshots__/index.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ These people contributed to the project:
<!-- prettier-ignore-start -->
<!-- markdownlint-disable -->
<table>
<tr>
<td align=\\"center\\">Kent C. Dodds is awesome!</td>
<td align=\\"center\\">Divjot Singh is awesome!</td>
<td align=\\"center\\">Jeroen Engels is awesome!</td>
</tr>
<tbody>
<tr>
<td align=\\"center\\">Kent C. Dodds is awesome!</td>
<td align=\\"center\\">Divjot Singh is awesome!</td>
<td align=\\"center\\">Jeroen Engels is awesome!</td>
</tr>
</tobdy>
</table>
<!-- markdownlint-restore -->
Expand All @@ -37,17 +39,19 @@ These people contributed to the project:
<!-- prettier-ignore-start -->
<!-- markdownlint-disable -->
<table>
<tr>
<td align=\\"center\\">Kent C. Dodds is awesome!</td>
<td align=\\"center\\">Kent C. Dodds is awesome!</td>
<td align=\\"center\\">Kent C. Dodds is awesome!</td>
<td align=\\"center\\">Kent C. Dodds is awesome!</td>
<td align=\\"center\\">Kent C. Dodds is awesome!</td>
</tr>
<tr>
<td align=\\"center\\">Kent C. Dodds is awesome!</td>
<td align=\\"center\\">Kent C. Dodds is awesome!</td>
</tr>
<tbody>
<tr>
<td align=\\"center\\">Kent C. Dodds is awesome!</td>
<td align=\\"center\\">Kent C. Dodds is awesome!</td>
<td align=\\"center\\">Kent C. Dodds is awesome!</td>
<td align=\\"center\\">Kent C. Dodds is awesome!</td>
<td align=\\"center\\">Kent C. Dodds is awesome!</td>
</tr>
<tr>
<td align=\\"center\\">Kent C. Dodds is awesome!</td>
<td align=\\"center\\">Kent C. Dodds is awesome!</td>
</tr>
</tobdy>
</table>
<!-- markdownlint-restore -->
Expand Down
10 changes: 5 additions & 5 deletions src/generate/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const formatBadge = require('./format-badge')
const formatContributor = require('./format-contributor')

function injectListBetweenTags(newContent) {
return function(previousContent) {
return function (previousContent) {
const tagToLookFor = `<!-- ALL-CONTRIBUTORS-LIST:`
const closingTag = '-->'
const startOfOpeningTagIndex = previousContent.indexOf(
Expand Down Expand Up @@ -39,7 +39,7 @@ function injectListBetweenTags(newContent) {

function formatLine(contributors) {
return `<td align="center">${contributors.join(
'</td>\n <td align="center">',
'</td>\n <td align="center">',
)}</td>`
}

Expand All @@ -55,15 +55,15 @@ function generateContributorsList(options, contributors) {
}),
_.chunk(options.contributorsPerLine),
_.map(formatLine),
_.join('\n </tr>\n <tr>\n '),
_.join('\n </tr>\n <tr>\n '),
newContent => {
return `\n<table>\n <tr>\n ${newContent}\n </tr>\n</table>\n\n`
return `\n<table>\n <tbody>\n <tr>\n ${newContent}\n </tr>\n </tobdy>\n</table>\n\n`
},
)(contributors)
}

function replaceBadge(newContent) {
return function(previousContent) {
return function (previousContent) {
const tagToLookFor = `<!-- ALL-CONTRIBUTORS-BADGE:`
const closingTag = '-->'
const startOfOpeningTagIndex = previousContent.indexOf(
Expand Down
46 changes: 27 additions & 19 deletions src/util/__tests__/url.js
Original file line number Diff line number Diff line change
@@ -1,49 +1,57 @@
import url from '../url';
import url from '../url'

test(`Result of protocol validation should be true`, () => {
expect(url.isHttpProtocol('http:')).toBe(true)
expect(url.isHttpProtocol('https:')).toBe(true)
expect(url.isHttpProtocol('http:')).toBe(true)
expect(url.isHttpProtocol('https:')).toBe(true)
})

test(`Result of protocol validation should be false`, () => {
expect(url.isHttpProtocol('ftp:')).toBe(false)
expect(url.isHttpProtocol('ftp:')).toBe(false)
})

test(`Result of url validation should be true`, () => {
expect(url.isValidHttpUrl('https://api.github.com/users/octocat')).toBe(true)
expect(url.isValidHttpUrl('https://api.github.com/users/octocat')).toBe(true)
})

test(`Result of url validation should be false when url uses wrong protocol`, () => {
expect(url.isValidHttpUrl('git://[email protected]:all-contributors/all-contributors-cli.git')).toBe(false)
expect(
url.isValidHttpUrl(
'git://[email protected]:all-contributors/all-contributors-cli.git',
),
).toBe(false)
})

test(`Result of url validation should be false when input isn't url`, () => {
expect(url.isValidHttpUrl('github-octocat')).toBe(false)
expect(url.isValidHttpUrl('github-octocat')).toBe(false)
})

test(`Result of parsed url should be equal`, () => {
const input = 'https://api.github.com/users/octocat'
const expected = 'https://api.github.com/users/octocat'
expect(url.parseHttpUrl(input)).toBe(expected)
const input = 'https://api.github.com/users/octocat'
const expected = 'https://api.github.com/users/octocat'
expect(url.parseHttpUrl(input)).toBe(expected)
})

test(`Result of parsed url without protocol should be equal`, () => {
const input = 'example.com'
const expected = 'http://example.com/'
expect(url.parseHttpUrl(input)).toBe(expected)
const input = 'example.com'
const expected = 'http://example.com/'
expect(url.parseHttpUrl(input)).toBe(expected)
})

test(`Throw an error when parsed input isn't a string`, () => {
const input = 123
expect(url.parseHttpUrl.bind(null, input)).toThrowError('input must be a string')
const input = 123
expect(url.parseHttpUrl.bind(null, input)).toThrowError(
'input must be a string',
)
})

test(`Throw an error when parsed url has wrong protocol`, () => {
const input = 'ftp://domain.xyz'
expect(url.parseHttpUrl.bind(null, input)).toThrowError('Provided URL has an invalid protocol')
const input = 'ftp://domain.xyz'
expect(url.parseHttpUrl.bind(null, input)).toThrowError(
'Provided URL has an invalid protocol',
)
})

test(`Throw an error when parsed input isn't a URL`, () => {
const input = 'some string'
expect(url.parseHttpUrl.bind(null, input)).toThrowError('Invalid URL: http://some string')
const input = 'some string'
expect(url.parseHttpUrl.bind(null, input)).toThrowError('Invalid URL')
})

0 comments on commit deb6be9

Please sign in to comment.