Script para ejecutar pruebas en Jest y obtener el coverage de un archivo específico
Necesitaba automatizar el proceso de ejecutar pruebas en Jest y obtener el coverage de un archivo específico. Creé este script para ayudarme con eso. #!/bin/bash # Color definitions BLUE='\033[0;34m' GREEN='\033[0;32m' RED='\033[0;31m' YELLOW='\033[1;33m' CYAN='\033[0;36m' NC='\033[0m' # No Color BOLD='\033[1m' # Function to display usage show_usage() { echo -e "${YELLOW}Usage:${NC} $0 [--find-by-name] <relative-file-path> [additional test options]" echo -e "${YELLOW}Examples:${NC}" echo -e " $0 src/components/Button.tsx --watch" echo -e " $0 src/components/Button.tsx --find-by-name --watch" exit 1 } # Initialize variables FIND_BY_NAME=false RELATIVE_FILE_PATH="" # Parse arguments while [[ $# -gt 0 ]]; do case $1 in --find-by-name) FIND_BY_NAME=true shift ;; *) if [ -z "$RELATIVE_FILE_PATH" ]; then RELATIVE_FILE_PATH="$1" else break # Stop parsing and keep remaining args for test options fi shift ;; esac done # Check if a file name is provided if [ -z "$RELATIVE_FILE_PATH" ]; then show_usage fi # Check if the file exists if [ ! -f "$RELATIVE_FILE_PATH" ]; then echo -e "${RED}Error: ${NC}File '${YELLOW}${RELATIVE_FILE_PATH}${NC}' not found. 😕" exit 1 fi FILE_PATH=$(echo "$RELATIVE_FILE_PATH" | cut -d'/' -f3-) # Get just the file name without extension for --find-by-name mode FILE_NAME=$(basename "$RELATIVE_FILE_PATH") FILE_NAME_NO_EXT="${FILE_NAME%.*}" # Construct the corresponding test file path TEST_FILE_NAME="${FILE_PATH%.*}.test" if [ "$FIND_BY_NAME" = true ]; then # Search by file name TEST_PATH=$(find "tests" -type f \( -name "${FILE_NAME_NO_EXT}.test.tsx" -o -name "${FILE_NAME_NO_EXT}.test.ts" \)) else # Original search by path TEST_PATH=$(find "tests" -type f \( -path "*/${TEST_FILE_NAME}.tsx" -o -path "*/${TEST_FILE_NAME}.ts" \)) fi # Check if the test file exists if [ -z "$TEST_PATH" ]; then echo -e "${RED}Error: ${NC}Test file for '${YELLOW}${RELATIVE_FILE_PATH}${NC}' not found in 'tests' directory. 😕" echo -e "Test file name: ${YELLOW}${FILE_NAME_NO_EXT}.test.tsx${NC}" echo -e "${YELLOW}Hint:${NC} If you're looking for a file by name, try using the --find-by-name flag." exit 1 fi # Print test information with styling echo -e "\n${BLUE}╔════════════════════════════════════════════════════════════╗${NC}" echo -e "${GREEN}▶ Running Coverage Test${NC}" echo -e "${CYAN}📁 Source file:${NC} ${RELATIVE_FILE_PATH}" echo -e "${CYAN}🧪 Test file:${NC} ${TEST_PATH}" echo -e "${CYAN}⚙️ Options:${NC} $@" echo -e "${BLUE}╚════════════════════════════════════════════════════════════╝${NC}\n" yarn test "$TEST_PATH" --coverage --collectCoverageFrom="$RELATIVE_FILE_PATH" "$@" Uso Los casos de prueba están en la carpeta tests. El script buscará el archivo de prueba por ruta de manera predeterminada. Si deseas buscar por nombre, puedes usar la bandera --find-by-name. ...
Crear descripciones de pull requests usando Aider y OpenRouter
Para reducir el tiempo que dedico a escribir instrucciones de pull requests, he estado usando Aider con OpenRouter para generarlas. ¿Cómo funciona? Aider es una herramienta que utiliza IA para ayudarte a escribir código. Es un chatbot que puede ayudarte a escribir código, corregir errores e incluso escribir pruebas. OpenRouter es una herramienta que te permite enrutar peticiones a diferentes APIs. En este caso, la usaremos para enrutar la petición a Aider. ...
Tailscale con NordVPN al mismo tiempo en GNU/Linux
NordVPN por defecto no permite que los usuarios se conecten a Tailscale. Esto es debido a que NordVPN bloquea el trafico de tailscale. Para solucionar esto, solo debes ejecutar los siguientes comandos: nordvpn whitelist add subnet 100.64.0.0/10 nordvpn whitelist add subnet fd7a:115c:a1e0::/48 nordvpn whitelist add port 41641 Luego, reiniciar la conexión de NordVPN: nordvpn d nordvpn c US Finalmente, si no estas conectado a Tailscale, entonces conectate a Tailscale: tailscale up --accept-routes --shields-up
Habilitar bluetooth en Arch Linux
Primero, verifica el estado del servicio de bluetooth: systemctl status bluetooth.service Si el estado no es active (running), entonces habilítalo: systemctl enable bluetooth.service Luego, inicia el servicio: systemctl start bluetooth.service Finalmente, verifica el estado nuevamente: systemctl status bluetooth.service Si el estado ahora es active (running), entonces el servicio de bluetooth está habilitado.
Alias de correo electronico para mejorar tu privacidad
Recientemente revisando reddit encontré una de las herramientas más útiles que he visto, un email alias. Como su nombre indica puedes crear nombres alternativos para correos electrónicos. Estos correos electrónicos están vinculados a un correo principal. La forma en que funciona es muy simple, uno crea un alias, y este alias, que no es más que otra direccion de correo electrónico, se vincula a tu correo principal. Cuando se envía un correo electrónico, reenviara todos los correos que lleguen al alias a tu correo principal. ...