I am trying to create a gulp task that combines 3 instances of Browsersync, runs end-to-end tests against them using Protractor, and then nicely closes the instances of Browsersync.
So far I have come up with the following solution:
gulp.task('test:protractor', [
'serve:user',
'serve:bootstrap',
'serve:website'
], function(done) {
var protractor = spawn('protractor', [
path.resolve(__dirname, '..', 'protractor.conf.js'),
'--suite=bootstrap',
'--param.host.user', 'http://' + util.getDockerIp() + ':' + serve.userServer.getOption('port'),
'--param.host.bootstrap', 'http://' + util.getDockerIp() + ':' + serve.bootstrapServer.getOption('port'),
'--param.host.website', 'http://' + util.getDockerIp() + ':' + serve.websiteServer.getOption('port')
], {stdio: 'inherit'});
protractor.on('close', function(code) {
if (code) {
throw new Error(chalk.red('End-to-end tests failed'));
}
serve.userServer.exit();
serve.bootstrapServer.exit();
serve.websiteServer.exit();
done();
});
});
The problem is here xxxServer.exit(). This call process.exit()internally, closing the entire instance of NodeJS. Thus, I cannot close each server nicely and let gulp handle the rest.
I could not find any information about disabling Browsersync in any other way, so I looked at a function exitthat looks like this:
function exit() {
if (browserSync.active) {
browserSync.events.emit("service:exit");
browserSync.cleanup();
}
process.exit();
}
So, I tried to manually clean up without calling process.exit()
serve.userServer.instance.events.emit('service:exit');
serve.userServer.instance.cleanup();
serve.bootstrapServer.instance.events.emit('service:exit');
serve.bootstrapServer.instance.cleanup();
serve.websiteServer.instance.events.emit('service:exit');
serve.websiteServer.instance.cleanup();
This still disables the NodeJS instance.
Browsersync process.exit()?