diff --git a/gulpfile.js b/gulpfile.js index b11debdc8..1cd0beaec 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -57,12 +57,14 @@ const paths = { "popup/*.{ts,tsx}", "pages/*.{ts,tsx}", "!**/*.d.ts", + "!**/*-test*.ts", ], decl: [ "lib/refs.d.ts", ], dev: [ "testlib/**/.ts", + "**/*-test*.ts", ], }, dist: [ diff --git a/lib/wallet/cryptoApi-test.ts b/lib/wallet/cryptoApi-test.ts index 6399367b1..ea3045c29 100644 --- a/lib/wallet/cryptoApi-test.ts +++ b/lib/wallet/cryptoApi-test.ts @@ -1,6 +1,9 @@ import {CryptoApi} from "./cryptoApi"; import {test, TestLib} from "testlib/talertest"; -test("string hashing", (t: TestLib) => { - +test("string hashing bla", async (t: TestLib) => { + let crypto = new CryptoApi(); + let s = await crypto.hashString("hello taler"); + console.log(s); + t.pass(); }); diff --git a/node_modules/.yarn-integrity b/node_modules/.yarn-integrity index 4324f37c5..13bf7167d 100644 --- a/node_modules/.yarn-integrity +++ b/node_modules/.yarn-integrity @@ -1 +1 @@ -4ba2f689d57511507e94d43fc06be3ad7c3198ea985e1cb661c2eef84d2fc993 \ No newline at end of file +b17d9b8daaa8d5ec093068da508250296323997ac6ead0747fcdc5090a390154 \ No newline at end of file diff --git a/package.json b/package.json index cd08e3196..c59a8e569 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "license": "GPL-3.0", "devDependencies": { "better-assert": "^1.0.2", + "connect": "^3.5.0", "del": "^2.2.0", "glob": "^7.0.3", "gulp": "^3.9.1", @@ -30,9 +31,11 @@ "gulp-zip": "^3.1.0", "istanbul-lib-instrument": "^1.0.0-alpha.6", "map-stream": "0.0.6", + "minimist": "^1.2.0", "mocha": "^2.4.5", "po2json": "git+https://github.com/mikeedwards/po2json", "selenium-webdriver": "^3.0.0-beta-3", + "serve-static": "^1.11.1", "systemjs": "^0.19.14", "through2": "^2.0.1", "typescript": "^2.0.3", diff --git a/testlib/node/runtime.js b/testlib/node/runtime.js index 29ee508cc..dfdada9e8 100644 --- a/testlib/node/runtime.js +++ b/testlib/node/runtime.js @@ -53,6 +53,11 @@ let mod = System.newModule({Module: emsc, default: emsc}); let modName = System.normalizeSync(__dirname + "/../../lib/emscripten/taler-emscripten-lib.js"); System.set(modName, mod); +process.on('unhandledRejection', function(reason, p){ + console.log("Possibly Unhandled Rejection at: Promise ", p, " reason: ", reason); + process.exit(1); +}); + let testName = process.argv[2]; System.import("testlib/talertest") diff --git a/testlib/selenium/runtime.js b/testlib/selenium/runtime.js index 0cf6c6d18..2253bafbc 100644 --- a/testlib/selenium/runtime.js +++ b/testlib/selenium/runtime.js @@ -25,21 +25,63 @@ var webdriver = require('selenium-webdriver'); var chrome = require('selenium-webdriver/chrome'); var path = require("path"); var process = require("process"); +var fs = require("fs"); -var p = "file://" + __dirname + "/testhost.html"; +var connect = require('connect'); +var serveStatic = require('serve-static'); -if (!process.argv[2]) { - console.log("no test script given"); +// Port of the web server used to serve the test files +var httpPort = 8080; + +var p = `http://localhost:${httpPort}/testlib/selenium/testhost.html`; + +var argv = require('minimist')(process.argv.slice(2), {"boolean": ["keep-open"]}); + +console.log(argv); + +function printUsage() { + console.log(`Usage: [--keep-open] TESTSCRIPT`); +} + +if (argv._.length != 1) { + console.log("exactly one test script must be given"); + printUsage(); process.exit(1); } -var testScript = path.resolve(process.argv[2]); +var testScriptName = path.resolve(argv._[0]); +var projectRoot = path.resolve(__dirname, "../../"); +if (!testScriptName.startsWith(projectRoot)) { + console.log("test file must be inside wallet project root"); + process.exit(1); +} + +var testScript = "./" + testScriptName.substring(projectRoot.length); +console.log("test script:", testScript); +console.log("test script name:", testScriptName); +console.log("root:", projectRoot); + +try { + var stats = fs.lstatSync(path.resolve(projectRoot, testScript)); + if (!stats.isFile()) { + throw Error("test must be a file"); + } +} catch (e) { + console.log("can't execute test"); + console.log(e); + process.exit(e); +} + var script = ` function f() { + if ("undefined" == typeof System) { + console.log("can't access module loader"); + return + } System.import("testlib/talertest") .then(tt => { - SystemJS.import("file://${testScript}") + SystemJS.import("http://localhost:${httpPort}/${testScript}") .then(() => { return tt.run(); }) @@ -69,6 +111,9 @@ function untilTestOver() { console.log("TAP version 13"); +let srv = connect().use(serveStatic(__dirname + "/../../")); +let l = srv.listen(8080); + var driver = new webdriver.Builder() .setLoggingPrefs({browser: 'ALL'}) .forBrowser('chrome') @@ -80,9 +125,6 @@ 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 @@ -94,7 +136,10 @@ driver.manage().logs().get("browser").then((logs) => { // Skip file url and LINE:COL console.log(l.message.substring(s2)); } + + if (!argv["keep-open"]) { + driver.quit(); + l.close(); + } }); -driver.quit(); - diff --git a/testlib/selenium/testhost.html b/testlib/selenium/testhost.html index 263fe6316..62c1a4e82 100644 --- a/testlib/selenium/testhost.html +++ b/testlib/selenium/testhost.html @@ -2,10 +2,10 @@ Browser Test Host - +