Skip to content

Commit 57b90fc

Browse files
committed
spawn tests should be developed
1 parent 7c8c0ff commit 57b90fc

5 files changed

Lines changed: 22 additions & 20 deletions

File tree

lib/execProc.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,18 @@ function buildExecRunner(failedByAssert, runOpts) {
1717
let additionalOpts = null
1818
let originalCmd = cmd
1919
let specificCallBack = null
20-
let killTooLongExecution = null
2120
let executionStack = ''
2221

2322
/**
2423
* @now this variable will be used for process kill if time more than @longestProcessTime
2524
*/
2625
const now = +Date.now()
2726

27+
const killTooLongExecution = (proc) => {
28+
if(Date.now() - now >= longestProcessTime) {
29+
proc.kill()
30+
}
31+
}
2832
/**
2933
* @param {undefined|function} addSpecificOptions if function cmd will go to this function as argument
3034
*/

lib/spawnProc.js

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,51 @@
1-
const {spawn} = require('child_process')
1+
const {exec} = require('child_process')
22
const {returnStringType} = require('./helpers')
33

4-
function getRunProcess(cmd) {
5-
const {command, args = [], runOpts = {}} = cmd
6-
return spawn(command, args, runOpts)
7-
}
8-
9-
function buildSpawnRunner(failedByAssert, runOpts) {
4+
function buildExecRunner(failedByAssert, runOpts) {
105

116
const {
127
addSpecificOptionsBeforeRun,
13-
currentExecutionVariable,
148
longestProcessTime,
159
debugProcess,
1610
reformatCommand,
1711
stackAnalize
1812
} = runOpts
1913

20-
const executeCommandAsync = (cmd) => new Promise((resolve) => {
21-
const now = +Date.now()
2214

15+
const executeCommandAsync = (cmd) => new Promise((resolve) => {
2316
let watcher = null
2417
let additionalOpts = null
2518
let originalCmd = cmd
2619
let specificCallBack = null
27-
let killTooLongExecution = null
2820
let executionStack = ''
2921

3022
/**
3123
* @now this variable will be used for process kill if time more than @longestProcessTime
3224
*/
25+
const now = +Date.now()
3326

27+
const killTooLongExecution = (proc) => {
28+
if(Date.now() - now >= longestProcessTime) {
29+
proc.kill()
30+
}
31+
}
3432
/**
3533
* @param {undefined|function} addSpecificOptions if function cmd will go to this function as argument
3634
*/
37-
3835
if(addSpecificOptionsBeforeRun) {
36+
3937
const cmdObj = addSpecificOptionsBeforeRun(cmd)
4038
cmd = cmdObj.cmd
4139

4240
specificCallBack = cmdObj.cmdExecutableCB
41+
additionalOpts = cmd.replace(originalCmd, '')
4342
}
4443

4544
if(debugProcess) {console.log(cmd)}
4645

47-
const proc = getRunProcess(cmd)
48-
46+
const proc = spawn(cmd.command, cmd.args, cmd.options)
4947

50-
watcher = setInterval(() => executionWatcher(debugProcess, now, longestProcessTime, watcher, proc, resolve, cmd), 5000)
48+
watcher = setInterval(killTooLongExecution, 5000)
5149

5250
proc.on('exit', () => {clearInterval(watcher)})
5351

@@ -100,5 +98,5 @@ function buildSpawnRunner(failedByAssert, runOpts) {
10098
}
10199

102100
module.exports = {
103-
buildSpawnRunner
101+
buildExecRunner
104102
}

unit_specs/commandExecutorBuilder.spec.js renamed to unit_specs/exec/commandExecutorBuilder.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const {expect} = require('chai')
22

3-
const {buildCommandExecutor} = require('../lib/commandExecutorBuilder')
3+
const {buildCommandExecutor} = require('../../lib/commandExecutorBuilder')
44

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const {getPollTime, getFormedRunCommand} = require('../lib/helpers')
1+
const {getPollTime, getFormedRunCommand} = require('../../lib/helpers')
22
const {expect} = require('chai')
33
const path = require('path')
44

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

44
describe('kernel', () => {
55
it('buildExeRun basic execution', async () => {

0 commit comments

Comments
 (0)