From d0a0695fb5d34996850723f7d4b1b59c3df909c2 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Thu, 3 Nov 2016 00:47:22 +0100 Subject: test harness for both browser and node --- testlib/node/runtime.js | 70 +++++++++++++++++++++++++++++ testlib/selenium/runtime.js | 100 +++++++++++++++++++++++++++++++++++++++++ testlib/selenium/testhost.html | 19 ++++++++ testlib/talertest.ts | 1 + testlib/testruntime.js | 70 ----------------------------- 5 files changed, 190 insertions(+), 70 deletions(-) create mode 100644 testlib/node/runtime.js create mode 100644 testlib/selenium/runtime.js create mode 100644 testlib/selenium/testhost.html delete mode 100644 testlib/testruntime.js (limited to 'testlib') diff --git a/testlib/node/runtime.js b/testlib/node/runtime.js new file mode 100644 index 000000000..29ee508cc --- /dev/null +++ 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 + */ + +/** + * + * @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 new file mode 100644 index 000000000..0cf6c6d18 --- /dev/null +++ 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 + */ + +/** + * + * @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 new file mode 100644 index 000000000..263fe6316 --- /dev/null +++ b/testlib/selenium/testhost.html @@ -0,0 +1,19 @@ + + + + Browser Test Host + + + + diff --git a/testlib/talertest.ts b/testlib/talertest.ts index 5dcaff457..14074620b 100644 --- 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 deleted file mode 100644 index 236807265..000000000 --- a/testlib/testruntime.js +++ /dev/null @@ -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 - */ - -/** - * - * @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); - }); - -- cgit v1.2.3