Some User
Some User

Reputation: 5847

Running Command-Line Commands in Gulp

Have a Gulp task that I'm trying to create. The task has to do the following:

  1. Start my web server
  2. Start the selenium server
  3. Run my tests

I am able to do these three things manually from the command line. At this time, I open one tab from the terminal window in Mac OS X and I run:

dnx . run

That command starts my web server. Then, in another tab in the terminal window, I run:

java -jar node_modules/selenium-server-standalone-jar/jar/selenium-server-standalone-2.45.0.jar

That command starts the selenium test server. Then, in a third tab in the terminal window, I run:

gulp test

The gulp test task is responsible for executing my tests. I would really like gulp test to also a) start my web server and b) start the selenium server. Basically, gulp test would run through all of my tests once, then return to a command prompt. In an attempt to do this, I am using gulp-exec. I'm not sure if that's the package I should use for this approach. Still, at this time, I have the following:

gulp.task('test', function() {
  return gulp.src('./tests/*.js')
    .pipe(jasmine())
  ;
});

The above task successfully executes my tests. However, it only does so after the web server and selenium server have been manually started. How do I start the web server, then the selenium server, and then execute the tests in my task with Gulp?

Thank you!

Upvotes: 1

Views: 2141

Answers (1)

Isaac Adams
Isaac Adams

Reputation: 160

The primary, built in, way to accomplish this is through require('child_process').exec('echo Hello World')

In addition to that, there are three github / npm projects that accomplish this

  1. gulp-run
  2. gulp-spawn
  3. gulp-shell

Upvotes: 1

Related Questions