Pruebas Frontend con Cypress

Hola @AlexTrovato :wave:

Hoy probé la rama Cypress que desarrollaste y funciona bien :slight_smile:
Empecé a probar el front del servicio Tp-Link y puedo avanzar bien. La parte de fixture/mock de las llamadas backend es un poco más compleja, pero también funciona.
Creo que realmente deberíamos ponernos en modo TDD para escribir este tipo de pruebas.

Para la parte de la API backend, ¿queremos probar solo el core? El resto (servicios) está demasiado vinculado al hardware, por lo que queremos mockear todo, ¿es así?

Creo que hay un error entre la documentación y el comando en el package.json para iniciar el servidor para las pruebas de Cypress (npm run start:cypress <=> npm run cypress:start)

Gracias por el trabajo :clap: y tengo ganas de verlo en la CI y en el coverage :rocket:

¡Genial, buenas noticias!

Sí, será más fácil para implementar nuestras pruebas y también para validar nuestros desarrollos.

Sería bueno probar el core al máximo. Pero sí, para las interacciones con los dispositivos, es complicado, por lo que hay que intentar mockear solo los WebServices que llaman a los servicios reales.
Si lo hacemos en una página de configuración (como para el Bluetooth y la frecuencia de escaneo, que solo registra parámetros en la base de datos).

El script npm run cypress:start no debería estar en el archivo package.json de la raíz, y la documentación especifica que debes estar en la raíz de Gladys (ni en front, ni en server).
(sí, lo sé cypress:start vs start:cypress, intenté seguir la « lógica » ya existente, pero todo es modificable :slight_smile: ).

Con mi PR, la CI ya ejecuta las pruebas (bloqueando en caso de error), solo falta la cobertura.

Gracias por probar, con @pierre-gilles habíamos acordado que yo debía probar el componente « react-select » que es un poco especial (para proporcionar la técnica a aplicar), y dejar que la comunidad juegue con él antes de hacer merge, luego hacer merge poco a poco, para evitar el efecto túnel (y admito que trabajar 5 días seguidos en ello, cansa).

@AlexTrovato ¿Crees que puedo fusionar pronto la PR de Cypress? Pienso que, como dijimos, podemos fusionarla aunque no todo esté cubierto, así al menos la estructura estará en master y podremos basarnos en ella para hacer PRs que añadan cobertura :slight_smile:

Sí, podemos, si ella pasa, no estoy seguro de tener un rebase reciente.
Complacemos con el tiempo, como dices, me parece bien.

¡Hola!

Lo siento, no debo ser muy bueno ^^ @AlexTrovato ¿podrías ayudarme a lanzar Cypress bajo WSL? Bueno, si hay algo que no he entendido o hecho…

  • Seguí la documentación:
  • Por lo tanto, ejecuté el comando del servidor:
terdieu@DUBLEM-PC-01:~/gladys-dev/requeteAPI/Gladys/server[ExpandIconSelectionScenes !]$ npm run cypress

> gladys-server@ cypress /home/terdieu/gladys-dev/requeteAPI/Gladys/server
> npm run cypress:clean && npm run cypress:start


> gladys-server@ cypress:clean /home/terdieu/gladys-dev/requeteAPI/Gladys/server
> npx rimraf ./gladys-cypress.db*


> gladys-server@ cypress:start /home/terdieu/gladys-dev/requeteAPI/Gladys/server
> cross-env SQLITE_FILE_PATH=./gladys-cypress.db node index.js

2022-04-12T09:56:38+0200 <debug> index.js:370 (Umzug.log) == 20190205063641-create-user: migrating =======
2022-04-12T09:56:38+0200 <debug> index.js:370 (Umzug.log) == 20190205063641-create-user: migrated (0.036s)
  • Luego ejecuté el comando front:
terdieu@DUBLEM-PC-01:~/gladys-dev/requeteAPI/Gladys/front[ExpandIconSelectionScenes !]$ npm run start:cypress

> gladys-front@ start:cypress /home/terdieu/gladys-dev/requeteAPI/Gladys/front
> cross-env DEMO_MODE=false WEBSOCKET_URL=ws://localhost:1443 LOCAL_API_URL=http://localhost:1443 npm start


> gladys-front@ start /home/terdieu/gladys-dev/requeteAPI/Gladys/front
> per-env


> gladys-front@ start:development /home/terdieu/gladys-dev/requeteAPI/Gladys/front
> npm run -s dev

 Build  [                    ] 0% (0.0s) compilingℹ 「wds」: Project is running at http://0.0.0.0:1444/
