alonisser
alonisser

Reputation: 12068

Passing cli parameters to casperjs through grunt task and npm test

I'm running tests with npm test - that actually runs a grunt task grunt casperjs:

casperjs:{
            options:{},
            files:
                ['./test_index.js',
                './test_map_regression.js',
                './test_index_get_gush.js'] /

        },

using the grunt-casperjs-plugin in order to automate testing with slimerjs along with phantomjs, both running under casperjs in Travis-ci.

In order to do that, I need to pass the engine as a variable from the command line. something like:

casperjs --engine=slimerjs test_suite.js

Question: I can't find a way to pass the options from grunt cli (and I assume npm command line options would delegate to grunt. correctly?) to the files array.

I tried to add:

var engine = grunt.option('engine') || 'phantomjs';
    engine = '--engine='+engine;

and then in the file array do:

files:['./test_index.js '+engine,
    './test_map_regression.js '+enging,
    './test_index_get_gush.js '+engine]

but seems that file array has to get real file names without the added args.

I'll be glad for any ideas on how to solve this through.

Upvotes: 0

Views: 1209

Answers (1)

hexid
hexid

Reputation: 3811

I haven't tested this, but looking at the grunt-casperjs source, it looks as though you would want to pass the engine as an option.

So, something like this should work:

casperjs:{
    options: {
        'engine': 'slimerjs'
    },
    files: [
        './test_index.js',
        './test_map_regression.js',
        './test_index_get_gush.js'
    ]
}

Upvotes: 1

Related Questions