|
| 1 | +import { ComponentFixture } from '@angular/core/testing'; |
| 2 | +import { DebugElement } from '@angular/core'; |
| 3 | +import { highlight, Theme } from 'pretty-html-log'; |
| 4 | +import { prettyPrintFixture } from './pretty-fixture'; |
| 5 | +import { |
| 6 | + prettyPrintDebugElement, |
| 7 | + prettyPrintDebugElements |
| 8 | +} from './pretty-debugElement'; |
| 9 | +import { |
| 10 | + prettyPrintHtmlEleemnt, |
| 11 | + prettyPrintHtmlElements |
| 12 | +} from './pretty-htmlelement'; |
| 13 | + |
| 14 | +export type NgHTMLElement<T> = |
| 15 | + | ComponentFixture<T> |
| 16 | + | DebugElement |
| 17 | + | DebugElement[] |
| 18 | + | HTMLElement |
| 19 | + | HTMLElement[]; |
| 20 | + |
| 21 | +export const logNgHTML = <T>( |
| 22 | + ngHTMLElement: NgHTMLElement<T>, |
| 23 | + theme?: Theme |
| 24 | +) => { |
| 25 | + if (ngHTMLElement instanceof ComponentFixture) { |
| 26 | + prettyPrintFixture<T>(ngHTMLElement); |
| 27 | + return; |
| 28 | + } |
| 29 | + |
| 30 | + if (Array.isArray(ngHTMLElement)) { |
| 31 | + if (ngHTMLElement[0] instanceof DebugElement) { |
| 32 | + prettyPrintDebugElements(ngHTMLElement as DebugElement[]); |
| 33 | + return; |
| 34 | + } |
| 35 | + |
| 36 | + if (ngHTMLElement[0] instanceof HTMLElement) { |
| 37 | + prettyPrintHtmlElements(ngHTMLElement as HTMLElement[]); |
| 38 | + return; |
| 39 | + } |
| 40 | + } |
| 41 | + |
| 42 | + if (ngHTMLElement instanceof DebugElement) { |
| 43 | + prettyPrintDebugElement(ngHTMLElement); |
| 44 | + return; |
| 45 | + } |
| 46 | + |
| 47 | + if (ngHTMLElement instanceof HTMLElement) { |
| 48 | + prettyPrintHtmlEleemnt(ngHTMLElement); |
| 49 | + return; |
| 50 | + } |
| 51 | + console.log( |
| 52 | + '@angular-extension/pretty-html-log: Unknown type - try to format anyway' |
| 53 | + ); |
| 54 | + console.log(highlight(ngHTMLElement as any, theme)); |
| 55 | +}; |
0 commit comments