Cypress Frontend Tests

Hi @AlexTrovato :wave:

I tested the Cypress branch you developed today and it works well :slight_smile:
I started testing the front end of the Tp-Link service and I’m making good progress. The fixture/mock part of the backend calls is a bit more complex but it works too.
I think we really need to switch to TDD mode to write this kind of tests.

For the backend API part, do we want to test only the core? The rest (services) is too tied to the hardware so we want to mock everything, right?

I think there is a mistake between the doc and the command in the package.json to start the server for the Cypress tests (npm run start:cypress <= npm run cypress:start)

Thanks for the work :clap: and looking forward to seeing it in the CI and in the coverage :rocket:

Great news.

Yes, it will be simpler to set up our tests and also to validate our developments.

It would be good to test the core as much as possible. However, for interactions with devices, it’s complicated, so we need to try to mock only the WebServices calling the real services.
If we do it on a config page (like for Bluetooth and the scan frequency, which only records parameters in the database).

The npm run cypress:start script should not be in the root package.json file, and the documentation specifies that you need to be at the root of Gladys (neither on front nor on server).
(yes I know cypress:start vs start:cypress, I tried to follow the « logic » already in place, but everything is changeable :slight_smile: ).

With my PR, the CI already runs the tests (blocking in case of error), only the coverage is missing.

Thanks for trying, with @pierre-gilles we agreed that I should test the « react-select » component which is a bit particular (in order to provide the technique to apply), and let the community play with it before merging, then merge little by little, to avoid the tunnel effect (and I admit that working 5 days in a row on it, it’s tiring).

@AlexTrovato So do you think I can merge the Cypress PR soon? I think, as we discussed, we can merge it even if not everything is covered, that way at least the structure is on master and we can base further PRs on it to add coverage :slight_smile:

Yes, we can, if she passes, I’m not sure if I have a recent rebase.
We’ll play along with time, just as you say, that’s fine with me.

Hi !!

Sorry, I must not be good at it ^^ @AlexTrovato could you help me launch Cypress under WSL? Well, if there is a point that I did not understand or do…

  • I followed the documentation:
  • I then launched the server command:
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)
  • I then launched the front command:
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) building
Browserslist: 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) building
Browserslist: 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
  • And finally tried to launch Cypress (attempt from the front and the root of 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
  • I then tried to follow the link you provide in your slides:

But nothing works :smiling_face_with_tear: :smiling_face_with_tear:

Thanks in advance !!

I followed the WSL 2 procedure and it’s OK on my side

Oh no!^^

Have you launched xlaunch on Windows before?

Before cypress:open yes.

After that, I tried to restart the server and front end as well, but nothing. I have no client on Xlaunch. Any specific ports to open?

The only and unique root command npm run cypress :slight_smile:

image

Oops lol I followed the doc:

Well, however, it works even less with the only one ^^

And in the log file:

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 ]

Hello,
Did you run npm install at the root of Gladys first?

Install nodejs v14 too :grin:

Sure :sweat_smile:, :smiling_face_with_tear:
Better to ask ^^

Oh yes indeed that may not be the case… I’ll check it out!!

According to the log, you’re on 12

Indeed ^^

Well, it’s done, so it adds things, at least it really tries to launch ^^
But it crashes ^^ - I’ll check that this evening when I get home ^^:

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

Didn’t you mean to put node 16 instead of 14? :smiley:

Mmmmh not even ^^
image
It’s crazy when it doesn’t work ^^ There must be a reason but …
I’m going to sift through the logs to see if there’s a clue …

However, you need to run npm rebuild if you changed the Node.js version (it’s written in the previous logs) because the packages were installed under Node 12.