import { resolve } from 'path' import { BODY_CODE_UNPACK_SCRIPT, wrapBodyCustomCode } from '../src/body-code/body-code-component' /** * The unpacker run against a DOM: what it does to each kind of script in the * project's body custom code. This repo's own jsdom 16 cannot load (see * teleport-project-generator-html/__tests__/state-runtime/runtime.ts), so the * editor checkout next to this one lends its jsdom. * * What a DOM cannot show is why an inline script names the document: Chromium * reports no file for an error thrown by a script inserted after the page was * parsed, and _document's inline script error guard knows the project's own * scripts by the document's address. Measured over http with the built * packages: without the name such an error reaches the app's own error * listener in Chromium, with it the guard stops it (WebKit names the document * either way). */ const loadJSDOM = () => { const candidates = ['jsdom', resolve(__dirname, '../../../../teleport-gui/node_modules/jsdom')] for (const candidate of candidates) { try { // tslint:disable-next-line no-var-requires return require(candidate).JSDOM } catch (error) { // the next candidate } } return undefined } const JSDOM = loadJSDOM() if (!JSDOM) { // tslint:disable-next-line no-console console.warn('body code unpack tests skipped: no jsdom loads (see the note in this file)') } const describeInDom = JSDOM ? describe : describe.skip const PAGE = 'https://site.test/pricing' const NAMED_AFTER_THE_PAGE = `\n//# sourceURL=${PAGE}` const STRUCTURED_DATA = '{"@context":"https://schema.org","@type":"Organization","name":"Holm"}' const BODY_CODE = [ '', '', '', ``, '', '', '
', ].join('\n') /** The page a visitor is on, with the body custom code shipped inert, then unpacked as TqBodyCode does. */ const unpackOn = (address: string) => { const dom = new JSDOM( `{{ name }}
') }) })