Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: add tbody to contributors table #307

Merged
merged 4 commits into from
Sep 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
tenshiAMD marked this conversation as resolved.
Show resolved Hide resolved
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)
tenshiAMD marked this conversation as resolved.
Show resolved Hide resolved
expect(url.isHttpProtocol('https:')).toBe(true)
tenshiAMD marked this conversation as resolved.
Show resolved Hide resolved
})

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://github.com/gitapi/users/octocat')).toBe(true)
expect(url.isValidHttpUrl('https://github.com/gitapi/users/octocat')).toBe(true)
tenshiAMD marked this conversation as resolved.
Show resolved Hide resolved
})

test(`Result of url validation should be false when url uses wrong protocol`, () => {
expect(url.isValidHttpUrl('git://git@github.com:all-contributors/all-contributors-cli.git')).toBe(false)
expect(
url.isValidHttpUrl(
'git://git@github.com: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://github.com/gitapi/users/octocat'
const expected = 'https://github.com/gitapi/users/octocat'
expect(url.parseHttpUrl(input)).toBe(expected)
const input = 'https://github.com/gitapi/users/octocat'
const expected = 'https://github.com/gitapi/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(
tenshiAMD marked this conversation as resolved.
Show resolved Hide resolved
'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',
tenshiAMD marked this conversation as resolved.
Show resolved Hide resolved
)
})

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')
tenshiAMD marked this conversation as resolved.
Show resolved Hide resolved
})