From 636870bdb8c38843297efac4c9d72684577a9aeb Mon Sep 17 00:00:00 2001 From: Marvin Chin Date: Wed, 10 Apr 2019 18:02:12 +0800 Subject: [PATCH 1/4] Move declaration of test site directories to separate file Declaration of test site directories are replicated across test.bat and test.sh. Let's move the declaration to a separate file and have the scripts obtain the directory names from the file instead. --- test/functional/test.bat | 8 ++------ test/functional/test.sh | 4 +--- test/functional/test_convert_sites | 1 + test/functional/test_sites | 2 ++ 4 files changed, 6 insertions(+), 9 deletions(-) create mode 100644 test/functional/test_convert_sites create mode 100644 test/functional/test_sites diff --git a/test/functional/test.bat b/test/functional/test.bat index 4b19f22707..677a6d1508 100644 --- a/test/functional/test.bat +++ b/test/functional/test.bat @@ -1,8 +1,6 @@ @ECHO off -set sites=test_site test_site_algolia_plugin - -for %%a in (%sites%) do ( +for /f "tokens=* delims=" %%a in (test_sites) do ( echo( echo Running %%a tests @@ -17,9 +15,7 @@ for %%a in (%sites%) do ( ) ) -set sites_convert=test_site_convert - -for %%a in (%sites_convert%) do ( +for /f "tokens=* delims=" %%a in (test_convert_sites) do ( echo( echo Running %%a tests diff --git a/test/functional/test.sh b/test/functional/test.sh index d5371e969a..c43d5c4b25 100755 --- a/test/functional/test.sh +++ b/test/functional/test.sh @@ -1,8 +1,6 @@ #!/bin/bash -declare -a sites=("test_site" "test_site_algolia_plugin") - -for site in "${sites[@]}" +for site in $(cat test_sites); do # print site name echo diff --git a/test/functional/test_convert_sites b/test/functional/test_convert_sites new file mode 100644 index 0000000000..d9a9e8d536 --- /dev/null +++ b/test/functional/test_convert_sites @@ -0,0 +1 @@ +test_site_convert diff --git a/test/functional/test_sites b/test/functional/test_sites new file mode 100644 index 0000000000..b32a5667c2 --- /dev/null +++ b/test/functional/test_sites @@ -0,0 +1,2 @@ +test_site +test_site_algolia_plugin From 151ac6a13d701ee92225a69240ac2f83c6342e3f Mon Sep 17 00:00:00 2001 From: Marvin Chin Date: Fri, 12 Apr 2019 15:26:45 +0800 Subject: [PATCH 2/4] Standardize test script implementation The implementation of the bash and batch test script differs slightly. The batch script implementation allows multiple test convert sites, but the bash script implementation only allows a single test convert site. Let's update the bash script to allow it to be extensible to multiple test convert sites. --- test/functional/test.sh | 50 ++++++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/test/functional/test.sh b/test/functional/test.sh index c43d5c4b25..72d59b9209 100755 --- a/test/functional/test.sh +++ b/test/functional/test.sh @@ -21,35 +21,43 @@ done function cleanup_convert { # delete generated files - rm -rf "$site_convert"/_site - rm -rf "$site_convert"/non_markbind_site/_markbind "$site_convert"/non_markbind_site/_site - rm "$site_convert"/non_markbind_site/about.md "$site_convert"/non_markbind_site/index.md "$site_convert"/non_markbind_site/site.json + rm -rf $site_convert/_site + rm -rf $site_convert/non_markbind_site/_markbind $site_convert/non_markbind_site/_site + rm -f $site_convert/non_markbind_site/about.md $site_convert/non_markbind_site/index.md $site_convert/non_markbind_site/site.json } -trap cleanup_convert EXIT -declare -r site_convert="test_site_convert" +for site_convert in $(cat test_convert_sites); +do + # print site name + echo "Running $site_convert test" -# print site name -echo -echo "Running $site_convert test" + # set cleanup trap + trap cleanup_convert EXIT -# convert site -node ../../index.js init "$site_convert"/non_markbind_site -c + # convert site + node ../../index.js init $site_convert/non_markbind_site -c -# build site -node ../../index.js build "$site_convert"/non_markbind_site + # build site + node ../../index.js build $site_convert/non_markbind_site -# copy generated site -cp -r "$site_convert"/non_markbind_site/_site "$site_convert" + # copy generated site + cp -r $site_convert/non_markbind_site/_site $site_convert -# run our test script to compare html files -node testUtil/test.js "$site_convert" + # run our test script to compare html files + node testUtil/test.js $site_convert -if [ $? -ne 0 ] -then - echo "Test result: $site FAILED" - exit 1 -fi + if [ $? -ne 0 ] + then + echo "Test result: $site_convert FAILED" + exit 1 + fi + + # cleanup generated files + cleanup_convert + + # remove trap + trap - EXIT +done # if there were no diffs echo "Test result: PASSED" From 040abb1d50ea6fd46f08d40797dcc96f4bd181be Mon Sep 17 00:00:00 2001 From: Marvin Chin Date: Wed, 10 Apr 2019 18:07:52 +0800 Subject: [PATCH 3/4] Add script to update expected files for test sites Developers have to update the expected folder for test sites by hand. Updating the expected folders for each site manually becomes especially unwieldy as the number of test sites increase. Let's have a script which automates the updating of expected folders in all of the test sites. --- package.json | 6 +++-- test/functional/update.bat | 33 +++++++++++++++++++++++++ test/functional/update.sh | 49 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 86 insertions(+), 2 deletions(-) create mode 100644 test/functional/update.bat create mode 100755 test/functional/update.sh diff --git a/package.json b/package.json index f9e0423d1e..eb09343eda 100644 --- a/package.json +++ b/package.json @@ -62,12 +62,14 @@ }, "scripts": { "csslint": "./node_modules/.bin/stylelint \"**/*.css\" \"!**/*.min.css\"", + "jest": "jest", "lint": "./node_modules/.bin/eslint .", "pretest": "npm run lint && npm run csslint", "pretestwin": "npm run lint && npm run csslint", - "testwin": "jest && cd test/functional && test.bat", "test": "jest && cd test/functional && ./test.sh", - "jest": "jest" + "testwin": "jest && cd test/functional && test.bat", + "updatetest": "cd test/functional && ./update.sh", + "updatetestwin": "cd test/functional && update.bat" }, "jest": { "testPathIgnorePatterns": [ diff --git a/test/functional/update.bat b/test/functional/update.bat new file mode 100644 index 0000000000..a660d82453 --- /dev/null +++ b/test/functional/update.bat @@ -0,0 +1,33 @@ +@ECHO off + +for /f "tokens=* delims=" %%a in (test_sites) do ( + + echo( + echo Updating %%a + + node ../../index.js build %%a + + rmdir /s /q %%a\expected + xcopy /e /y /i /q %%a\_site %%a\expected +) + +for /f "tokens=* delims=" %%a in (test_convert_sites) do ( + + echo( + echo Updating %%a + + node ../../index.js init %%a\non_markbind_site -c + + node ../../index.js build %%a\non_markbind_site + + rmdir /s /q %%a\expected + xcopy /e /y /i /q %%a\non_markbind_site\_site %%a\expected + + rmdir /s /q %%a\_site + rmdir /q %%a\non_markbind_site\_markbind + rmdir /s /q %%a\non_markbind_site\_site + del %%a\non_markbind_site\about.md %%a\non_markbind_site\index.md %%a\non_markbind_site\site.json +) + +echo Updated all test sites +exit /b %errorlevel% diff --git a/test/functional/update.sh b/test/functional/update.sh new file mode 100755 index 0000000000..178f046ec1 --- /dev/null +++ b/test/functional/update.sh @@ -0,0 +1,49 @@ +#!/bin/bash + +for site in $(cat test_sites); +do + # print site name + echo "Updating $site" + + # build site + node ../../index.js build "$site" + + # replace the expected folder with the newly generated files + rm -rf $site/expected + cp -r $site/_site $site/expected +done + +function cleanup_convert { + # delete generated files + rm -rf $site_convert/_site + rm -rf $site_convert/non_markbind_site/_markbind $site_convert/non_markbind_site/_site + rm -f $site_convert/non_markbind_site/about.md $site_convert/non_markbind_site/index.md "$site_convert"/non_markbind_site/site.json +} + +for site_convert in $(cat test_convert_sites); +do + # print site name + echo "Updating $site_convert test" + + # set cleanup trap + trap cleanup_convert EXIT + + # convert site + node ../../index.js init $site_convert/non_markbind_site -c + + # build site + node ../../index.js build $site_convert/non_markbind_site + + # replace the expected folder with the newly generated files + rm -rf $site_convert/expected + cp -r $site_convert/non_markbind_site/_site $site_convert/expected + + # cleanup generated files + cleanup_convert + + # remove trap + trap - EXIT +done + +echo "Updated all test sites" +exit 0 From 329b333995805b0bed5f551f3d5c793f3b76187f Mon Sep 17 00:00:00 2001 From: Marvin Chin Date: Thu, 11 Apr 2019 00:39:11 +0800 Subject: [PATCH 4/4] Update testing instructions for developer and maintainer guides The updatetest and updatetestwin scripts have been added for developers to update the expected output for all test sites. Also, testing instructions for the developer and maintainer guides assume that there is only one test site. Let's update the developer and maintainer guides to include usage instructions for the test site update scripts. Let's also generalize the testing instructions for multiple test sites. --- docs/devGuide/devGuide.md | 31 ++++++++++++++++++++++++------- docs/devGuide/maintainerGuide.md | 10 ++++------ 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/docs/devGuide/devGuide.md b/docs/devGuide/devGuide.md index a0794c8c3d..9d3adfe703 100644 --- a/docs/devGuide/devGuide.md +++ b/docs/devGuide/devGuide.md @@ -120,8 +120,8 @@ A: If your npm version is v6.0.0 or higher, there is a change in behaviour on ho Our test script does the following: 1. Lints the code for any code and style errors using ESLint. -1. Builds the test site found in `test/test_site/`. -1. Compares the HTML files generated with the HTML files in `test/test_site/expected/`. +1. Builds the test sites whose directory names are listed in `test/functional/test_sites`. +1. For each test site, compares the HTML files generated with the HTML files in its `expected` directory. #### Running tests @@ -136,20 +136,37 @@ $ npm run test For Windows users: ``` -$ npm run testwin +> npm run testwin ``` #### Updating tests -When adding new features, updating existing features or fixing bugs, you should update the expected site to reflect the changes. +Whether you are adding a new feature, updating existing features or fixing bugs, make sure to update the test sites to reflect the changes. -##### Changes to existing features +You may use the following script to do this: -Simply update the expected HTML files in `test/test_site/expected/` to reflect the changes. +On Unix: + +``` +$ npm run updatetest +``` + +On Windows: + +``` +> npm run updatetestwin +``` + + You should always check that the generated output is correct before committing any changes to the test sites. + ##### New features -Add new site content into the `test/test_site/` folder to demonstrate the new feature. Ensure that the new content is included in the test site so that your feature will be tested when `markbind build` is run on the test site. Remember to update the expected HTML files in `test/test_site/expected/`. +When adding new features, you should also add new site content into an existing test site or create a new test site to demonstrate the new feature. This is to ensure that your feature can be tested by building that test site. + + + When creating a new test site, the directory name of the new test site should be added to test/functional/test_sites. + ### Using ESLint diff --git a/docs/devGuide/maintainerGuide.md b/docs/devGuide/maintainerGuide.md index 21a32aa945..31f4bd5241 100644 --- a/docs/devGuide/maintainerGuide.md +++ b/docs/devGuide/maintainerGuide.md @@ -115,13 +115,11 @@ $ git commit -m 'Update vue-strap version to v2.0.1-markbind.XYZ' 2. Rebuild the test files. ``` -$ cd test/functional/ +# on Unix +$ npm run updatetest -# for each test site -$ cd -$ markbind build -$ cp _site/* expected/ -$ cd .. +# on Windows +> npm run updatetestwin ``` When rebuilding the expected test files, ensure that **only** the version number is updated. For example, this is correct: