Skip to content

Commit 6a86629

Browse files
committed
fix failed test pushing
1 parent 17dea84 commit 6a86629

4 files changed

Lines changed: 85 additions & 22 deletions

File tree

lib/commandExecutorBuilder.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,14 @@ function buildCommandExecutor(failedByAssert, runOpts) {
6666

6767
proc.on('close', async (code) => {
6868

69+
let commandToRerun = null
6970

7071
if(debugProcess) {console.log(executionStack, code)}
7172

72-
let commandToRerun = null
73+
// if process code 0 - exit as a success result
74+
if(code === 0) {
75+
resolve(commandToRerun); return
76+
}
7377
// stackAnalize - check that stack contains or not contains some specific data
7478
if(code !== 0 && stackAnalize && stackAnalize(executionStack)) {
7579
commandToRerun = cmd
@@ -90,7 +94,6 @@ function buildCommandExecutor(failedByAssert, runOpts) {
9094
if(addCommandOptionsAfterRun && commandToRerun) {
9195
commandToRerun = addCommandOptionsAfterRun(commandToRerun, executionStack)
9296
}
93-
9497
resolve(commandToRerun)
9598
})
9699
})

lib/index.js

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,23 +43,38 @@ function reRunnerBuilder(runOptions) {
4343
.map((file) => getFormedRunCommand(file)))
4444
.filter(function(cmd) {return cmd.includes(grepWord)})
4545

46-
const failedTests = await new Array(commandRunTriesCount)
46+
const failedCommands = await new Array(commandRunTriesCount)
47+
// create array with current length
4748
.fill(commandRunTriesCount)
49+
// execute run
4850
.reduce((resolver, /*current*/ current, index) => {
49-
return resolver.then((resolvedCommandsArray) => runCommandsArray(resolvedCommandsArray, [], index)
50-
.then((failedCommandsArray) => failedCommandsArray))
51+
52+
return resolver.then((resolvedCommandsArray) => {
53+
54+
// console.log(resolvedCommandsArray, 'Commands array', index)
55+
56+
return runCommandsArray(resolvedCommandsArray, [], index)
57+
58+
.then((failedCommandsArray) => {
59+
console.log(failedCommandsArray, 'failed commands')
60+
return failedCommandsArray
61+
})
62+
})
5163
}, Promise.resolve(commandsArray))
5264

5365
/**
5466
* @param {Array} commands command array what should be executed
5567
* @param {Array} failedCommands array what will contains failed commands
5668
* @returns {void}
5769
*/
70+
5871
async function runCommand(commands, failedCommands) {
5972
if(maxSessionCount > currentSessionCount && commands.length) {
6073
currentSessionCount += 1
61-
const result = await executeCommandAsync(commands.splice(0, 1)[0]).catch(console.error);
62-
if(result) {failedCommands.push(result)}
74+
const result = await executeCommandAsync(commands.splice(0, 1)[0]).catch(console.error)
75+
if(result) {
76+
failedCommands.push(result)
77+
}
6378
currentSessionCount -= 1
6479
}
6580
}
@@ -80,8 +95,11 @@ function reRunnerBuilder(runOptions) {
8095
return failedCommands
8196
}
8297

83-
console.log(failedTests.length, 'Failed test count')
84-
return [...failedTests, ...failedByAssert]
98+
const combinedFailedProcesses = [...failedCommands, ...failedByAssert]
99+
100+
console.log(combinedFailedProcesses.length, 'Failed test count')
101+
102+
return combinedFailedProcesses
85103
}
86104

87105
return reRunner
@@ -101,7 +119,7 @@ module.exports = {
101119
formCommanWithOption,
102120
pollTime = 1000,
103121
currentExecutionVariable
104-
}) => {
122+
} = {}) => {
105123

106124
const reformattedArgs = {
107125
formCommanWithOption,

unit_specs/commandExecutorBuilder.spec.js

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,41 @@ const {buildCommandExecutor} = require('../lib/commandExecutorBuilder')
44

55
describe('buildCommandExecutor', () => {
66

7-
it('addSpecificOptionsBeforeRun', async () => {
8-
const failedByAssert = []
9-
let holder = null
7+
it.only('addSpecificOptionsBeforeRun', async () => {
8+
{
9+
const cmd = 'node -e "console.log(\'test\')"'
10+
const failedByAssert = []
11+
let holder = null
1012

11-
const addSpecificOptionsBeforeRun = (cmd) => {
12-
const reformatedCmd = `${cmd} && echo "FOO"`
13-
holder = {cmd: reformatedCmd}
14-
const cmdExecutableCB = () => {holder.exec = true}
13+
const addSpecificOptionsBeforeRun = (cmd) => {
14+
const reformatedCmd = `${cmd} && echo "FOO"`
15+
holder = {cmd: reformatedCmd}
16+
const cmdExecutableCB = () => {holder.exec = true}
17+
return {cmd, cmdExecutableCB}
18+
}
1519

16-
return {cmd, cmdExecutableCB}
20+
const executeCommandAsync = buildCommandExecutor(failedByAssert, {addSpecificOptionsBeforeRun})
21+
await executeCommandAsync(cmd)
22+
expect(holder.cmd).to.eq(`${cmd} && echo "FOO"`)
23+
expect(holder.exec).to.eq(undefined)
1724
}
25+
{
26+
const cmd = 'node -e "console.log(\'test\'); process.exit(100)"'
27+
const failedByAssert = []
28+
let holder = null
1829

19-
const executeCommandAsync = buildCommandExecutor(failedByAssert, {addSpecificOptionsBeforeRun})
20-
await executeCommandAsync('node -e "console.log(\'test\')"')
21-
expect(holder.cmd).to.eq('node -e "console.log(\'test\')" && echo "FOO"')
22-
expect(holder.exec).to.eq(true)
30+
const addSpecificOptionsBeforeRun = (cmd) => {
31+
const reformatedCmd = `${cmd} && echo "FOO"`
32+
holder = {cmd: reformatedCmd}
33+
const cmdExecutableCB = () => {holder.exec = true}
34+
return {cmd, cmdExecutableCB}
35+
}
36+
37+
const executeCommandAsync = buildCommandExecutor(failedByAssert, {addSpecificOptionsBeforeRun})
38+
await executeCommandAsync(cmd)
39+
expect(holder.cmd).to.eq(`${cmd} && echo "FOO"`)
40+
expect(holder.exec).to.eq(true)
41+
}
2342
})
2443

2544
it('addCommandOptionsAfterRun', async () => {

unit_specs/index.spec.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
const {expect} = require('chai')
2+
const {buildExeRun} = require('../lib')
3+
4+
describe('kernel', () => {
5+
it('buildExeRun', async () => {
6+
// all negative
7+
{
8+
const cmd = `node -e "console.log('test'); process.exit(1)"`
9+
const cmds = [cmd, cmd, cmd]
10+
const reRunner = buildExeRun()
11+
const failedCmds = await reRunner(cmds)
12+
expect(failedCmds.length).to.eq(3)
13+
}
14+
// all positive
15+
{
16+
const cmd = `node -e "console.log('test')"`
17+
const cmds = [cmd, cmd, cmd]
18+
const reRunner = buildExeRun()
19+
const failedCmds = await reRunner(cmds)
20+
expect(failedCmds.length).to.eq(0)
21+
}
22+
})
23+
})

0 commit comments

Comments
 (0)