mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-04-08 17:15:08 +02:00
commit
0a58ecb477
19
test/frontend/cases/static-page-test.js
Normal file
19
test/frontend/cases/static-page-test.js
Normal file
@ -0,0 +1,19 @@
|
||||
/**
|
||||
*
|
||||
* This test simply checks the icinga build server and tests
|
||||
* if the title is correct
|
||||
**/
|
||||
i2w = require('./i2w-config');
|
||||
|
||||
var casper = i2w.getTestEnv();
|
||||
|
||||
casper.start("http://build.icinga.org/jenkins");
|
||||
|
||||
casper.then(function() {
|
||||
this.test.assertTitle("icinga-web test [Jenkins]", "The jenkins page");
|
||||
});
|
||||
|
||||
casper.run(function() {
|
||||
this.test.done();
|
||||
});
|
||||
|
5
test/frontend/casperjs.config
Normal file
5
test/frontend/casperjs.config
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"host": "localhost",
|
||||
"port": 80,
|
||||
"path": "icinga2-web"
|
||||
}
|
107
test/frontend/i2w-config.js
Normal file
107
test/frontend/i2w-config.js
Normal file
@ -0,0 +1,107 @@
|
||||
/**
|
||||
* Tools for setting up the casperjs tests
|
||||
* mainly setting host, port and path path
|
||||
**/
|
||||
|
||||
// load config files
|
||||
var fs = require('fs');
|
||||
var env = require('system').env;
|
||||
var args = require('system').args;
|
||||
var utils = require('utils');
|
||||
|
||||
|
||||
var configFile = fs.absolute('./casperjs.config');
|
||||
var host = null;
|
||||
var port = null;
|
||||
var path = null;
|
||||
var verbose = false;
|
||||
|
||||
|
||||
if (typeof(env.CASPERJS_HOST) === "string")
|
||||
host = env.CASPERJS_HOST;
|
||||
if (typeof(env.CASPERJS_PORT) === "string")
|
||||
port = parseInt(env.CASPERJS_PORT, 10);
|
||||
if (typeof(env.CASPERJS_PATH) === "string")
|
||||
path = env.CASPERJS_PATH;
|
||||
|
||||
|
||||
for (var i=0;i<args.length;i++) {
|
||||
switch(args[i]) {
|
||||
case '--verbose':
|
||||
verbose = true;
|
||||
break;
|
||||
case '--configFile':
|
||||
configFile = args[++i];
|
||||
break;
|
||||
case '--host':
|
||||
host = args[++i];
|
||||
break;
|
||||
case '--port':
|
||||
port = parseInt(args[++i], 10);
|
||||
break;
|
||||
case '--path':
|
||||
path = args[++i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (fs.isReadable(configFile)) {
|
||||
var cfg = fs.read(configFile);
|
||||
try {
|
||||
config = JSON.parse(cfg);
|
||||
if(host === null)
|
||||
host = config.host;
|
||||
if(port === null)
|
||||
port = parseInt(config.port, 10);
|
||||
if(path === null)
|
||||
path = config.path;
|
||||
} catch(e) {
|
||||
console.error("Configuration "+cfg+" is invalid: "+e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (host === null)
|
||||
throw "Can't initialize tests: No host given in casperjs.config or via CASPERJS_HOST environment";
|
||||
if (port === null)
|
||||
throw "Can't initialize tests: No port given in casperjs.config or via CASPERJS_PORT environment";
|
||||
if (path === null)
|
||||
throw "Can't initialize tests: No path given in casperjs.config or via CASPERJS_PATH environment";
|
||||
|
||||
|
||||
(function() {
|
||||
"use strict";
|
||||
|
||||
var getBaseURL = function(url) {
|
||||
url = url || "";
|
||||
if (url.substr(0,4) == "http") {
|
||||
return url;
|
||||
}
|
||||
url = "http://"+host+":"+port+"/"+path+"/"+url;
|
||||
};
|
||||
var cstart = casper.start;
|
||||
var copen = casper.open;
|
||||
var copenFrom = casper.openFrom;
|
||||
var startFromBase = function(url, then) {
|
||||
return cstart.apply(casper,[this.getBaseURL(url), then]);
|
||||
};
|
||||
|
||||
var thenOpenFromBase = function(url, options) {
|
||||
return copen.apply(casper,[this.getBaseURL(url), options]);
|
||||
};
|
||||
|
||||
var openFromBase = function(url, options) {
|
||||
return copenFrom.apply(casper,[this.getBaseURL(url), options]);
|
||||
};
|
||||
|
||||
exports.getTestEnv = function() {
|
||||
casper.getBaseURL = getBaseURL;
|
||||
casper.start = startFromBase;
|
||||
casper.thenOpen = thenOpenFromBase;
|
||||
casper.open = openFromBase;
|
||||
return casper;
|
||||
};
|
||||
|
||||
})();
|
||||
|
||||
|
1
test/frontend/regression/test.txt
Executable file
1
test/frontend/regression/test.txt
Executable file
@ -0,0 +1 @@
|
||||
test
|
115
test/frontend/runtests
Executable file
115
test/frontend/runtests
Executable file
@ -0,0 +1,115 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
set -o nounset
|
||||
|
||||
pushd `dirname $0` > /dev/null
|
||||
DIR=`pwd`
|
||||
popd > /dev/null
|
||||
CASPER=$(which casperjs)
|
||||
INCLUDE=""
|
||||
EXCLUDE=""
|
||||
VERBOSE=0
|
||||
BUILD=0
|
||||
|
||||
if [ ! -x $CASPER ]; then
|
||||
echo "CasperJS is not installed but required to run frontend tests\n"\
|
||||
"Take a look at http://casperjs.org/installation.html to see how the installation works for your system"
|
||||
exit 1
|
||||
fi;
|
||||
|
||||
PARAM="0"
|
||||
for arg in $@;do
|
||||
if [ ! "$PARAM" == "0" ]; then
|
||||
export $PARAM=$arg
|
||||
PARAM="0"
|
||||
continue
|
||||
fi;
|
||||
case $arg in
|
||||
--verbose)
|
||||
VERBOSE=1
|
||||
;;
|
||||
--include)
|
||||
PARAM="INCLUDE"
|
||||
continue
|
||||
;;
|
||||
--exclude)
|
||||
PARAM="EXCLUDE"
|
||||
continue
|
||||
;;
|
||||
--build)
|
||||
BUILD=1
|
||||
continue
|
||||
;;
|
||||
**)
|
||||
if [ "$arg" != "--help" ]; then
|
||||
echo "Unknown option $arg"
|
||||
fi;
|
||||
printf "%b" "Testrunner for interface tests\n\n"
|
||||
printf "%b" "Usage: ./$0 [--verbose] [--include %include%] [--exclude %exclude%] [--build]\n\n"
|
||||
printf "%b" " --verbose \t\t\t Print verbose output when testing\n"
|
||||
printf "%b" " --include %filelist%\t\t Include only files matching this patterns\n"
|
||||
printf "%b" " --exclude %filelist%\t\t Exclude files matching this patterns\n"
|
||||
printf "%b" " --build \t\t\t Write test results to ../../build/log/casper_results.xml\n"
|
||||
printf "%b" " --help \t\t\t Print this message\n\n"
|
||||
exit 1
|
||||
esac;
|
||||
done;
|
||||
|
||||
EXEC="$CASPER test"
|
||||
|
||||
#
|
||||
# If build is set, the results are written for our jenkins server
|
||||
#
|
||||
if [ $BUILD -eq 1 ];then
|
||||
mkdir -p $DIR/../../build/log
|
||||
EXEC="$EXEC --xunit=$DIR/../../build/log/casper_results.xml"
|
||||
fi;
|
||||
if [ "$PARAM" != "0" ]; then
|
||||
echo "Missing parameter for $PARAM"
|
||||
exit 1
|
||||
fi;
|
||||
|
||||
cd $DIR
|
||||
FILELIST=""
|
||||
#
|
||||
# Default : Run regression and cases directory
|
||||
#
|
||||
if [ "$INCLUDE" == "" -a "$EXCLUDE" == "" ];then
|
||||
FILELIST="./cases ./regression"
|
||||
fi;
|
||||
|
||||
#
|
||||
# Include patterns set with the --include directive
|
||||
#
|
||||
if [ "$INCLUDE" != "" ];then
|
||||
NAME="\("
|
||||
GLUE=""
|
||||
for INC in $INCLUDE;do
|
||||
NAME="$NAME${GLUE}${INC}.*js"
|
||||
GLUE="\|"
|
||||
done;
|
||||
NAME=$NAME"\)$"
|
||||
FILELIST=`find . | grep "$NAME"`
|
||||
fi;
|
||||
|
||||
#
|
||||
# Exclude patterns that match the include directive
|
||||
#
|
||||
if [ "$EXCLUDE" != "" ];then
|
||||
NAME="\("
|
||||
GLUE=""
|
||||
for EXC in $EXCLUDE;do
|
||||
NAME="$NAME${GLUE}${EXC}.*js"
|
||||
GLUE="\|"
|
||||
done;
|
||||
NAME=$NAME"\)$"
|
||||
if [ "$FILELIST" == "" ]; then
|
||||
FILELIST=`find .|grep ".*js$"`
|
||||
fi
|
||||
FILELIST=`echo $FILELIST | grep -v "$NAME"`
|
||||
fi;
|
||||
|
||||
echo $EXEC $FILELIST
|
||||
$EXEC $FILELIST
|
||||
|
||||
exit 0
|
Loading…
x
Reference in New Issue
Block a user