Skip to content

Commit e8b06c1

Browse files
authored
Merge pull request #10 from AlesJiranek/options
Enable passing arguments via main options object
2 parents 5ce5651 + 56bc810 commit e8b06c1

File tree

2 files changed

+84
-2
lines changed

2 files changed

+84
-2
lines changed

README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,42 @@ gulp.task('test', function () {
4444
Default is `casperjs` (global)
4545

4646

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 | <filename>,<filename> |
73+
| logLevel | --log-level | [debug | info | warning | error] |
74+
| noColors | --no-colors | |
75+
| post | --post | <filename> |
76+
| pre | --pre | <filename> |
77+
| webSecurity | --web-security | no |
78+
| xunit | --xunit | <filename> |
79+
80+
81+
82+
4783
## LICENSE
4884

4985
The MIT License (MIT)

index.js

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,50 @@ const PLUGIN_NAME = 'gulp-casper-js';
88
function casper(options) {
99
options = options || {};
1010

11-
var cmd = (typeof options.command === 'undefined') ? 'test' : options.command;
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+
}
1252

1353
var binPath = (typeof options.binPath === 'undefined') ? 'casperjs' : options.binPath;
54+
var cmd = (typeof options.command === 'undefined') ? 'test' : options.command;
1455

1556
var files = [];
1657

@@ -36,8 +77,13 @@ function casper(options) {
3677

3778
var end = function(cb) {
3879
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+
}
3985

40-
var casperChild = spawn(binPath, cmd.concat(files));
86+
var casperChild = spawn('casperjs', tempArr);
4187

4288
casperChild.stdout.on('data', function(data) {
4389
var msg = data.toString().slice(0, -1);

0 commit comments

Comments
 (0)