import { TestSearcher } from "./testSearcher" import { TestRunner } from "../testRunner" import { QueryParser } from "../partial-src/component/queryParser" export class Page extends R.Page { constructor() { super() this.testSearcher = new TestSearcher() this.testSearcher.events.listenBy(this, "test", (path: string) => { window.location.hash = `testcase=${path}` let pathes: string[] = [] if (path === "all") { pathes = this.getMatchesTest("") } else { pathes = [path] } this.runTests(pathes) }) } runTests(pathes: string[]) { let runner = new TestRunner(...pathes) this.UI.mocha.innerHTML = "" runner.run() } initialCheck() { let urlObject = QueryParser.parse(window.location.hash.slice(1)) if (urlObject["testcase"]) { let path = urlObject["testcase"] if (path == "all") path = "" let matches = this.getMatchesTest(path) this.runTests(matches) } } getMatchesTest(path) { let matches = LeafTestContext.scripts.filter(item => item.scriptPath.indexOf("test.js") >= 0).map(item => item.scriptPath).filter(name => name.indexOf(path) >= 0) return matches } }