I'm kind of new to grunt and jasmine, so I hope i'm not wasting your time.
I'm getting this error when trying to run more than 29 tests:
Warning: PhantomJS failed to load your page. Use --force to continue.
Aborted due to warnings.
Process finished with exit code 90
It doesn't matter which tests I comment out, as long as there are less than 30 test, I will not receive this warning.
All my tests pass, so I don't think it's something to do with them.
My (simplified) gruntfile:
module.exports = function (grunt) {
// Load grunt tasks automatically
require('load-grunt-tasks')(grunt);
// Time how long tasks take. Can help when optimizing build times
require('time-grunt')(grunt);
// Define the configuration for all the tasks
grunt.initConfig({
connect: {
options: {
port: 9000,
// Change this to '0.0.0.0' to access the server from outside.
hostname: 'localhost',
livereload: 35729
},
livereload: {
options: {
open: true,
base: [
'.tmp',
'<%= yeoman.app %>'
]
}
},
}
jasmine: {
pivotal: {
src: ['/scripts/*.js'],
options: {
specs: 'tests/**/*Spec.js',
helpers: 'tests/**/*Helper.js',
summary: true
}
}
}
});
grunt.registerTask('unit-tests', [
'jasmine'
]);
}
I'm using:
grunt-cli v0.1.13
grunt v0.4.5
and
grunt-contrib-jasmine ^0.9.0
I'd be happy to add more information if needed.
Thanks
Clarification
I mean there are 29 it(...) clauses (not expect(...)'s)
Update 1
When running with the --debug flag, I see that the last log is this (This does not appear when running less than 30 specs):
[D] ["phantomjs","onResourceReceived",{"contentType":"image/svg+xml","headers":[{"name":"Content-Type","value":"image/svg+xml"},{"name":"Content-Length","value":"8834"}],"id":68,"redirectURL":null,"stage":"end","status":null,"statusText":null,"time":"2016-01-11T10:06:46.813Z","url":"data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj..."}]
I didn't put the whole base64 representation of the image file, because it is big.
And when I opened the file in the browser I saw that it is the Jasmine logo.
Update 2
I noticed it doesn't happen when I run it on a different computer (our Jenkins server)
Related
I'm running Grunt on Windows 10 (using old console). All tasks works perfectly fine except grunt-contrib-less. There's relevant part of my Gruntfile.js:
less: {
development: {
options: {
compress: true,
yuicompress: true,
optimization: 2
},
files: {
"css/jg_shop.css": "css/jg_shop.less"
}
}
}
...
grunt.loadNpmTasks('grunt-contrib-less');
grunt.registerTask('less', ['less:development']);
When I type grunt less the console freezes and produces no output.
Rename the task less to less_abc and try grunt less_abc in console.
grunt.registerTask('less_abc', ['less:development']);
I am trying to get desktop notifications working with Grunt, and have installed Grunt notify. As per the instructions, I have also installed "Growl" (I'm on Windows 7), and also included the line grunt.loadNpmTasks('grunt-notify'); in my Gruntfile, however desktop notifications are not showing at all.
Am I missing something? The Grunt Notify page seems to imply that adding in the loadNpmTasks line is the only addition needed in my gruntfile for it to work with default options.
Here is my Gruntfile:
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
less: {
development: {
options: {
paths: ["less"],
compress: true,
strictMath: true,
sourceMap: false,
sourceMapFilename: 'css/styles.css.map',
sourceMapRootpath: '/'
},
files: {
"css/styles.css": "css/style.less"
}
}
},
uglify: {
my_target: {
files: {
'js/custom.min.js': ['js/custom.js']
}
}
},
watch: {
compile: {
files: ['**/*.php', 'css/**/*.less', 'js/**/*.js', '!js/custom.min.js'],
tasks: ['less', 'uglify'],
options: {
atBegin: true,
livereload: true
}
}
}
});
grunt.loadNpmTasks('grunt-contrib-less');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-notify');
// Default task(s).
grunt.registerTask('default', ['less']);
};
Hum... I never used the grunt-notify plugin, but as the doc says, this plugin shows warning or errors of your tasks. So if your task run successfully, you shouldn't be notified.
If you wan't custom messages on success too, you'll have to add the optionnal messages.
To be sure that the problem isn't an effect of a bad installation, try to run the simple gruntfile shown as example on the plugin's page.
If it works, you should consider my first explanation and add a custom message on success.
[Edit: try to run your task with the attribute -v to have a verbose run. As specified in the doc, it will write logs if there is errors with the plugin]
This is the grunt-notify example file (from the plugin's doc) :
grunt.initConfig({
// This is optional!
notify_hooks: {
options: {
enabled: true,
max_jshint_notifications: 5, // maximum number of notifications from jshint output
title: "Project Name", // defaults to the name in package.json, or will use project directory's name
success: false, // whether successful grunt executions should be notified automatically
duration: 3 // the duration of notification in seconds, for `notify-send only
}
}
});
// Load the task
grunt.loadNpmTasks('grunt-notify');
// This is required if you use any options.
grunt.task.run('notify_hooks');
Whenever I do "grunt server" it automatically gives me this error:
Running "watch" task
Waiting...
Warning: EMFILE, too many open files
and next this:
(node) warning: Recursive process.nextTick detected. This will break in the next version of node. Please use setImmediate for recursive deferral.
This usual fix I've seen on the web is changing the name as shown bellow:
grunt.registerTask('uglify', ['jshint', 'uglify']);
grunt.registerTask('myuglify', ['jshint', 'uglify']);
Although my problem cannot be fixed with such method because I'm not using the same name as the task.
My gruntfile.js:
module.exports = function(grunt){
grunt.initConfig({
sass: {
dist: {
files: {
'styles/css/main.css': 'styles/sass/main.scss'
}
}
}
,watch: {
options:{livereload:true},
sass:{
files:'styles/sass/*.scss',
tasks:'sass'
}
},
express:{
all:{
options:{
port:9000,
hostname:'localhost',
bases:'.',
livereload:true
}
}
}
});
grunt.loadNpmTasks('grunt-contrib-sass');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-express');
grunt.registerTask('default', ['sass'])
grunt.registerTask('server',['express','watch'])
}
Any idea?
I encountered this time-wasting error today, and the solution on the GitHub repository did not work for me. After searching for this issue in relation to the process.nextTick deprecation warning, I came to the conclusion that running a task dependent on a watched file/glob is a potential cause.
Here's the Gruntfile for my website:
module.exports = function (grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
watch: {
dev: {
files: ['**/*.js', 'public/stylesheets/**/*.scss'],
tasks: ['express:dev'],
options: {
spawn: false
}
}
},
express: {
dev: {
options: {
script: 'server.js',
node_env: 'development'
}
}
}
});
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-express-server');
grunt.registerTask('default', ['express:dev', 'watch']);
};
I resolved the issue by removing js files from my watch task, which restarts Express. The below configuration of the aforementioned task works fine for me:
watch: {
dev: {
files: ['public/stylesheets/**/*.scss'],
tasks: ['express:dev'],
options: {
spawn: false
}
}
},
This SO answer provides a similar fix. Interestingly, I've never encountered this problem on my Ubuntu machine; it happened on my MacBook today when I cloned my repository.
worked for me when i typed
sudo grunt serve
possibly another solution. just increase increase read file limit.
https://github.com/gruntjs/grunt-contrib-watch#how-do-i-fix-the-error-emfile-too-many-opened-files
ulimit -n 10480
I'm having trouble configuring Grunt to watch my project files, rebuild and update a page hosted in a connect server. If I run any of the build tasks and then 'watch' as part of a combined task, then 'watch' seems to get stuck in a loop, endlessly printing the message.
Running "watch" task
Waiting...
Warning: must provide pattern
If instead I just run $ grunt watch, it will happily watch my source files and compile/build as appropriate.
I think the relevant task configurations are these:
watch: {
html: {
files: [ '<%= site.partials %>', '<%= site.layouts %>', '<%= site.pages %>' ],
tasks: [ 'html' ]
},
sass: {
files: [ '<%= site.src %>sass/*.scss' ],
tasks: [ 'styles' ]
}
},
// development server
connect: {
options: {
port: 8080,
livereload: 35729,
hostname: 'localhost',
},
dev: {
options: {
directory: 'build',
}
}
},
and the task definitions:
grunt.registerTask( 'build', [ 'styles', 'html', ] );
grunt.registerTask( 'default', [ 'build','connect:dev', 'watch' ] );
The 'styles' and 'html' tasks run grunt-sass and assemble. As stated above, running any of these tasks, or even 'watch' on its own yields the expected results. This suggests my config object has site.partials, site.dest etc defined correctly. The problem only happens when I run any task and then 'watch', as in the default task.
I just encountered a similar problem when I had been editing my Gruntfile and left a field (that should have had a file pattern) blank.
Check your Gruntfile for an empty file field.
In my specific example:
wiredep: {
options: {
overrides: {
"jquery-ui": {
"main": [
"jquery-ui.js",
"themes/base/jquery-ui.css",
""
]
}
}
}
}
Note the empty string above. That generated an error very similar to yours. It seems that Grunt doesn't tell you where the error is, unfortunately. You'll just need to scan through your Gruntfile manually to find the error.
connect:dev is the problem. Remove that and it should work fine.
I use the grunt-contrib-watch task (v. 0.5.3) in order to enable LiveReload:
livereload: {
options: {
middleware: function (connect) {
return [lrSnippet, mountFolder(connect, '.tmp'),
mountFolder(connect, 'src'),
proxySnippet];
}
}
}
//...some other tasks...
watch: {
livereload: {
options: {
livereload: LIVERELOAD_PORT
},
files: [
'src/*.html'
]
}
}
//...................................
grunt.registerTask('server', [
'clean:server',
'recess:compile',
'configureProxies',
'connect:livereload',
'open',
'watch'
]);
While running grunt server --verbose (including watch task), I end up with this console output:
Running "watch" task
Waiting...Verifying property watch exists in config...OK
Verifying property watch.livereload.files exists in config...OK
Live reload server started on port: 35729
Watching src/404.html for changes.
Watching src/app for changes.
Watching src/assets for changes.
Watching src/common for changes.
Watching src/less for changes.
Watching src/vendor for changes.
Watching src/index.html for changes.
For instance, we see here that src/index.html is observed, thus I attempt to change the page title to see the live modification. But, process exits as soon as I save my file..
I read about the fact that watch task may exit if the provided file paths are invalid.
But, Watching src/index.html for changes asserts that it exists, doesn't it?
I don't figure it out.
So the problem was.... a bug with NodeJs 0.10.18.
I updated to 0.10.21 and the whole works without changing anything in my first Gist.
In one word, if you have OSX 10.9 (Mavericks), you have to update Node to 0.10.21
Not sure if that's the issue you're having, but it seems like you're using the connect-livereload middleware directly instead of setting the livereload option directly, as supported by grunt-contrib-connect.
Here's a simple example GruntFile, using just grunt-contrib-watch and grunt-contrib-connect:
module.exports = function (grunt) {
var LIVERELOAD_PORT = 12345;
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
connect: {
server: {
options: {
port: 9001,
base: './src',
livereload: LIVERELOAD_PORT
}
}
},
watch: {
develop: {
files: 'src/*.html',
options: {
livereload: {
port: LIVERELOAD_PORT
}
}
}
}
});
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.registerTask('server', [
'connect:server',
'watch'
]);
};
If you don't need to configure a specific port and can use the default port, it's even simpler - just change the livereload properties for both tasks to true:
livereload: true