-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ref: Introduce test runner for node session health tests (#3728)
* ref: Introduce test runner for node session health tests * Make it work on Node 6
- Loading branch information
1 parent
ac3cf20
commit 28bce1c
Showing
10 changed files
with
111 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const { spawn } = require('child_process'); | ||
|
||
const COLOR_RESET = '\x1b[0m'; | ||
const COLORS = { | ||
green: '\x1b[32m', | ||
red: '\x1b[31m', | ||
yellow: '\x1b[33m', | ||
}; | ||
|
||
const colorize = (str, color) => { | ||
if (!(color in COLORS)) { | ||
throw new Error(`Unknown color. Available colors: ${Object.keys(COLORS).join(', ')}`); | ||
} | ||
|
||
return `${COLORS[color]}${str}${COLOR_RESET}`; | ||
}; | ||
|
||
const scenariosDirs = ['session-aggregates', 'single-session']; | ||
const scenarios = []; | ||
|
||
for (const dir of scenariosDirs) { | ||
const scenarioDir = path.resolve(__dirname, dir); | ||
const filenames = fs.readdirSync(scenarioDir); | ||
const paths = filenames.map(filename => [filename, path.resolve(scenarioDir, filename)]); | ||
scenarios.push(...paths); | ||
} | ||
|
||
const processes = scenarios.map(([filename, filepath]) => { | ||
return new Promise(resolve => { | ||
const scenarioProcess = spawn('/usr/bin/env', ['node', filepath]); | ||
const output = []; | ||
const errors = []; | ||
|
||
scenarioProcess.stdout.on('data', data => { | ||
output.push(data.toString()); | ||
}); | ||
|
||
scenarioProcess.stderr.on('data', data => { | ||
errors.push(data.toString()); | ||
}); | ||
|
||
scenarioProcess.on('exit', code => { | ||
if (code === 0) { | ||
console.log(colorize(`PASSED: ${filename}`, 'green')); | ||
} else { | ||
console.log(colorize(`FAILED: ${filename}`, 'red')); | ||
|
||
if (output.length) { | ||
console.log(colorize(output.join('\n'), 'yellow')); | ||
} | ||
if (errors.length) { | ||
console.log(colorize(errors.join('\n'), 'yellow')); | ||
} | ||
} | ||
|
||
resolve(code); | ||
}); | ||
}); | ||
}); | ||
|
||
Promise.all(processes).then(codes => { | ||
if (codes.some(code => code !== 0)) { | ||
process.exit(1); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters