Skip to content

Commit

Permalink
small fixes, backward compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
potapovDim committed Jul 10, 2020
1 parent 0dbe888 commit 4d3ebd7
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ package-lock.json
ex.js
spa-report
.idea
playground.js
playground.*
4 changes: 2 additions & 2 deletions bin/rerun
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ process.title = 'protractor-rerun'

const path = require('path')
const fs = require('fs')
const {walkSync, buildExeRun, getRunCommand} = require('../lib')
const {getFilesList, buildExeRun, getRunCommand} = require('../lib')

const argv = require('minimist')(process.argv.slice(2))

Expand Down Expand Up @@ -48,7 +48,7 @@ if(argv.protractor) {
process.exit(1)
}

const specFiles = walkSync(argv.specDir ? argv.specDir : defaultSpecDir)
const specFiles = getFilesList(argv.specDir ? argv.specDir : defaultSpecDir)
.filter((file) => file.includes(defaultBuilder.grepWord))

if(!specFiles.length) {
Expand Down
7 changes: 1 addition & 6 deletions lib/execProc.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
const {exec} = require('child_process');
const {returnStringType} = require('./helpers');

function millisecondsToMinutes(milliseconds) {
const minutes = Math.floor(milliseconds / 60000);
const seconds = ((milliseconds % 60000) / 1000).toFixed(0);
return (seconds === '60' ? (minutes + 1) + ":00" : minutes + ":" + (seconds < 10 ? "0" : "") + seconds);
}
const {millisecondsToMinutes} = require('./utils')

function buildExecRunner(failedByAssert, runOpts) {
const {
Expand Down
10 changes: 6 additions & 4 deletions lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ const getFormedRunCommand = (file, conf = path.resolve(process.cwd(), './protrac
* @param {string} dir a path to the director what should be read
* @param {array<string>} fileList option, empty array what will contains all files
* @param {array<string>} directoryToSkip option, directories what should be exclude from files list
* @param {boolean} ignoreSubDirs option, directories what should be exclude from files list
* @returns {array<string>}
*/
const getFilesArray = function(dir, fileList = [], directoryToSkip = []) {
const getFilesList = function(dir, fileList = [], directoryToSkip = [], ignoreSubDirs) {

const files = fs.readdirSync(dir)
files.forEach(function(file) {
const isDirr = fs.statSync(path.join(dir, file)).isDirectory()
Expand All @@ -30,8 +32,8 @@ const getFilesArray = function(dir, fileList = [], directoryToSkip = []) {

if(shouldBeExcluded) {return }

if(isDirr) {
fileList = getFilesArray(path.join(dir, file), fileList, directoryToSkip)
if(isDirr && !ignoreSubDirs) {
fileList = getFilesList(path.join(dir, file), fileList, directoryToSkip, ignoreSubDirs)
} else {
fileList.push(path.join(dir, file))
}
Expand Down Expand Up @@ -60,6 +62,6 @@ module.exports = {
getFormedRunCommand,
getPollTime,
sleep,
getFilesArray,
getFilesList,
returnStringType
}
6 changes: 3 additions & 3 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const {buildCommandExecutor} = require('./commandExecutorBuilder')
const {sleep, getFormedRunCommand, getFilesArray, getPollTime} = require('./helpers')
const {sleep, getFormedRunCommand, getFilesList, getPollTime} = require('./helpers')

function reRunnerBuilder(runOptions) {

Expand Down Expand Up @@ -42,7 +42,7 @@ function reRunnerBuilder(runOptions) {

async function reRunner(commandsArray) {
// if run arr was not defined as argument commandsArray will defined as default array
commandsArray = (commandsArray || getFilesArray(specsDir)
commandsArray = (commandsArray || getFilesList(specsDir)
.map((file) => getFormedRunCommand(file)))
.filter(function(cmd) {return cmd.includes(grepWord)})

Expand Down Expand Up @@ -165,6 +165,6 @@ module.exports = {
return reRunnerBuilder(reformattedArgs)
},
sleep,
walkSync: getFilesArray,
getFilesList,
getRunCommand: getFormedRunCommand
}
9 changes: 8 additions & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ function executionWatcher(debugProcess, currentTime, limitTime, intervalWatcher,
}
};

function millisecondsToMinutes(milliseconds) {
const minutes = Math.floor(milliseconds / 60000);
const seconds = ((milliseconds % 60000) / 1000).toFixed(0);
return (seconds === '60' ? (minutes + 1) + ":00" : minutes + ":" + (seconds < 10 ? "0" : "") + seconds);
}

module.exports = {
executionWatcher
executionWatcher,
millisecondsToMinutes
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "process-rerun",
"version": "0.0.15",
"version": "0.0.17",
"bin": {
"protractor-rerun": "./bin/rerun"
},
Expand Down
5 changes: 3 additions & 2 deletions rerun.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@

const {walkSync, buildExeRun} = require('./lib')
const {getFilesList, buildExeRun} = require('./lib')

module.exports = {
getReruner: function(optsObj) {
return buildExeRun(optsObj)
},
getSpecFilesArr: walkSync,
getFilesList,
getSpecFilesArr: getFilesList,
getSpecCommands: function(pathToSpecDir, getRunCommandPattern) {
return walkSync(pathToSpecDir).map(getRunCommandPattern)
}
Expand Down

0 comments on commit 4d3ebd7

Please sign in to comment.