Skip to content

Commit d01f19b

Browse files
committed
add specs and fixes
1 parent 6a86629 commit d01f19b

4 files changed

Lines changed: 33 additions & 9 deletions

File tree

lib/commandExecutorBuilder.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function buildCommandExecutor(failedByAssert, runOpts) {
3636

3737
if(currentExecutionVariable) {
3838
if(cmd.includes(currentExecutionVariable)) {
39-
cmd = cmd.replace(new RegExp(`${currentExecutionVariable}=\\d`, 'ig'), `${currentExecutionVariable}=${index}`)
39+
cmd = cmd.replace(new RegExp(`${currentExecutionVariable}=\\d+`, 'ig'), `${currentExecutionVariable}=${index}`)
4040
} else {
4141
cmd = `${currentExecutionVariable}=${index} ${cmd}`
4242
}

lib/index.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const {buildCommandExecutor} = require('./commandExecutorBuilder')
22
const {sleep, getFormedRunCommand, getSpecFilesPath, getPollTime} = require('./helpers')
33

44
function reRunnerBuilder(runOptions) {
5+
56
const failedByAssert = []
67
let currentSessionCount = 0
78

@@ -51,12 +52,9 @@ function reRunnerBuilder(runOptions) {
5152

5253
return resolver.then((resolvedCommandsArray) => {
5354

54-
// console.log(resolvedCommandsArray, 'Commands array', index)
55-
5655
return runCommandsArray(resolvedCommandsArray, [], index)
5756

5857
.then((failedCommandsArray) => {
59-
console.log(failedCommandsArray, 'failed commands')
6058
return failedCommandsArray
6159
})
6260
})
@@ -68,10 +66,10 @@ function reRunnerBuilder(runOptions) {
6866
* @returns {void}
6967
*/
7068

71-
async function runCommand(commands, failedCommands) {
69+
async function runCommand(commands, failedCommands, runIndex) {
7270
if(maxSessionCount > currentSessionCount && commands.length) {
7371
currentSessionCount += 1
74-
const result = await executeCommandAsync(commands.splice(0, 1)[0]).catch(console.error)
72+
const result = await executeCommandAsync(commands.splice(0, 1)[0], runIndex).catch(console.error)
7573
if(result) {
7674
failedCommands.push(result)
7775
}
@@ -83,7 +81,7 @@ function reRunnerBuilder(runOptions) {
8381
const asserter = setInterval(() => runCommand(commands, failedCommands, executionCount), intervalPoll);
8482

8583
do {
86-
if(commands.length) {await runCommand(commands, failedCommands)}
84+
if(commands.length) {await runCommand(commands, failedCommands, executionCount)}
8785
if(currentSessionCount) {await sleep(2000)}
8886
} while(commands.length || currentSessionCount)
8987

unit_specs/commandExecutorBuilder.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const {buildCommandExecutor} = require('../lib/commandExecutorBuilder')
44

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

7-
it.only('addSpecificOptionsBeforeRun', async () => {
7+
it('addSpecificOptionsBeforeRun', async () => {
88
{
99
const cmd = 'node -e "console.log(\'test\')"'
1010
const failedByAssert = []

unit_specs/index.spec.js

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const {expect} = require('chai')
22
const {buildExeRun} = require('../lib')
33

44
describe('kernel', () => {
5-
it('buildExeRun', async () => {
5+
it('buildExeRun basic execution', async () => {
66
// all negative
77
{
88
const cmd = `node -e "console.log('test'); process.exit(1)"`
@@ -20,4 +20,30 @@ describe('kernel', () => {
2020
expect(failedCmds.length).to.eq(0)
2121
}
2222
})
23+
it('buildExeRun currentExecutionVariable', async () => {
24+
// all negative
25+
{
26+
const cmd = `node -e "console.log('test'); process.exit(1)"`
27+
const cmds = [cmd]
28+
const reRunner = buildExeRun({currentExecutionVariable: 'CURRENT_EXECUTION_COUNT'})
29+
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)
32+
}
33+
// + stackAnalize
34+
{
35+
const cmd = `node -e "console.log('test'); process.exit(1)"`
36+
const stackAnalize = () => true
37+
const specRerunCount = 15
38+
const cmds = [cmd]
39+
const reRunner = buildExeRun({
40+
stackAnalize,
41+
specRerunCount,
42+
currentExecutionVariable: 'CURRENT_EXECUTION_COUNT'
43+
})
44+
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)
47+
}
48+
})
2349
})

0 commit comments

Comments
 (0)