quasar-testing
quasar-testing copied to clipboard
feat(cypress): Allow code coverage on builds
What kind of change does this PR introduce?
- Feature
Does this PR introduce a breaking change?
- No
The PR fulfills these requirements:
- It's submitted to the
dev
branch and not themaster
branch
Other information:
Sometimes it makes more sense to use quasar build
+quasar serve
instead of quasar dev
, especially with Vite to avoid timeouts due to compiling on the fly. I would say it's a best practice in CI pipelines because using the production build would yield results closer to the real production environment. One could even use their actual webserver instead of quasar serve
to also count it on the E2E tests. If you agree with any of these, I suppose we could add some information to the README file or even update the test:e2e:ci
script template.
So, anyways, vite-plugin-istanbul
doesn't include code coverage when building(_determined by the Vite mode, not NODE_ENV_
) by default. So, to run E2E tests with code coverage on builds, we would need to set forceBuildInstrument: true
.
I am classifying this as a feature, not a bug, because the scaffolded and recommended scripts use quasar dev
, in which code coverage works nicely.
It's fine for me, as it will only take place when using Vite and NODE_ENV is test
Not sure about changing the default CI command, IIRC I initially tried to make it work with quasar build + quasar serve
but dropped the idea due to problems with start-test
helper, but since then we managed to make it work in at least one of our projects with a command similar to
"test:e2e:ci": "cross-env NODE_ENV=test start-test \"quasar build && quasar serve\" http-get://localhost:<default Quasar serve port for Vite> \"cypress run\"",
We would need to test if this actually works and add a note on the README Has this problem been raised from the community somewhere?
Here is a somewhat simplified version of the script set I am using in the project I tried to get code coverage running on builds properly.
{
"test:e2e:ci": "cross-env NODE_ENV=test start http-get://localhost:9000 \"cypress run\"",
"start": "quasar build && yarn serve --silent -p 9000",
"serve": "quasar serve --history dist/spa"
}
It works properly(except for code coverage ofc). It can be simplified by falling back to the default port(4000), dropping the silent
flag(used for removing the unneeded noise in test outputs), inlining some scripts, etc. if need be.
Has this problem been raised from the community somewhere?
No, it was raised by me while working on a customer project.
I tried adding the quasar build
by default, but it would require adding a quasar serve
in the server setup command
Right now, unless we install @quasar/cli
locally and add some extra complexity to manage edge cases, this isn't really feasible while supporting all package managers
Right now it's a no-go, let's see if anything moves in the future