From 592569c8ae9f610b31d9b67f66b0d345ffb2b7d9 Mon Sep 17 00:00:00 2001 From: juliannyas Date: Mon, 5 Mar 2018 16:47:45 -0300 Subject: [PATCH] include script to run unit and integration tests together --- .gitignore | 1 - build-config-sample.cfg | 5 +-- build.sh | 10 +++--- cypress.json | 4 ++- cypress/integration/tainacan_spec.js | 7 ++++ cypress/plugins/index.js | 17 ++++++++++ cypress/support/index.js | 17 ++++++++++ run-cypress.sh | 49 ++++++++++++++++++++++++++++ run-tests.sh | 43 +++--------------------- 9 files changed, 106 insertions(+), 47 deletions(-) create mode 100644 cypress/integration/tainacan_spec.js create mode 100644 cypress/plugins/index.js create mode 100644 cypress/support/index.js create mode 100755 run-cypress.sh diff --git a/.gitignore b/.gitignore index 2372c5dbe..ccb9d0088 100644 --- a/.gitignore +++ b/.gitignore @@ -19,4 +19,3 @@ last-package-build.md5 src/admin/scss/.sass-cache src/assets/css/tainacan-admin.css src/assets/css/tainacan-admin.css.map -cypress \ No newline at end of file diff --git a/build-config-sample.cfg b/build-config-sample.cfg index 99d3fbedf..f3936b89c 100755 --- a/build-config-sample.cfg +++ b/build-config-sample.cfg @@ -1,4 +1,5 @@ # the destination folder, inside the plugins folder of some WordPress installation -destination=~/devel/wordpress/wp-content/plugins/tainacan + wp_base_dir=~/devel/wordpress -wp_url=http://localhost/wp \ No newline at end of file +wp_url=http://localhost/wordpress +wp_plugin_dir=~/devel/wordpress/wp-content/plugins/tainacan diff --git a/build.sh b/build.sh index 4da0a8945..4a51486fe 100755 --- a/build.sh +++ b/build.sh @@ -52,10 +52,10 @@ fi ### END npm build ### -echo "Updating files in $destination" -rm -rf $destination -mkdir $destination -cp -R src/* $destination/ -rm -rf $destination/scss +echo "Updating files in $wp_plugin_dir" +rm -rf $wp_plugin_dir +mkdir $wp_plugin_dir +cp -R src/* $wp_plugin_dir/ +rm -rf $wp_plugin_dir/scss echo "Build complete!" diff --git a/cypress.json b/cypress.json index 0967ef424..7a622b909 100644 --- a/cypress.json +++ b/cypress.json @@ -1 +1,3 @@ -{} +{ + "projectId": "tubzok" +} diff --git a/cypress/integration/tainacan_spec.js b/cypress/integration/tainacan_spec.js new file mode 100644 index 000000000..3138506b6 --- /dev/null +++ b/cypress/integration/tainacan_spec.js @@ -0,0 +1,7 @@ +describe('Tainacan Test', function () { + it('.should() - assert that is correct', function () { + cy.visit('http://localhost/wordpress/wp-admin') + cy.get('log').type('admin').should('have.value', 'amdin') + cy.get('pwd').type('root').should('have.value', 'root') + }) +}) diff --git a/cypress/plugins/index.js b/cypress/plugins/index.js new file mode 100644 index 000000000..fd170fba6 --- /dev/null +++ b/cypress/plugins/index.js @@ -0,0 +1,17 @@ +// *********************************************************** +// This example plugins/index.js can be used to load plugins +// +// You can change the location of this file or turn off loading +// the plugins file with the 'pluginsFile' configuration option. +// +// You can read more here: +// https://on.cypress.io/plugins-guide +// *********************************************************** + +// This function is called when a project is opened or re-opened (e.g. due to +// the project's config changing) + +module.exports = (on, config) => { + // `on` is used to hook into various events Cypress emits + // `config` is the resolved Cypress config +} diff --git a/cypress/support/index.js b/cypress/support/index.js new file mode 100644 index 000000000..4952e5b50 --- /dev/null +++ b/cypress/support/index.js @@ -0,0 +1,17 @@ +// *********************************************************** +// This example support/index.js is processed and +// loaded automatically before your test files. +// +// This is a great place to put global configuration and +// behavior that modifies Cypress. +// +// You can change the location of this file or turn off +// automatically serving support files with the +// 'supportFile' configuration option. +// +// You can read more here: +// https://on.cypress.io/configuration +// *********************************************************** + +// Alternatively you can use CommonJS syntax: +// require('./commands') diff --git a/run-cypress.sh b/run-cypress.sh new file mode 100755 index 000000000..768e940f4 --- /dev/null +++ b/run-cypress.sh @@ -0,0 +1,49 @@ +#!/bin/bash + +if [ $# - lt 2 ]; then + echo "usage: $0 [skip-head]" + exit 1 +fi + +SKIP_HEAD=${1-1} + +source build-config.cfg + +./build.sh + +plugin_name=`basename $wp_plugin_dir` +test_db_prefix='wptests_' + +################## set up cypress environment +# replace table prefix in wp_config +echo "Changing DB prefix in wp_config..." +sed -i s/"require_once(ABSPATH . 'wp-settings.php');"/"\$table_prefix = '$test_db_prefix';\nrequire_once(ABSPATH . 'wp-settings.php');"/ $wp_base_dir/wp-config.php + +# install WordPress +cd $wp_base_dir +echo "Installing WordPress..." +wp core install --url=$wp_url --title=Test --admin_user=admin --admin_password=admin --admin_email=admin@admin.com + +# Activate Tainacan +wp plugin activate $plugin_name + +# back to tainacan dev directory +cd - + +# cypress beginning +if [ ${SKIP_HEAD} = "0" ] +then + ./node_modules/.bin/cypress run +else + ./node_modules/.bin/cypress run --headed +fi + +################## teardown cypress environment +# remove WordPress +echo "Removing WordPress..." +cd $wp_base_dir +wp db query "DROP TABLES $(wp db tables | paste -s -d, -);" + +# recover table prefix in wp_config +echo "Restoring DB prefix in wp_config..." +sed -i s/"\$table_prefix = '$test_db_prefix';"/""/ $wp_base_dir/wp-config.php diff --git a/run-tests.sh b/run-tests.sh index 7d931f821..3b1b34dc6 100755 --- a/run-tests.sh +++ b/run-tests.sh @@ -1,41 +1,8 @@ #!/bin/bash -source build-config.cfg - -#./build.sh - - -plugin_name=`basename $destination` -test_db_prefix='wp_tainacan_test_' - - -################## set up cypress environment -# replace table prefix in wp_config -echo "Changing DB prefix in wp_config..." -sed -i s/"require_once(ABSPATH . 'wp-settings.php');"/"\$table_prefix = '$test_db_prefix';\nrequire_once(ABSPATH . 'wp-settings.php');"/ $wp_base_dir/wp-config.php - -# install WordPress -cd $wp_base_dir -echo "Installing WordPress..." -wp core install --url=$wp_url --title=Test --admin_user=admin --admin_password=admin --admin_email=admin@admin.com - -# Activate Tainacan -wp plugin activate $plugin_name - -# back to tainacan dev directory -cd - -#npx cypress run --env host=$wp_url,baseUrl=$wp_url - - - -################## teardown cypress environment - -# remove WordPress -echo "Removing WordPress..." -cd $wp_base_dir -wp db query "DROP TABLES $(wp db tables | paste -s -d, -);" - -# recover table prefix in wp_config -echo "Restoring DB prefix in wp_config..." -sed -i s/"\$table_prefix = '$test_db_prefix';"/""/ $wp_base_dir/wp-config.php +echo "Running unit tests in PHPUnit..." +phpunit +echo "Running integration tests headless in Crypess..." +# the value 0 leaves the cypress headless +./run-cypress.sh 0