grunt-protractor-runner not working correctly - gruntjs

My case is similar to case from other question
"I use protractor to test my angular app. When I manually launch protractor it works properly and tests everything but the trouble comes when I try to launch it through grunt.
When I launch my grunt task for testing, protractor finds the conf file (it displays the right number of specs to test) but just open the chrome driver for less than a seconds on a weird "data;" url, close it right away and marks all the tests as "passed"."
grunt-cli v1.2.0
grunt v0.4.5
node v6.4.0
protractor 4.0.4
module.exports = function () {
return {
protractor: {
options: {
// Location of your protractor config file
configFile: "test/protractor.conf.js",
noColor: false,
},
e2e: {
options: {
// Stops Grunt process if a test fails
keepAlive: false
}
},
continuous: {
options: {
keepAlive: true
}
}
}
}
};
This is my config for grunt

Not have a direct answer to your question, but here is what we have set up that works for us.
Here are the relevant dependencies (note that we had to "fork" grunt-protractor-runner to bump the protractor dependency):
"grunt-protractor-runner": "git+https://github.com/alecxe/grunt-protractor-runner.git",
"protractor": "^4.0.0",
Here is the relevant part of grunt config:
protractor: {
options: {
keepAlive: true,
noColor: false
},
remote: {
options: {
configFile: "test/e2e/config/remote.conf.js"
}
},
local: {
options: {
configFile: "test/e2e/config/local.conf.js"
}
}
},
And, we run our tests through grunt e2e:local and grunt e2e:remote.
Also, make sure to have the latest chromedriver downloaded via webdriver-manager update.

Related

How to run a grunt task without writing a file?

