Skip to content

Commit

Permalink
openvidu-components: Added basic test
Browse files Browse the repository at this point in the history
  • Loading branch information
CSantosM committed Jul 1, 2024
1 parent 223b521 commit 793aa9d
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 30 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/openvidu-components-angular.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Run OpenVidu Components Angular test

on:
push:
pull_request:
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'

- name: Run tests
run: |
cd openvidu-components-angular/test
./run-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,64 +17,64 @@ TUTORIALS=(
'../openvidu-toolbar-buttons'
'../openvidu-toolbar-panel-buttons'
)
# Inicializar contadores de tests exitosos y fallidos
# Initialize counters for successful and failed tests
SUCCESS=0
FAILURE=0

for tutorial in "${TUTORIALS[@]}"
do
echo "Processing $tutorial..."


if [ -d "$tutorial" ]; then

cd "$tutorial" || { echo "Cannot enter directory $tutorial"; exit 1; }
rm -rf node_modules
rm -f package-lock.json
npm install openvidu-components-angular@latest


# Verificar si el puerto 5080 está en uso y matar el proceso si es necesario
# Check if port 5080 is in use and kill the process if necessary
PORT_IN_USE=$(lsof -i :5080 | grep LISTEN)
if [ -n "$PORT_IN_USE" ]; then
echo "Port 5080 is in use. Killing the process..."
kill -9 $(lsof -ti :5080)
fi


# Iniciar la aplicación
# Start the application
echo "Starting the application in $tutorial..."
npm run start &
APP_PID=$!

# Esperar un tiempo para que la aplicación se inicie
# Wait some time for the application to start
sleep 20

# Ejecutar el test
# Run the test
echo "Running test for $tutorial..."
node ../test/test.js
node ../test/test.js "$tutorial"

# Verificar si el test falló
# Check if the test failed
if [ $? -eq 1 ]; then
echo "ERROR!! Test failed for $tutorial"
((FAILURE++)) # Incrementar el contador de fallos
((FAILURE++))
else
((SUCCESS++)) # Incrementar el contador de éxitos
((SUCCESS++))
fi


# Detener la aplicación
echo "Stopping the application in $tutorial..."
kill $APP_PID
wait $APP_PID 2>/dev/null # Esperar a que el proceso se detenga antes de continuar
wait $APP_PID 2>/dev/null # Wait for the process to stop before continuing

cd - || { echo "Cannot return to previous directory"; exit 1; }
else
echo "Directory $tutorial does not exist."
fi
done

# Mostrar resumen de los tests
echo "Summary:"
echo "Successful tests: $SUCCESS"
echo "Failed tests: $FAILURE"
echo "Failed tests: $FAILURE"

# Exit with an error code if there are failed tests
if [ $FAILURE -gt 0 ]; then
exit 1
fi
32 changes: 18 additions & 14 deletions openvidu-components-angular/test/test.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,38 @@
const puppeteer = require('puppeteer');

(async () => {
// Iniciar el navegador
console.log('Iniciando navegador');

const args = process.argv.slice(2);
const project = args[0];
let selector;

// Determine the correct selector based on the project
if (project.includes('openvidu-admin-dashboard')) {
selector = 'ov-admin-login';
} else {
selector = '#join-button';
}

const browser = await puppeteer.launch({
args: [
'--use-fake-ui-for-media-stream',
'--use-fake-device-for-media-stream',
],
});
const page = await browser.newPage();
await page.goto('http://localhost:5080');

console.log('Navegando a la aplicación');

// Navegar a la aplicación
await page.goto('https://192-168-1-47.openvidu-local.dev:5443');

// Esperar a que el elemento con el ID #join-button aparezca
try {
console.log('Esperando a que #join-button aparezca');
await page.waitForSelector('#join-button', { timeout: 10000 });
console.log('#join-button encontrado');
console.log(`Waiting for ${selctor} to appear in the DOM...`);
await page.waitForSelector(selector, { timeout: 10000 });
console.log(`${selctor} found!`);
} catch (error) {
const screenshotPath = `screenshot-${Date.now()}.png`;
await page.screenshot({ path: screenshotPath });
console.error('Error: #join-button no encontrado');
console.error(`Error: ${selector} not found`);
console.error('ERROR!! Test failed: #join-button not found');
process.exit(1); // Salir del script con un código de error
process.exit(1);
}

// Cerrar el navegador
await browser.close();
})();

0 comments on commit 793aa9d

Please sign in to comment.