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'],
}
Related
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.
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.
I have set up the grunt-contrib-watch task to copy a list of files to a "dist" directory every time I save one of the files of the "src" directory. Unfortunately it takes 7 to 9 seconds to accomplish this task.
I have heard about the "spawn" option for grunt-contrib-watch. Using load-grunt-tasks to load the config of each task from a separate JSON file, I changed my watch.json so that it looks like this :
{
"service": {
"files": [
"src/*.php"
],
"tasks": [
"copy:service"
],
"options": {
"spawn": "false",
"livereload": "true"
}
}
}
...but setting it to false doesn't seems to change anything : it still takes 7 to 9 seconds to run. I installed time-grunt to monitor the task timing, here is what I got when saving a file :
When saving a file, I got the following output :
Waiting...
>> File "src\myfile.php" changed.
Running "copy:service" (copy) task
Created 7 directories, copied 120 files
Done, without errors.
Execution Time (2015-06-04 11:38:23 UTC)
loading tasks 333ms ██████████████████ 40%
copy:service 490ms ██████████████████████████ 60%
Total 823ms
Completed in 7.105s at Thu Jun 04 2015 13:38:24 GMT+0200 (W. Europe Daylight Time)
So it looks like the task in itself took less than a second, meaning that Grunt itself would take 6 seconds to load ? That seems pretty high. I'm on Windows 7, I've heard that on Windows there could be some performance issues.
Same problem here, after changed and execute task all modules was reload.
But i found a very good solution on github
(https://github.com/steida/grunt-este-watch)
What's wrong with official grunt-contrib-watch?
It's slow and buggy, because it uses combination fs.fileWatch and fs.watch, for historical reason. From Node 0.9.2+, fs.watch is ok.
What to do?
install grunt-este-watch
npm install grunt-este-watch --save-dev
change contrib watch
grunt.loadNpmTasks('grunt-contrib-watch');
to este watch
grunt.loadNpmTasks('grunt-este-watch');
change task
watch: {
javascript: {
files: 'src/js/**/*',
tasks: ['uglify']
}
}
to
esteWatch: {
options: {
dirs: ['../src/**/*']
},
'js': function(filepath) { return 'uglify' }
}
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'] );
I keep getting "Warning: Spawn ENOENT" problem when I am running grunt-open.
My setup
I have all my project files on Google Drive.
I am doing my development on the files directly on them (using Google Drive desktop).
I just want to open the index.html file when I run grunt. Just that simple.
Part of my Gruntfile.js
open: {
all: {
path : 'index.html'
}
},
But I couldn't get it working? What am I missing?
I have figured out.
You have to change your system environment variable to include the following if on PC.
%SystemRoot%\system32;
I had similar problem for grunt-run task:
run: {
jasmine: {
cmd: 'jasmine-node.cmd',
args: ['--autotest', '--test-dir', 'test']
}
},
You have to specify jasmine-node.cmd as cmd - not just jasmine-node which is enough when running from command line.