Skip to content

Commit

Permalink
Set up Cypress e2e testing in CI (#1677)
Browse files Browse the repository at this point in the history
[Cypress](https://www.cypress.io) can now be used for e2e testing. We
should begin converting our Selenium and Protractor tests to Cypress
since Selenium is becoming outdated, and Protractor has been EOL for
some time.

This PR only includes a single example "spec" file. Future PRs will add
real test cases and eliminate the example spec file.

I also performed a light refactor of our CTest test structure. It would
be a good idea to take a closer look at our CTest setup in the future.
  • Loading branch information
williamjallen authored Dec 13, 2023
1 parent c062f14 commit 5871f3d
Show file tree
Hide file tree
Showing 15 changed files with 1,455 additions and 309 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ vendor/*
public/laravel/*
public/build/*
_build/*
cypress_cache/*
resources/js/components/shared/TextMutator.js
resources/js/components/shared/QueryParams.js
resources/js/components/shared/ApiLoader.js
Expand Down
17 changes: 17 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,27 @@ endif()

find_program(PHP_EXE NAMES php PATHS c:/xampp/php /xampp/php)

find_program(NPX_EXE NAMES npx PATHS c:/usr/bin/npx /usr/bin/npx)

if(CDASH_USE_SELENIUM)
find_program(PHPUNIT_EXE NAMES phpunit PATHS c:/xampp/php /xampp/php vendor/bin)
endif(CDASH_USE_SELENIUM)

set_property(GLOBAL PROPERTY INSTALL_CDASH_COUNT "0")
function(cdash_install)
get_property(OLD_COUNT GLOBAL PROPERTY INSTALL_CDASH_COUNT)
MATH(EXPR NEW_COUNT "${OLD_COUNT}+1")
set_property(GLOBAL PROPERTY INSTALL_CDASH_COUNT "${NEW_COUNT}")
add_test(
NAME install_${NEW_COUNT}
COMMAND ${PHP_EXE} ${testing_dir}/singletest.php ${testing_dir}/test_install.php
)
set_tests_properties(
install_${NEW_COUNT} PROPERTIES
FAIL_REGULAR_EXPRESSION ".*Failures: [1-9]+.*;.*Exceptions: [1-9]+.*"
)
endfunction(cdash_install)

# add the new tests directory
add_subdirectory(tests)

Expand Down
41 changes: 6 additions & 35 deletions app/cdash/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,7 @@ function(add_php_test TestName)
FAIL_REGULAR_EXPRESSION ".*Failures: [1-9]+.*;.*Exceptions: [1-9]+.*"
)
endfunction(add_php_test)
function(add_configured_php_test TestName)
add_test(
NAME ${TestName}
COMMAND ${PHP_EXE} ${testing_dir}/singletest.php ${binary_testing_dir}/test_${TestName}.php
)
set_tests_properties(
${TestName} PROPERTIES
FAIL_REGULAR_EXPRESSION ".*Failures: [1-9]+.*;.*Exceptions: [1-9]+.*"
)
endfunction(add_configured_php_test)

function(add_unit_test TestName)
add_test(
NAME ${TestName}
Expand All @@ -43,29 +34,9 @@ if (CDASH_CONFIGURE_HTACCESS_FILE)
set(phpunit_extra_arg "-d auto_prepend_file=${CMAKE_BINARY_DIR}/prepend_coverage.php")
endif()

add_test(
NAME php_style_check
COMMAND ${CMAKE_SOURCE_DIR}/vendor/bin/php-cs-fixer fix --dry-run
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})

# Run PHPStan static analysis tool
add_test(
NAME php_static_analysis
# Giving PHPStan 2GB of memory makes it run faster, and should be well inside the limits of the CI machines
COMMAND ${CMAKE_SOURCE_DIR}/vendor/bin/phpstan analyse --memory-limit=2G
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)

# Run the JS linter
add_test(
NAME eslint
COMMAND npm run eslint
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)

add_laravel_test(/Unit/app/ControllerNameTest)

add_php_test(install)
cdash_install()
add_laravel_test(/Unit/app/Validators/PasswordTest)
add_laravel_test(/Feature/CDashTest)
add_laravel_test(/Feature/LdapAuthWithRulesTest)
Expand Down Expand Up @@ -119,14 +90,13 @@ add_unit_test(/CDash/XmlHandler/TestingHandler)
add_unit_test(/CDash/XmlHandler/UpdateHandler)

add_laravel_test(/Feature/PurgeUnusedProjectsCommand)

add_laravel_test(/Feature/TestSchemaMigration)
add_laravel_test(/Feature/MeasurementPositionMigration)
add_laravel_test(/Feature/RemoveMeasurementCheckboxesMigration)
add_laravel_test(/Feature/IncreaseSiteInformationCPUColumnsSizeMigration)
add_php_test(install_into_empty_db)

cdash_install()
add_php_test(registeruser)
add_php_test(reinstall)
add_php_test(compressedtest)
add_php_test(createpublicdashboard)
add_php_test(email)
Expand Down Expand Up @@ -266,4 +236,5 @@ add_laravel_test(/Feature/AutoRemoveBuildsCommand)
# Slow tests that need more time in CI.
set_tests_properties(
actualtrilinossubmission
PROPERTIES TIMEOUT 1800)
PROPERTIES TIMEOUT 1800
)
16 changes: 0 additions & 16 deletions app/cdash/tests/test_install_into_empty_db.php

This file was deleted.

2 changes: 0 additions & 2 deletions app/cdash/tests/test_reinstall.php

This file was deleted.

18 changes: 18 additions & 0 deletions cypress.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const { defineConfig } = require('cypress');

module.exports = defineConfig({
fixturesFolder: 'tests/cypress/fixtures',
screenshotsFolder: 'tests/cypress/screenshots',
videosFolder: 'tests/cypress/videos',
downloadsFolder: 'tests/cypress/downloads',
pageLoadTimeout: 300000,
e2e: {
setupNodeEvents(on, config) {
// implement node event listeners here
},
baseUrl: 'http://localhost:8080',
specPattern: 'tests/cypress/e2e/**/*.cy.{js,jsx,ts,tsx}',
supportFile: 'tests/cypress/support/e2e.js',
experimentalStudio: true,
},
});
12 changes: 11 additions & 1 deletion docker/cdash.docker
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ RUN apt-get update \
RUN if [ "$DEVELOPMENT_BUILD" = '1' ]; then \
apt-get update \
&& apt-get install -y cmake rsync \
`# Cypress dependencies` \
&& apt-get install -y libgtk2.0-0 libgtk-3-0 libgbm-dev libnotify-dev \
libgconf-2-4 libnss3 libxss1 libasound2 libxtst6 xauth xvfb \
&& mkdir /tmp/.X11-unix \
&& chmod 1777 /tmp/.X11-unix \
&& chown root /tmp/.X11-unix/ \
&& mkdir -p /var/www/.cache/mesa_shader_cache \
&& pecl install xdebug \
&& docker-php-ext-enable xdebug; \
fi
Expand Down Expand Up @@ -109,10 +116,13 @@ RUN if [ "$DEVELOPMENT_BUILD" = '1' ]; then \
-DCDASH_SERVER=localhost:8080 \
-DCDASH_SELENIUM_HUB=selenium-hub \
-DCTEST_UPDATE_VERSION_ONLY=1 .. \
&& cp /cdash/.env.dev /cdash/.env; \
&& export CYPRESS_CACHE_FOLDER=/cdash/cypress_cache \
&& npm install \
&& cp /cdash/.env.dev /cdash/.env; \
else \
composer install --no-interaction --no-progress --prefer-dist --no-dev \
--optimize-autoloader \
&& npm install --omit=dev \
&& echo "LOG_CHANNEL=stderr" >> .env; \
fi

Expand Down
2 changes: 2 additions & 0 deletions docker/docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ services:
build:
args:
DEVELOPMENT_BUILD: 1
environment:
CYPRESS_CACHE_FOLDER: /cdash/cypress_cache
volumes:
- ..:/cdash_src:ro

Expand Down
Loading

0 comments on commit 5871f3d

Please sign in to comment.