test harness for both browser and node
This commit is contained in:
parent
e9a383ede7
commit
d0a0695fb5
6
.gitignore
vendored
6
.gitignore
vendored
@ -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
|
||||
@ -21,3 +23,7 @@ taler-wallet-*.tar.gz
|
||||
taler-wallet-*.directive
|
||||
taler-wallet-*.directive.asc
|
||||
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
|
||||
|
2
lib/emscripten/taler-emscripten-lib.d.ts
vendored
2
lib/emscripten/taler-emscripten-lib.d.ts
vendored
@ -52,3 +52,5 @@ export declare namespace Module {
|
||||
buffer: number,
|
||||
dontAddNull?: boolean): void;
|
||||
}
|
||||
|
||||
export default Module;
|
||||
|
6
lib/wallet/cryptoApi-test.ts
Normal file
6
lib/wallet/cryptoApi-test.ts
Normal file
@ -0,0 +1,6 @@
|
||||
import {CryptoApi} from "./cryptoApi";
|
||||
import {test, TestLib} from "testlib/talertest";
|
||||
|
||||
test("string hashing", (t: TestLib) => {
|
||||
|
||||
});
|
@ -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);
|
||||
|
11
lib/wallet/emscriptif-test.ts
Normal file
11
lib/wallet/emscriptif-test.ts
Normal 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();
|
||||
});
|
@ -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);
|
||||
|
@ -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",
|
||||
|
@ -1,3 +1,3 @@
|
||||
#!/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
3
scripts/prove-selenium
Executable file
@ -0,0 +1,3 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
exec prove -e "node ./testlib/selenium/runtime.js" "$@"
|
@ -26,7 +26,7 @@ let vm = require("vm");
|
||||
let fs = require("fs");
|
||||
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
|
||||
let System = require("systemjs");
|
||||
@ -49,13 +49,13 @@ System.config({
|
||||
|
||||
console.log("TAP version 13");
|
||||
|
||||
let mod = System.newModule({Module: emsc});
|
||||
let modName = System.normalizeSync(__dirname + "/../lib/emscripten/taler-emscripten-lib.js");
|
||||
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")
|
||||
System.import("testlib/talertest")
|
||||
.then(tt => {
|
||||
SystemJS.import(testName)
|
||||
.then(() => {
|
100
testlib/selenium/runtime.js
Normal file
100
testlib/selenium/runtime.js
Normal 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();
|
||||
|
19
testlib/selenium/testhost.html
Normal file
19
testlib/selenium/testhost.html
Normal 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>
|
@ -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}`);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user