commit d0a0695fb5d34996850723f7d4b1b59c3df909c2
parent e9a383ede7f98512f0dd351697759d75ddb67eac
Author: Florian Dold <florian.dold@gmail.com>
Date: Thu, 3 Nov 2016 00:47:22 +0100
test harness for both browser and node
Diffstat:
14 files changed, 226 insertions(+), 82 deletions(-)
diff --git a/.gitignore b/.gitignore
@@ -5,6 +5,8 @@ pages/**/*.js.map
pogen/**/*.js.map
test/**/*.js.map
content_scripts/**/*.js.map
+testlib/**/*.js.map
+testlib/talertest.js
background/*.js
pogen/*.js
test/*.js
@@ -20,4 +22,8 @@ build/
taler-wallet-*.tar.gz
taler-wallet-*.directive
taler-wallet-*.directive.asc
-taler-wallet-*.sig
-\ No newline at end of file
+taler-wallet-*.sig
+
+# Even though node_modules are tracked in git,
+# per default we don't want them to show up in git status
+node_modules
diff --git a/lib/emscripten/taler-emscripten-lib.d.ts b/lib/emscripten/taler-emscripten-lib.d.ts
@@ -51,4 +51,6 @@ export declare namespace Module {
function writeStringToMemory(s: string,
buffer: number,
dontAddNull?: boolean): void;
-}
-\ No newline at end of file
+}
+
+export default Module;
diff --git a/lib/wallet/cryptoApi-test.ts b/lib/wallet/cryptoApi-test.ts
@@ -0,0 +1,6 @@
+import {CryptoApi} from "./cryptoApi";
+import {test, TestLib} from "testlib/talertest";
+
+test("string hashing", (t: TestLib) => {
+
+});
diff --git a/lib/wallet/cryptoWorker.ts b/lib/wallet/cryptoWorker.ts
@@ -45,7 +45,7 @@ if ("object" !== typeof Module) {
// we can use it from TypeScript by importing it.
{
- let mod = System.newModule({Module: Module});
+ let mod = System.newModule({Module: Module, default: Module});
let modName = System.normalizeSync("../emscripten/taler-emscripten-lib");
console.log("registering", modName);
System.set(modName, mod);
@@ -58,4 +58,4 @@ System.import("./cryptoLib")
.catch((e) => {
console.log("crypto worker failed");
console.error(e.stack);
- });
-\ No newline at end of file
+ });
diff --git a/lib/wallet/emscriptif-test.ts b/lib/wallet/emscriptif-test.ts
@@ -0,0 +1,11 @@
+import {test, TestLib} from "testlib/talertest";
+import * as native from "./emscriptif";
+
+test("string hashing", (t: TestLib) => {
+ let x = native.ByteArray.fromStringWithNull("hello taler");
+ let h = "8RDMADB3YNF3QZBS3V467YZVJAMC2QAQX0TZGVZ6Q5PFRRAJFT70HHN0QF661QR9QWKYMMC7YEMPD679D2RADXCYK8Y669A2A5MKQFR"
+ let hc = x.hash().toCrock();
+ console.log(`# hc ${hc}`);
+ t.assert(h === hc, "must equal");
+ t.pass();
+});
diff --git a/lib/wallet/emscriptif.ts b/lib/wallet/emscriptif.ts
@@ -15,7 +15,7 @@
*/
import {AmountJson} from "./types";
-import * as EmscWrapper from "../emscripten/taler-emscripten-lib";
+import Module, {EmscFunGen} from "../emscripten/taler-emscripten-lib";
/**
* High-level interface to emscripten-compiled modules used
@@ -34,14 +34,12 @@ const GNUNET_YES = 1;
const GNUNET_NO = 0;
const GNUNET_SYSERR = -1;
-let Module = EmscWrapper.Module;
-
function myCcall(name: string, ret: any, argTypes: any[], args: any[]) {
return Module.ccall(name, ret, argTypes, args);
}
-let getEmsc: EmscWrapper.EmscFunGen = (name: string, ret: any,
+let getEmsc: EmscFunGen = (name: string, ret: any,
argTypes: any[]) => {
return (...args: any[]) => {
return myCcall(name, ret, argTypes, args);
diff --git a/package.json b/package.json
@@ -32,6 +32,7 @@
"map-stream": "0.0.6",
"mocha": "^2.4.5",
"po2json": "git+https://github.com/mikeedwards/po2json",
+ "selenium-webdriver": "^3.0.0-beta-3",
"systemjs": "^0.19.14",
"through2": "^2.0.1",
"typescript": "^2.0.3",
diff --git a/scripts/prove-node b/scripts/prove-node
@@ -1,3 +1,3 @@
#!/usr/bin/env bash
-exec prove -e "node ./testlib/testruntime.js" "$@"
+exec prove -e "node ./testlib/node/runtime.js" "$@"
diff --git a/scripts/prove-selenium b/scripts/prove-selenium
@@ -0,0 +1,3 @@
+#!/usr/bin/env bash
+
+exec prove -e "node ./testlib/selenium/runtime.js" "$@"
diff --git a/testlib/node/runtime.js b/testlib/node/runtime.js
@@ -0,0 +1,70 @@
+/*
+ This file is part of TALER
+ (C) 2016 Inria
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+
+/**
+ *
+ * @author Florian Dold
+ */
+
+
+"use strict";
+
+let vm = require("vm");
+let fs = require("fs");
+let process = require("process");
+
+let emsc = require("../../lib/emscripten/taler-emscripten-lib.js");
+
+// Do it here, since it breaks 'require'' for libwrapper
+let System = require("systemjs");
+
+
+// When instrumenting code with istanbul,
+// automatic module type detection fails,
+// thus we specify it here manually.
+System.config({
+ defaultJSExtensions: true,
+ //meta: {
+ // './test/tests/taler.js': {
+ // format: 'register'
+ // },
+ // './lib/wallet/*': {
+ // format: 'register'
+ // }
+ //}
+});
+
+console.log("TAP version 13");
+
+let mod = System.newModule({Module: emsc, default: emsc});
+let modName = System.normalizeSync(__dirname + "/../../lib/emscripten/taler-emscripten-lib.js");
+System.set(modName, mod);
+
+
+let testName = process.argv[2];
+System.import("testlib/talertest")
+ .then(tt => {
+ SystemJS.import(testName)
+ .then(() => {
+ return tt.run();
+ })
+ .catch((e) => console.error(e));
+ })
+ .catch((e) => {
+ console.error("can't locate talertest");
+ console.error(e);
+ });
+
diff --git a/testlib/selenium/runtime.js b/testlib/selenium/runtime.js
@@ -0,0 +1,100 @@
+/*
+ This file is part of TALER
+ (C) 2016 Inria
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+
+/**
+ *
+ * @author Florian Dold
+ */
+
+"use strict";
+
+var webdriver = require('selenium-webdriver');
+var chrome = require('selenium-webdriver/chrome');
+var path = require("path");
+var process = require("process");
+
+var p = "file://" + __dirname + "/testhost.html";
+
+if (!process.argv[2]) {
+ console.log("no test script given");
+ process.exit(1);
+}
+
+var testScript = path.resolve(process.argv[2]);
+
+var script = `
+ function f() {
+ System.import("testlib/talertest")
+ .then(tt => {
+ SystemJS.import("file://${testScript}")
+ .then(() => {
+ return tt.run();
+ })
+ .then(() => {
+ window.__test_over = true;
+ })
+ .catch((e) => {
+ window.__test_over = true;
+ console.error(e)
+ });
+ })
+ .catch((e) => {
+ console.error("can't locate talertest");
+ console.error(e);
+ });
+ }
+ if (document.readyState == "complete") {
+ f();
+ } else {
+ document.addEventListener("DOMContentLoaded", f);
+ }
+`;
+
+function untilTestOver() {
+ return driver.executeScript("return window.__test_over");
+}
+
+console.log("TAP version 13");
+
+var driver = new webdriver.Builder()
+ .setLoggingPrefs({browser: 'ALL'})
+ .forBrowser('chrome')
+ .build();
+
+driver.get(p);
+driver.executeScript(script);
+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
+ console.log(l.message);
+ continue;
+ }
+ let s1 = l.message.indexOf(" ") + 1;
+ let s2 = l.message.indexOf(" ", s1) + 1;
+ // Skip file url and LINE:COL
+ console.log(l.message.substring(s2));
+ }
+});
+
+driver.quit();
+
diff --git a/testlib/selenium/testhost.html b/testlib/selenium/testhost.html
@@ -0,0 +1,19 @@
+<!doctype html>
+<html>
+ <head>
+ <title>Browser Test Host</title>
+ <script src="../../lib/vendor/system-csp-production.src.js"></script>
+ <script>
+ System.config({
+ baseURL: "../../",
+ defaultJSExtensions: true,
+ meta: {
+ "lib/emscripten/taler-emscripten-lib": {
+ format: "global",
+ exports: "Module",
+ }
+ },
+ });
+ </script>
+ </head>
+</html>
diff --git a/testlib/talertest.ts b/testlib/talertest.ts
@@ -82,6 +82,7 @@ export async function run() {
await p;
console.log(`ok ${Number(i) + 1} ${lastMsg}`);
} catch (e) {
+ console.error(e);
console.log(`not ok ${Number(i) + 1} ${lastMsg}`);
}
}
diff --git a/testlib/testruntime.js b/testlib/testruntime.js
@@ -1,70 +0,0 @@
-/*
- This file is part of TALER
- (C) 2016 Inria
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
- */
-
-/**
- *
- * @author Florian Dold
- */
-
-
-"use strict";
-
-let vm = require("vm");
-let fs = require("fs");
-let process = require("process");
-
-let emsc = require("../lib/emscripten/taler-emscripten-lib.js");
-
-// Do it here, since it breaks 'require'' for libwrapper
-let System = require("systemjs");
-
-
-// When instrumenting code with istanbul,
-// automatic module type detection fails,
-// thus we specify it here manually.
-System.config({
- defaultJSExtensions: true,
- //meta: {
- // './test/tests/taler.js': {
- // format: 'register'
- // },
- // './lib/wallet/*': {
- // format: 'register'
- // }
- //}
-});
-
-console.log("TAP version 13");
-
-let mod = System.newModule({Module: emsc});
-let modName = System.normalizeSync(__dirname + "/../lib/emscripten/taler-emscripten-lib.js");
-System.set(modName, mod);
-
-
-let testName = process.argv[2];
-System.import("./testlib/talertest")
- .then(tt => {
- SystemJS.import(testName)
- .then(() => {
- return tt.run();
- })
- .catch((e) => console.error(e));
- })
- .catch((e) => {
- console.error("can't locate talertest");
- console.error(e);
- });
-