For example I define my own task named jasmine. It is based on the task server.
If I call grunt server jasmine – it’s ok. But I want to declare that dependency inside my task.
grunt.task.run – add task to the queue (after my task).
grunt.task.requires – only check dependency, not run it…
Does any way exist to run server task before my jasmine task?
P.S. I don’t want to create jasmine_orig task and then .registerTask('jasmine', 'server jasmine_orig'). It looks like silly.
The way the server task is currently written, no this isn’t possible. However, you may be able to do what you want by using the grunt-connect plugin, or rolling your own
grunt servertask. The source for the built-in one is here:https://github.com/gruntjs/grunt/blob/0.3-stable/tasks/server.js
As you can see, there isn’t much to it, other than reading a config, starting a connect server, and possibly logging when
--debugis passed. You could, in fact, copy all of that code into a helper (woefully underdocumented, I’m afraid), and call it from your jasmine task.It’s probably a good idea to start a separate server for your tests (for test independence), but if you needed to save the resources for some reason, or you find multiple servers distasteful in some other way, you’ll have to write some custom task code to check if the server is there, and then start the server if it’s not.
Probably the best solution is the following:
install the grunt-contrib-connect npm package:
Make configurations for your dev and test environments:
Register a
testtask that runsgrunt server:test jasminefor you.