Skip to content

Commit

Permalink
Merge pull request #2281 from 10up/tests/issue-2280
Browse files Browse the repository at this point in the history
Fix WP Acceptance tests
Rahmon authored Jul 30, 2021
2 parents d0099bc + b48103f commit 4707033
Showing 4 changed files with 18 additions and 19 deletions.
15 changes: 11 additions & 4 deletions run-wpacceptance.sh
Original file line number Diff line number Diff line change
@@ -57,15 +57,20 @@ http.cors.allow-methods : OPTIONS, HEAD, GET, POST, PUT, DELETE
http.cors.allow-headers : X-Requested-With,X-Auth-Token,Content-Type, Content-Length
EOT

docker run \
docker container inspect -f '{{.State.Running}}' ep_wpa_es_server || docker run \
-d \
-v "$(pwd)/wpa-elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml:cached" \
-p 9200:9200 -p 9300:9300 \
-e "xpack.security.enabled=false" \
-e "discovery.type=single-node" \
-e "ES_JAVA_OPTS=-Xms512m -Xmx512m" \
--name "ep_wpa_es_server" \
docker.elastic.co/elasticsearch/elasticsearch:5.6.16

docker exec -u root -i ep_wpa_es_server chown -R elasticsearch: plugins
docker exec -i ep_wpa_es_server bin/elasticsearch-plugin install ingest-attachment -b
docker restart ep_wpa_es_server

EP_HOST="http://host.docker.internal:9200/"
fi

@@ -104,16 +109,18 @@ REAL_FAILED_ATTEMPTS=0

for i in $(seq 1 $ATTEMPTS); do

TEST_OUTPUT=$(./vendor/bin/wpacceptance run --cache_environment --screenshot_on_failure)
TEST_OUTPUT=$(mktemp)

set -o pipefail
./vendor/bin/wpacceptance run --cache_environment --screenshot_on_failure | tee ${TEST_OUTPUT}

EXIT_CODE=$?

echo "${TEST_OUTPUT}"

if [ $EXIT_CODE -ge 1 ]; then

# List of errors for this specific attempt.
SUMMARY=$(echo "${TEST_OUTPUT}" | sed -e '/Summary of non-successful tests:/,//!d')
SUMMARY=$(sed -e '/Summary of non-successful tests:/,//!d' ${TEST_OUTPUT})

# Count all errors
TOTAL_ERRORS_COUNT=$(echo "${SUMMARY}" | grep '' | wc -l )
12 changes: 0 additions & 12 deletions tests/wpa/features/DocumentTest.php
Original file line number Diff line number Diff line change
@@ -17,10 +17,6 @@ public function testSearchPdf() {

$I->loginAs( 'wpsnapshots' );

if ( ! $this->isElasticPressIo() ) {
$this->markTestSkipped( 'Skipped while not using EP.io' );
}

$this->activateDocumentFeature( $I );

$I->moveTo( '/wp-admin/admin.php?page=elasticpress' );
@@ -44,10 +40,6 @@ public function testSearchPttx() {

$I->loginAs( 'wpsnapshots' );

if ( ! $this->isElasticPressIo() ) {
$this->markTestSkipped( 'Skipped while not using EP.io' );
}

$this->maybeSync( $I );

$this->activateDocumentFeature( $I );
@@ -67,10 +59,6 @@ public function testSearchPdfAfterCliIndexSetup() {

$I->loginAs( 'wpsnapshots' );

if ( ! $this->isElasticPressIo() ) {
$this->markTestSkipped( 'Skipped while not using EP.io' );
}

$this->activateDocumentFeature( $I );

$this->runCommand( 'wp elasticpress index --setup --yes' );
6 changes: 5 additions & 1 deletion tests/wpa/features/RelatedPostsTest.php
Original file line number Diff line number Diff line change
@@ -102,6 +102,8 @@ public function testSeeRelatedPostsWidgetIfActivated() {
* @testdox I can see the related posts widget.
*/
public function testRelatedPostsWidget() {
$this->maybeEnableFeature( 'related_posts' );

$I = $this->openBrowserPage();

$I->loginAs( 'wpsnapshots' );
@@ -118,9 +120,11 @@ public function testRelatedPostsWidget() {

$I->typeInField( 'input[name^="widget-ep-related-posts"]', 'Related Posts' );

sleep( 2 );

$I->click( ".edit-widgets-header__actions .components-button.is-primary" );

usleep( 1000000 );
$I->waitUntilPageSourceContains( 'Widgets saved.' );

$posts_data = [
[
4 changes: 2 additions & 2 deletions tests/wpa/inc/TestBase.php
Original file line number Diff line number Diff line change
@@ -197,7 +197,7 @@ public function publishPost( array $data, \WPAcceptance\PHPUnit\Actor $actor ) {
$actor->moveTo( 'wp-admin/post-new.php' );

try {
$actor->click( '.nux-dot-tip__disable' );
$actor->click( '.edit-post-welcome-guide .components-modal__header button' );
} catch ( \Exception $e ) {
// Do nothing
}
@@ -352,7 +352,7 @@ public function setPerIndexCycle( int $number, \WPAcceptance\PHPUnit\Actor $acto
* @param string $feature Feature slug.
*/
public function maybeEnableFeature( $feature ) {
$cli_result = $this->runCommand( "wp elasticpress list-features {$feature}" )['stdout'];
$cli_result = $this->runCommand( 'wp elasticpress list-features' )['stdout'];
if ( false === strpos( $cli_result, $feature ) ) {
$this->runCommand( "wp elasticpress activate-feature {$feature}" );
}

0 comments on commit 4707033

Please sign in to comment.