tatsuyafw / gulp-nightwatch

gulp plugin for Nightwatch.js
MIT License
30 stars 18 forks source link

overriding nightwatch.json #36

Open chrtang-exp opened 8 years ago

chrtang-exp commented 8 years ago

Nightwatch out of the box provides the ability to override the defaults in nightwatch.json at run-time if nightwatch.conf.js is present. While using gulp-nightwatch, only the path to nightwatch.json is considered and I am unable to do any overrides. Is there a way as a user to work around this or would this be a new feature?

tatsuyafw commented 8 years ago

Hi @chrtang-exp , thank you for your comment.

Unfortunately, I don't come up with a good workaround, and this would be a new feature.

gcpantazis commented 8 years ago

If you'd like to define the configuration programmatically, you could make a .js file that returns the configuration object, or a method that returns configuration object when called (if you want to pass arguments).

const rename = require('gulp-rename');
const streamMap = require('map-stream');

return gulp.src('./my-browserstack-config.js')

    // `gulp-nightwatch` works with a configuration JSON, but we want to generate that
    // programatically. This takes the input config JS, gathers its output, and
    // writes that to disk for `gulp-nightwatch` to use.
    .pipe(
        streamMap((file, cb) => {
            const output = require(file.path);
            file.contents = new Buffer(JSON.stringify(output));
            cb(null, file);
        })
    )

    // Change the extension to JSON
    .pipe(rename({
        extname: '.json',
    }))

    // Throw it into a `./tmp` folder
    .pipe(gulp.dest('./tmp/'))

    // Run Nightwatch Tests.
    .pipe(nightwatch({
        configFile: './tmp/my-browserstack-config.json',
        cliArgs: ['--env chrome,firefox,edge,ie,iphoneIOS8,iphoneIOS9'],
    }))