UNPKG

@o3world/backstopjs

Version:

A commandline utility and node server to assist in creating drupal backstop tests

47 lines (36 loc) 1.34 kB
#!/usr/bin/env node var fs = require('fs-extra'); let myArgs = process.argv.slice(2); let commandToRun = myArgs[0]; let pathToPackage = require("global-modules-path").getPath("@o3world/backstopjs"); const _ = require('lodash'); const request = require('request'); const args = require('yargs').argv; if(commandToRun == 'init') { fs.copySync(__dirname + '/config.example.js', process.cwd()+ '/config.js'); return; } const config = require(process.cwd()+ '/' + args.configFile); const backstop = require('backstopjs'); let referenceUrl = config.referenceUrl; let testUrl = config.testUrl; let backstopConfig = config.backstopConfig; if (args.testUrl) { testUrl = args.testUrl.replace(/\/$/, ""); } if (args.referenceUrl) { referenceUrl = args.referenceUrl.replace(/\/$/, ""); } backstopConfig.paths.engine_scripts = pathToPackage + "/engine_scripts"; for (let [key, value] of Object.entries(config.pathsToTest)) { backstopConfig.scenarios.push({ ...{label: key, url: testUrl + value, referenceUrl: referenceUrl + value }, ...config.defaultScenarioSettings }); } for (let [key, value] of Object.entries(config.customScenarios)) { value.url = testUrl + value.url; value.referenceUrl = referenceUrl + value.referenceUrl; backstopConfig.scenarios.push(value); } backstop(commandToRun, { config: backstopConfig });