aboutsummaryrefslogtreecommitdiff
path: root/testlib
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2016-11-08 16:52:03 +0100
committerFlorian Dold <florian.dold@gmail.com>2016-11-08 16:52:03 +0100
commit5dfa8d79e1ec28093056e5f52529ee3103361534 (patch)
tree9166aa62eeb54ed87f9d754b6ad750ce05f2b6a1 /testlib
parentafb9fba64be1f15a3ce3ed31214a704e73e5e8bb (diff)
fixes to test harness
Diffstat (limited to 'testlib')
-rw-r--r--testlib/node/runtime.js5
-rw-r--r--testlib/selenium/runtime.js65
-rw-r--r--testlib/selenium/testhost.html4
-rw-r--r--testlib/talertest.ts15
4 files changed, 75 insertions, 14 deletions
diff --git a/testlib/node/runtime.js b/testlib/node/runtime.js
index 29ee508cc..dfdada9e8 100644
--- a/testlib/node/runtime.js
+++ b/testlib/node/runtime.js
@@ -53,6 +53,11 @@ let mod = System.newModule({Module: emsc, default: emsc});
let modName = System.normalizeSync(__dirname + "/../../lib/emscripten/taler-emscripten-lib.js");
System.set(modName, mod);
+process.on('unhandledRejection', function(reason, p){
+ console.log("Possibly Unhandled Rejection at: Promise ", p, " reason: ", reason);
+ process.exit(1);
+});
+
let testName = process.argv[2];
System.import("testlib/talertest")
diff --git a/testlib/selenium/runtime.js b/testlib/selenium/runtime.js
index 0cf6c6d18..2253bafbc 100644
--- a/testlib/selenium/runtime.js
+++ b/testlib/selenium/runtime.js
@@ -25,21 +25,63 @@ var webdriver = require('selenium-webdriver');
var chrome = require('selenium-webdriver/chrome');
var path = require("path");
var process = require("process");
+var fs = require("fs");
-var p = "file://" + __dirname + "/testhost.html";
+var connect = require('connect');
+var serveStatic = require('serve-static');
-if (!process.argv[2]) {
- console.log("no test script given");
+// Port of the web server used to serve the test files
+var httpPort = 8080;
+
+var p = `http://localhost:${httpPort}/testlib/selenium/testhost.html`;
+
+var argv = require('minimist')(process.argv.slice(2), {"boolean": ["keep-open"]});
+
+console.log(argv);
+
+function printUsage() {
+ console.log(`Usage: [--keep-open] TESTSCRIPT`);
+}
+
+if (argv._.length != 1) {
+ console.log("exactly one test script must be given");
+ printUsage();
process.exit(1);
}
-var testScript = path.resolve(process.argv[2]);
+var testScriptName = path.resolve(argv._[0]);
+var projectRoot = path.resolve(__dirname, "../../");
+if (!testScriptName.startsWith(projectRoot)) {
+ console.log("test file must be inside wallet project root");
+ process.exit(1);
+}
+
+var testScript = "./" + testScriptName.substring(projectRoot.length);
+console.log("test script:", testScript);
+console.log("test script name:", testScriptName);
+console.log("root:", projectRoot);
+
+try {
+ var stats = fs.lstatSync(path.resolve(projectRoot, testScript));
+ if (!stats.isFile()) {
+ throw Error("test must be a file");
+ }
+} catch (e) {
+ console.log("can't execute test");
+ console.log(e);
+ process.exit(e);
+}
+
var script = `
function f() {
+ if ("undefined" == typeof System) {
+ console.log("can't access module loader");
+ return
+ }
System.import("testlib/talertest")
.then(tt => {
- SystemJS.import("file://${testScript}")
+ SystemJS.import("http://localhost:${httpPort}/${testScript}")
.then(() => {
return tt.run();
})
@@ -69,6 +111,9 @@ function untilTestOver() {
console.log("TAP version 13");
+let srv = connect().use(serveStatic(__dirname + "/../../"));
+let l = srv.listen(8080);
+
var driver = new webdriver.Builder()
.setLoggingPrefs({browser: 'ALL'})
.forBrowser('chrome')
@@ -80,9 +125,6 @@ driver.wait(untilTestOver);
driver.manage().logs().get("browser").then((logs) => {
for (let l of logs) {
- if (l.level.name != "INFO") {
- continue;
- }
if (l.message.startsWith("{")) {
// format not understood, sometimes messages are logged
// with more structure, just pass it on
@@ -94,7 +136,10 @@ driver.manage().logs().get("browser").then((logs) => {
// Skip file url and LINE:COL
console.log(l.message.substring(s2));
}
-});
-driver.quit();
+ if (!argv["keep-open"]) {
+ driver.quit();
+ l.close();
+ }
+});
diff --git a/testlib/selenium/testhost.html b/testlib/selenium/testhost.html
index 263fe6316..62c1a4e82 100644
--- a/testlib/selenium/testhost.html
+++ b/testlib/selenium/testhost.html
@@ -2,10 +2,10 @@
<html>
<head>
<title>Browser Test Host</title>
- <script src="../../lib/vendor/system-csp-production.src.js"></script>
+ <script src="/lib/vendor/system-csp-production.src.js"></script>
<script>
System.config({
- baseURL: "../../",
+ baseURL: "/",
defaultJSExtensions: true,
meta: {
"lib/emscripten/taler-emscripten-lib": {
diff --git a/testlib/talertest.ts b/testlib/talertest.ts
index 14074620b..16d8ec14e 100644
--- a/testlib/talertest.ts
+++ b/testlib/talertest.ts
@@ -19,7 +19,7 @@
* @author Florian Dold
*/
-type TestFn = (t: TestLib) => void;
+type TestFn = (t: TestLib) => void | Promise<void>;
interface Test {
name: string;
@@ -51,9 +51,15 @@ export async function run() {
console.log(`1..${tests.length}`);
for (let i in tests) {
let t = tests[i];
+ let passed = false;
let lastMsg: string|undefined = undefined;
let p = new Promise((resolve, reject) => {
let pass = (msg?: string) => {
+ if (passed) {
+ reject(Error("called pass twice"));
+ return;
+ }
+ passed = true;
lastMsg = msg;
resolve();
};
@@ -69,7 +75,9 @@ export async function run() {
throw Error("test failed");
}
};
- t.testFn({pass,fail, assert});
+ // Test might return a promise. If so, wait for it.
+ let r = t.testFn({pass,fail, assert});
+ r.then(() => resolve(), (e) => reject(e));
});
console.log(`# ${t.name}`);
@@ -80,6 +88,9 @@ export async function run() {
try {
await p;
+ if (passed) {
+ throw Error("test did not call 'pass'");
+ }
console.log(`ok ${Number(i) + 1} ${lastMsg}`);
} catch (e) {
console.error(e);