ℹ 「wds」: webpack output is served from /
ℹ 「wds」: Content not from webpack is served from /home/terdieu/gladys-dev/requeteAPI/Gladys/front/src
ℹ 「wds」: 404s will fallback to /index.html
 Build  [==                  ] 10% (0.1s) buildingBrowserslist: caniuse-lite is outdated. Please run:
npx browserslist@latest --update-db

Why you should do it regularly:
https://github.com/browserslist/browserslist#browsers-data-updating
 Build  [==========          ] 49% (13.9s) buildingBrowserslist: caniuse-lite is outdated. Please run:
npx browserslist@latest --update-db

Why you should do it regularly:
https://github.com/browserslist/browserslist#browsers-data-updating
Compiled successfully!

You can view the application in browser.

Local:            http://0.0.0.0:1444
On Your Network:  http://172.29.212.22:1444
  • Y finalmente intenté lanzar Cypress (intento desde el front y la raíz de Gladys).
terdieu@DUBLEM-PC-01:~/gladys-dev/requeteAPI/Gladys[ExpandIconSelectionScenes !]$ npm run cypress:open

> gladys@4.8.3 cypress:open /home/terdieu/gladys-dev/requeteAPI/Gladys
> cd front && npm run cypress:open


> gladys-front@ cypress:open /home/terdieu/gladys-dev/requeteAPI/Gladys/front
> cypress open --config-file cypress/cypress.json

It looks like this is your first time using Cypress: 6.9.1

  ✖  Verifying Cypress can run /home/terdieu/.cache/Cypress/6.9.1/Cypress
    → Cypress Version: 6.9.1
Cypress verification timed out.

This command failed with the following output:

/home/terdieu/.cache/Cypress/6.9.1/Cypress/Cypress --no-sandbox --smoke-test --ping=156

----------

Command timed out after 30000 milliseconds: /home/terdieu/.cache/Cypress/6.9.1/Cypress/Cypress --no-sandbox --smoke-test --ping=156
Timed out

----------

Platform: linux (Ubuntu - 20.04)
Cypress Version: 6.9.1
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! gladys-front@ cypress:open: `cypress open --config-file cypress/cypress.json`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the gladys-front@ cypress:open script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/terdieu/.npm/_logs/2022-04-12T08_25_08_213Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! gladys@4.8.3 cypress:open: `cd front && npm run cypress:open`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the gladys@4.8.3 cypress:open script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/terdieu/.npm/_logs/2022-04-12T08_25_08_243Z-debug.log
  • Luego intenté seguir el enlace que das en tus diapositivas:

Pero nada funciona :smiling_face_with_tear: :smiling_face_with_tear:

¡Gracias de antemano!!

He seguido el procedimiento y WSL 2 está bien por mi parte

¡Mierda!!^^

¿Has lanzado xlaunch en Windows antes?

Antes de cypress:open sí.

Después intenté reiniciar la parte del servidor y del frontend también, pero nada.
No tengo ningún cliente en Xlaunch. ¿Algún puerto en particular que deba abrir?

El único y único comando en la raíz npm run cypress :slight_smile:

image

Oups lol seguí la documentación:

Bueno, sin embargo, funciona aún menos con la única y única ^^


Y en el archivo de registro:

