diff --git a/.gitignore b/.gitignore index 3cfc081b7d..7e19db2d70 100644 --- a/.gitignore +++ b/.gitignore @@ -40,7 +40,7 @@ jspm_packages docs/_site/* # Generated site (MarkBind) -test/test_site/_site +test/functional/*/_site # vscode configuration .vscode/ diff --git a/.travis.yml b/.travis.yml index 184cf29caf..28d46ec5ca 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,7 @@ language: node_js node_js: - '8' before_install: - - chmod +x ./test/test_site/test.sh + - chmod +x ./test/functional/test.sh cache: directories: - node_modules diff --git a/package.json b/package.json index 28d8029dde..80542a38ed 100644 --- a/package.json +++ b/package.json @@ -61,14 +61,14 @@ "lint": "./node_modules/.bin/eslint .", "pretest": "npm run lint", "pretestwin": "npm run lint", - "testwin": "jest && cd test/test_site && test.bat", - "test": "jest && cd test/test_site && ./test.sh", + "testwin": "jest && cd test/functional && test.bat", + "test": "jest && cd test/functional && ./test.sh", "jest": "jest" }, "jest": { "testPathIgnorePatterns": [ "/node_modules/", - "test/test_site/" + "test/functional" ] }, "devDependencies": { diff --git a/test/functional/test.bat b/test/functional/test.bat new file mode 100644 index 0000000000..444c618814 --- /dev/null +++ b/test/functional/test.bat @@ -0,0 +1,21 @@ +@ECHO off + +set sites=test_site + +for %%a in (%sites%) do ( + + echo( + echo Running %%a tests + + node ../../index.js build %%a + + node testUtil/test.js %%a + + if errorlevel 1 ( + echo Test %%a Failed + exit /b %errorlevel% + ) +) + +echo Test passed +exit /b %errorlevel% diff --git a/test/functional/test.sh b/test/functional/test.sh new file mode 100644 index 0000000000..19b2686320 --- /dev/null +++ b/test/functional/test.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +declare -a sites=("test_site") + +for site in "${sites[@]}" +do + # print site name + echo + echo "Running $site tests" + + # build site + node ../../index.js build "$site" + + # run our test script to compare html files + node testUtil/test.js "$site" + + if [ $? -ne 0 ] + then + echo "Test result: $site FAILED" + exit 1 + fi +done + +# if there were no diffs +echo "Test result: PASSED" +exit 0 diff --git a/test/test_site/testUtil/diffHtml.js b/test/functional/testUtil/diffHtml.js similarity index 100% rename from test/test_site/testUtil/diffHtml.js rename to test/functional/testUtil/diffHtml.js diff --git a/test/functional/testUtil/test.js b/test/functional/testUtil/test.js new file mode 100644 index 0000000000..abb6b2b9d4 --- /dev/null +++ b/test/functional/testUtil/test.js @@ -0,0 +1,50 @@ +const diffHtml = require('./diffHtml'); +const fs = require('fs'); +const path = require('path'); +const walkSync = require('walk-sync'); + +const _ = {}; +_.isEqual = require('lodash/isEqual'); + +function readFileSync(...paths) { + return fs.readFileSync(path.resolve(...paths), 'utf8'); +} + +const sitePath = process.argv[2]; +const expectedDirectory = path.join(sitePath, 'expected'); +const actualDirectory = path.join(sitePath, '_site'); + +const expectedPaths = walkSync(expectedDirectory, { directories: false }); +const actualPaths = walkSync(actualDirectory, { directories: false }); + +if (expectedPaths.length !== actualPaths.length) { + throw new Error('Unequal number of files'); +} + +for (let i = 0; i < expectedPaths.length; i += 1) { + const expectedFilePath = expectedPaths[i]; + const actualFilePath = actualPaths[i]; + + if (expectedFilePath !== actualFilePath) { + throw new Error('Different files built'); + } + + const parsed = path.parse(actualFilePath); + if (parsed.ext === '.html') { + // compare html files + const expected = readFileSync(expectedDirectory, expectedFilePath); + const actual = readFileSync(actualDirectory, actualFilePath); + try { + diffHtml(expected, actual); + } catch (err) { + throw new Error(`${err.message} in ${expectedFilePath}`); + } + } else if (parsed.base === 'siteData.json') { + // compare site data + const expected = readFileSync(expectedDirectory, expectedFilePath); + const actual = readFileSync(actualDirectory, actualFilePath); + if (!_.isEqual(JSON.parse(expected), JSON.parse(actual))) { + throw new Error('Site data does not match with the expected file.'); + } + } +} diff --git a/test/test_site/_markbind/boilerplates/boilerTest.md b/test/functional/test_site/_markbind/boilerplates/boilerTest.md similarity index 100% rename from test/test_site/_markbind/boilerplates/boilerTest.md rename to test/functional/test_site/_markbind/boilerplates/boilerTest.md diff --git a/test/test_site/_markbind/boilerplates/boilerTestPanel.md b/test/functional/test_site/_markbind/boilerplates/boilerTestPanel.md similarity index 100% rename from test/test_site/_markbind/boilerplates/boilerTestPanel.md rename to test/functional/test_site/_markbind/boilerplates/boilerTestPanel.md diff --git a/test/test_site/_markbind/boilerplates/folder/inside.md b/test/functional/test_site/_markbind/boilerplates/folder/inside.md similarity index 100% rename from test/test_site/_markbind/boilerplates/folder/inside.md rename to test/functional/test_site/_markbind/boilerplates/folder/inside.md diff --git a/test/test_site/_markbind/boilerplates/folder/panelBoilerplate.md b/test/functional/test_site/_markbind/boilerplates/folder/panelBoilerplate.md similarity index 100% rename from test/test_site/_markbind/boilerplates/folder/panelBoilerplate.md rename to test/functional/test_site/_markbind/boilerplates/folder/panelBoilerplate.md diff --git a/test/test_site/_markbind/footers/footer.md b/test/functional/test_site/_markbind/footers/footer.md similarity index 100% rename from test/test_site/_markbind/footers/footer.md rename to test/functional/test_site/_markbind/footers/footer.md diff --git a/test/test_site/_markbind/head/myCustomHead.md b/test/functional/test_site/_markbind/head/myCustomHead.md similarity index 100% rename from test/test_site/_markbind/head/myCustomHead.md rename to test/functional/test_site/_markbind/head/myCustomHead.md diff --git a/test/test_site/_markbind/head/myCustomHead2.md b/test/functional/test_site/_markbind/head/myCustomHead2.md similarity index 100% rename from test/test_site/_markbind/head/myCustomHead2.md rename to test/functional/test_site/_markbind/head/myCustomHead2.md diff --git a/test/test_site/_markbind/head/overwriteLayoutHead.md b/test/functional/test_site/_markbind/head/overwriteLayoutHead.md similarity index 100% rename from test/test_site/_markbind/head/overwriteLayoutHead.md rename to test/functional/test_site/_markbind/head/overwriteLayoutHead.md diff --git a/test/test_site/_markbind/layouts/default/footer.md b/test/functional/test_site/_markbind/layouts/default/footer.md similarity index 100% rename from test/test_site/_markbind/layouts/default/footer.md rename to test/functional/test_site/_markbind/layouts/default/footer.md diff --git a/test/test_site/_markbind/layouts/default/head.md b/test/functional/test_site/_markbind/layouts/default/head.md similarity index 100% rename from test/test_site/_markbind/layouts/default/head.md rename to test/functional/test_site/_markbind/layouts/default/head.md diff --git a/test/test_site/_markbind/layouts/default/navigation.md b/test/functional/test_site/_markbind/layouts/default/navigation.md similarity index 100% rename from test/test_site/_markbind/layouts/default/navigation.md rename to test/functional/test_site/_markbind/layouts/default/navigation.md diff --git a/test/test_site/_markbind/layouts/default/scripts.js b/test/functional/test_site/_markbind/layouts/default/scripts.js similarity index 100% rename from test/test_site/_markbind/layouts/default/scripts.js rename to test/functional/test_site/_markbind/layouts/default/scripts.js diff --git a/test/test_site/_markbind/layouts/default/styles.css b/test/functional/test_site/_markbind/layouts/default/styles.css similarity index 100% rename from test/test_site/_markbind/layouts/default/styles.css rename to test/functional/test_site/_markbind/layouts/default/styles.css diff --git a/test/test_site/_markbind/layouts/testLayout/footer.md b/test/functional/test_site/_markbind/layouts/testLayout/footer.md similarity index 100% rename from test/test_site/_markbind/layouts/testLayout/footer.md rename to test/functional/test_site/_markbind/layouts/testLayout/footer.md diff --git a/test/test_site/_markbind/layouts/testLayout/head.md b/test/functional/test_site/_markbind/layouts/testLayout/head.md similarity index 100% rename from test/test_site/_markbind/layouts/testLayout/head.md rename to test/functional/test_site/_markbind/layouts/testLayout/head.md diff --git a/test/test_site/_markbind/layouts/testLayout/navigation.md b/test/functional/test_site/_markbind/layouts/testLayout/navigation.md similarity index 100% rename from test/test_site/_markbind/layouts/testLayout/navigation.md rename to test/functional/test_site/_markbind/layouts/testLayout/navigation.md diff --git a/test/test_site/_markbind/layouts/testLayout/scripts.js b/test/functional/test_site/_markbind/layouts/testLayout/scripts.js similarity index 100% rename from test/test_site/_markbind/layouts/testLayout/scripts.js rename to test/functional/test_site/_markbind/layouts/testLayout/scripts.js diff --git a/test/test_site/_markbind/layouts/testLayout/styles.css b/test/functional/test_site/_markbind/layouts/testLayout/styles.css similarity index 100% rename from test/test_site/_markbind/layouts/testLayout/styles.css rename to test/functional/test_site/_markbind/layouts/testLayout/styles.css diff --git a/test/test_site/_markbind/navigation/site-nav.md b/test/functional/test_site/_markbind/navigation/site-nav.md similarity index 100% rename from test/test_site/_markbind/navigation/site-nav.md rename to test/functional/test_site/_markbind/navigation/site-nav.md diff --git a/test/test_site/_markbind/variables.md b/test/functional/test_site/_markbind/variables.md similarity index 100% rename from test/test_site/_markbind/variables.md rename to test/functional/test_site/_markbind/variables.md diff --git a/test/test_site/bugs/index.md b/test/functional/test_site/bugs/index.md similarity index 100% rename from test/test_site/bugs/index.md rename to test/functional/test_site/bugs/index.md diff --git a/test/test_site/bugs/modal.md b/test/functional/test_site/bugs/modal.md similarity index 100% rename from test/test_site/bugs/modal.md rename to test/functional/test_site/bugs/modal.md diff --git a/test/test_site/components/header.md b/test/functional/test_site/components/header.md similarity index 100% rename from test/test_site/components/header.md rename to test/functional/test_site/components/header.md diff --git a/test/test_site/expected/bugs/index.html b/test/functional/test_site/expected/bugs/index.html similarity index 100% rename from test/test_site/expected/bugs/index.html rename to test/functional/test_site/expected/bugs/index.html diff --git a/test/test_site/expected/favicon.png b/test/functional/test_site/expected/favicon.png similarity index 100% rename from test/test_site/expected/favicon.png rename to test/functional/test_site/expected/favicon.png diff --git a/test/test_site/expected/headFiles/customScriptBottom.js b/test/functional/test_site/expected/headFiles/customScriptBottom.js similarity index 100% rename from test/test_site/expected/headFiles/customScriptBottom.js rename to test/functional/test_site/expected/headFiles/customScriptBottom.js diff --git a/test/test_site/expected/headFiles/customScriptBottom2.js b/test/functional/test_site/expected/headFiles/customScriptBottom2.js similarity index 100% rename from test/test_site/expected/headFiles/customScriptBottom2.js rename to test/functional/test_site/expected/headFiles/customScriptBottom2.js diff --git a/test/test_site/expected/headFiles/customScriptTop.js b/test/functional/test_site/expected/headFiles/customScriptTop.js similarity index 100% rename from test/test_site/expected/headFiles/customScriptTop.js rename to test/functional/test_site/expected/headFiles/customScriptTop.js diff --git a/test/test_site/expected/headFiles/customScriptTop2.js b/test/functional/test_site/expected/headFiles/customScriptTop2.js similarity index 100% rename from test/test_site/expected/headFiles/customScriptTop2.js rename to test/functional/test_site/expected/headFiles/customScriptTop2.js diff --git a/test/test_site/expected/headFiles/overwriteLayoutScript.js b/test/functional/test_site/expected/headFiles/overwriteLayoutScript.js similarity index 100% rename from test/test_site/expected/headFiles/overwriteLayoutScript.js rename to test/functional/test_site/expected/headFiles/overwriteLayoutScript.js diff --git a/test/test_site/expected/index.html b/test/functional/test_site/expected/index.html similarity index 100% rename from test/test_site/expected/index.html rename to test/functional/test_site/expected/index.html diff --git a/test/test_site/expected/markbind/css/bootstrap-glyphicons.min.css b/test/functional/test_site/expected/markbind/css/bootstrap-glyphicons.min.css similarity index 100% rename from test/test_site/expected/markbind/css/bootstrap-glyphicons.min.css rename to test/functional/test_site/expected/markbind/css/bootstrap-glyphicons.min.css diff --git a/test/test_site/expected/markbind/css/bootstrap-vue.min.css b/test/functional/test_site/expected/markbind/css/bootstrap-vue.min.css similarity index 100% rename from test/test_site/expected/markbind/css/bootstrap-vue.min.css rename to test/functional/test_site/expected/markbind/css/bootstrap-vue.min.css diff --git a/test/test_site/expected/markbind/css/bootstrap.min.css b/test/functional/test_site/expected/markbind/css/bootstrap.min.css similarity index 100% rename from test/test_site/expected/markbind/css/bootstrap.min.css rename to test/functional/test_site/expected/markbind/css/bootstrap.min.css diff --git a/test/test_site/expected/markbind/css/bootstrap.min.css.map b/test/functional/test_site/expected/markbind/css/bootstrap.min.css.map similarity index 100% rename from test/test_site/expected/markbind/css/bootstrap.min.css.map rename to test/functional/test_site/expected/markbind/css/bootstrap.min.css.map diff --git a/test/test_site/expected/markbind/css/font-awesome.min.css b/test/functional/test_site/expected/markbind/css/font-awesome.min.css similarity index 100% rename from test/test_site/expected/markbind/css/font-awesome.min.css rename to test/functional/test_site/expected/markbind/css/font-awesome.min.css diff --git a/test/test_site/expected/markbind/css/github.min.css b/test/functional/test_site/expected/markbind/css/github.min.css similarity index 100% rename from test/test_site/expected/markbind/css/github.min.css rename to test/functional/test_site/expected/markbind/css/github.min.css diff --git a/test/test_site/expected/markbind/css/markbind.css b/test/functional/test_site/expected/markbind/css/markbind.css similarity index 100% rename from test/test_site/expected/markbind/css/markbind.css rename to test/functional/test_site/expected/markbind/css/markbind.css diff --git a/test/test_site/expected/markbind/css/page-nav.css b/test/functional/test_site/expected/markbind/css/page-nav.css similarity index 100% rename from test/test_site/expected/markbind/css/page-nav.css rename to test/functional/test_site/expected/markbind/css/page-nav.css diff --git a/test/test_site/expected/markbind/css/site-nav.css b/test/functional/test_site/expected/markbind/css/site-nav.css similarity index 100% rename from test/test_site/expected/markbind/css/site-nav.css rename to test/functional/test_site/expected/markbind/css/site-nav.css diff --git a/test/test_site/expected/markbind/fonts/fa-brands-400.eot b/test/functional/test_site/expected/markbind/fonts/fa-brands-400.eot similarity index 100% rename from test/test_site/expected/markbind/fonts/fa-brands-400.eot rename to test/functional/test_site/expected/markbind/fonts/fa-brands-400.eot diff --git a/test/test_site/expected/markbind/fonts/fa-brands-400.svg b/test/functional/test_site/expected/markbind/fonts/fa-brands-400.svg similarity index 100% rename from test/test_site/expected/markbind/fonts/fa-brands-400.svg rename to test/functional/test_site/expected/markbind/fonts/fa-brands-400.svg diff --git a/test/test_site/expected/markbind/fonts/fa-brands-400.ttf b/test/functional/test_site/expected/markbind/fonts/fa-brands-400.ttf similarity index 100% rename from test/test_site/expected/markbind/fonts/fa-brands-400.ttf rename to test/functional/test_site/expected/markbind/fonts/fa-brands-400.ttf diff --git a/test/test_site/expected/markbind/fonts/fa-brands-400.woff b/test/functional/test_site/expected/markbind/fonts/fa-brands-400.woff similarity index 100% rename from test/test_site/expected/markbind/fonts/fa-brands-400.woff rename to test/functional/test_site/expected/markbind/fonts/fa-brands-400.woff diff --git a/test/test_site/expected/markbind/fonts/fa-brands-400.woff2 b/test/functional/test_site/expected/markbind/fonts/fa-brands-400.woff2 similarity index 100% rename from test/test_site/expected/markbind/fonts/fa-brands-400.woff2 rename to test/functional/test_site/expected/markbind/fonts/fa-brands-400.woff2 diff --git a/test/test_site/expected/markbind/fonts/fa-regular-400.eot b/test/functional/test_site/expected/markbind/fonts/fa-regular-400.eot similarity index 100% rename from test/test_site/expected/markbind/fonts/fa-regular-400.eot rename to test/functional/test_site/expected/markbind/fonts/fa-regular-400.eot diff --git a/test/test_site/expected/markbind/fonts/fa-regular-400.svg b/test/functional/test_site/expected/markbind/fonts/fa-regular-400.svg similarity index 100% rename from test/test_site/expected/markbind/fonts/fa-regular-400.svg rename to test/functional/test_site/expected/markbind/fonts/fa-regular-400.svg diff --git a/test/test_site/expected/markbind/fonts/fa-regular-400.ttf b/test/functional/test_site/expected/markbind/fonts/fa-regular-400.ttf similarity index 100% rename from test/test_site/expected/markbind/fonts/fa-regular-400.ttf rename to test/functional/test_site/expected/markbind/fonts/fa-regular-400.ttf diff --git a/test/test_site/expected/markbind/fonts/fa-regular-400.woff b/test/functional/test_site/expected/markbind/fonts/fa-regular-400.woff similarity index 100% rename from test/test_site/expected/markbind/fonts/fa-regular-400.woff rename to test/functional/test_site/expected/markbind/fonts/fa-regular-400.woff diff --git a/test/test_site/expected/markbind/fonts/fa-regular-400.woff2 b/test/functional/test_site/expected/markbind/fonts/fa-regular-400.woff2 similarity index 100% rename from test/test_site/expected/markbind/fonts/fa-regular-400.woff2 rename to test/functional/test_site/expected/markbind/fonts/fa-regular-400.woff2 diff --git a/test/test_site/expected/markbind/fonts/fa-solid-900.eot b/test/functional/test_site/expected/markbind/fonts/fa-solid-900.eot similarity index 100% rename from test/test_site/expected/markbind/fonts/fa-solid-900.eot rename to test/functional/test_site/expected/markbind/fonts/fa-solid-900.eot diff --git a/test/test_site/expected/markbind/fonts/fa-solid-900.svg b/test/functional/test_site/expected/markbind/fonts/fa-solid-900.svg similarity index 100% rename from test/test_site/expected/markbind/fonts/fa-solid-900.svg rename to test/functional/test_site/expected/markbind/fonts/fa-solid-900.svg diff --git a/test/test_site/expected/markbind/fonts/fa-solid-900.ttf b/test/functional/test_site/expected/markbind/fonts/fa-solid-900.ttf similarity index 100% rename from test/test_site/expected/markbind/fonts/fa-solid-900.ttf rename to test/functional/test_site/expected/markbind/fonts/fa-solid-900.ttf diff --git a/test/test_site/expected/markbind/fonts/fa-solid-900.woff b/test/functional/test_site/expected/markbind/fonts/fa-solid-900.woff similarity index 100% rename from test/test_site/expected/markbind/fonts/fa-solid-900.woff rename to test/functional/test_site/expected/markbind/fonts/fa-solid-900.woff diff --git a/test/test_site/expected/markbind/fonts/fa-solid-900.woff2 b/test/functional/test_site/expected/markbind/fonts/fa-solid-900.woff2 similarity index 100% rename from test/test_site/expected/markbind/fonts/fa-solid-900.woff2 rename to test/functional/test_site/expected/markbind/fonts/fa-solid-900.woff2 diff --git a/test/test_site/expected/markbind/fonts/glyphicons-halflings-regular.eot b/test/functional/test_site/expected/markbind/fonts/glyphicons-halflings-regular.eot similarity index 100% rename from test/test_site/expected/markbind/fonts/glyphicons-halflings-regular.eot rename to test/functional/test_site/expected/markbind/fonts/glyphicons-halflings-regular.eot diff --git a/test/test_site/expected/markbind/fonts/glyphicons-halflings-regular.svg b/test/functional/test_site/expected/markbind/fonts/glyphicons-halflings-regular.svg similarity index 100% rename from test/test_site/expected/markbind/fonts/glyphicons-halflings-regular.svg rename to test/functional/test_site/expected/markbind/fonts/glyphicons-halflings-regular.svg diff --git a/test/test_site/expected/markbind/fonts/glyphicons-halflings-regular.ttf b/test/functional/test_site/expected/markbind/fonts/glyphicons-halflings-regular.ttf similarity index 100% rename from test/test_site/expected/markbind/fonts/glyphicons-halflings-regular.ttf rename to test/functional/test_site/expected/markbind/fonts/glyphicons-halflings-regular.ttf diff --git a/test/test_site/expected/markbind/fonts/glyphicons-halflings-regular.woff b/test/functional/test_site/expected/markbind/fonts/glyphicons-halflings-regular.woff similarity index 100% rename from test/test_site/expected/markbind/fonts/glyphicons-halflings-regular.woff rename to test/functional/test_site/expected/markbind/fonts/glyphicons-halflings-regular.woff diff --git a/test/test_site/expected/markbind/fonts/glyphicons-halflings-regular.woff2 b/test/functional/test_site/expected/markbind/fonts/glyphicons-halflings-regular.woff2 similarity index 100% rename from test/test_site/expected/markbind/fonts/glyphicons-halflings-regular.woff2 rename to test/functional/test_site/expected/markbind/fonts/glyphicons-halflings-regular.woff2 diff --git a/test/test_site/expected/markbind/js/bootstrap-utility.min.js b/test/functional/test_site/expected/markbind/js/bootstrap-utility.min.js similarity index 100% rename from test/test_site/expected/markbind/js/bootstrap-utility.min.js rename to test/functional/test_site/expected/markbind/js/bootstrap-utility.min.js diff --git a/test/test_site/expected/markbind/js/bootstrap-vue.min.js b/test/functional/test_site/expected/markbind/js/bootstrap-vue.min.js similarity index 100% rename from test/test_site/expected/markbind/js/bootstrap-vue.min.js rename to test/functional/test_site/expected/markbind/js/bootstrap-vue.min.js diff --git a/test/test_site/expected/markbind/js/polyfill.min.js b/test/functional/test_site/expected/markbind/js/polyfill.min.js similarity index 100% rename from test/test_site/expected/markbind/js/polyfill.min.js rename to test/functional/test_site/expected/markbind/js/polyfill.min.js diff --git a/test/test_site/expected/markbind/js/setup.js b/test/functional/test_site/expected/markbind/js/setup.js similarity index 100% rename from test/test_site/expected/markbind/js/setup.js rename to test/functional/test_site/expected/markbind/js/setup.js diff --git a/test/test_site/expected/markbind/js/vue-strap.min.js b/test/functional/test_site/expected/markbind/js/vue-strap.min.js similarity index 100% rename from test/test_site/expected/markbind/js/vue-strap.min.js rename to test/functional/test_site/expected/markbind/js/vue-strap.min.js diff --git a/test/test_site/expected/markbind/js/vue.min.js b/test/functional/test_site/expected/markbind/js/vue.min.js similarity index 100% rename from test/test_site/expected/markbind/js/vue.min.js rename to test/functional/test_site/expected/markbind/js/vue.min.js diff --git a/test/test_site/expected/markbind/layouts/default/footer.md b/test/functional/test_site/expected/markbind/layouts/default/footer.md similarity index 100% rename from test/test_site/expected/markbind/layouts/default/footer.md rename to test/functional/test_site/expected/markbind/layouts/default/footer.md diff --git a/test/test_site/expected/markbind/layouts/default/head.md b/test/functional/test_site/expected/markbind/layouts/default/head.md similarity index 100% rename from test/test_site/expected/markbind/layouts/default/head.md rename to test/functional/test_site/expected/markbind/layouts/default/head.md diff --git a/test/test_site/expected/markbind/layouts/default/navigation.md b/test/functional/test_site/expected/markbind/layouts/default/navigation.md similarity index 100% rename from test/test_site/expected/markbind/layouts/default/navigation.md rename to test/functional/test_site/expected/markbind/layouts/default/navigation.md diff --git a/test/test_site/expected/markbind/layouts/default/scripts.js b/test/functional/test_site/expected/markbind/layouts/default/scripts.js similarity index 100% rename from test/test_site/expected/markbind/layouts/default/scripts.js rename to test/functional/test_site/expected/markbind/layouts/default/scripts.js diff --git a/test/test_site/expected/markbind/layouts/default/styles.css b/test/functional/test_site/expected/markbind/layouts/default/styles.css similarity index 100% rename from test/test_site/expected/markbind/layouts/default/styles.css rename to test/functional/test_site/expected/markbind/layouts/default/styles.css diff --git a/test/test_site/expected/markbind/layouts/testLayout/footer.md b/test/functional/test_site/expected/markbind/layouts/testLayout/footer.md similarity index 100% rename from test/test_site/expected/markbind/layouts/testLayout/footer.md rename to test/functional/test_site/expected/markbind/layouts/testLayout/footer.md diff --git a/test/test_site/expected/markbind/layouts/testLayout/head.md b/test/functional/test_site/expected/markbind/layouts/testLayout/head.md similarity index 100% rename from test/test_site/expected/markbind/layouts/testLayout/head.md rename to test/functional/test_site/expected/markbind/layouts/testLayout/head.md diff --git a/test/test_site/expected/markbind/layouts/testLayout/navigation.md b/test/functional/test_site/expected/markbind/layouts/testLayout/navigation.md similarity index 100% rename from test/test_site/expected/markbind/layouts/testLayout/navigation.md rename to test/functional/test_site/expected/markbind/layouts/testLayout/navigation.md diff --git a/test/test_site/expected/markbind/layouts/testLayout/scripts.js b/test/functional/test_site/expected/markbind/layouts/testLayout/scripts.js similarity index 100% rename from test/test_site/expected/markbind/layouts/testLayout/scripts.js rename to test/functional/test_site/expected/markbind/layouts/testLayout/scripts.js diff --git a/test/test_site/expected/markbind/layouts/testLayout/styles.css b/test/functional/test_site/expected/markbind/layouts/testLayout/styles.css similarity index 100% rename from test/test_site/expected/markbind/layouts/testLayout/styles.css rename to test/functional/test_site/expected/markbind/layouts/testLayout/styles.css diff --git a/test/test_site/expected/requirements/NonFunctionalRequirements._include_.html b/test/functional/test_site/expected/requirements/NonFunctionalRequirements._include_.html similarity index 100% rename from test/test_site/expected/requirements/NonFunctionalRequirements._include_.html rename to test/functional/test_site/expected/requirements/NonFunctionalRequirements._include_.html diff --git a/test/test_site/expected/requirements/SpecifyingRequirements._include_.html b/test/functional/test_site/expected/requirements/SpecifyingRequirements._include_.html similarity index 100% rename from test/test_site/expected/requirements/SpecifyingRequirements._include_.html rename to test/functional/test_site/expected/requirements/SpecifyingRequirements._include_.html diff --git a/test/test_site/expected/requirements/UserStories._include_.html b/test/functional/test_site/expected/requirements/UserStories._include_.html similarity index 100% rename from test/test_site/expected/requirements/UserStories._include_.html rename to test/functional/test_site/expected/requirements/UserStories._include_.html diff --git a/test/test_site/expected/requirements/notInside._include_.html b/test/functional/test_site/expected/requirements/notInside._include_.html similarity index 100% rename from test/test_site/expected/requirements/notInside._include_.html rename to test/functional/test_site/expected/requirements/notInside._include_.html diff --git a/test/test_site/expected/siteData.json b/test/functional/test_site/expected/siteData.json similarity index 100% rename from test/test_site/expected/siteData.json rename to test/functional/test_site/expected/siteData.json diff --git a/test/test_site/expected/sub_site/images/I'm not allowed to use my favorite tool.png b/test/functional/test_site/expected/sub_site/images/I'm not allowed to use my favorite tool.png similarity index 100% rename from test/test_site/expected/sub_site/images/I'm not allowed to use my favorite tool.png rename to test/functional/test_site/expected/sub_site/images/I'm not allowed to use my favorite tool.png diff --git a/test/test_site/expected/sub_site/index._include_.html b/test/functional/test_site/expected/sub_site/index._include_.html similarity index 100% rename from test/test_site/expected/sub_site/index._include_.html rename to test/functional/test_site/expected/sub_site/index._include_.html diff --git a/test/test_site/expected/sub_site/index.html b/test/functional/test_site/expected/sub_site/index.html similarity index 100% rename from test/test_site/expected/sub_site/index.html rename to test/functional/test_site/expected/sub_site/index.html diff --git a/test/test_site/expected/testEmptyFrontmatter.html b/test/functional/test_site/expected/testEmptyFrontmatter.html similarity index 100% rename from test/test_site/expected/testEmptyFrontmatter.html rename to test/functional/test_site/expected/testEmptyFrontmatter.html diff --git a/test/test_site/expected/testExternalScripts.html b/test/functional/test_site/expected/testExternalScripts.html similarity index 100% rename from test/test_site/expected/testExternalScripts.html rename to test/functional/test_site/expected/testExternalScripts.html diff --git a/test/test_site/expected/testInclude.html b/test/functional/test_site/expected/testInclude.html similarity index 100% rename from test/test_site/expected/testInclude.html rename to test/functional/test_site/expected/testInclude.html diff --git a/test/test_site/expected/testIncludeMbd.mbd b/test/functional/test_site/expected/testIncludeMbd.mbd similarity index 100% rename from test/test_site/expected/testIncludeMbd.mbd rename to test/functional/test_site/expected/testIncludeMbd.mbd diff --git a/test/test_site/expected/testIncludeMbdf.mbdf b/test/functional/test_site/expected/testIncludeMbdf.mbdf similarity index 100% rename from test/test_site/expected/testIncludeMbdf.mbdf rename to test/functional/test_site/expected/testIncludeMbdf.mbdf diff --git a/test/test_site/expected/testLayouts.html b/test/functional/test_site/expected/testLayouts.html similarity index 100% rename from test/test_site/expected/testLayouts.html rename to test/functional/test_site/expected/testLayouts.html diff --git a/test/test_site/expected/testLayoutsOverride.html b/test/functional/test_site/expected/testLayoutsOverride.html similarity index 100% rename from test/test_site/expected/testLayoutsOverride.html rename to test/functional/test_site/expected/testLayoutsOverride.html diff --git a/test/test_site/expected/testPanels/NestedPanel._include_.html b/test/functional/test_site/expected/testPanels/NestedPanel._include_.html similarity index 100% rename from test/test_site/expected/testPanels/NestedPanel._include_.html rename to test/functional/test_site/expected/testPanels/NestedPanel._include_.html diff --git a/test/test_site/expected/testPanels/NormalPanelContent._include_.html b/test/functional/test_site/expected/testPanels/NormalPanelContent._include_.html similarity index 100% rename from test/test_site/expected/testPanels/NormalPanelContent._include_.html rename to test/functional/test_site/expected/testPanels/NormalPanelContent._include_.html diff --git a/test/test_site/expected/testPanels/PanelNormalSource._include_.html b/test/functional/test_site/expected/testPanels/PanelNormalSource._include_.html similarity index 100% rename from test/test_site/expected/testPanels/PanelNormalSource._include_.html rename to test/functional/test_site/expected/testPanels/PanelNormalSource._include_.html diff --git a/test/test_site/expected/testPanels/PanelSourceContainsSegment._include_.html b/test/functional/test_site/expected/testPanels/PanelSourceContainsSegment._include_.html similarity index 100% rename from test/test_site/expected/testPanels/PanelSourceContainsSegment._include_.html rename to test/functional/test_site/expected/testPanels/PanelSourceContainsSegment._include_.html diff --git a/test/test_site/expected/testPanels/boilerTestPanel._include_.html b/test/functional/test_site/expected/testPanels/boilerTestPanel._include_.html similarity index 100% rename from test/test_site/expected/testPanels/boilerTestPanel._include_.html rename to test/functional/test_site/expected/testPanels/boilerTestPanel._include_.html diff --git a/test/test_site/expected/testPanels/notInside._include_.html b/test/functional/test_site/expected/testPanels/notInside._include_.html similarity index 100% rename from test/test_site/expected/testPanels/notInside._include_.html rename to test/functional/test_site/expected/testPanels/notInside._include_.html diff --git a/test/test_site/expected/testTags.html b/test/functional/test_site/expected/testTags.html similarity index 100% rename from test/test_site/expected/testTags.html rename to test/functional/test_site/expected/testTags.html diff --git a/test/test_site/expected/test_md_fragment.html b/test/functional/test_site/expected/test_md_fragment.html similarity index 100% rename from test/test_site/expected/test_md_fragment.html rename to test/functional/test_site/expected/test_md_fragment.html diff --git a/test/test_site/favicon.png b/test/functional/test_site/favicon.png similarity index 100% rename from test/test_site/favicon.png rename to test/functional/test_site/favicon.png diff --git a/test/test_site/headFiles/customScriptBottom.js b/test/functional/test_site/headFiles/customScriptBottom.js similarity index 100% rename from test/test_site/headFiles/customScriptBottom.js rename to test/functional/test_site/headFiles/customScriptBottom.js diff --git a/test/test_site/headFiles/customScriptBottom2.js b/test/functional/test_site/headFiles/customScriptBottom2.js similarity index 100% rename from test/test_site/headFiles/customScriptBottom2.js rename to test/functional/test_site/headFiles/customScriptBottom2.js diff --git a/test/test_site/headFiles/customScriptTop.js b/test/functional/test_site/headFiles/customScriptTop.js similarity index 100% rename from test/test_site/headFiles/customScriptTop.js rename to test/functional/test_site/headFiles/customScriptTop.js diff --git a/test/test_site/headFiles/customScriptTop2.js b/test/functional/test_site/headFiles/customScriptTop2.js similarity index 100% rename from test/test_site/headFiles/customScriptTop2.js rename to test/functional/test_site/headFiles/customScriptTop2.js diff --git a/test/test_site/headFiles/overwriteLayoutScript.js b/test/functional/test_site/headFiles/overwriteLayoutScript.js similarity index 100% rename from test/test_site/headFiles/overwriteLayoutScript.js rename to test/functional/test_site/headFiles/overwriteLayoutScript.js diff --git a/test/test_site/index.md b/test/functional/test_site/index.md similarity index 100% rename from test/test_site/index.md rename to test/functional/test_site/index.md diff --git a/test/test_site/requirements/EstablishingRequirements.md b/test/functional/test_site/requirements/EstablishingRequirements.md similarity index 100% rename from test/test_site/requirements/EstablishingRequirements.md rename to test/functional/test_site/requirements/EstablishingRequirements.md diff --git a/test/test_site/requirements/NonFunctionalRequirements.md b/test/functional/test_site/requirements/NonFunctionalRequirements.md similarity index 100% rename from test/test_site/requirements/NonFunctionalRequirements.md rename to test/functional/test_site/requirements/NonFunctionalRequirements.md diff --git a/test/test_site/requirements/SpecifyingRequirements.md b/test/functional/test_site/requirements/SpecifyingRequirements.md similarity index 100% rename from test/test_site/requirements/SpecifyingRequirements.md rename to test/functional/test_site/requirements/SpecifyingRequirements.md diff --git a/test/test_site/requirements/UserStories.md b/test/functional/test_site/requirements/UserStories.md similarity index 100% rename from test/test_site/requirements/UserStories.md rename to test/functional/test_site/requirements/UserStories.md diff --git a/test/test_site/requirements/nestedInclude.md b/test/functional/test_site/requirements/nestedInclude.md similarity index 100% rename from test/test_site/requirements/nestedInclude.md rename to test/functional/test_site/requirements/nestedInclude.md diff --git a/test/test_site/site.json b/test/functional/test_site/site.json similarity index 100% rename from test/test_site/site.json rename to test/functional/test_site/site.json diff --git a/test/test_site/siteData.json b/test/functional/test_site/siteData.json similarity index 100% rename from test/test_site/siteData.json rename to test/functional/test_site/siteData.json diff --git a/test/test_site/sub_site/images/I'm not allowed to use my favorite tool.png b/test/functional/test_site/sub_site/images/I'm not allowed to use my favorite tool.png similarity index 100% rename from test/test_site/sub_site/images/I'm not allowed to use my favorite tool.png rename to test/functional/test_site/sub_site/images/I'm not allowed to use my favorite tool.png diff --git a/test/test_site/sub_site/index.md b/test/functional/test_site/sub_site/index.md similarity index 100% rename from test/test_site/sub_site/index.md rename to test/functional/test_site/sub_site/index.md diff --git a/test/test_site/sub_site/site.json b/test/functional/test_site/sub_site/site.json similarity index 100% rename from test/test_site/sub_site/site.json rename to test/functional/test_site/sub_site/site.json diff --git a/test/test_site/test.bat b/test/functional/test_site/test.bat similarity index 100% rename from test/test_site/test.bat rename to test/functional/test_site/test.bat diff --git a/test/test_site/test.sh b/test/functional/test_site/test.sh old mode 100755 new mode 100644 similarity index 100% rename from test/test_site/test.sh rename to test/functional/test_site/test.sh diff --git a/test/test_site/testEmptyFrontmatter.md b/test/functional/test_site/testEmptyFrontmatter.md similarity index 100% rename from test/test_site/testEmptyFrontmatter.md rename to test/functional/test_site/testEmptyFrontmatter.md diff --git a/test/test_site/testExternalScripts.md b/test/functional/test_site/testExternalScripts.md similarity index 100% rename from test/test_site/testExternalScripts.md rename to test/functional/test_site/testExternalScripts.md diff --git a/test/test_site/testInclude.html b/test/functional/test_site/testInclude.html similarity index 100% rename from test/test_site/testInclude.html rename to test/functional/test_site/testInclude.html diff --git a/test/test_site/testIncludeMbd.mbd b/test/functional/test_site/testIncludeMbd.mbd similarity index 100% rename from test/test_site/testIncludeMbd.mbd rename to test/functional/test_site/testIncludeMbd.mbd diff --git a/test/test_site/testIncludeMbdf.mbdf b/test/functional/test_site/testIncludeMbdf.mbdf similarity index 100% rename from test/test_site/testIncludeMbdf.mbdf rename to test/functional/test_site/testIncludeMbdf.mbdf diff --git a/test/test_site/testIncludeVariableLeak.md b/test/functional/test_site/testIncludeVariableLeak.md similarity index 100% rename from test/test_site/testIncludeVariableLeak.md rename to test/functional/test_site/testIncludeVariableLeak.md diff --git a/test/test_site/testIncludeVariableLeakInner.md b/test/functional/test_site/testIncludeVariableLeakInner.md similarity index 100% rename from test/test_site/testIncludeVariableLeakInner.md rename to test/functional/test_site/testIncludeVariableLeakInner.md diff --git a/test/test_site/testIncludeVariables.md b/test/functional/test_site/testIncludeVariables.md similarity index 100% rename from test/test_site/testIncludeVariables.md rename to test/functional/test_site/testIncludeVariables.md diff --git a/test/test_site/testIncludeVariablesIncludedFile.md b/test/functional/test_site/testIncludeVariablesIncludedFile.md similarity index 100% rename from test/test_site/testIncludeVariablesIncludedFile.md rename to test/functional/test_site/testIncludeVariablesIncludedFile.md diff --git a/test/test_site/testKeyword.md b/test/functional/test_site/testKeyword.md similarity index 100% rename from test/test_site/testKeyword.md rename to test/functional/test_site/testKeyword.md diff --git a/test/test_site/testKeywordHeading.md b/test/functional/test_site/testKeywordHeading.md similarity index 100% rename from test/test_site/testKeywordHeading.md rename to test/functional/test_site/testKeywordHeading.md diff --git a/test/test_site/testLayouts.md b/test/functional/test_site/testLayouts.md similarity index 100% rename from test/test_site/testLayouts.md rename to test/functional/test_site/testLayouts.md diff --git a/test/test_site/testLayoutsOverride.md b/test/functional/test_site/testLayoutsOverride.md similarity index 100% rename from test/test_site/testLayoutsOverride.md rename to test/functional/test_site/testLayoutsOverride.md diff --git a/test/test_site/testPanels/NestedPanel.md b/test/functional/test_site/testPanels/NestedPanel.md similarity index 100% rename from test/test_site/testPanels/NestedPanel.md rename to test/functional/test_site/testPanels/NestedPanel.md diff --git a/test/test_site/testPanels/NormalPanelContent.md b/test/functional/test_site/testPanels/NormalPanelContent.md similarity index 100% rename from test/test_site/testPanels/NormalPanelContent.md rename to test/functional/test_site/testPanels/NormalPanelContent.md diff --git a/test/test_site/testPanels/PanelNormalSource.md b/test/functional/test_site/testPanels/PanelNormalSource.md similarity index 100% rename from test/test_site/testPanels/PanelNormalSource.md rename to test/functional/test_site/testPanels/PanelNormalSource.md diff --git a/test/test_site/testPanels/PanelSourceContainsSegment.md b/test/functional/test_site/testPanels/PanelSourceContainsSegment.md similarity index 100% rename from test/test_site/testPanels/PanelSourceContainsSegment.md rename to test/functional/test_site/testPanels/PanelSourceContainsSegment.md diff --git a/test/test_site/testTagDivs.md b/test/functional/test_site/testTagDivs.md similarity index 100% rename from test/test_site/testTagDivs.md rename to test/functional/test_site/testTagDivs.md diff --git a/test/test_site/testTags.md b/test/functional/test_site/testTags.md similarity index 100% rename from test/test_site/testTags.md rename to test/functional/test_site/testTags.md diff --git a/test/test_site/testTrimInclude.md b/test/functional/test_site/testTrimInclude.md similarity index 100% rename from test/test_site/testTrimInclude.md rename to test/functional/test_site/testTrimInclude.md diff --git a/test/functional/test_site/testUtil/diffHtml.js b/test/functional/test_site/testUtil/diffHtml.js new file mode 100644 index 0000000000..db4fe2dd3f --- /dev/null +++ b/test/functional/test_site/testUtil/diffHtml.js @@ -0,0 +1,105 @@ +const jsdiff = require('diff'); + +/** + * Checks if fragment ends with an unclosed path + * true: src=" + * false: src="" + * src="..." + */ +const endsWithUnclosedPath = (fragment) => { + for (let i = fragment.length - 1; i > 4; i -= 1) { + if (fragment[i] === '"') { + if (fragment.substring(i - 4, i) === 'src=' || fragment.substring(i - 5, i) === 'href=') { + return true; + } + return false; + } + } + return false; +}; + +/** + * Checks if the ending portion of the fragment is inside an html tag + * true: link" src=".../ + * false: src=".. + *
+ * src="... + */ +const endsWithOpeningTag = (fragment) => { + let numUnmatchedClosingBracket = 0; + for (let i = fragment.length - 1; i >= 0; i -= 1) { + if (fragment[i] === '>') { + numUnmatchedClosingBracket += 1; + } else if (fragment[i] === '<') { + if (numUnmatchedClosingBracket === 0) { + return true; + } + numUnmatchedClosingBracket -= 1; + } + } + return false; +}; + +/** + * Checks if the start portion of the fragment closes a path + * Assumes that previous fragment was the start of or was within an unclosed path + * true: " + * path/to/file.jpg" + * file.jpg" < + * false: < src="... + * > "... + */ +const startsWithClosedPath = (fragment) => { + for (let i = 0; i <= fragment.length - 1; i += 1) { + if (fragment[i] === '<' || fragment[i] === '>') { + return false; + } + if (fragment[i] === '"') { + return true; + } + } + return false; +}; + +/** + * Checks if diff is a path separator character + */ +const isPathSeparatorDiff = diff => diff === '\\' || diff === '/'; + +/** + * Checks for any diffs between expected.html and actual.html + * @param {string} expected + * @param {string} actual + * @throws {Error} if any diffs that are not path separators are found + */ +const diffHtml = (expected, actual) => { + let insidePath = false; + + const diff = jsdiff.diffChars(expected, actual); + const isDiff = part => part.added || part.removed; + + // assumes no space between paths + const isClosedPath = fragment => + insidePath + && startsWithClosedPath(fragment); + + diff.forEach((part) => { + if (isClosedPath(part.value)) { + insidePath = false; + } + + if (endsWithUnclosedPath(part.value) && endsWithOpeningTag(part.value)) { + // Any diffs following this fragment will be diffs within a path + insidePath = true; + } + + if (isDiff(part) && !insidePath) { + throw new Error(`Diff outside path!: '${part.value}'`); + } else if (isDiff(part) && !isPathSeparatorDiff(part.value)) { + throw new Error(`Diff in path!: '${part.value}'`); + } + }); +}; + +module.exports = diffHtml; diff --git a/test/test_site/testUtil/test.js b/test/functional/test_site/testUtil/test.js similarity index 100% rename from test/test_site/testUtil/test.js rename to test/functional/test_site/testUtil/test.js diff --git a/test/test_site/test_md_fragment.md b/test/functional/test_site/test_md_fragment.md similarity index 100% rename from test/test_site/test_md_fragment.md rename to test/functional/test_site/test_md_fragment.md