Is there a way where one can just dry run a grunt task and see what the output would be if it was an actual file? I am using grunt requirejs task but need to check if it is properly configured.
Note: "grunt requirejs --no-write" does not work for me
grunt.initConfig({
requirejs: {
task: {
options: {
baseUrl: "a/b/c/directory",
mainConfigFile: "a/b/c/grunt_main.js",
name: "../grunt_main",
excludeShallow: ["../grunt_main"],
out: "a/b/c/directory/<%= version.name %>.js",
optimize: "uglify",
preserveLicenseComments: false
}
}
}
}

Grunt default task only runs first task in the list

I'm just getting started with grunt and just trying to get a few basic tasks working.
Here's my Gruntfile:
module.exports = function(grunt) {
grunt.initConfig({
compass: {
dist: {
options: {
config: 'config.rb',
watch: true
}
}
},
livecopy: {
your_target: {
options: {
source: "C:/Websites/xxx/styles/screen.css",
target: "W:/Websites/xxx/styles/screen.css"
},
},
},
watch: {
assets: {
files: ['**//*.css', '**/*.js'],
options: {
livereload: true,
},
},
},
});
grunt.loadNpmTasks('grunt-contrib-compass');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-livecopy');
grunt.task.registerTask('default', ['compass','livecopy','watch']);
};
I can run each of these tasks individually without any issues. When I run the grunt default task, only the first task in the default task list runs. It doesn't matter which order they are in, only the first one runs.
What am I missing?
When you run Compass with the watch option it runs compass watch which is a blocking task. From the grunt-contrib-compass docs:
watch
Type: Boolean
Runs compass watch instead of compass compile. This will use Compass'
native watch command to listen for changes to Sass files and recompile
your CSS on changes. While much faster than running compass compile
each time you want to compile your Sass, Compass becomes a blocking
task. This means that if you would like to use it in conjunction with
another blocking task, such as watch, you will need to use it in
conjunction with a paralleling task such as grunt-concurrent.

running a dynamically named grunt task with grunt-contrib-watch

Is there a way to dynamically specify the task to run based on the file changed?
In other words:
watch: {
exec: {
files: [html/*.html],
tasks: ['exec:my_exec_task:THE_FILE_THAT_CHANGED']
}
}
I can catch the watch events, but I can't run tasks from within the callback as it's "doing it wrong".
grunt.event.on('watch', function(action, filepath, target) {
if (target === 'exec') {
grunt.task.run('exec:my_exec_task:' + filepath); /* this doesn't work */
grunt.config('filepath', filepath); /* and neither does this, it's undefined in my exec task */
}
});
At least that's what the documentation says: https://github.com/gruntjs/grunt-contrib-watch#using-the-watch-event
Any ideas?
According to docs
The watch event is not intended for replacing the standard Grunt API for configuring and running tasks. If you're trying to run tasks from within the watch event you're more than likely doing it wrong. Please read configuring tasks.
You can't run task from event, but you can change config before task starts. Add to watch config options section spawn: false
grunt.initConfig({
watch: {
scripts: {
files: ['app/*.js'],
tasks: ['jshint:one'],
options: {
spawn: false,
},
},
},
jshint: {
one: {src: ""},
},
});
and on watch event change config "on fly"
grunt.event.on('watch', function(action, filepath) {
grunt.config('jshint.one.src', filepath);
});
after applying config that watch section will run task jahint:one.

Need to Perform a Grunt Watch Forever

I'm new to Node.js and Grunt... I'm attempting to use Node.js and Grunt on a Windows server to watch my main.less file and do a standard compile and concatinate. I'm able to do this while the command prompt is open, but I need this to run as a daemon while not logged into the server since the .less files get deployed from our CMS that sits in the cloud.
I found promising documentation in Grunt-Forever, but it requires you to point to an application, while I just want to perform the grunt watch task.
Someone else asked a similar question 9 months ago, but nobody gave an answer:
Grunt.js Watch Forever
I tried this from the command line:
FWIW, you can do forever /usr/local/bin/grunt --base . watch to use forever with grunt watch atm.
But, I got errors.
Here is my gruntfile:
module.exports = function(grunt) {
grunt.registerTask('watch', [ 'watch' ]);
grunt.initConfig({
concat: {
js: {
src: [
'js/global.js','js/googlemap.js'
],
dest: 'js/main.min.js'
},
},
uglify: {
options: {
mangle: false
},
js: {
files: {
'js/main.min.js': ['js/main.min.js']
}
}
},
less: {
style: {
files: {
"css/style.css": "less/main.less"
}
}
},
watch: {
js: {
files: ['js/global.js','js/googlemap.js'],
tasks: ['concat:js', 'uglify:js']
},
css: {
files: ['less/*.less'],
tasks: ['less:style']
}
}
});
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-less');
grunt.loadNpmTasks('grunt-contrib-watch');
};
Any help is much appreciated!
Use node to call grunt, use PM2 to run and manage node.
Try running the grunt watch task with nohup. Since you mentioned "Windows server" you can check this answer about nohup equivalent in Windows. Then you will have the grunt task running even when you log out of the server.

grunt: watch command never runs when including other tasks in registerTask method

I'm having some unexpected behavior with my Gruntfile. I've registered a task that looks like this: grunt.registerTask('dev', ['jekyll:server', 'watch:jekyll']) with the hopes that it will sequentially start a jekyll server, and then watch my project for specific file changes (using the grunt-contrib-watch plugin). Once it detects those changes, it would re-run jekyll:server automatically.
The problem I'm having is that when I run grunt dev, it will start the Jekyll server, but it will not run the watch commands. However, if I remove the server task from grunt dev, it will run the watch command as expected.
Below is the contents of my Gruntfile. Can anyone help me understand what is happening?
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
jekyll: {
server : {
server: true,
server_port: 4000,
exclude: ['node_modules']
},
prod: {
dest: './_site-release'
}
},
watch: {
jekyll: {
files: ['_posts/**/*.md', '_layout/*.html', '_includes/*.html', 'index.html'],
tasks: ['jekyll:server']
}
}
});
grunt.loadNpmTasks('grunt-jekyll');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.registerTask('default', 'jekyll:server');
grunt.registerTask('dev', ['jekyll:server', 'watch:jekyll']);
grunt.registerTask('release', 'jekyll:prod');
};
The server option makes the task block since it's persistent. You can either use the tasks watch option or something like grunt-concurrent to run jekyll and watch concurrently:
grunt.initConfig({
concurrent: {
target: {
tasks: ['jekyll:server', 'watch'],
options: {
logConcurrentOutput: true
}
}
}
});
grunt.loadNpmTasks('grunt-concurrent');
grunt.registerTask('default', ['concurrent:target']);

Resources