diff --git a/cypress_test/.gitignore b/cypress_test/.gitignore index 0b6b5b539a..4b22d66562 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 a4bf5ae4a4..fc0be504a8 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 9f86196c0f..9fd00f4463 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 78ea17d251..eb18371209 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')()