Grunt-karma:Continue grunt process after test failures in karma - gruntjs

is there a way to continue grunt process after unit test failed in singlerun=true in karma??
karma: {
unit: {
configFile: 'karma.conf.js'/*,
browsers: ['PhantomJS']*/
},
//continuous integration mode: run tests once in PhantomJS browser.
continuous: {
configFile: 'karma.conf.js',
singleRun: true,
browsers: ['PhantomJS']
}
}
grunt.registerTask('test', [
'karma:continuous' ,
'e2e-test'
]);
when i run grunt task test, karma test failed and stopped the grunt process to continue.Is there any option in karma to continue the grunt process even after test failed???

Execute grunt --force in order to continue executing without validation, I think.

Related

I get an error when I run grunt jshint

I'm also going through Steven Foote's book Learning to Program and am currently on chapter 4, which uses Grunt. This post has a similar problem, but the problem is different (this person capitalized the "f" in Gruntfile.js).
I've seemed to have installed NPM and Node properly
npm#5.10.0 /usr/local/lib/node_modules/npm
andrews-macbook-air:Kittenbook Andrew$ node -v
v8.11.3
Here is my Gruntfile.js:
module.exports = function(grunt){
grunt.initConfig({
concat: {
release: {
src: ['js/values.js', 'js/prompt.js'],
dest: 'release/main.js'
}
},
copy: {
release: {
src: 'manifest.json',
dest: 'release/main.js'
}
},
jshint: {
files: ['js/values.js', 'js/prompt.js']
}
});
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.registerTasks('default', ['jshint', 'concat' 'copy']);
In checking to see if I did it correctly I run grunt jshint in the command line, but I get back an error
andrews-macbook-air:Kittenbook Andrew$ grunt jshint
Loading "Gruntfile.js" tasks...ERROR
>> SyntaxError: Unexpected string
Warning: Task "jshint" not found. Use --force to continue.
Aborted due to warnings.
Any ideas on what is going on?

Visual Studio 2015: Destination wwwroot/css/site.css not written because no source files were found.

I'm trying to use grunt in my ASP project, but for whatever reasons have get a stupid warning-message from Visual Studio.
How you can see down, the bower-task has been executed, but haven't uglify- and less-tasks. Gruntfile.js and folder "wwwroot" are in the same folder. What's wrong ?
This is console output in Visual Studio 2015:
> cmd.exe /c grunt -b "c:\T\BW\src\BW" --gruntfile "c:\T\BW\src\BW\gruntfile.js" bower
Running "bower:install" (bower) task
>> Installed bower packages
>> Copied packages to c:\T\BW\src\BW\wwwroot\lib
Done, without errors.
Process terminated with code 0.
> cmd.exe /c grunt -b "c:\T\BW\src\BW" --gruntfile "c:\T\BW\src\BW\gruntfile.js" uglify_default
Running "uglify:uglify_target" (uglify) task
Process terminated with code 0.
>> Destination wwwroot/lib/angular/angular.js not written because src files were empty.
>> No files created.
Done, without errors.
> cmd.exe /c grunt -b "c:\T\BW\src\BW" --gruntfile "c:\T\BW\src\BW\gruntfile.js" less
Running "less:dev" (less) task
>> Destination wwwroot/css/site.css not written because no source files were found.
Done, without errors.
Process terminated with code 0.
This is my gruntfile.js:
grunt.initConfig({
bower: {
install: {
options: {
targetDir: "wwwroot/lib",
layout: "byComponent",
cleanTargetDir: false
}
}
},
uglify: {
uglify_target: {
files: {
"wwwroot/lib/angular/angular.js":["src/angular.min.js"]
}
}
},
less: {
dev: {
files: {
"wwwroot/css/site.css": ["less/site.less"]
},
options: {
sourceMap: true,
}
}
},
});
grunt.registerTask("default", ["bower:install"]);
grunt.loadNpmTasks("grunt-bower-task");
grunt.loadNpmTasks("grunt-contrib-uglify");
grunt.loadNpmTasks("grunt-contrib-less");
Are you sure "wwwroot/lib/angular/angular.js":["src/angular.min.js"] is correct in your uglify step? Uglify is for minifying files, so it would seem as if you have the destination and source parameters reversed. You are also getting the message Destination wwwroot/lib/angular/angular.js not written because src files were empty. which would seem to indicate that as well.
The less step seems correct, but it can't find the less file you are trying to compile. Are you sure that site.less exists in a less folder?
Here is the less portion of the grunt file I just wrote, and it seems to work well, although getting the sourcemap to actually generate is still an issue. This is pretty much an exact equivalent of VS 2013 with Web Essentials installed. Compiling all less files in the content folder using autoprefix for the browsers we support, and puts the .css back into the content folder. It doesn't compile any less file that starts with _, as those are just includes/variables.
less: {
development: {
options: {
paths: ["content"],
compress: true,
plugins: [
new (require('less-plugin-autoprefix'))({ browsers: ["IE >= 9, firefox > 10, last 2 Chrome versions, last 2 safari versions, last 2 ios versions"], map: { inline: false } })
]
},
files: [{
expand: true,
cwd: 'content',
src: ['*.less', '!_*.less'],
dest: 'content',
ext: '.css'
}]
}
},

ctrl-c [SIGINT] not working with Grunt while using grunt-shell

If I use Grunt Task Runner with grunt-shell, I'm not able to exit the grunt using ctrl-c [SIGINT].
grunt.registerTask('serve', [
'less',
'autoprefixer',
'shell:hologram', // grunt-shell task
'connect:livereload',
'watch'
]);
Here is how the shell is configured:
grunt.initConfig({
...
shell: {
options: {
failOnError: false
},
hologram: {
command: 'bundle exec hologram'
},
},
...
}
I had the same problem when I run Grunt from Git Bash. And my solution was to update to the latest version of git bash and exit with CTRL+SHIFT+C.
It is very likely that CTRL+SHIFT+C will suffice (even with older versions).

Grunt - Task "undefined" not found

I'm currently getting the same error for all tasks that I run via grunt.
Initializing
Command-line options: --verbose
Reading "Gruntfile.js" Gruntfile...OK
Registering Gruntfile tasks.
Reading package.json...OK
Parsing package.json...OK
Initializing config...OK
Loading "Gruntfile.js" tasks...OK
+ build,default,nick,server,test
No tasks specified, running default tasks.
Running tasks: default
Running "default" task
Warning: Task "undefined" not found. Use --force to continue.
The last warning happens for any task I run.
Grunfile.js(important stuff):
...
grunt.initConfig({
jshint: {
options: {
jshintrc: '.jshintrc'
},
all: [
'Gruntfile.js',
'<%= yeoman.app %>/scripts/{,*/}*.js',
'!<%= yeoman.app %>/scripts/libs/{,*/}*.js'
]
},
...
});
...
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.registerTask('nick', [ ]);
grunt.registerTask('default', [
'jshint'
]);
running jshint by itself works fine..
grunt jshint
>Running "jshint:all" (jshint) task
>> 52 files lint free.
>>
>>Done, without errors.
Done, without errors.
Any help? Let me know if there is any other info you need to help.
Nick.
Another potential cause of this problem is having double commas in a Gruntfile.js's registerTask section. For instance:
grunt.registerTask('dist', ['clean',, 'uglify:dist']);
Note that this will also produce the same error:
grunt.registerTask('dist', ['clean', /*unnecessarytask */, 'uglify:dist']);
I had the same issue and all I needed to do was update grunt with:
npm --global update grunt-cli

How to get grunt task name given on command line?

In order to customize my grunt tasks, I need access to the grunt task name given on the command line when starting grunt.
The options is no problem, since its well documented (grunt.options).
It's also well documented how to find out the task name, when running a grunt task.
But I need access to the task name before.
Eg, the user writes
grunt build --target=client
When configuring the grunt job in my Gruntfile.js, I can use
grunt.option('target') to get 'client'.
But how do I get hold of parameter build before the task build starts?
Any guidance is much appreciated!
Your grunt file is basically just a function. Try adding this line to the top:
module.exports = function( grunt ) {
/*==> */ console.log(grunt.option('target'));
/*==> */ console.log(grunt.cli.tasks);
// Add your pre task code here...
Running with grunt build --target=client should give you the output:
client
[ 'build' ]
At that point, you can run any code you need to before your task is run including setting values with new dependencies.
A better way is to use grunt.task.current which has information about the currently running task, including a name property. Within a task, the context (i.e. this) is the same object. So . . .
grunt.registerTask('foo', 'Foobar all the things', function() {
console.log(grunt.task.current.name); // foo
console.log(this.name); // foo
console.log(this === grunt.task.current); // true
});
If build is an alias to other tasks and you just want to know what command was typed that led to the current task execution, I typically use process.argv[2]. If you examine process.argv, you'll see that argv[0] is node (because grunt is a node process), argv[1] is grunt, and argv[2] is the actual grunt task (followed by any params in the remainder of argv).
EDIT:
Example output from console.log(grunt.task.current) on grunt#0.4.5 from within a task (can't have a current task from not a current task).
{
nameArgs: 'server:dev',
name: 'server',
args: [],
flags: {},
async: [Function],
errorCount: [Getter],
requires: [Function],
requiresConfig: [Function],
options: [Function],
target: 'dev',
data: { options: { debugPort: 5858, cwd: 'server' } },
files: [],
filesSrc: [Getter]
}
You can use grunt.util.hooker.hook for this.
Example (part of Gruntfile.coffee):
grunt.util.hooker.hook grunt.task, (opt) ->
if grunt.task.current and grunt.task.current.nameArgs
console.log "Task to run: " + grunt.task.current.nameArgs
CMD:
C:\some_dir>grunt concat --cmp my_cmp
Task to run: concat
Running "concat:coffee" (concat) task
Task to run: concat:coffee
File "core.coffee" created.
Done, without errors.
There is also a hack that I've used to prevent certain task execution:
grunt.util.hooker.hook grunt.task, (opt) ->
if grunt.task.current and grunt.task.current.nameArgs
console.log "Task to run: " + grunt.task.current.nameArgs
if grunt.task.current.nameArgs is "<some task you don't want user to run>"
console.log "Ooooh, not <doing smth> today :("
exit() # Not valid. Don't know how to exit :), but will stop grunt anyway
CMD, when allowed:
C:\some_dir>grunt concat:coffee --cmp my_cmp
Running "concat:coffee" (concat) task
Task to run: concat:coffee
File "core.coffee" created.
Done, without errors.
CMD, when prevented:
C:\some_dir>grunt concat:coffee --cmp my_cmp
Running "concat:coffee" (concat) task
Task to run: concat:coffee
Ooooh, not concating today :(
Warning: exit is not defined Use --force to continue.
Aborted due to warnings.

Resources