diff --git a/.github/workflows/openvidu-components-angular.yml b/.github/workflows/openvidu-components-angular.yml new file mode 100644 index 00000000..9d3703ab --- /dev/null +++ b/.github/workflows/openvidu-components-angular.yml @@ -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-tests.sh diff --git a/openvidu-components-angular/test/start-test.sh b/openvidu-components-angular/test/run-test.sh similarity index 71% rename from openvidu-components-angular/test/start-test.sh rename to openvidu-components-angular/test/run-test.sh index d8bb7ecb..325c0f56 100755 --- a/openvidu-components-angular/test/start-test.sh +++ b/openvidu-components-angular/test/run-test.sh @@ -17,7 +17,7 @@ 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 @@ -25,7 +25,6 @@ for tutorial in "${TUTORIALS[@]}" do echo "Processing $tutorial..." - if [ -d "$tutorial" ]; then cd "$tutorial" || { echo "Cannot enter directory $tutorial"; exit 1; } @@ -33,40 +32,37 @@ do 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 @@ -74,7 +70,11 @@ do fi done -# Mostrar resumen de los tests echo "Summary:" echo "Successful tests: $SUCCESS" -echo "Failed tests: $FAILURE" \ No newline at end of file +echo "Failed tests: $FAILURE" + +# Exit with an error code if there are failed tests +if [ $FAILURE -gt 0 ]; then + exit 1 +fi \ No newline at end of file diff --git a/openvidu-components-angular/test/test.js b/openvidu-components-angular/test/test.js index 7f986901..94af9f5b 100644 --- a/openvidu-components-angular/test/test.js +++ b/openvidu-components-angular/test/test.js @@ -1,8 +1,18 @@ 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', @@ -10,25 +20,19 @@ const puppeteer = require('puppeteer'); ], }); 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(); })();