-
Notifications
You must be signed in to change notification settings - Fork 181
/
hermione.js
64 lines (53 loc) · 1.69 KB
/
hermione.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/* eslint-disable no-console */
const {exec, execSync} = require('child_process');
const path = require('path');
const browserStackLocal = require('browserstack-local');
const kill = require('kill-port');
require('dotenv').config();
const browserstack = new browserStackLocal.Local();
const browserstackPort = 45690;
// eslint-disable-next-line no-magic-numbers
const STDOUT_BUFFER_SIZE = 1024 * 1024 * 20; // 20 Mb
module.exports = callback => kill(browserstackPort).catch(e => {
console.error(e);
}).then(() => {
browserstack.start({
key: process.env.BROWSERSTACK_KEY,
verbose: true,
logfile: 'browserstack.log'
}, err => {
if (err) {
console.error(err.message);
return;
}
console.log('BrowserStack is connected and ready');
const cleanup = () => {
browserstack.stop(error => {
console.log('Closed BrowserStack process', error || '');
});
// eslint-disable-next-line no-use-before-define
hermioneProcess.kill();
exec('git add hermione');
callback();
};
process.on('SIGINT', () => {
console.log('killed by SIGINT');
cleanup();
});
execSync('npx jest packages/hermione/get-stories-tree.js \'--testMatch=**\'', {
cwd: path.resolve(__dirname, '../..'),
stdio: 'inherit'
});
const hermioneProcess = exec(
// eslint-disable-next-line no-magic-numbers
`npx hermione ${process.argv.slice(2).join(' ')}`,
{maxBuffer: STDOUT_BUFFER_SIZE},
error => {
console.log('hermione execution have been done, error =', error);
cleanup();
}
);
hermioneProcess.stdout.pipe(process.stdout);
hermioneProcess.stderr.pipe(process.stderr);
});
});