Skip to content

Commit 04c06d1

Browse files
authored
fix: undefined string when using ucfirst (#4842)
* fix: undefined string when using ucfirst * fix: retries is not a function in shell command
1 parent e283c73 commit 04c06d1

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

lib/command/interactive.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,23 @@ module.exports = async function (path, options) {
2323

2424
if (options.verbose) output.level(3)
2525

26+
let addGlobalRetries
27+
28+
if (config.retry) {
29+
addGlobalRetries = function retries() {}
30+
}
31+
2632
output.print('Starting interactive shell for current suite...')
2733
recorder.start()
2834
event.emit(event.suite.before, {
2935
fullTitle: () => 'Interactive Shell',
3036
tests: [],
37+
retries: addGlobalRetries,
3138
})
3239
event.emit(event.test.before, {
3340
title: '',
3441
artifacts: {},
42+
retries: addGlobalRetries,
3543
})
3644

3745
const enabledHelpers = Container.helpers()

lib/utils.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,19 +94,19 @@ module.exports.template = function (template, data) {
9494
/**
9595
* Make first char uppercase.
9696
* @param {string} str
97-
* @returns {string}
97+
* @returns {string | undefined}
9898
*/
9999
module.exports.ucfirst = function (str) {
100-
return str.charAt(0).toUpperCase() + str.substr(1)
100+
if (str) return str.charAt(0).toUpperCase() + str.substr(1)
101101
}
102102

103103
/**
104104
* Make first char lowercase.
105105
* @param {string} str
106-
* @returns {string}
106+
* @returns {string | undefined}
107107
*/
108108
module.exports.lcfirst = function (str) {
109-
return str.charAt(0).toLowerCase() + str.substr(1)
109+
if (str) return str.charAt(0).toLowerCase() + str.substr(1)
110110
}
111111

112112
module.exports.chunkArray = function (arr, chunk) {

test/unit/utils_test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ describe('utils', () => {
3838
it('should capitalize first letter', () => {
3939
expect(utils.ucfirst('hello')).equal('Hello')
4040
})
41+
42+
it('should handle the undefined', () => {
43+
expect(utils.ucfirst()).to.be.undefined
44+
})
4145
})
4246

4347
describe('#beautify', () => {

0 commit comments

Comments
 (0)