test harness for both browser and node

This commit is contained in:
Florian Dold 2016-11-03 00:47:22 +01:00
parent e9a383ede7
commit d0a0695fb5
13 changed files with 160 additions and 13 deletions

8
.gitignore vendored
View File

@ -5,6 +5,8 @@ pages/**/*.js.map
pogen/**/*.js.map pogen/**/*.js.map
test/**/*.js.map test/**/*.js.map
content_scripts/**/*.js.map content_scripts/**/*.js.map
testlib/**/*.js.map
testlib/talertest.js
background/*.js background/*.js
pogen/*.js pogen/*.js
test/*.js test/*.js
@ -20,4 +22,8 @@ build/
taler-wallet-*.tar.gz taler-wallet-*.tar.gz
taler-wallet-*.directive taler-wallet-*.directive
taler-wallet-*.directive.asc taler-wallet-*.directive.asc
taler-wallet-*.sig 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

View File

@ -51,4 +51,6 @@ export declare namespace Module {
function writeStringToMemory(s: string, function writeStringToMemory(s: string,
buffer: number, buffer: number,
dontAddNull?: boolean): void; dontAddNull?: boolean): void;
} }
export default Module;

View File

@ -0,0 +1,6 @@
import {CryptoApi} from "./cryptoApi";
import {test, TestLib} from "testlib/talertest";
test("string hashing", (t: TestLib) => {
});

View File

@ -45,7 +45,7 @@ if ("object" !== typeof Module) {
// we can use it from TypeScript by importing it. // 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"); let modName = System.normalizeSync("../emscripten/taler-emscripten-lib");
console.log("registering", modName); console.log("registering", modName);
System.set(modName, mod); System.set(modName, mod);
@ -58,4 +58,4 @@ System.import("./cryptoLib")
.catch((e) => { .catch((e) => {
console.log("crypto worker failed"); console.log("crypto worker failed");
console.error(e.stack); console.error(e.stack);
}); });

View File

@ -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();
});

View File

@ -15,7 +15,7 @@
*/ */
import {AmountJson} from "./types"; 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 * High-level interface to emscripten-compiled modules used
@ -34,14 +34,12 @@ const GNUNET_YES = 1;
const GNUNET_NO = 0; const GNUNET_NO = 0;
const GNUNET_SYSERR = -1; const GNUNET_SYSERR = -1;
let Module = EmscWrapper.Module;
function myCcall(name: string, ret: any, argTypes: any[], args: any[]) { function myCcall(name: string, ret: any, argTypes: any[], args: any[]) {
return Module.ccall(name, ret, argTypes, args); return Module.ccall(name, ret, argTypes, args);
} }
let getEmsc: EmscWrapper.EmscFunGen = (name: string, ret: any, let getEmsc: EmscFunGen = (name: string, ret: any,
argTypes: any[]) => { argTypes: any[]) => {
return (...args: any[]) => { return (...args: any[]) => {
return myCcall(name, ret, argTypes, args); return myCcall(name, ret, argTypes, args);

View File

@ -32,6 +32,7 @@
"map-stream": "0.0.6", "map-stream": "0.0.6",
"mocha": "^2.4.5", "mocha": "^2.4.5",
"po2json": "git+https://github.com/mikeedwards/po2json", "po2json": "git+https://github.com/mikeedwards/po2json",
"selenium-webdriver": "^3.0.0-beta-3",
"systemjs": "^0.19.14", "systemjs": "^0.19.14",
"through2": "^2.0.1", "through2": "^2.0.1",
"typescript": "^2.0.3", "typescript": "^2.0.3",

View File

@ -1,3 +1,3 @@
#!/usr/bin/env bash #!/usr/bin/env bash
exec prove -e "node ./testlib/testruntime.js" "$@" exec prove -e "node ./testlib/node/runtime.js" "$@"

3
scripts/prove-selenium Executable file
View File

@ -0,0 +1,3 @@
#!/usr/bin/env bash
exec prove -e "node ./testlib/selenium/runtime.js" "$@"

View File

@ -26,7 +26,7 @@ let vm = require("vm");
let fs = require("fs"); let fs = require("fs");
let process = require("process"); let process = require("process");
let emsc = require("../lib/emscripten/taler-emscripten-lib.js"); let emsc = require("../../lib/emscripten/taler-emscripten-lib.js");
// Do it here, since it breaks 'require'' for libwrapper // Do it here, since it breaks 'require'' for libwrapper
let System = require("systemjs"); let System = require("systemjs");
@ -49,13 +49,13 @@ System.config({
console.log("TAP version 13"); console.log("TAP version 13");
let mod = System.newModule({Module: emsc}); let mod = System.newModule({Module: emsc, default: emsc});
let modName = System.normalizeSync(__dirname + "/../lib/emscripten/taler-emscripten-lib.js"); let modName = System.normalizeSync(__dirname + "/../../lib/emscripten/taler-emscripten-lib.js");
System.set(modName, mod); System.set(modName, mod);
let testName = process.argv[2]; let testName = process.argv[2];
System.import("./testlib/talertest") System.import("testlib/talertest")
.then(tt => { .then(tt => {
SystemJS.import(testName) SystemJS.import(testName)
.then(() => { .then(() => {

100
testlib/selenium/runtime.js Normal file
View File

@ -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();

View File

@ -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>

View File

@ -82,6 +82,7 @@ export async function run() {
await p; await p;
console.log(`ok ${Number(i) + 1} ${lastMsg}`); console.log(`ok ${Number(i) + 1} ${lastMsg}`);
} catch (e) { } catch (e) {
console.error(e);
console.log(`not ok ${Number(i) + 1} ${lastMsg}`); console.log(`not ok ${Number(i) + 1} ${lastMsg}`);
} }
} }