-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6d9b94b
commit cbeb453
Showing
5 changed files
with
72 additions
and
76 deletions.
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
packages/test-lib/src/client/html-reporter/diagnostic.component.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
const prettyPrint = (value) => JSON.stringify(value, null, 2); | ||
|
||
const diagnosticTemplate = document.createElement('template'); | ||
diagnosticTemplate.innerHTML = ` | ||
<details open> | ||
<summary> | ||
<span> | ||
<span class="description"></span><br/> | ||
<span>at <a class="location"></a></span> | ||
</span> | ||
</summary> | ||
<div class="comparison-container"> | ||
<figure> | ||
<figcatpion>actual</figcatpion> | ||
<pre></pre> | ||
</figure> | ||
<figure> | ||
<figcatpion>expected</figcatpion> | ||
<pre></pre> | ||
</figure> | ||
</div> | ||
</details> | ||
`; | ||
export class Diagnostic extends HTMLElement { | ||
#_diagnostic; | ||
|
||
get diagnostic() { | ||
return this.#_diagnostic; | ||
} | ||
|
||
set diagnostic(value) { | ||
this.#_diagnostic = value; | ||
this.render(); | ||
} | ||
|
||
connectedCallback() { | ||
this.replaceChildren(diagnosticTemplate.content.cloneNode(true)); | ||
} | ||
|
||
render() { | ||
if (!this.#_diagnostic) { | ||
return; | ||
} | ||
|
||
const { at, operator, description, expected, actual } = this.#_diagnostic; | ||
|
||
this.querySelector( | ||
'.description', | ||
).textContent = `[${operator}] ${description}`; | ||
|
||
const locationElement = this.querySelector('.location'); | ||
const locationURL = new URL(at); | ||
const [_, row, column] = locationURL.search.split(':'); | ||
locationElement.textContent = `${locationURL.pathname}:${row}:${column}`; | ||
locationElement.setAttribute('href', at); | ||
|
||
const [actualEl, expectedEl] = this.querySelectorAll('pre'); | ||
actualEl.textContent = prettyPrint(actual); | ||
expectedEl.textContent = prettyPrint(expected); | ||
} | ||
} |
3 changes: 2 additions & 1 deletion
3
packages/test-lib/src/client/html-repoter.js → .../src/client/html-reporter/html-repoter.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export * from './test.js'; | ||
export * from './socket-sink.js'; | ||
export * from './html-repoter.js'; | ||
export * from './html-reporter/html-repoter.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters