index.js
function setup() {
    return browser.getProcessedConfig()
        .then((configuration) => {
            let cucumberFormat = configuration.cucumberOpts.format;

            IS_JSON_FORMAT = cucumberFormat && cucumberFormat.includes('json');

            if (Array.isArray(cucumberFormat)) {
                IS_JSON_FORMAT = cucumberFormat.find((format) => {
                    cucumberFormat = format;
                    return format.includes('json')
                });
            }

            if (IS_JSON_FORMAT) {
                /**
                 * If options are provided override the values to the PLUGIN_CONFIG object
                 */
                if (this.config.options) {
                    Object.assign(PLUGIN_CONFIG, this.config.options);
                }

                /**
                 * Get the JSON folder path and file name if they are still empty
                 */
                const formatPathMatch = cucumberFormat.match(/(.+):(.+)/);
                const filePathMatch = formatPathMatch[2].match(/(.*)\/(.*)\.json/);

                // Get the cucumber results path
                PLUGIN_CONFIG.cucumberResultsPath = filePathMatch[1];

                // Get the cucumber report name
                PLUGIN_CONFIG.cucumberReportName = filePathMatch[2];

                /**
                 * If the json output folder is still default, then create a new one
                 */
                if (PLUGIN_CONFIG.jsonOutputPath === JSON_OUTPUT_FOLDER) {
                    PLUGIN_CONFIG.jsonOutputPath = path.join(PLUGIN_CONFIG.cucumberResultsPath, JSON_OUTPUT_FOLDER);
                }

                /**
                 * Check whether the file name need to be unique
                 */
                PLUGIN_CONFIG.uniqueReportFileName = (Array.isArray(configuration.multiCapabilities)
                    && configuration.multiCapabilities.length > 0)
                    || typeof configuration.getMultiCapabilities === 'function'
                    || configuration.capabilities.shardTestFiles;

                /**
                 * Prepare the PID_INSTANCE_DATA
                 */
                const metadata = {
                    browser: {
                        name: '',
                        version: ''
                    },
                    device: '',
                    platform: {
                        name: '',
                        version: ''
                    }
                };

                PID_INSTANCE_DATA = {
                    pid: process.pid,
                    metadata: Object.assign(metadata, configuration.capabilities[PLUGIN_CONFIG.metadataKey] || {})
                };

                /**
                 * Create the needed folders if they are not present
                 */
                fs.ensureDirSync(PLUGIN_CONFIG.cucumberResultsPath);
                fs.ensureDirSync(PLUGIN_CONFIG.jsonOutputPath);
            } else {
                console.warn('\n### NO `JSON` FORMAT IS SPECIFIED IN THE PROTRACTOR CONF FILE UNDER `cucumberOpts.format ###`\n');
            }
        });
}
function setup() {
    return browser.getProcessedConfig()
        .then((configuration) => {
            let cucumberFormat = configuration.cucumberOpts.format;

            IS_JSON_FORMAT = cucumberFormat && cucumberFormat.includes('json');

            if (Array.isArray(cucumberFormat)) {
                IS_JSON_FORMAT = cucumberFormat.find((format) => {
                    cucumberFormat = format;
                    return format.includes('json')
                });
            }

            if (IS_JSON_FORMAT) {
                /**
                 * If options are provided override the values to the PLUGIN_CONFIG object
                 */
                if (this.config.options) {
                    Object.assign(PLUGIN_CONFIG, this.config.options);
                }

                /**
                 * Get the JSON folder path and file name if they are still empty
                 */
                const formatPathMatch = cucumberFormat.match(/(.+):(.+)/);
                const filePathMatch = formatPathMatch[2].match(/(.*)\/(.*)\.json/);

                // Get the cucumber results path
                PLUGIN_CONFIG.cucumberResultsPath = filePathMatch[1];

                // Get the cucumber report name
                PLUGIN_CONFIG.cucumberReportName = filePathMatch[2];

                /**
                 * If the json output folder is still default, then create a new one
                 */
                if (PLUGIN_CONFIG.jsonOutputPath === JSON_OUTPUT_FOLDER) {
                    PLUGIN_CONFIG.jsonOutputPath = path.join(PLUGIN_CONFIG.cucumberResultsPath, JSON_OUTPUT_FOLDER);
                }

                /**
                 * Check whether the file name need to be unique
                 */
                PLUGIN_CONFIG.uniqueReportFileName = (Array.isArray(configuration.multiCapabilities)
                    && configuration.multiCapabilities.length > 0)
                    || typeof configuration.getMultiCapabilities === 'function'
                    || configuration.capabilities.shardTestFiles;

                /**
                 * Prepare the PID_INSTANCE_DATA
                 */
                const metadata = {
                    browser: {
                        name: '',
                        version: ''
                    },
                    device: '',
                    platform: {
                        name: '',
                        version: ''
                    }
                };

                PID_INSTANCE_DATA = {
                    pid: process.pid,
                    metadata: Object.assign(metadata, configuration.capabilities[PLUGIN_CONFIG.metadataKey] || {})
                };

                /**
                 * Create the needed folders if they are not present
                 */
                fs.ensureDirSync(PLUGIN_CONFIG.cucumberResultsPath);
                fs.ensureDirSync(PLUGIN_CONFIG.jsonOutputPath);
            } else {
                console.warn('\n### NO `JSON` FORMAT IS SPECIFIED IN THE PROTRACTOR CONF FILE UNDER `cucumberOpts.format ###`\n');
            }
        });
}
function setup ( ) { return browser . getProcessedConfig ( ) . then ( ( configuration ) => { let cucumberFormat = configuration . cucumberOpts . format ; IS_JSON_FORMAT = cucumberFormat && cucumberFormat . includes ( 'json' ) ; if ( Array . isArray ( cucumberFormat ) ) { IS_JSON_FORMAT = cucumberFormat . find ( ( format ) => { cucumberFormat = format ; return format . includes ( 'json' ) } ) ; } if ( IS_JSON_FORMAT ) { /**
                 * If options are provided override the values to the PLUGIN_CONFIG object
                 */ if ( this . config . options ) { Object . assign ( PLUGIN_CONFIG , this . config . options ) ; } /**
                 * Get the JSON folder path and file name if they are still empty
                 */ const formatPathMatch = cucumberFormat . match ( / (.+):(.+) / ) ; const filePathMatch = formatPathMatch [ 2 ] . match ( / (.*)\/(.*)\.json / ) ; // Get the cucumber results path PLUGIN_CONFIG . cucumberResultsPath = filePathMatch [ 1 ] ; // Get the cucumber report name PLUGIN_CONFIG . cucumberReportName = filePathMatch [ 2 ] ; /**
                 * If the json output folder is still default, then create a new one
                 */ if ( PLUGIN_CONFIG . jsonOutputPath === JSON_OUTPUT_FOLDER ) { PLUGIN_CONFIG . jsonOutputPath = path . join ( PLUGIN_CONFIG . cucumberResultsPath , JSON_OUTPUT_FOLDER ) ; } /**
                 * Check whether the file name need to be unique
                 */ PLUGIN_CONFIG . uniqueReportFileName = ( Array . isArray ( configuration . multiCapabilities ) && configuration . multiCapabilities . length > 0 ) || typeof configuration . getMultiCapabilities === 'function' || configuration . capabilities . shardTestFiles ; /**
                 * Prepare the PID_INSTANCE_DATA
                 */ const metadata = { browser : { name : '' , version : '' } , device : '' , platform : { name : '' , version : '' } } ; PID_INSTANCE_DATA = { pid : process . pid , metadata : Object . assign ( metadata , configuration . capabilities [ PLUGIN_CONFIG . metadataKey ] || { } ) } ; /**
                 * Create the needed folders if they are not present
                 */ fs . ensureDirSync ( PLUGIN_CONFIG . cucumberResultsPath ) ; fs . ensureDirSync ( PLUGIN_CONFIG . jsonOutputPath ) ; } else { console . warn ( '\n### NO `JSON` FORMAT IS SPECIFIED IN THE PROTRACTOR CONF FILE UNDER `cucumberOpts.format ###`\n' ) ; } } ) ; }
Configures the plugin with the correct data

@see docs/plugins.md
@returns {Promise} A promise which resolves into a configured setup
@public
Configures the plugin with the correct data