TAP-based test harness

This commit is contained in:
Florian Dold 2016-11-02 21:13:56 +01:00
parent d76fce8077
commit db9177bb17
11 changed files with 167 additions and 95 deletions

View File

@ -62,7 +62,7 @@ const paths = {
"lib/refs.d.ts",
],
dev: [
"test/tests/*.{ts,tsx}",
"testlib/**/.ts",
],
},
dist: [

View File

@ -257,4 +257,4 @@ export class CryptoApi {
newCoinDenoms,
meltFee);
}
}
}

View File

@ -351,4 +351,4 @@ namespace RpcFunctions {
const b = native.ByteArray.fromStringWithNull(str);
return b.hash().toCrock();
}
}
}

View File

@ -1281,4 +1281,4 @@ export function setupFreshCoin(secretSeed: TransferSecretP,
return {priv, blindingKey};
}
}

3
scripts/prove Executable file
View File

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

View File

@ -1,21 +0,0 @@
#!/usr/bin/python3
import unittest
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
class PythonOrgSearch(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Chrome()
def test_taler_reachable(self):
driver = self.driver
driver.get("https://bank.demo.taler.net")
def tearDown(self):
self.driver.close()
if __name__ == "__main__":
unittest.main()

View File

@ -1,56 +0,0 @@
/**
* Bridge between the mocha test runner / nodejs
* and the typescript / the wallet's module system.
*
* The test cases use better-assert as assert library
* with mocha's bdd UI.
*/
"use strict";
let assert = require("better-assert");
let vm = require("vm");
let fs = require("fs");
let instrument = require("typhonjs-istanbul-instrument-jspm").default;
if ("function" !== typeof run) {
throw Error("test must be run with 'mocha --delay ...'");
}
let emsc = require("../lib/emscripten/libwrapper.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'
}
}
});
instrument(System);
let mod = System.newModule({Module: emsc});
let modName = System.normalizeSync(__dirname + "/../lib/emscripten/emsc");
console.log("registering", modName);
System.set(modName, mod);
System.import("./test/tests/taler.js")
.then((t) => {
t.declareTests(assert, context, it);
setTimeout(run, 1);
})
.catch((e) => {
console.error("failed to load module", e.stack);
});

View File

@ -1,13 +0,0 @@
import * as Emsc from '../../lib/wallet/emscriptif';
declare var HttpMockLib: any;
export function declareTests(assert: any, context: any, it: any) {
it("calls native emscripten code", function() {
let x = new Emsc.Amount({value: 42, fraction: 42, currency: "EUR"});
let j = x.toJson();
assert("value" in j);
});
}

88
testlib/talertest.ts Normal file
View File

@ -0,0 +1,88 @@
/*
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
*/
type TestFn = (t: TestLib) => void;
interface Test {
name: string;
testFn: TestFn;
}
export interface TestLib {
pass(msg?: string): void;
fail(msg?: string): void;
assert(v: any, msg?: string): void;
}
let tests: Test[] = [];
let testRunner: any;
/**
* Register a test case.
*/
export function test(name: string, testFn: TestFn) {
tests.push({name, testFn});
}
/**
* Run all registered test case, producing a TAP stream.
*/
export async function run() {
console.log(`1..${tests.length}`);
for (let i in tests) {
let t = tests[i];
let lastMsg: string|undefined = undefined;
let p = new Promise((resolve, reject) => {
let pass = (msg?: string) => {
lastMsg = msg;
resolve();
};
let fail = (msg?: string) => {
lastMsg = msg;
reject();
throw Error("test failed");
};
let assert = (v: any, msg?: string) => {
if (!v) {
lastMsg = msg;
reject();
throw Error("test failed");
}
};
t.testFn({pass,fail, assert});
});
console.log(`# ${t.name}`);
if (!lastMsg) {
lastMsg = "-";
}
try {
await p;
console.log(`ok ${Number(i) + 1} ${lastMsg}`);
} catch (e) {
console.log(`not ok ${Number(i) + 1} ${lastMsg}`);
}
}
}

70
testlib/testruntime.js Normal file
View File

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

View File

@ -14,16 +14,17 @@
},
"files": [
"lib/components.ts",
"test/tests/taler.ts",
"lib/refs.d.ts",
"lib/i18n.ts",
"lib/taler-wallet-lib.ts",
"lib/wallet/checkable.ts",
"lib/wallet/chromeBadge.ts",
"lib/wallet/cryptoApi-test.ts",
"lib/wallet/cryptoApi.ts",
"lib/wallet/cryptoLib.ts",
"lib/wallet/cryptoWorker.ts",
"lib/wallet/db.ts",
"lib/wallet/emscriptif-test.ts",
"lib/wallet/emscriptif.ts",
"lib/wallet/helpers.ts",
"lib/wallet/http.ts",