1+ import { default as fetch } from "unfetch" ;
12import styleSheet from "./docdiff.css" ;
23import docdiffGeneralStyleSheet from "./docdiff.document.css" ;
34
@@ -16,9 +17,15 @@ import {
1617 EVENT_READTHEDOCS_DOCDIFF_HIDE ,
1718 EVENT_READTHEDOCS_ROOT_DOM_CHANGED ,
1819} from "./events" ;
19- import { nothing , LitElement } from "lit" ;
20+ import { CSSResult , nothing , LitElement } from "lit" ;
2021import { default as objectPath } from "object-path" ;
21- import { AddonBase , getQueryParam , docTool } from "./utils" ;
22+ import {
23+ AddonBase ,
24+ getQueryParam ,
25+ docTool ,
26+ IS_LOCALHOST_DEVELOPMENT ,
27+ IS_TESTING ,
28+ } from "./utils" ;
2229import { EMBED_API_ENDPOINT } from "./constants" ;
2330
2431export const DOCDIFF_URL_PARAM = "readthedocs-diff" ;
@@ -100,7 +107,11 @@ export class DocDiffElement extends LitElement {
100107 // NOTE: maybe there is a better way to inject this styles?
101108 // Conditionally inject our base styles
102109 if ( this . injectStyles ) {
103- document . adoptedStyleSheets . push ( docdiffGeneralStyleSheet ) ;
110+ let styleSheet = docdiffGeneralStyleSheet ;
111+ if ( styleSheet instanceof CSSResult ) {
112+ styleSheet = styleSheet . styleSheet ;
113+ }
114+ document . adoptedStyleSheets . push ( styleSheet ) ;
104115 }
105116
106117 // Enable DocDiff if the URL parameter is present
@@ -125,6 +136,10 @@ export class DocDiffElement extends LitElement {
125136 params [ "maincontent" ] = this . rootSelector ;
126137 }
127138
139+ if ( IS_LOCALHOST_DEVELOPMENT ) {
140+ return "/_/readthedocs-docdiff-embed.json" ;
141+ }
142+
128143 // NOTE: we don't send ``doctool`` and ``docversion`` on purpose here
129144 // because we don't want the backed to pre-process the response. We need the
130145 // HTML as-is without any pre-processing.
@@ -175,7 +190,13 @@ export class DocDiffElement extends LitElement {
175190 throw new Error ( "Element not found in both documents." ) ;
176191 }
177192
178- const diffNode = visualDomDiff . visualDomDiff (
193+ // Depending on the context, visualDomDiff function is found under a different path.
194+ // When running tests we use a different path for it.
195+ let visualDomDiffFunction = visualDomDiff . visualDomDiff ;
196+ if ( ! visualDomDiffFunction && IS_TESTING ) {
197+ visualDomDiffFunction = visualDomDiff . default . visualDomDiff ;
198+ }
199+ const diffNode = visualDomDiffFunction (
179200 oldBody ,
180201 newBody ,
181202 VISUAL_DIFF_OPTIONS ,
0 commit comments