diff --git a/jest.config.js b/jest.config.js index 8cd635e3..845aab48 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,13 +1,9 @@ -const path = require('path'); const { globals: serverGlobals } = require('./test/config/server.js'); const sharedConfig = { errorOnDeprecated: true, globals: { - ...serverGlobals, // BLANK_URL, DOCS_URL, LIB_URL, NODE_MODULES_URL, TEST_HOST - DOCS_PATH: path.resolve(__dirname, 'docs'), - LIB_PATH: path.resolve(__dirname, 'lib'), - SRC_PATH: path.resolve(__dirname, 'src'), + ...serverGlobals, // BLANK_URL, TEST_HOST }, globalSetup: './test/config/jest.setup.js', globalTeardown: './test/config/jest.teardown.js', diff --git a/test/README.md b/test/README.md index 5c5af864..eca1b05a 100644 --- a/test/README.md +++ b/test/README.md @@ -14,18 +14,7 @@ ## Global Variables -### File paths - -- `DOCS_PATH`: File path to `/docs` directory -- `LIB_PATH`: File path to `/lib` directory -- `SRC_PATH`: File path to `/src` directory - -### URLs - - `BLANK_URL`: Test server route to virtual `_blank.html` file -- `DOCS_URL`: Test server route to `/docs` directory -- `LIB_URL`: Test server route to `/lib` directory -- `NODE_MODULES_URL`: Test server route to `/node_modules` directory - `TEST_HOST`: Test server ip:port ## CLI commands diff --git a/test/config/server.js b/test/config/server.js index cb9f82b0..031842eb 100644 --- a/test/config/server.js +++ b/test/config/server.js @@ -108,15 +108,6 @@ module.exports = { get BLANK_URL() { return `${this.TEST_HOST}/_blank.html`; }, - get DOCS_URL() { - return `${this.TEST_HOST}/docs`; - }, - get LIB_URL() { - return `${this.TEST_HOST}/lib`; - }, - get NODE_MODULES_URL() { - return `${this.TEST_HOST}/node_modules`; - }, TEST_HOST: `http://${serverConfig.host}:${serverConfig.port}`, }, start: startServer, diff --git a/test/e2e/example.test.js b/test/e2e/example.test.js index 34aa84aa..2b8e027d 100644 --- a/test/e2e/example.test.js +++ b/test/e2e/example.test.js @@ -112,11 +112,11 @@ describe(`Example Tests`, function() { // Inject docsify theme (vue.css) // https://playwright.dev/#path=docs%2Fapi.md&q=pageaddstyletagoptions - await page.addStyleTag({ url: `${LIB_URL}/themes/vue.css` }); + await page.addStyleTag({ url: '/lib/themes/vue.css' }); // Inject docsify.js // https://playwright.dev/#path=docs%2Fapi.md&q=pageaddscripttagoptions - await page.addScriptTag({ url: `${LIB_URL}/docsify.js` }); + await page.addScriptTag({ url: '/lib/docsify.js' }); // Wait for docsify to initialize // https://playwright.dev/#path=docs%2Fapi.md&q=pagewaitforselectorselector-options diff --git a/test/e2e/vue.test.js b/test/e2e/vue.test.js index 1b6dbe6c..b4d1f3ad 100644 --- a/test/e2e/vue.test.js +++ b/test/e2e/vue.test.js @@ -2,8 +2,8 @@ const stripIndent = require('common-tags/lib/stripIndent'); const docsifyInit = require('../helpers/docsify-init'); const vueURLs = [ - `${NODE_MODULES_URL}/vue2/dist/vue.js`, - `${NODE_MODULES_URL}/vue3/dist/vue.global.js`, + '/node_modules/vue2/dist/vue.js', + '/node_modules/vue3/dist/vue.global.js', ]; describe('Vue.js Compatibility', function() { diff --git a/test/helpers/docsify-init.js b/test/helpers/docsify-init.js index 3855a637..a7d1ce11 100644 --- a/test/helpers/docsify-init.js +++ b/test/helpers/docsify-init.js @@ -6,8 +6,8 @@ const axios = require('axios'); const prettier = require('prettier'); const stripIndent = require('common-tags/lib/stripIndent'); -const docsifyPATH = `${LIB_PATH}/docsify.js`; // JSDOM -const docsifyURL = `${LIB_URL}/docsify.js`; // Playwright +const docsifyPATH = '../../lib/docsify.js'; // JSDOM +const docsifyURL = '/lib/docsify.js'; // Playwright const isJSDOM = 'window' in global; const isPlaywright = 'page' in global; diff --git a/test/integration/docs.test.js b/test/integration/docs.test.js index 0702b36c..c3f75f10 100644 --- a/test/integration/docs.test.js +++ b/test/integration/docs.test.js @@ -1,5 +1,3 @@ -const fs = require('fs').promises; -const path = require('path'); const docsifyInit = require('../helpers/docsify-init'); // Suite @@ -13,14 +11,13 @@ describe('Docs Site', function() { const mathSpy = jest.spyOn(Math, 'random').mockReturnValue(0.5); await docsifyInit({ + config: { + coverpage: 'docs/_coverpage.md', + }, markdown: { homepage: '# Hello World', - coverpage: await fs.readFile( - path.resolve(DOCS_PATH, '_coverpage.md'), - 'utf8' - ), }, - // _logHTML: true, + waitForSelector: '.cover.show', }); const coverpageElm = document.querySelector('section.cover'); @@ -33,14 +30,13 @@ describe('Docs Site', function() { test('sidebar renders and is unchanged', async () => { await docsifyInit({ + config: { + loadSidebar: 'docs/_sidebar.md', + }, markdown: { homepage: '# Hello World', - sidebar: await fs.readFile( - path.resolve(DOCS_PATH, '_sidebar.md'), - 'utf8' - ), }, - // _logHTML: true, + waitForSelector: '.sidebar-nav > ul', }); const sidebarElm = document.querySelector('.sidebar'); @@ -52,14 +48,13 @@ describe('Docs Site', function() { test('navbar renders and is unchanged', async () => { await docsifyInit({ + config: { + loadNavbar: 'docs/_navbar.md', + }, markdown: { homepage: '# Hello World', - navbar: await fs.readFile( - path.resolve(DOCS_PATH, '_navbar.md'), - 'utf8' - ), }, - // _logHTML: true, + waitForSelector: '.app-nav > ul', }); const navbarElm = document.querySelector('nav.app-nav'); diff --git a/test/unit/router-history-base.test.js b/test/unit/router-history-base.test.js index 309286cb..b586b153 100644 --- a/test/unit/router-history-base.test.js +++ b/test/unit/router-history-base.test.js @@ -1,4 +1,4 @@ -const { History } = require(`${SRC_PATH}/core/router/history/base`); +const { History } = require('../../src/core/router/history/base'); class MockHistory extends History { parse(path) { diff --git a/test/unit/router-util.test.js b/test/unit/router-util.test.js index d359b2d3..b3d230af 100644 --- a/test/unit/router-util.test.js +++ b/test/unit/router-util.test.js @@ -1,4 +1,4 @@ -const { resolvePath } = require(`${SRC_PATH}/core/util`); +const { resolvePath } = require('../../src/core/util'); // Suite // -----------------------------------------------------------------------------