├── .travis.yml ├── .gitignore ├── .npmignore ├── demo ├── gulpfile.js ├── package.json └── test.js ├── package.json ├── LICENSE ├── README.md └── index.js /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "0.10" 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | npm-debug.log 3 | .idea 4 | *.sublime-project 5 | *.sublime-workspace 6 | .DS_Store -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | .*.swp 2 | ._* 3 | .DS_Store 4 | .git 5 | .hg 6 | .lock-wscript 7 | .svn 8 | .wafpickle-* 9 | CVS 10 | npm-debug.log 11 | demo -------------------------------------------------------------------------------- /demo/gulpfile.js: -------------------------------------------------------------------------------- 1 | var gulp = require('gulp'); 2 | var casperJs = require('gulp-casperjs'); 3 | var gutil = require('gulp-util'); 4 | 5 | gulp.task('test', function () { 6 | gulp.src('./test.js') 7 | .pipe(casperJs().on('error', gutil.log)); 8 | }); -------------------------------------------------------------------------------- /demo/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "gulp_polygon", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "devDependencies": { 12 | "casperjs": "^1.1.1", 13 | "gulp-casperjs": "0.0.6", 14 | "gulp-util": "^3.0.7" 15 | }, 16 | "dependencies": { 17 | "casperjs": "^1.1.1", 18 | "gulp": "^3.9.1" 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /demo/test.js: -------------------------------------------------------------------------------- 1 | casper.test.begin('a twitter bootstrap dropdown can be opened', 2, function(test) { 2 | casper.start('http://getbootstrap.com/2.3.2/javascript.html#dropdowns', function() { 3 | test.assertExists('#navbar-example'); 4 | this.click('#dropdowns .nav-pills .dropdown:last-of-type a.dropdown-toggle'); 5 | this.waitUntilVisible('#dropdowns .nav-pills .open', function() { 6 | test.pass('Dropdown is open'); 7 | }); 8 | }).run(function() { 9 | test.done(); 10 | }); 11 | }); -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "gulp-casperjs", 3 | "description": "Gulp plugin for running CasperJS scripts", 4 | "version": "0.0.7", 5 | "main": "index.js", 6 | "dependencies": { 7 | "fancy-log": "^1.3.2", 8 | "plugin-error": "^1.0.1", 9 | "through2": "*" 10 | }, 11 | "author": { 12 | "name": "Dmytro Karpovych", 13 | "email": "ZAYEC77@gmail.com" 14 | }, 15 | "repository": { 16 | "type": "git", 17 | "url": "git://github.com/NullRefExcep/gulp-casperjs" 18 | }, 19 | "license": "MIT", 20 | "keywords": [ 21 | "gulp", 22 | "gulpplugin", 23 | "casper", 24 | "casperjs" 25 | ] 26 | } 27 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 NullRefExcep 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # gulp-casperjs 2 | 3 | A [gulp](https://github.com/gulpjs/gulp) plugin for running [CasperJS](https://github.com/n1k0/casperjs) scripts 4 | 5 | ## Install 6 | 7 | ``` 8 | npm install --save-dev gulp-casperjs 9 | ``` 10 | 11 | ## Usages 12 | 13 | ```js 14 | var casperJs = require('gulp-casperjs'); 15 | gulp.task('test', function () { 16 | gulp.src('Globs of test files') 17 | .pipe(casperJs()); //run casperjs test 18 | }); 19 | ``` 20 | 21 | To change the command (default: `test`) use parameter `command`: 22 | 23 | ```js 24 | var casperJs = require('gulp-casperjs'); 25 | gulp.task('casperCmd', function () { 26 | gulp.src('test.js') 27 | .pipe(casperJs({command:''})); //run casperjs test.js 28 | }); 29 | ``` 30 | 31 | Command can be `array` or `string`. 32 | If command has value which cast to `false`, this parameter will be ignored. 33 | 34 | To set custom path to CasperJS use parameter `binPath`: 35 | 36 | ```js 37 | var casperJs = require('gulp-casperjs'); 38 | gulp.task('test', function () { 39 | gulp.src('test.js') 40 | .pipe(casperJs({binPath: './node_modules/casperjs/bin/casperjs'})); //custom path to CasperJs 41 | }); 42 | ``` 43 | 44 | Default is `casperjs` (global) 45 | 46 | 47 | ## Options 48 | 49 | It is possible to pass casperjs options via main options object. 50 | 51 | ```js 52 | var casperJs = require('gulp-casperjs'); 53 | gulp.task('casperCmd', function () { 54 | const options = { 55 | logLevel: 'debug', 56 | includes: 'node_modules/package/index.js,node_modules/pacakge2/index.js', 57 | webSecurity: 'no' 58 | }; 59 | gulp.src('test.js') 60 | .pipe(casperJs(options)); //run casperjs test.js 61 | }); 62 | ``` 63 | 64 | Options are documented in official CasperJS documentation http://docs.casperjs.org 65 | Possible values are 66 | 67 | | Option | Parameter Name | Possible Values | 68 | |-------------|----------------|---------------------------------------| 69 | | concise | --concise | | 70 | | engine | --engine | [phantomjs \| slimerjs] | 71 | | failFast | --fail-fast | | 72 | | includes | --includes | `,` | 73 | | logLevel | --log-level | `[debug \| info \| warning \| error]` | 74 | | noColors | --no-colors | | 75 | | post | --post | `` | 76 | | pre | --pre | `` | 77 | | webSecurity | --web-security | no | 78 | | xunit | --xunit | `` | 79 | 80 | 81 | 82 | 83 | ## LICENSE 84 | 85 | The MIT License (MIT) 86 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | var through = require('through2'); 2 | var spawn = require('child_process').spawn; 3 | var log = require('fancy-log'); 4 | var PluginError = require('plugin-error'); 5 | 6 | const PLUGIN_NAME = 'gulp-casper-js'; 7 | 8 | function casper(options) { 9 | options = options || {}; 10 | 11 | var args = []; 12 | 13 | if (options.xunit) { 14 | args.push('--xunit=' + options.xunit); 15 | } 16 | 17 | if (options.logLevel) { 18 | args.push('--log-level=' + options.loglevel); 19 | } 20 | 21 | if (options.engine) { 22 | args.push('--engine=' + options.engine); 23 | } 24 | 25 | if (options.includes) { 26 | args.push('--includes=' + options.includes); 27 | } 28 | 29 | if (options.pre) { 30 | args.push('--pre=' + options.pre); 31 | } 32 | 33 | if (options.post) { 34 | args.push('--post=' + options.post); 35 | } 36 | 37 | if (options.failfast) { 38 | args.push('--fail-fast='); 39 | } 40 | 41 | if (options.concise) { 42 | args.push('--concise='); 43 | } 44 | 45 | if (options.nocolors) { 46 | args.push('--no-colors'); 47 | } 48 | 49 | if (options.websecurity) { 50 | args.push('--web-security=' + options.websecurity); 51 | } 52 | 53 | var binPath = (typeof options.binPath === 'undefined') ? 'casperjs' : options.binPath; 54 | var cmd = (typeof options.command === 'undefined') ? 'test' : options.command; 55 | 56 | var files = []; 57 | 58 | var read = function(file, enc, cb) { 59 | if (file.isNull()) { 60 | cb(null, file); 61 | return; 62 | } 63 | 64 | if (file.isStream()) { 65 | this.emit('error', new PluginError({ 66 | plugin: PLUGIN_NAME, 67 | message: 'Streams are not supported.' 68 | })); 69 | return cb(null, file); 70 | } 71 | files.push(file.path); 72 | 73 | this.push(file); 74 | 75 | cb(null, file); 76 | }; 77 | 78 | var end = function(cb) { 79 | cmd = cmd ? (Array.isArray(cmd) ? cmd : cmd.split(' ')) : []; 80 | var tempArr = cmd.concat(files); 81 | 82 | if (args.length) { 83 | tempArr = tempArr.concat(args); 84 | } 85 | 86 | var casperChild = spawn(binPath, tempArr); 87 | 88 | casperChild.stdout.on('data', function(data) { 89 | var msg = data.toString().slice(0, -1); 90 | log(PLUGIN_NAME + ':', msg); 91 | }); 92 | 93 | var self = this; 94 | casperChild.on('close', function(code) { 95 | var success = code === 0; 96 | if (!success) { 97 | self.emit('error', new PluginError({ 98 | plugin: PLUGIN_NAME, 99 | message: 'code ' + code 100 | })); 101 | } 102 | cb(); 103 | }); 104 | }; 105 | 106 | return through.obj(read, end); 107 | } 108 | 109 | module.exports = casper; 110 | --------------------------------------------------------------------------------