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
scripts/test.sh: only test added pages or scripts #12112
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: Sebastiaan Speck <12570668+sebastiaanspeck@users.noreply.github.com>
Co-authored-by: Sebastiaan Speck <12570668+sebastiaanspeck@users.noreply.github.com>
scripts/test.sh
Outdated
@@ -14,14 +14,39 @@ function exists { | |||
command -v "$1" >/dev/null 2>&1 | |||
} | |||
|
|||
function check_for_unstaged_changes { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not think this is something we want. It is a test script. Keep it clean and only for the purpose it is meant for
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can potentially cause some imprecisions when an already added file is modified, so I see some options:
- Continue to do it interactively
- Ignore this possibility and assume the user knows it
- Warn the user in some way
2.1 Warn in the docs
2.2 Warn in every execution
2.3 Warn only when there are unstaged changes
2.4 Warn only when unstaged and staged files conflict - Take a specific action for the user (whenever there is unstaged changes OR if they conflict with staged ones)
4.1 Stash the unstaged changes
4.2 Stash the unstaged changes and pop the stash after the checks
4.3 Discard the unstaged changes
4.4 Add the unstaged changes - Throw an error under a specific condition
5.1 Throw an error if there are any unstaged changes
5.2 Throw an error if the unstaged changes conflict with staged ones - Let the user configure the action to be taken before the test is executed
6.1 Configure through a config file
6.2 Configure through an environment variable
6.2 Configure through an option
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The script itself was originally intended to be used in the CI, so it is a nice catch you can also run it locally. I personally do not want git stuff like this in the test script.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, there is a CI variable already. Maybe we could split out the test scripts to keep the CI script minimal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would agree. We don't want to check for unstaged changes here. If you have another use-case for interactive testing, this should be a separate script that is separately documented.
8de33b6
to
04afa76
Compare
The build for this PR failed with the following error(s):
Please fix the error(s) and push again. |
@@ -1 +1 @@ | |||
npm test | |||
COMMIT=true npm test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
COMMIT=true needs to be passed directly because of Husky v9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey, thanks for the script update! I've got some comments below for you to review.
I do have an additional general question though. What happens in the case of a page edit? Do edited pages also get checked?
scripts/test-non-ci.sh
Outdated
# This script is the entrypoint for test.sh. | ||
# | ||
# NOTE: must be run from the repository root directory to correctly work! | ||
# NOTE: `set -e` is applied conditionally only if needed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please document the purpose of this script more fully.
if [[ $stash_pop == 0 ]]; then | ||
git stash pop | ||
fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this stash command for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #12112 (comment) and the comments below it.
for script in $1; do | ||
flake8 $script | ||
done |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm somewhat confused here. This implies an argument is now passed to this function. Where does it come from?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it only runs flake8
on the passed scripts, on test-non-ci.run_tests_commit, it only sends to run_flake8 the scripts that were modified
@vitorhcl any update on this one? |
@vitorhcl sending a friendly nudge to remind you of this open PR. |
Any file that was modified or added gets checked. |
@vitorhcl could you resolve the merge conflicts? After that we can merge it IMO |
common
,linux
,osx
,windows
,sunos
,android
, etc.This PR modify test.sh so that, if $COMMIT == true, the tests are only ran on files that were added to commit. It also modify the pre-commit hook.
This greatly improves the commit test, only testing files that weren't tested yet, i.e., only files that will be in fact modified by the commit, and not the entire repository 🎉
You can still run npm test without environment variables to test all files, though.