I no longer use or maintain this project. Let me know if you are interested in maintaining this project.
Grunt task to run CasperJS tests.
If you haven't used grunt before, be sure to check out the Getting Started guide, as it explains how to create a gruntfile as well as install and use grunt plugins. Once you're familiar with that process, install this plugin with this command:
npm install grunt-ghost --save-dev
Then add this line to your project's Gruntfile.js
gruntfile:
grunt.loadNpmTasks('grunt-ghost');
####Basic use without options
Specify the files/directories of the tests you want to run in the filesSrc
array. Files will be run in alphabetic and numerical order.
ghost: {
dist: {
filesSrc: ['tests/1_userLogin.js','tests/2_userLogout']
}
}
####Dependencies
The only dependencies are CasperJS and Grunt
I have included all the test command options listed in the CasperJS documentation and some options of my own.
ghost: {
dist: {
filesSrc: ['tests/userSuite/*'],
// CasperJS test command options
options: {
// Allows you to pass variables to casper that can be accesed in files,
// for example, if you used the following args object then
// casper.cli.get('username') would return 'colin'
args: {
username: 'colin'
},
// Exports results of test to a xUnit XML file
xunit: 'xunit/userSuite.xml',
// Outputs additional log messages
direct: true,
// Sets logging level, check out http://casperjs.org/logging.html
logLevel: 'info',
// Specifies files to be included for each test file, accepts file paths or globs as input
includes: [
'tests/config.js',
'lib/jquery.min.js'
],
// Adds tests from specified files before running the test suite
pre: ['tests/pre-test.js'],
// Adds tests from specified files after running the test suite
post: ['tests/post-test.js'],
// Terminates test suite upon failure of first test
failFast: true,
// Specify a custom test runner
runner: 'tests/customRunner.js'
// grunt-ghost specific options
// Prints the command given to CasperJS
printCommand: true,
// Prints list of filepaths
printFilePaths: true
}
}
}
Thanks to the CasperJS authors for making a great tool, the descriptions of the test command options are modifications from their documentation. I also want to thank the authors of grunt-casperjs and grunt-recess because I learned a lot from looking at their source.
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using grunt.
Copyright (c) 2013 Colin Wren Licensed under the MIT license.
- v1.1.0 Add globbing pattern support for options.includes
- v1.0.13 Fixed Fix printCommand infinite loop bug
- v1.0.12 Fixed glob filematching
- v1.0.11 Enabled streaming output