Skip to content

Commit

Permalink
PR feedback: created constant for color, added space
Browse files Browse the repository at this point in the history
Consistent indentation in util file
  • Loading branch information
rfreitas committed Apr 30, 2019
1 parent d3067c1 commit 1b4afef
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 21 deletions.
17 changes: 9 additions & 8 deletions test/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import config from './config.json'
import Mocha from 'mocha'
import {createBrowserStackLocal,stopBrowserstackLocal} from './utils/browserstack'
import {eachP,asyncForEach} from './utils/async'
import {spawnP, spawnPrinter} from './utils/misc'
import {spawnP, spawnPrinter, SHELL_COLOR_BLUE} from './utils/misc'
import {exec} from 'child_process'

// Input capabilities
Expand Down Expand Up @@ -103,12 +103,13 @@ const runner = async () => {
const rubyTestSpawn = (command, args, options={}, optionCallback) =>
spawnP(command, args, {cwd: __dirname+"/../",...options}, optionCallback)

const rubyTestPrinter = outFilter => spawnPrinter("\x1b[34m", {
prefix:"Ruby:",
...(outFilter && {filter:outFilter})
},
"Ruby Error:"
)
const rubyTestPrinter = outFilter =>
spawnPrinter(SHELL_COLOR_BLUE, {
prefix:"Ruby:",
...(outFilter && {filter:outFilter})
},
"Ruby Error:"
)

await rubyTestSpawn('bundle', ['install'], {
env: {...process.env, GIT_SSH_COMMAND: process.env.CI === "true" ? "ssh -i ~/.ssh/monster_rsa" : ""}
Expand Down Expand Up @@ -152,7 +153,7 @@ const runner = async () => {

try {
const result = await rubyTestPromise
console.log("result of ruby test:",result)
console.log("result of ruby test:", result)
if (result > 0) totalFailures += 1
}
catch (e){
Expand Down
27 changes: 14 additions & 13 deletions test/js/utils/misc.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
import {spawn} from 'child_process'
import { spawn } from 'child_process'

export const spawnP = (command, args, options={}, optionCallback=()=>{}) => {
return new Promise(function(resolve, reject) {

const process = spawn(command, args, options);
optionCallback(process)
process.on('close', resolve);
process.on('error', reject);
});
export const spawnP = (command, args, options = {}, optionCallback = () => {}) => {
return new Promise(function(resolve, reject) {
const process = spawn(command, args, options);
optionCallback(process)
process.on('close', resolve);
process.on('error', reject);
});
}

export const spawnPrinter = (color, stdout, stderrorPrefix) => process => {
stdout = {prefix:"", filter: ()=>true, ...stdout}
stdout = { prefix: "", filter: () => true, ...stdout }

process.stdout.on('data', data => {
const output = data.toString()
if (stdout.filter(output)){
console.log(color,stdout.prefix, output)
if (stdout.filter(output)) {
console.log(color, stdout.prefix, output)
}
});
process.stderr.on('data', data => {
console.log(color,stderrorPrefix,data.toString())
console.log(color, stderrorPrefix, data.toString())
});
}

export const SHELL_COLOR_BLUE = "\x1b[34m"

0 comments on commit 1b4afef

Please sign in to comment.