* Jest / Playwright helper for creating custom docsify test sites * * @param {Object} options options object * @param {Function|Object} [options.config] docsify configuration (merged with default) * @param {String} [options.html] HTML content to use for docsify `index.html` page * @param {Objec
(options = {})
| 34 | * @returns {Promise} |
| 35 | */ |
| 36 | async function docsifyInit(options = {}) { |
| 37 | const isJSDOM = 'window' in global; |
| 38 | const isPlaywright = 'page' in global; |
| 39 | |
| 40 | const defaults = { |
| 41 | config: { |
| 42 | basePath: process.env.TEST_HOST, |
| 43 | el: '#app', |
| 44 | }, |
| 45 | html: ` |
| 46 | <!DOCTYPE html> |
| 47 | <html> |
| 48 | <head> |
| 49 | <meta charset="UTF-8" /> |
| 50 | </head> |
| 51 | <body> |
| 52 | <div id="app"></div> |
| 53 | </body> |
| 54 | </html> |
| 55 | `, |
| 56 | markdown: { |
| 57 | coverpage: '', |
| 58 | homepage: '', |
| 59 | navbar: '', |
| 60 | sidebar: '', |
| 61 | }, |
| 62 | routes: {}, |
| 63 | script: '', |
| 64 | scriptURLs: [], |
| 65 | style: '', |
| 66 | styleURLs: [], |
| 67 | testURL: `${process.env.TEST_HOST}/docsify-init.html`, |
| 68 | waitForSelector: '#main > *', |
| 69 | }; |
| 70 | const settings = { |
| 71 | ...defaults, |
| 72 | ...options, |
| 73 | get config() { |
| 74 | const sharedConfig = { |
| 75 | ...defaults.config, |
| 76 | // Conditionally set options but allow explicit overrides |
| 77 | coverpage: Boolean(settings.markdown.coverpage), |
| 78 | loadNavbar: Boolean(settings.markdown.navbar), |
| 79 | loadSidebar: Boolean(settings.markdown.sidebar), |
| 80 | }; |
| 81 | |
| 82 | const updateBasePath = config => { |
| 83 | if (config.basePath) { |
| 84 | config.basePath = new URL( |
| 85 | config.basePath, |
| 86 | process.env.TEST_HOST |
| 87 | ).href; |
| 88 | } |
| 89 | }; |
| 90 | |
| 91 | // Config as function |
| 92 | if (typeof options.config === 'function') { |
| 93 | return function (vm) { |
no test coverage detected
searching dependent graphs…