0 info it worked if it ends with ok
1 verbose cli [ '/usr/bin/node', '/usr/bin/npm', 'run', 'cypress' ]
2 info using npm@6.14.10
3 info using node@v12.20.1
4 verbose run-script [ 'precypress', 'cypress', 'postcypress' ]
5 info lifecycle gladys@4.8.3~precypress: gladys@4.8.3
6 info lifecycle gladys@4.8.3~cypress: gladys@4.8.3
7 verbose lifecycle gladys@4.8.3~cypress: unsafe-perm in lifecycle true
8 verbose lifecycle gladys@4.8.3~cypress: PATH: /usr/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/home/terdieu/gladys-dev/requeteAPI/Gladys/node_modules/.bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/wsl/lib:/mnt/c/Python39/Scripts/:/mnt/c/Python39/:/mnt/c/Program Files (x86)/Common Files/Oracle/Java/javapath:/mnt/c/ProgramData/Oracle/Java/javapath:/mnt/c/Program Files (x86)/Intel/iCLS Client/:/mnt/c/Program Files/Intel/iCLS Client/:/mnt/c/WINDOWS/system32:/mnt/c/WINDOWS:/mnt/c/WINDOWS/System32/Wbem:/mnt/c/WINDOWS/System32/WindowsPowerShell/v1.0/:/mnt/c/Program Files (x86)/Intel/Intel(R) Management Engine Components/DAL:/mnt/c/Program Files/Intel/Intel(R) Management Engine Components/DAL:/mnt/c/Program Files (x86)/Intel/Intel(R) Management Engine Components/IPT:/mnt/c/Program Files/Intel/Intel(R) Management Engine Components/IPT:/mnt/c/Program Files/PuTTY/:/mnt/c/Program Files/Git/cmd:/mnt/c/Program Files (x86)/NVIDIA Corporation/PhysX/Common:/mnt/c/WINDOWS/system32:/mnt/c/WINDOWS:/mnt/c/WINDOWS/System32/Wbem:/mnt/c/WINDOWS/System32/WindowsPowerShell/v1.0/:/mnt/c/WINDOWS/System32/OpenSSH/:/mnt/c/Program Files/dotnet/:/mnt/c/Program Files (x86)/dotnet/:/mnt/c/Program Files (x86)/Windows Kits/10/Windows Performance Toolkit/:/mnt/c/Program Files (x86)/Windows Kits/10/Microsoft Application Virtualization/Sequencer/:/mnt/c/Program Files/Microsoft VS Code/bin:/mnt/c/ProgramData/chocolatey/bin:/mnt/c/Users/Thomas/AppData/Local/Microsoft/WindowsApps:/mnt/c/Users/Thomas/AppData/Local/GitHubDesktop/bin:/mnt/c/Users/Thomas/AppData/Local/Microsoft/WindowsApps:/mnt/c/Program Files (x86)/Nmap:/snap/bin
9 verbose lifecycle gladys@4.8.3~cypress: CWD: /home/terdieu/gladys-dev/requeteAPI/Gladys
10 silly lifecycle gladys@4.8.3~cypress: Args: [ '-c', 'run-p start:cypress cypress:open' ]
11 info lifecycle gladys@4.8.3~cypress: Failed to exec cypress script
12 verbose stack Error: gladys@4.8.3 cypress: `run-p start:cypress cypress:open`
12 verbose stack spawn ENOENT
12 verbose stack     at ChildProcess.<anonymous> (/usr/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:48:18)
12 verbose stack     at ChildProcess.emit (events.js:314:20)
12 verbose stack     at maybeClose (internal/child_process.js:1022:16)
12 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:287:5)
13 verbose pkgid gladys@4.8.3
14 verbose cwd /home/terdieu/gladys-dev/requeteAPI/Gladys
15 verbose Linux 5.10.102.1-microsoft-standard-WSL2
16 verbose argv "/usr/bin/node" "/usr/bin/npm" "run" "cypress"
17 verbose node v12.20.1
18 verbose npm  v6.14.10
19 error code ELIFECYCLE
20 error syscall spawn
21 error file sh
22 error errno ENOENT
23 error gladys@4.8.3 cypress: `run-p start:cypress cypress:open`
23 error spawn ENOENT
24 error Failed at the gladys@4.8.3 cypress script.
24 error This is probably not a problem with npm. There is likely additional logging output above.
25 verbose exit [ 1, true ]

Hola,
¿Has hecho npm install en la raíz de Gladys primero?

Instala nodejs v14 también :grin:

Voui :sweat_smile:, :smiling_face_with_tear:
Pero mejor preguntar ^^

¡Ah sí, en efecto, quizá no sea el caso! ¡Lo verifico!

Según el log estás en 12

Efectivamente ^^

Bueno, ya está hecho, entonces añade cosas, al menos intenta realmente lanzarlo ^^
Pero se bloquea ^^ - Lo miraré esta noche al llegar ^^ :

terdieu@DUBLEM-PC-01:~/gladys-dev/requeteAPI/Gladys[ExpandIconSelectionScenes !]$ npm run cypress

> gladys@4.8.3 cypress /home/terdieu/gladys-dev/requeteAPI/Gladys
> run-p start:cypress cypress:open


> gladys@4.8.3 cypress:open /home/terdieu/gladys-dev/requeteAPI/Gladys
> cd front && npm run cypress:open


> gladys@4.8.3 start:cypress /home/terdieu/gladys-dev/requeteAPI/Gladys
> run-p start-server:cypress start-front:cypress


> gladys-front@ cypress:open /home/terdieu/gladys-dev/requeteAPI/Gladys/front
> cypress open --config-file cypress/cypress.json


> gladys@4.8.3 start-server:cypress /home/terdieu/gladys-dev/requeteAPI/Gladys
> cd server && npm run cypress


> gladys@4.8.3 start-front:cypress /home/terdieu/gladys-dev/requeteAPI/Gladys
> cd front && npm run start:cypress


> gladys-server@ cypress /home/terdieu/gladys-dev/requeteAPI/Gladys/server
> npm run cypress:clean && npm run cypress:start


