-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
85 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
.github | ||
/bin | ||
node_modules | ||
/scripts | ||
/src | ||
/tests | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#!/usr/bin/env bash | ||
|
||
# This script runs Cypress clean tests (reset db before test) for a specific module. | ||
|
||
# Source utils | ||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" | ||
cd "$SCRIPT_DIR" | ||
source ./utils | ||
|
||
# Project root | ||
cd ../ | ||
|
||
# Check if a module is provided | ||
if [ -z "$1" ]; then | ||
print_error "No module provided." | ||
echo "Usage: npm run test:clean-module -- <wp-module-name>" | ||
exit 1 | ||
fi | ||
|
||
MODULE=$1 | ||
MODULE_DIR="vendor/newfold-labs/$MODULE" | ||
|
||
# Check if the module exists | ||
if [ ! -d "$MODULE_DIR" ]; then | ||
print_error "Can't find $MODULE in vendor/newfold-labs." | ||
exit 1 | ||
fi | ||
|
||
# Check if the module has tests | ||
if ! find "$MODULE_DIR/tests" -type f -name "*.cy.js" 2>/dev/null | grep -q .; then | ||
print_error "Can't find any test files in $MODULE_DIR." | ||
exit 1 | ||
fi | ||
|
||
# Warn the user that the database will be reset | ||
confirm_prompt "${YELLOW}Running a clean test will reset the database. Proceed?${TEXT}" | ||
|
||
# Check if the answer is "y" or "Y" | ||
if [[ $REPLY =~ ^[Yy]$ ]]; then | ||
echo -e "Proceeding with tests for ${CYAN}${MODULE}${TEXT}..." | ||
|
||
# Run the commands | ||
wp-env stop | ||
wp-env clean all | ||
wp-env start | ||
npm run test:e2e -- --browser chrome --spec "vendor/(newfold-labs/$MODULE/tests/**/*.cy.js)" | ||
else | ||
echo "Cancelled." | ||
exit 0 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Colors | ||
GREEN='\033[0;32m' | ||
TEXT='\033[0m' | ||
BLUE='\033[0;34m' | ||
RED='\033[0;31m' | ||
CYAN='\033[0;36m' | ||
YELLOW='\033[0;33m' | ||
|
||
print_success() { | ||
echo -e "${GREEN}Success:${TEXT} $1" | ||
} | ||
|
||
print_error() { | ||
echo -e "${RED}Error:${TEXT} $1" | ||
} | ||
|
||
print_info() { | ||
echo -e "${CYAN}$1" | ||
} | ||
|
||
print_warning() { | ||
echo -e "${YELLOW}Warning:${TEXT} $1" | ||
} | ||
|
||
confirm_prompt() { | ||
local message=$1 | ||
read -p "$(echo -e ${message}) (y/n): " -n 1 -r | ||
echo # Move to a new line | ||
[[ $REPLY =~ ^[Yy]$ ]] # Returns 0 if y/Y is entered, 1 otherwise | ||
} |