export default class extends HTMLElement {
static name = 'x-test-harness';
static register() {
console.debug('Registering Element', this.name, this);
customElements.define(this.name, this);
}
static get elements() {
return Array.from(document.querySelectorAll(this.name));
}
tests = []
connectedCallback() {
console.debug('TestHarness#connectedCallback', this);
const passedCount = this.querySelector('.passed-count');
const failedCount = this.querySelector('.failed-count');
const skippedCount = this.querySelector('.skipped-count');
[passedCount, failedCount, skippedCount].forEach(e => e.innerHTML = '0');
const runLink = this.querySelector('a');
runLink.onclick = e => {
e.preventDefault();
this.run();
};
}
addTests(fn) {
this.tests.push(fn);
}
run() {
this.tests.forEach(t => t());
}
}