> gladys-front@ start:cypress /home/terdieu/gladys-dev/requeteAPI/Gladys/front
> cross-env DEMO_MODE=false WEBSOCKET_URL=ws://localhost:1443 LOCAL_API_URL=http://localhost:1443 npm start

It looks like this is your first time using Cypress: 6.9.1

  ⠹  Verifying Cypress can run /home/terdieu/.cache/Cypress/6.9.1/Cypress

> gladys-server@ cypress:clean /home/terdieu/gladys-dev/requeteAPI/Gladys/server
> npx rimraf ./gladys-cypress.db*


> gladys-front@ start /home/terdieu/gladys-dev/requeteAPI/Gladys/front
> per-env
  ⠴  Verifying Cypress can run /home/terdieu/.cache/Cypress/6.9.1/Cypress

> gladys-server@ cypress:start /home/terdieu/gladys-dev/requeteAPI/Gladys/server
> cross-env SQLITE_FILE_PATH=./gladys-cypress.db node index.js


> gladys-front@ start:development /home/terdieu/gladys-dev/requeteAPI/Gladys/front
> npm run -s dev
  ⠋  Verifying Cypress can run /home/terdieu/.cache/Cypress/6.9.1/Cypress
internal/modules/cjs/loader.js:1144
  return process.dlopen(module, path.toNamespacedPath(filename));
                 ^

Error: The module '/home/terdieu/gladys-dev/requeteAPI/Gladys/server/node_modules/node-webcrypto-ossl/build/Release/nodessl.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 72. This version of Node.js requires
NODE_MODULE_VERSION 83. Please try re-compiling or re-installing
the module (for instance, using `npm rebuild` or `npm install`).
    at Object.Module._extensions..node (internal/modules/cjs/loader.js:1144:18)
    at Module.load (internal/modules/cjs/loader.js:950:32)
    at Function.Module._load (internal/modules/cjs/loader.js:790:12)
    at Module.require (internal/modules/cjs/loader.js:974:19)
    at require (internal/modules/cjs/helpers.js:101:18)
    at Object.<anonymous> (/home/terdieu/gladys-dev/requeteAPI/Gladys/server/node_modules/node-webcrypto-ossl/buildjs/native.js:3:16)
    at Module._compile (internal/modules/cjs/loader.js:1085:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Module.load (internal/modules/cjs/loader.js:950:32)
    at Function.Module._load (internal/modules/cjs/loader.js:790:12)
    at Module.require (internal/modules/cjs/loader.js:974:19)
    at require (internal/modules/cjs/helpers.js:101:18)
    at Object.<anonymous> (/home/terdieu/gladys-dev/requeteAPI/Gladys/server/node_modules/node-webcrypto-ossl/buildjs/key_storage.js:8:16)
    at Module._compile (internal/modules/cjs/loader.js:1085:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Module.load (internal/modules/cjs/loader.js:950:32) {
  code: 'ERR_DLOPEN_FAILED'
}
npm ERR! code ELIFECYCLE
  ⠙  Verifying Cypress can run /home/terdieu/.cache/Cypress/6.9.1/Cypress
npm ERR! gladys-server@ cypress:start: `cross-env SQLITE_FILE_PATH=./gladys-cypress.db node index.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the gladys-server@ cypress:start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/terdieu/.npm/_logs/2022-04-13T04_06_38_053Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! gladys-server@ cypress: `npm run cypress:clean && npm run cypress:start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the gladys-server@ cypress script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/terdieu/.npm/_logs/2022-04-13T04_06_38_092Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! gladys@4.8.3 start-server:cypress: `cd server && npm run cypress`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the gladys@4.8.3 start-server:cypress script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/terdieu/.npm/_logs/2022-04-13T04_06_38_114Z-debug.log
  ⠹  Verifying Cypress can run /home/terdieu/.cache/Cypress/6.9.1/Cypress
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! gladys@4.8.3 start:cypress: `run-p start-server:cypress start-front:cypress`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the gladys@4.8.3 start:cypress script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/terdieu/.npm/_logs/2022-04-13T04_06_38_161Z-debug.log
ERROR: "start:cypress" exited with 1.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! gladys@4.8.3 cypress: `run-p start:cypress cypress:open`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the gladys@4.8.3 cypress script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/terdieu/.npm/_logs/2022-04-13T04_06_38_202Z-debug.log

¿No habrías puesto node 16 en lugar de 14? :smiley:

Mmmmh ni siquiera ^^
image
Es increíble cuando no funciona ^^ Tiene que haber una razón, pero …

Voy a revisar los logs a ver si hay alguna pista …

Sin embargo, debes ejecutar un npm rebuild si has cambiado la versión de Node (está escrito en los logs anteriores) porque los paquetes se instalaron con Node 12.