Skip to content

Commit

Permalink
fix no git repo error (#92)
Browse files Browse the repository at this point in the history
* fix no git repo error

* Add encoding to tests

* trim project root
  • Loading branch information
eddiemoore authored May 12, 2021
1 parent 8be63a6 commit 9bc76a6
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 16 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@
"it",
"describe",
"beforeEach",
"afterEach"
"afterEach",
"jest"
]
}
}
12 changes: 5 additions & 7 deletions src/helpers/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,13 @@ function fetchGitRoot () {
try {
return (
childProcess
.spawnSync('git', ['rev-parse', '--show-toplevel'])
.stdout.toString()
.trimRight() ||
.spawnSync('git', ['rev-parse', '--show-toplevel'], { encoding: 'utf-8' })
.stdout ||
childProcess
.spawnSync('hg', ['root'])
.stdout.toString()
.trimRight() ||
.spawnSync('hg', ['root'], { encoding: 'utf-8' })
.stdout ||
process.cwd()
)
).trimRight()
} catch (error) {
throw new Error('Error fetching git root. Please try using the -R flag.')
}
Expand Down
7 changes: 3 additions & 4 deletions src/helpers/web.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,10 @@ async function uploadToCodecov (uploadURL, token, query, uploadFile, version) {
}
}


function camelToSnake(str) {
function camelToSnake (str) {
return str && str.match(/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g)
.map(s => s.toLowerCase())
.join('_')
.map(s => s.toLowerCase())
.join('_')
}

function generateQuery (queryParams) {
Expand Down
2 changes: 1 addition & 1 deletion test/helpers/files.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('File Helpers', () => {
const cwd = td.replace(process, 'cwd')
const spawnSync = td.replace(childProcess, 'spawnSync')
td.when(cwd()).thenReturn({ stdout: 'fish' })
td.when(spawnSync('git', ['rev-parse', '--show-toplevel'])).thenReturn({ stdout: 'gitRoot' })
td.when(spawnSync('git', ['rev-parse', '--show-toplevel'], { encoding:'utf-8' })).thenReturn({ stdout: 'gitRoot' })

expect(fileHelpers.fetchGitRoot()).toBe('gitRoot')
})
Expand Down
1 change: 0 additions & 1 deletion test/helpers/validate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ describe('Input Validators', function () {
})

describe('Flags', function () {

it('Should pass without a dash', function () {
expect(validate.validateFlags('moo')).toBe(true)
})
Expand Down
4 changes: 2 additions & 2 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ describe('Uploader Core', function () {
const result = await app.main({
token: 'abcdefg',
url: 'https://codecov.io',
parent,
parent
})
expect(result).toEqual({ status: 'success', resultURL: 'https://results.codecov.io' })
}, 30000)
Expand All @@ -117,7 +117,7 @@ describe('Uploader Core', function () {
name: 'customname',
token: 'abcdefg',
url: 'https://codecov.io',
dryRun: true,
dryRun: true
})
expect(log).toHaveBeenCalledWith(expect.stringMatching(/An example coverage root file/))
expect(log).toHaveBeenCalledWith(expect.stringMatching(/An example coverage other file/))
Expand Down

0 comments on commit 9bc76a6

Please sign in to comment.