From b6d54072b3b3f7c72623efa25725b920ff0a2709 Mon Sep 17 00:00:00 2001 From: John Hildenbiddle Date: Sat, 24 Oct 2020 20:44:24 -0500 Subject: [PATCH] Fix basePath --- test/helpers/docsify-init.js | 26 +++++++++++++++++++------- test/integration/example.test.js | 8 ++++---- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/test/helpers/docsify-init.js b/test/helpers/docsify-init.js index 195efa9f..3855a637 100644 --- a/test/helpers/docsify-init.js +++ b/test/helpers/docsify-init.js @@ -77,15 +77,27 @@ async function docsifyInit(options = {}) { loadSidebar: Boolean(settings.markdown.sidebar), }; + const updateBasePath = config => { + config.basePath = new URL(config.basePath, TEST_HOST).href; + }; + // Config as function if (typeof options.config === 'function') { return function(vm) { - return { ...sharedConfig, ...options.config(vm) }; + const config = { ...sharedConfig, ...options.config(vm) }; + + updateBasePath(config); + + return config; }; } // Config as object else { - return { ...sharedConfig, ...options.config }; + const config = { ...sharedConfig, ...options.config }; + + updateBasePath(config); + + return config; } }, get markdown() { @@ -101,10 +113,10 @@ async function docsifyInit(options = {}) { get routes() { const helperRoutes = { [settings.testURL]: stripIndent`${settings.html}`, - ['/README.md']: settings.markdown.homepage, - ['/_coverpage.md']: settings.markdown.coverpage, - ['/_navbar.md']: settings.markdown.navbar, - ['/_sidebar.md']: settings.markdown.sidebar, + ['README.md']: settings.markdown.homepage, + ['_coverpage.md']: settings.markdown.coverpage, + ['_navbar.md']: settings.markdown.navbar, + ['_sidebar.md']: settings.markdown.sidebar, }; const finalRoutes = Object.fromEntries( @@ -116,7 +128,7 @@ async function docsifyInit(options = {}) { .filter(([url, responseText]) => url && responseText) .map(([url, responseText]) => [ // Convert relative to absolute URL - new URL(url, TEST_HOST).href, + new URL(url, settings.config.basePath).href, // Strip indentation from responseText stripIndent`${responseText}`, ]) diff --git a/test/integration/example.test.js b/test/integration/example.test.js index e0f8b747..0d7d7b45 100644 --- a/test/integration/example.test.js +++ b/test/integration/example.test.js @@ -10,7 +10,7 @@ describe('Example Tests', function() { test('Docsify /docs/ site using docsifyInit()', async () => { await docsifyInit({ config: { - basePath: `${TEST_HOST}/docs`, + basePath: '/docs/', }, // _logHTML: true, }); @@ -51,12 +51,12 @@ describe('Example Tests', function() { `, }, routes: { - '/test.md': ` + 'test.md': ` # Test Page This is a custom route. `, - '/data-test-scripturls.js': ` + 'data-test-scripturls.js': ` document.body.setAttribute('data-test-scripturls', 'pass'); `, }, @@ -65,7 +65,7 @@ describe('Example Tests', function() { `, scriptURLs: [ // docsifyInit() route - '/data-test-scripturls.js', + 'data-test-scripturls.js', // Server route '/lib/plugins/search.min.js', ],