Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add script to update expected folder for test sites #828

Merged
merged 4 commits into from
Apr 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 24 additions & 7 deletions docs/devGuide/devGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -136,20 +136,37 @@ $ npm run test
For Windows users:

```
$ npm run testwin
> npm run testwin
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💥
☁️
😮

```

#### 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
```
<box type="warning">
You should always check that the generated output is correct before committing any changes to the test sites.
</box>

##### 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.

<box type="info">
When creating a new test site, the directory name of the new test site should be added to <code>test/functional/test_sites</code>.
</box>

### Using ESLint

Expand Down
10 changes: 4 additions & 6 deletions docs/devGuide/maintainerGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <TEST_SITE_NAME>
$ 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:
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
8 changes: 2 additions & 6 deletions test/functional/test.bat
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
54 changes: 30 additions & 24 deletions test/functional/test.sh
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -23,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"

# set cleanup trap
trap cleanup_convert EXIT

# convert site
node ../../index.js init $site_convert/non_markbind_site -c

# print site name
echo
echo "Running $site_convert test"
# build site
node ../../index.js build $site_convert/non_markbind_site

# convert site
node ../../index.js init "$site_convert"/non_markbind_site -c
# copy generated site
cp -r $site_convert/non_markbind_site/_site $site_convert

# build site
node ../../index.js build "$site_convert"/non_markbind_site
# run our test script to compare html files
node testUtil/test.js $site_convert

# copy generated site
cp -r "$site_convert"/non_markbind_site/_site "$site_convert"
if [ $? -ne 0 ]
then
echo "Test result: $site_convert FAILED"
exit 1
fi

# run our test script to compare html files
node testUtil/test.js "$site_convert"
# cleanup generated files
cleanup_convert

if [ $? -ne 0 ]
then
echo "Test result: $site FAILED"
exit 1
fi
# remove trap
trap - EXIT
done

# if there were no diffs
echo "Test result: PASSED"
Expand Down
1 change: 1 addition & 0 deletions test/functional/test_convert_sites
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test_site_convert
2 changes: 2 additions & 0 deletions test/functional/test_sites
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
test_site
test_site_algolia_plugin
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Screenshot of the current docs:
Screenshot 2019-04-10 at 11 32 31 PM

Given that we no longer have one ("the") test site, it would be great to also update the details of this new testing approach in our developer guide (in the Running tests and Updating tests sections). In particular, mentioning that whenever a new test site is added, its folder name will need to be added to this file.

33 changes: 33 additions & 0 deletions test/functional/update.bat
Original file line number Diff line number Diff line change
@@ -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%
49 changes: 49 additions & 0 deletions test/functional/update.sh
Original file line number Diff line number Diff line change
@@ -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