Skip to content

Commit e92c0a4

Browse files
committed
add unit tests, fixes
1 parent 5d6c088 commit e92c0a4

3 files changed

Lines changed: 44 additions & 9 deletions

File tree

lib/commandExecutorBuilder.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,11 @@ function buildCommandExecutor(failedByAssert, runOpts) {
9393
specificCallBack()
9494
}
9595
}
96+
9697
if(addCommandOptionsAfterRun && commandToRerun) {
9798
commandToRerun = addCommandOptionsAfterRun(commandToRerun, executionStack)
9899
}
99-
100+
// addSpecificOptionsBeforeRun was defined - we should remove useless opts what will be added in next iteration
100101
if(additionalOpts) {
101102
commandToRerun = commandToRerun.replace(additionalOpts, '')
102103
}

lib/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,10 @@ function reRunnerBuilder(runOptions) {
9797

9898
console.log(combinedFailedProcesses.length, 'Failed test count')
9999

100-
return combinedFailedProcesses
100+
return {
101+
failedCommands,
102+
failedByAssert
103+
}
101104
}
102105

103106
return reRunner

unit_specs/index.spec.js

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,16 @@ describe('kernel', () => {
99
const cmds = [cmd, cmd, cmd]
1010
const reRunner = buildExeRun()
1111
const failedCmds = await reRunner(cmds)
12-
expect(failedCmds.length).to.eq(3)
12+
expect(failedCmds.failedByAssert.length).to.eq(3)
1313
}
1414
// all positive
1515
{
1616
const cmd = `node -e "console.log('test')"`
1717
const cmds = [cmd, cmd, cmd]
1818
const reRunner = buildExeRun()
1919
const failedCmds = await reRunner(cmds)
20-
expect(failedCmds.length).to.eq(0)
20+
expect(failedCmds.failedByAssert.length).to.eq(0)
21+
expect(failedCmds.failedCommands.length).to.eq(0)
2122
}
2223
})
2324
it('buildExeRun currentExecutionVariable', async () => {
@@ -27,8 +28,8 @@ describe('kernel', () => {
2728
const cmds = [cmd]
2829
const reRunner = buildExeRun({currentExecutionVariable: 'CURRENT_EXECUTION_COUNT'})
2930
const failedCmds = await reRunner(cmds)
30-
expect(failedCmds.length).to.eq(1)
31-
expect(failedCmds.every((failedCmd) => failedCmd.includes('CURRENT_EXECUTION_COUNT=0'))).to.eq(true)
31+
expect(failedCmds.failedByAssert.length).to.eq(1)
32+
expect(failedCmds.failedCommands.every((failedCmd) => failedCmd.includes('CURRENT_EXECUTION_COUNT=0'))).to.eq(true)
3233
}
3334
// + stackAnalize
3435
{
@@ -42,8 +43,8 @@ describe('kernel', () => {
4243
currentExecutionVariable: 'CURRENT_EXECUTION_COUNT'
4344
})
4445
const failedCmds = await reRunner(cmds)
45-
expect(failedCmds.length).to.eq(1)
46-
expect(failedCmds.every((failedCmd) => failedCmd.includes(`CURRENT_EXECUTION_COUNT=${specRerunCount - 1}`))).to.eq(true)
46+
expect(failedCmds.failedCommands.length).to.eq(1)
47+
expect(failedCmds.failedCommands.every((failedCmd) => failedCmd.includes(`CURRENT_EXECUTION_COUNT=${specRerunCount - 1}`))).to.eq(true)
4748
}
4849
})
4950
it('formCommanWithOption', async () => {
@@ -64,7 +65,37 @@ describe('kernel', () => {
6465
specRerunCount
6566
})
6667
const failedCmds = await reRunner(cmds)
67-
expect(failedCmds).to.eql([`${cmd}`])
68+
expect(failedCmds.failedByAssert).to.eql([])
69+
expect(failedCmds.failedCommands).to.eql([`${cmd}`])
6870
expect(holder).to.eq(true)
6971
})
72+
73+
it('failedByAssert', async () => {
74+
{
75+
const cmd = `node -e "console.log('test'); process.exit(1)"`
76+
const cmds = [cmd, cmd, cmd]
77+
const reRunner = buildExeRun()
78+
const result = await reRunner(cmds)
79+
expect(result.failedByAssert.length).to.eq(3)
80+
expect(result.failedCommands.length).to.eq(0)
81+
}
82+
{
83+
const cmd = `node -e "console.log('test'); process.exit(0)"`
84+
const cmds = [cmd, cmd, cmd]
85+
const reRunner = buildExeRun()
86+
const result = await reRunner(cmds)
87+
expect(result.failedByAssert.length).to.eq(0)
88+
expect(result.failedCommands.length).to.eq(0)
89+
}
90+
{
91+
const cmd = `node -e "console.log('test'); process.exit(1)"`
92+
const cmdToRerrun = `node -e "console.log('should be rerruned'); process.exit(1)"`
93+
const cmds = [cmd, cmd, cmdToRerrun]
94+
const stackAnalize = (stack) => stack.includes('should be rerruned')
95+
const reRunner = buildExeRun({stackAnalize})
96+
const result = await reRunner(cmds)
97+
expect(result.failedByAssert.length).to.eq(2)
98+
expect(result.failedCommands.length).to.eq(1)
99+
}
100+
})
70101
})

0 commit comments

Comments
 (0)