Skip to content

Commit de8ead9

Browse files
committed
refactor
1 parent 266644d commit de8ead9

7 files changed

Lines changed: 39 additions & 35 deletions

File tree

bin/rerun

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const argv = require('minimist')(process.argv.slice(2))
1111
if(argv.protractor) {
1212
const defaultBuilder = {
1313
maxSessionCount: argv.maxSessionCount || 5,
14-
specRerunCount: argv.specRerunCount || 2,
14+
attemptsCount: argv.attemptsCount || 2,
1515
stackAnalize: () => true,
1616
everyCycleCallback: async () => true,
1717
grepWord: argv.grepWord || '',

lib/commandExecutorBuilder.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ function buildCommandExecutor(failedByAssert, runOpts) {
88
currentExecutionVariable,
99
longestProcessTime,
1010
debugProcess,
11-
addCommandOptionsAfterRun,
11+
reformatCommand,
1212
stackAnalize
1313
} = runOpts
1414

@@ -85,7 +85,7 @@ function buildCommandExecutor(failedByAssert, runOpts) {
8585
// stackAnalize - check that stack contains or not contains some specific data
8686
if(code !== 0 && stackAnalize && stackAnalize(executionStack)) {
8787
commandToRerun = cmd
88-
} else if(code !== 0 && addCommandOptionsAfterRun) {
88+
} else if(code !== 0 && reformatCommand) {
8989
commandToRerun = cmd
9090
} else {
9191
failedByAssert.push(cmd)
@@ -100,8 +100,8 @@ function buildCommandExecutor(failedByAssert, runOpts) {
100100
}
101101
}
102102

103-
if(addCommandOptionsAfterRun && commandToRerun) {
104-
commandToRerun = addCommandOptionsAfterRun(commandToRerun, executionStack)
103+
if(reformatCommand && commandToRerun) {
104+
commandToRerun = reformatCommand(commandToRerun, executionStack)
105105
}
106106
// addSpecificOptionsBeforeRun was defined - we should remove useless opts what will be added in next iteration
107107
if(additionalOpts) {

lib/helpers.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const getFormedRunCommand = (file, conf = path.resolve(process.cwd(), './protrac
1919
* @param {array<string>} directoryToSkip option, directories what should be exclude from files list
2020
* @returns {array<string>}
2121
*/
22-
const getSpecFilesPath = function(dir, fileList = [], directoryToSkip = []) {
22+
const getFilesArray = function(dir, fileList = [], directoryToSkip = []) {
2323
const files = fs.readdirSync(dir)
2424
files.forEach(function(file) {
2525
const isDirr = fs.statSync(path.join(dir, file)).isDirectory()
@@ -31,7 +31,7 @@ const getSpecFilesPath = function(dir, fileList = [], directoryToSkip = []) {
3131
if(shouldBeExcluded) {return }
3232

3333
if(isDirr) {
34-
fileList = getSpecFilesPath(path.join(dir, file), fileList, directoryToSkip)
34+
fileList = getFilesArray(path.join(dir, file), fileList, directoryToSkip)
3535
} else {
3636
fileList.push(path.join(dir, file))
3737
}
@@ -60,6 +60,6 @@ module.exports = {
6060
getFormedRunCommand,
6161
getPollTime,
6262
sleep,
63-
getSpecFilesPath,
63+
getFilesArray,
6464
returnStringType
6565
}

lib/index.js

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const {buildCommandExecutor} = require('./commandExecutorBuilder')
2-
const {sleep, getFormedRunCommand, getSpecFilesPath, getPollTime} = require('./helpers')
2+
const {sleep, getFormedRunCommand, getFilesArray, getPollTime} = require('./helpers')
33

44
function reRunnerBuilder(runOptions) {
55

@@ -8,12 +8,12 @@ function reRunnerBuilder(runOptions) {
88

99
const {
1010
stackAnalize,
11-
specRerunCount: commandRunTriesCount,
11+
attemptsCount,
1212
grepWord,
1313
debugProcess,
14-
reformatCommand: addCommandOptionsAfterRun,
14+
reformatCommand,
1515
intervalPoll,
16-
everyCycleCallback: afterSingleRunCallBack,
16+
everyCycleCallback,
1717
specsDir,
1818
longestProcessTime,
1919
formCommanWithOption: addSpecificOptionsBeforeRun,
@@ -33,20 +33,20 @@ function reRunnerBuilder(runOptions) {
3333
currentExecutionVariable,
3434
longestProcessTime,
3535
debugProcess,
36-
addCommandOptionsAfterRun,
36+
reformatCommand,
3737
stackAnalize
3838
})
3939

4040

4141
async function reRunner(commandsArray) {
4242
// if run arr was not defined as argument commandsArray will defined as default array
43-
commandsArray = (commandsArray || getSpecFilesPath(specsDir)
43+
commandsArray = (commandsArray || getFilesArray(specsDir)
4444
.map((file) => getFormedRunCommand(file)))
4545
.filter(function(cmd) {return cmd.includes(grepWord)})
4646

47-
const failedCommands = await new Array(commandRunTriesCount)
47+
const failedCommands = await new Array(attemptsCount)
4848
// create array with current length
49-
.fill(commandRunTriesCount)
49+
.fill(attemptsCount)
5050
// execute run
5151
.reduce((resolver, /*current*/ current, index) => {
5252

@@ -85,8 +85,12 @@ function reRunnerBuilder(runOptions) {
8585
if(currentSessionCount) {await sleep(2000)}
8686
} while(commands.length || currentSessionCount)
8787

88-
if(afterSingleRunCallBack && typeof afterSingleRunCallBack === 'function') {
89-
try {await afterSingleRunCallBack()} catch(e) {console.log(e)}
88+
if(everyCycleCallback && typeof everyCycleCallback === 'function') {
89+
try {
90+
await everyCycleCallback()
91+
} catch(e) {
92+
console.log(e)
93+
}
9094
}
9195

9296
clearInterval(asserter)
@@ -110,7 +114,7 @@ function reRunnerBuilder(runOptions) {
110114
module.exports = {
111115
buildExeRun: ({
112116
maxSessionCount = 5,
113-
specRerunCount = 2,
117+
attemptsCount = 2,
114118
stackAnalize,
115119
everyCycleCallback,
116120
reformatCommand,
@@ -127,7 +131,7 @@ module.exports = {
127131
debugProcess,
128132
longestProcessTime,
129133
maxSessionCount,
130-
specRerunCount,
134+
attemptsCount,
131135
reformatCommand,
132136
stackAnalize,
133137
grepWord,
@@ -139,6 +143,6 @@ module.exports = {
139143
return reRunnerBuilder(reformattedArgs)
140144
},
141145
sleep,
142-
walkSync: getSpecFilesPath,
146+
walkSync: getFilesArray,
143147
getRunCommand: getFormedRunCommand
144148
}

readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ const commandsArray = specsArr.map(filePath)
5252
getReruner(obj) params
5353
@{everyCycleCallback} function, will execute after full cycle done, before next cycle
5454
@{maxSessionCount} number, for example we have hub for 10 browsers, so maxSessionCount equal 10
55-
@{specRerunCount} number, hom many times will reruned failed processes
55+
@{attemptsCount} number, hom many times will reruned failed processes
5656
@{stackAnalize} function, if stack trace includes some math this process will not go to rerun scope
5757
*/
5858
const cycleCB = () => console.log('Cycle done')
@@ -61,7 +61,7 @@ const stackAnalize = (stack) => !stack.includes('ASSERTION ERROR')
6161
const runner = getReruner({
6262
everyCycleCallback: cycleCB,
6363
maxSessionCount: 1,
64-
specRerunCount: 3,
64+
attemptsCount: 3,
6565
stackAnalize: stackAnalize,
6666
debugProcess: processEnv.DEBUG_PROCESS
6767
})

unit_specs/commandExecutorBuilder.spec.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,18 @@ describe('buildCommandExecutor', () => {
4141
}
4242
})
4343

44-
it('addCommandOptionsAfterRun', async () => {
44+
it('reformatCommand', async () => {
4545
const failedByAssert = []
4646
let holder = null
4747

4848
const cmd = `node -e "console.log('test'); process.exit(1)"`
4949

50-
const addCommandOptionsAfterRun = (cmd, stack) => {
50+
const reformatCommand = (cmd, stack) => {
5151
holder = {}
5252
holder.cmd = cmd
5353
holder.stack = stack
5454
}
55-
const executeCommandAsync = buildCommandExecutor(failedByAssert, {addCommandOptionsAfterRun})
55+
const executeCommandAsync = buildCommandExecutor(failedByAssert, {reformatCommand})
5656
await executeCommandAsync(cmd)
5757
expect(holder.cmd).to.eq(cmd)
5858
expect(holder.stack).to.eql('test\n')
@@ -63,7 +63,7 @@ describe('buildCommandExecutor', () => {
6363
let holder = null
6464
const cmd = `node -e "console.log('test'); process.exit(1)"`
6565

66-
const addCommandOptionsAfterRun = (cmd, stack) => {
66+
const reformatCommand = (cmd, stack) => {
6767
if(!holder) holder = {}
6868
holder.cmd = cmd
6969
holder.stack = stack
@@ -74,7 +74,7 @@ describe('buildCommandExecutor', () => {
7474
return false
7575
}
7676
const executeCommandAsync = buildCommandExecutor(failedByAssert, {
77-
addCommandOptionsAfterRun, stackAnalize
77+
reformatCommand, stackAnalize
7878
})
7979
await executeCommandAsync(cmd)
8080
expect(holder.fromStackAnalize).to.eq('test\n')
@@ -128,7 +128,7 @@ describe('buildCommandExecutor', () => {
128128
return false
129129
}
130130

131-
const addCommandOptionsAfterRun = (cmd, stack) => {
131+
const reformatCommand = (cmd, stack) => {
132132
if(!holder) holder = {}
133133
holder.cmd = cmd
134134
holder.stack = stack
@@ -137,7 +137,7 @@ describe('buildCommandExecutor', () => {
137137

138138
const executeCommandAsync = buildCommandExecutor(failedByAssert, {
139139
stackAnalize,
140-
addCommandOptionsAfterRun,
140+
reformatCommand,
141141
currentExecutionVariable
142142
})
143143

unit_specs/index.spec.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,23 +35,23 @@ describe('kernel', () => {
3535
{
3636
const cmd = `node -e "console.log('test'); process.exit(1)"`
3737
const stackAnalize = () => true
38-
const specRerunCount = 15
38+
const attemptsCount = 15
3939
const cmds = [cmd]
4040
const reRunner = buildExeRun({
4141
stackAnalize,
42-
specRerunCount,
42+
attemptsCount,
4343
currentExecutionVariable: 'CURRENT_EXECUTION_COUNT'
4444
})
4545
const failedCmds = await reRunner(cmds)
4646
expect(failedCmds.failedCommands.length).to.eq(1)
47-
expect(failedCmds.failedCommands.every((failedCmd) => failedCmd.includes(`CURRENT_EXECUTION_COUNT=${specRerunCount - 1}`))).to.eq(true)
47+
expect(failedCmds.failedCommands.every((failedCmd) => failedCmd.includes(`CURRENT_EXECUTION_COUNT=${attemptsCount - 1}`))).to.eq(true)
4848
}
4949
})
5050
it('formCommanWithOption', async () => {
5151
let holder = null
5252
const cmd = `node -e "console.log('test'); process.exit(1)"`
5353
const stackAnalize = () => true
54-
const specRerunCount = 2
54+
const attemptsCount = 2
5555
const formCommanWithOption = (cmd) => {
5656
return {
5757
cmd: `TEST_ENV=test ${cmd}`,
@@ -62,7 +62,7 @@ describe('kernel', () => {
6262
const reRunner = buildExeRun({
6363
stackAnalize,
6464
formCommanWithOption,
65-
specRerunCount
65+
attemptsCount
6666
})
6767
const failedCmds = await reRunner(cmds)
6868
expect(failedCmds.failedByAssert).to.eql([])

0 commit comments

Comments
 (0)