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

scripts/test.sh: only test added pages or scripts #12112

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

vitorhcl
Copy link
Member

  • The page(s) are in the correct platform directories: common, linux, osx, windows, sunos, android, etc.
  • The page(s) have at most 8 examples.
  • The page description(s) have links to documentation or a homepage.
  • The page(s) follow the content guidelines.
  • The PR title conforms to the recommended templates.

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.

@github-actions github-actions bot added the tooling Helper tools, scripts and automated processes. label Jan 23, 2024
.husky/pre-commit Show resolved Hide resolved
scripts/test.sh Outdated Show resolved Hide resolved
vitorhcl and others added 4 commits January 23, 2024 15:20
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 {
Copy link
Member

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

Copy link
Member Author

@vitorhcl vitorhcl Jan 24, 2024

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:

  1. Continue to do it interactively
  2. Ignore this possibility and assume the user knows it
  3. 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
  4. 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
  5. 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
  6. 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

Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

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.

@vitorhcl vitorhcl requested a review from sbrl as a code owner February 2, 2024 03:13
@tldr-bot
Copy link

tldr-bot commented Feb 2, 2024

The build for this PR failed with the following error(s):

scripts/test-ci.sh: line 20: run_pages_tests: command not found

Please fix the error(s) and push again.

@@ -1 +1 @@
npm test
COMMIT=true npm test
Copy link
Member Author

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

@sebastiaanspeck sebastiaanspeck added the review needed Prioritized PRs marked for reviews from maintainers. label Feb 2, 2024
Copy link
Member

@sbrl sbrl left a 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?

Comment on lines 4 to 7
# 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.
Copy link
Member

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.

Comment on lines +65 to +67
if [[ $stash_pop == 0 ]]; then
git stash pop
fi
Copy link
Member

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?

Copy link
Member Author

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.

Comment on lines +53 to +55
for script in $1; do
flake8 $script
done
Copy link
Member

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?

Copy link
Member Author

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

@sebastiaanspeck
Copy link
Member

@vitorhcl any update on this one?

@sebastiaanspeck
Copy link
Member

@vitorhcl sending a friendly nudge to remind you of this open PR.

@vitorhcl
Copy link
Member Author

vitorhcl commented Apr 4, 2024

I do have an additional general question though. What happens in the case of a page edit? Do edited pages also get checked?

Any file that was modified or added gets checked.

@vitorhcl vitorhcl requested review from sbrl, sebastiaanspeck and kbdharun and removed request for sebastiaanspeck and kbdharun April 4, 2024 13:33
@sebastiaanspeck
Copy link
Member

@vitorhcl could you resolve the merge conflicts? After that we can merge it IMO

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
review needed Prioritized PRs marked for reviews from maintainers. tooling Helper tools, scripts and automated processes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants