[Libreoffice-commits] online.git: cypress_test/.gitignore cypress_test/Makefile.am cypress_test/plugins cypress_test/README
Tamás Zolnai (via logerrit)
logerrit at kemper.freedesktop.org
Thu Jun 25 11:28:12 UTC 2020
cypress_test/.gitignore | 2 ++
cypress_test/Makefile.am | 29 ++++++++++++++++++++++++++---
cypress_test/README | 20 ++++++++++++++++++++
cypress_test/plugins/index.js | 2 ++
4 files changed, 50 insertions(+), 3 deletions(-)
New commits:
commit 9ac9bc8be4cf89d6e0eb3c0bd19acd0557d1fa36
Author: Tamás Zolnai <tamas.zolnai at collabora.com>
AuthorDate: Wed Jun 24 12:50:29 2020 +0200
Commit: Tamás Zolnai <tamas.zolnai at collabora.com>
CommitDate: Thu Jun 25 13:27:53 2020 +0200
cypress: add initial code coverage support.
It's not optimal now, beacuse it changes source files.
Change-Id: I01cfb0be37eb0ef21dd1d606d9260b455a1cd585
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/97036
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
Tested-by: Jenkins
Reviewed-by: Tamás Zolnai <tamas.zolnai at collabora.com>
diff --git a/cypress_test/.gitignore b/cypress_test/.gitignore
index 0b6b5b539..4b22d6656 100644
--- a/cypress_test/.gitignore
+++ b/cypress_test/.gitignore
@@ -3,3 +3,5 @@ cypress
package-lock.json
workdir
support/commands.js
+coverage
+.nyc_output
diff --git a/cypress_test/Makefile.am b/cypress_test/Makefile.am
index a4bf5ae4a..fc0be504a 100644
--- a/cypress_test/Makefile.am
+++ b/cypress_test/Makefile.am
@@ -12,7 +12,8 @@ NPM_INSTALLED = $(abs_builddir)/workdir/npm_installed
PID_FILE=$(abs_builddir)/workdir/loolwsd.pid
ERROR_LOG=$(abs_builddir)/workdir/error.log
-SUPPORT_FILE = $(if $(findstring $(abs_srcdir),$(abs_builddir)),support/index.js,$(abs_srcdir)/support/index.js)
+SUPPORT_FILE_ABS = $(abs_srcdir)/support/index.js
+SUPPORT_FILE = $(if $(findstring $(abs_srcdir),$(abs_builddir)),support/index.js,$(SUPPORT_FILE_ABS))
DESKTOP_USER_AGENT = "cypress"
DESKTOP_TEST_FOLDER = $(abs_srcdir)/integration_tests/desktop
@@ -35,6 +36,8 @@ export DISPLAY=$(if $(HEADLESS_BUILD),:$(DISPLAY_NUMBER),$(shell echo $$DISPLAY)
CORE_VERSION := $(shell "@LO_PATH@"/program/soffice.bin --version 2> /dev/null)
+COMMA :=,
+
if ENABLE_DEBUG
FILTER_DEBUG=cypress:electron,cypress:launcher
export DEBUG=$(if $(ENABLE_LOGGING),$(FILTER_DEBUG),)
@@ -122,6 +125,24 @@ run-mobile: @JAILS_PATH@ $(NODE_BINS)
|| true
@$(KILL_COMMAND) || true
+run-cov: @JAILS_PATH@ $(NODE_BINS)
+ @echo
+ @echo "Setup coverage tools..."
+ @echo
+ rm -rf .nyc_output
+ rm -rf coverage
+ npm install @cypress/code-coverage --no-save
+ @echo "import '@cypress/code-coverage/support';" >> $(SUPPORT_FILE_ABS)
+ @echo "" >> $(SUPPORT_FILE_ABS)
+ cd .. && npx nyc instrument --compact=false loleaflet/dist/src --in-place && cd cypress_test
+ @echo
+ @echo "Run all tests..."
+ @echo
+ $(call start_loolwsd)
+ $(call run_desktop_tests,,COVERAGE_RUN="1")
+ $(call run_mobile_tests,,COVERAGE_RUN="1")
+ @$(KILL_COMMAND) || true
+
define run_JS_error_check
@echo "Checking for JS errors in test code..."
@echo
@@ -186,7 +207,7 @@ define run_desktop_tests
$(CYPRESS_BINARY) run \
--browser $(CHROME) \
--headless \
- $(DESKTOP_CONFIG) \
+ $(DESKTOP_CONFIG)$(if $(2),$(COMMA)$(2),) \
$(if $(1), --spec=$(abs_dir)/integration_tests/desktop/$(1)) \
$(if $(PARALLEL_BUILD),,|| ($(KILL_COMMAND) && false)))
$(if $(PARALLEL_BUILD),\
@@ -203,7 +224,7 @@ define run_mobile_tests
$(CYPRESS_BINARY) run \
--browser $(CHROME) \
--headless \
- $(MOBILE_CONFIG) \
+ $(MOBILE_CONFIG)$(if $(2),$(COMMA)$(2),) \
$(if $(1), --spec=$(abs_dir)/integration_tests/mobile/$(1)) \
$(if $(PARALLEL_BUILD),,|| ($(KILL_COMMAND) && false)))
$(if $(PARALLEL_BUILD),\
@@ -263,4 +284,6 @@ clean-local:
rm -rf workdir
rm -rf cypress
rm -rf package-lock.json
+ rm -rf .nyc_output
+ rm -rf coverage
endif
diff --git a/cypress_test/README b/cypress_test/README
index 9f86196c0..9fd00f446 100644
--- a/cypress_test/README
+++ b/cypress_test/README
@@ -128,3 +128,23 @@ is different from the source directory. So to avoid this
issue with the supportFile, you should build in the source
directory or you should avoid symlinks in the path of the
build directory.
+
+Code coverage
+------------
+
+We use nyc to instrument the code and then cypress code coverage
+plugin is used to generate coverage numbers. This workflow
+is called by the following command:
+
+ make run-cov
+
+The output is put under cypress_test/covarage folder.
+Open the cypress_test/covarage/lcov-report/index.html
+file to get the summary report.
+
+The make command above touches the source files under
+loleaflet/dist/src folder, so after testing the coverage
+doing a clean build is a good idea (e.g. make clean).
+
+See also this link:
+https://docs.cypress.io/guides/tooling/code-coverage.html
diff --git a/cypress_test/plugins/index.js b/cypress_test/plugins/index.js
index 78ea17d25..eb1837120 100644
--- a/cypress_test/plugins/index.js
+++ b/cypress_test/plugins/index.js
@@ -6,6 +6,8 @@ var blacklists = require('./blacklists');
var selectTests = require('cypress-select-tests');
function plugin(on, config) {
+ if (config.env.COVERAGE_RUN)
+ require('@cypress/code-coverage/task')(on, config);
on('task', {
copyFile: tasks.copyFile,
failed: require('cypress-failed-log/src/failed')()
More information about the Libreoffice-commits
mailing list