Can you use the --verbose flag for individual Grunt tasks? - gruntjs

Here's an example GruntFile for a "clean" task (using the grunt-contrib-clean plugin):
clean: {
dry: {
src: ["build/css"],
options: {
'no-write': true
}
}
}
Running grunt clean:dry would output:
Running "clean:dry" (clean) task
>> 2 paths cleaned.
Done, without errors.
Using grunt clean:dry -v, gives me what I want:
Running "clean:dry" (clean) task
Not actually cleaning live/css...
Not actually cleaning live/js...
...but it also displays a bunch of configuration logs that have nothing to do with the current task. Can I use the --verbose flag (or something else) to show the full output of a task without having to scroll through all of the non-related config logs?
PS: My other plugins suffer from the same problem, displaying only a single line of output when their documentation indicates that I should expect more.
(Related questions: Logging from grunt-contrib-jasmine and How can I force JSHint running in grunt to always use the --verbose flag do not answer this question).

There are some insights into this.
grunt.initConfig({
verbosity: {
default: {
options: { mode: 'dot' }, // normal, oneline, dot, hidden
tasks: ['groundskeeper', 'requirejs']
}
}
grunt.registerTask( '_start', ['verbosity:default', 'projectInfo'] );

Related

Using dart sass implementation, grunt-sass is not compiling the css file without throwing an error

Here is my grunt-sass declaration.
sass: {
site: {
options: {
implementation: 'dart-sass',
style: 'compressed',
noCache: true
},
dist: {
files: {
'dist/css/jk.css' : 'src/sass/jk.scss'
}
}
}
},
When I run grunt, or grunt triggers on the watch clause, I get this output.
Running "sass:site" (sass) task
The file "dist/css/jk.css" is never created. I get no other output from Grunt. If I run sass from the command line, the file completes without any trouble.
I'm not sure why it's failing, as it's failing silently. If nothing else, I'd love to know how to enable verbose failures.
UPDATE. Tried running grunt with -v, this is the output.
Running "sass:site" (sass) task
Verifying property sass.site exists in config...OK
File: [no files]
Options: precision=10, implementation="dart-sass", style="compressed", noCache
undefined
It looks like I'm not declaring the files correctly. I'm quite certain the paths are correct. If I run sass from the command line with the same paths it succeeds as expected.
Adding -v or --verbose has returned errors. I'm still not able to compile sass, but the issue of the missing errors is resolved.

Grunt error task "default" not found

When trying to run grunt, I get an error message:
Warning: Task "default" not found. Use --force to continue.
Aborted due to warnings.
I have already found several posts on this topic, and in each of them the problem was a missing comma. But in my case I have no idea what's wrong, I think I didn't miss any comma (btw, this content was copy/pasted from the internet).
module.exports = (grunt) => {
grunt.initConfig({
execute: {
target: {
src: ['server.js']
}
},
watch: {
scripts: {
files: ['server.js'],
tasks: ['execute'],
},
}
});
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-execute');
};
What could be the problem?
You didn't registered the default task. Add this after the last loadNpmTask
grunt.registerTask('default', ['execute']);
The second parameter is what you want to be executed from the config, you can put there more tasks.
Or you can run run existing task by providing the name as parameter in cli.
grunt execute
With you config you can use execute and watch. See https://gruntjs.com/api/grunt.task for more information.
If you run grunt in your terminal it is going to search for a "default" task, so you have to register a task to be executed with Grunt defining it with the grunt.registerTask method, with a first parameter which is the name of your task, and a second parameter which is an array of subtasks that it will run.
In your case, the code could be something like that:
...
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-execute');
grunt.registerTask("default", ["execute", "watch"]);
...
In this way the "default" task will run rispectively the "execute" and the "watch" commands.
However here you can find the documentation to create tasks with Grunt.
Hope it was helpful.

Protractor Headless browser Testing using XVFB+Grunt runner on centos 7 linux distribution

Below is my gruntfile.js . I can run the protractor tests on UI using 'grunt protractor:run command.
However, when i try running command ' grunt protractor-xvfb' so that i can run my tests in headless mode, the browser still launches and tests execute in the same way as using grunt protractor:run command.
What i am expecting is that the tests run in background.
module.exports = function (grunt) {
require('load-grunt-tasks')(grunt);
grunt.initConfig({
protractor: {
options: {
keepAlive: true,
configFile: "../spike-protractor/app/Conf/conf.js",
noColor: false,
args: {
baseUrl: 'https://xxx/xxx/'
}
},
run: {}
},
shell: {
xvfb: {
command: 'Xvfb :99 -ac -screen 0 1600x1200x24',
options: {
async: true
}
}
},
env: {
xvfb: {
DISPLAY: ':99'
}
}
});
grunt.loadNpmTasks('grunt-protractor-runner');
grunt.loadNpmTasks('grunt-shell-spawn');
grunt.loadNpmTasks('grunt-env');
grunt.loadNpmTasks('grunt-protractor-webdriver');
grunt.registerTask('protractor-chrome', ['protractor:chrome']);
grunt.registerTask('protractor-xvfb', [
'shell:xvfb',
'env:xvfb',
'protractor:run',
'shell:xvfb:kill'
]);
}
I tried commenting out line code 'protractor:run'from grunt.registerTask and running grunt protractor-xvfb gives me the below output which is correct as per code. This executes so fast as if nothing happened. i think there is something that i am missing in config/code to achieve headless testing .
Running "shell:xvfb" (shell) task
Running "env:xvfb" (env) task
Running "shell:xvfb:kill" (shell) task
Done.
how do i actually proceed on doing headless testing using xvfb + grunt+ protractor ?
Is probably more practical for your use case to go with Zalenium if you want headless Chrome or Firefox testing, video recording, VNC live preview, local dashboard.html among other features.
You can get started with the one-liner:
curl -sSL https://raw.githubusercontent.com/dosel/t/i/p | bash -s start
And/or also watch the presentation:
https://www.youtube.com/watch?v=W5qMsVrob6I
You did not specify to run your conf.js properly.
Remove the part
grunt.registerTask('protractor-chrome', ['protractor:chrome']);
from your gruntfile.js specified in your question.
Edit your gruntfile.js and add below:
grunt.registerTask('protractor-xvfb', [
'shell:xvfb',
'env:xvfb',
'protractor:run',
'shell:xvfb:kill'
]);
Once you add it if you want to run without xvfb use command "grunt protractor:run".
If you want to run using xvfb then use command "grunt protractor-xvfb"
I found a workaround for this to use the below command and specify conf.js -
xvfb-run --server-args='-screen 0, 1600x1200x24' protractor app/Conf/conf.js
Doing this allows to me run my tests in headless mode.
Even if you are not using Grunt in your project, you can directly do npm install xvfb and use this command... pass it to teamcity command line parameters and it will work there as well.

Grunt watch doesn't run

I've been having trouble figuring out how to run grunt-contrib-watch. Running grunt watch as specified only results in:
Running "watch" task
Waiting...
Then I'm back at my command prompt again, with no watch process blocking the input, or showing up in Task Manager; and I've been messing with this since last night and still can't figure out what am I doing wrong. Here's my gruntfile; I'm working on a Windows 7 machine, if that's any help.
Just noticed your gruntfile has filed where it should be files:
watch: {
filed: ['src/**/*'],
tasks: ['stylus:compile', 'coffee:compile', 'jade:compile'],
}
Try this instead:
watch: {
files: ['src/**/*'],
tasks: ['stylus:compile', 'coffee:compile', 'jade:compile'],
}

Grunt uglifym - call stack size exceeded

I am trying to use uglify with grunt to concat and minify some files. I have already used the npm to install grunt-contrib-uglify.
I have the following in my grunt.js file: (I have removed some other tasks for anonymity)
module.exports = function(grunt) {
'use strict';
grunt.loadNpmTasks('grunt-contrib-uglify');
uglify: {
options: {
sourceMap: 'app/map/source-map.js'
},
files: {
'app/dist/sourcefiles.min.js': [
'app/test_js/test.js'
]
}
}
};
I then run:
grunt uglify
but I keep getting the following error:
Warning: Maximum call stack size exceeded Use --force to continue.
If I use force, the grunt task never stops running.
Can someone tell me where I am going wrong? I am tearing my hair out on this one.
I had the same problem, using an other Grunt plugin called recess.
The error message was not explicit.
Warning: Cannot read property 'message' of undefined Use --force to continue.
But the verbose mode showed that my task was called hundred of times.
The problem was that I created a "cyclic dependency" (causing an infinite loop) when I registered my task.
grunt.registerTask('recess', ['recess']); //does not work => cyclic dependency!
The first parameter of registerTask method is an "alias task" and has to be different from the task names defined in the second parameter.
I corrected like this:
grunt.registerTask('my-recess-task', ['recess']);
And I runned the task calling this (in the Command prompt window)
grunt my-recess-task
And then it was OK!
More about registerTask() method, from grunt API:
http://gruntjs.com/api/grunt.task#grunt.task.registertask
I also met this problem, i solved this by removing
grunt.registerTask('uglify', ['uglify']);
before i solved this, i ran grunt uglify -v to check what happend.
I found it because that where you using this grunt.loadNpmTasks('grunt-contrib-uglify'); ,it implicitly executes the grunt.registerTask('uglify', ['uglify']); ^_^

Resources