Adds SFRA 6.0

This commit is contained in:
Isaac Vallee
2021-12-21 10:57:31 -08:00
parent d04eb5dd16
commit 823c7608c3
1257 changed files with 137087 additions and 0 deletions

View File

@@ -0,0 +1,140 @@
'use strict';
/* global cat, cd, cp, echo, exec, exit, find, ls, mkdir, pwd, rm, target, test */
require('shelljs/make');
var chalk = require('chalk'),
path = require('path'),
spawn = require('child_process').spawn,
fs = require('fs'),
shell = require('shelljs');
function getSandboxUrl() {
if (test('-f', path.join(process.cwd(), 'dw.json'))) {
var config = cat(path.join(process.cwd(), 'dw.json'));
var parsedConfig = JSON.parse(config);
return '' + parsedConfig.hostname;
}
return '';
}
function getOptions(defaults, args) {
var params = {};
var i = 0;
while (i < args.length) {
var item = args[i];
if (item.indexOf('--') === 0) {
if (i + 1 < args.length && args[i + 1].indexOf('--') < 0) {
var value = args[i + 1];
value = value.replace(/\/+$/, "");
params[item.substr(2)] = value;
i += 2;
} else {
params[item.substr(2)] = true;
i++;
}
} else {
params[item] = true;
i++;
}
}
var options = Object.assign({}, defaults, params);
return options;
}
function getOptionsString(options) {
if (!options.baseUrl) {
console.error(chalk.red('Could not find baseUrl parameter.'));
process.exit();
}
var optionsString = '';
Object.keys(options).forEach(function (key) {
if (options[key] === true) {
optionsString += key + ' ';
} else {
optionsString += '--' + key + ' ' + options[key] + ' ';
}
});
return optionsString;
}
target.compileFonts = function () {
var fontsDir = 'cartridges/app_storefront_base/cartridge/static/default/fonts';
mkdir('-p', fontsDir);
cp('-r', 'node_modules/font-awesome/fonts/', 'cartridges/app_storefront_base/cartridge/static/default');
cp('-r', 'node_modules/flag-icon-css/flags', fontsDir + '/flags');
};
target.functional = function (args) {
var defaults = {
baseUrl: 'https://' + getSandboxUrl() + '/s/RefArch',
client: 'chrome'
};
var configFile = 'test/functional/webdriver/wdio.conf.js';
if(args.indexOf('appium') > -1) {
args.splice(args.indexOf('appium'), 1);
configFile = 'test/functional/webdriver/wdio.appium.js';
defaults = {
baseUrl: 'https://' + getSandboxUrl() + '/s/RefArch'
}
}
var options = getOptions(defaults, args);
var optionsString = getOptionsString(options);
console.log(chalk.green('Installing selenium'));
exec('node_modules/.bin/selenium-standalone install', { silent: true });
console.log(chalk.green('Selenium Server started'));
var selenium = exec('node_modules/.bin/selenium-standalone start', { async: true, silent: true });
console.log(chalk.green('Running functional tests'));
var tests = spawn('./node_modules/.bin/wdio ' + configFile + ' ' + optionsString, { stdio: 'inherit', shell: true });
tests.on('exit', function (code) {
selenium.kill();
console.log(chalk.green('Stopping Selenium Server'));
process.exit(code);
});
};
target.release = function (args) {
if (!args) {
console.log('No version type provided. Please specify release type patch/minor/major');
return;
}
var type = args[0].replace(/"/g, '');
if (['patch', 'minor', 'major'].indexOf(type) >= 0) {
console.log('Updating package.json version with ' + args[0] + ' release.');
var version = spawn('npm version ' + args[0], { stdio: 'inherit', shell: true });
var propertiesFileName = path.resolve('./cartridges/app_storefront_base/cartridge/templates/resources/version.properties')
version.on('exit', function (code) {
if (code === 0) {
var versionNumber = JSON.parse(fs.readFileSync('./package.json').toString()).version;
//modify version.properties file
var propertiesFile = fs.readFileSync(propertiesFileName).toString();
var propertiesLines = propertiesFile.split('\n');
var newLines = propertiesLines.map(function (line) {
if (line.indexOf('global.version.number=') === 0) {
line = 'global.version.number=' + versionNumber;
}
return line;
});
fs.writeFileSync(propertiesFileName, newLines.join('\n'));
shell.exec('git add -A');
shell.exec('git commit -m "Release ' + versionNumber + '"');
console.log('Version updated to ' + versionNumber);
console.log('Please do not forget to push your changes to the integration branch');
}
});
} else {
console.log('Could not release new version. Please specify version type (patch/minor/major).');
}
}

View File

@@ -0,0 +1,46 @@
#!/usr/bin/env bash
HUB_RUNNING=$(docker inspect --format="{{ .State.Running }}" selenium-hub 2> /dev/null)
if [ $? -eq 1 ]; then
echo "Selenium Hub does not exist. Attempting to run it..."
docker run -d -p 4444:4444 --name selenium-hub --restart always selenium/hub:2.53.0
sleep 2
fi
if [ "$HUB_RUNNING" == "false" ]; then
echo "Selenium Hub is not running. Attempting to start it..."
docker start selenium-hub
sleep 2
fi
CONTAINER_NAME="sg-functional-test-chrome-$JOB_NAME"
# remove any pre-existing container
if [ $(docker ps -a | grep $CONTAINER_NAME | awk '{print $NF}' | wc -l) -gt 0 ]; then
docker rm -f $CONTAINER_NAME 1>/dev/null
fi
# if a debug flag is passed in, use the debug image and open vnc screen sharing
if [[ $@ == *"--debug"* ]]; then
ip=$(grep -Eo '([0-9]{1,3}\.){3}[0-9]{1,3}' <<< "$@")
docker run -d --link selenium-hub:hub --name $CONTAINER_NAME -p 5900:5900 -v /dev/shm:/dev/shm selenium/node-chrome-debug:2.53.0 1>/dev/null
sleep 2 # wait a bit for container to start
open vnc://:secret@"$ip":5900
else
docker run -d --link selenium-hub:hub --name $CONTAINER_NAME -v /dev/shm:/dev/shm selenium/node-chrome:2.53.0 1>/dev/null
sleep 2
fi
# run actual test command in a subshell to be able to rm docker container afterwards
# this command is for Jenkins job to by pass the Makefile.js
(
./node_modules/.bin/wdio test/functional/webdriver/wdio.conf.js "$@" 2> /dev/null
)
# save exit code of subshell
testresult=$?
docker stop $CONTAINER_NAME 1>/dev/null && docker rm $CONTAINER_NAME 1>/dev/null
exit $testresult