Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

Fixes #787: Re-introduce PhantomJS along side Selenium. #839

Merged
merged 8 commits into from
Dec 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions bin/blt-console
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env php
<?php

use Acquia\Blt\Console\Command\ConfigurePhantomJsCommand;
use Acquia\Blt\Console\Command\ComposerMungeCommand;
use Acquia\Blt\Console\Command\YamlMungeCommand;
use Acquia\Blt\Console\Command\UpdateCommand;
Expand All @@ -23,6 +24,7 @@ else {
}

$application = new Application();
$application->add(new ConfigurePhantomJsCommand());
$application->add(new ComposerMungeCommand());
$application->add(new YamlMungeCommand());
$application->add(new UpdateCommand());
Expand Down
2 changes: 2 additions & 0 deletions phing/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ behat:
server-url: http://127.0.0.1:8888
# If true, Selenium standalone server will be launched with Behat.
launch-selenium: true
# If true, PhantomJS GhostDriver will be launched with Behat.
launch-phantomjs: false
# An array of paths with behat tests that should be executed.
paths:
# - ${docroot}/modules
Expand Down
91 changes: 87 additions & 4 deletions phing/tasks/tests.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,28 @@

<!-- If you experience 'Maximum function nesting level' errors in your PHP
error log, set 'xdebug.max_nesting_level=1000' in php.ini. -->
<target name="tests:behat" depends="test:behat:check, tests:run-server, tests:selenium:launch" description="Executes Behat all behat tests in behat.paths.">
<target name="tests:behat" depends="test:behat:check, tests:run-server" description="Executes Behat all behat tests in behat.paths.">

<phingcall target="tests:selenium:kill"/>
<phingcall target="tests:phantomjs:kill"/>

<if>
<equals arg1="${behat.launch-phantomjs}" arg2="true"/>
<then>
<phingcall target="tests:phantomjs:launch"/>
</then>
</if>
<if>
<equals arg1="${behat.launch-selenium}" arg2="true"/>
<then>
<phingcall target="tests:selenium:launch"/>
</then>
</if>

<mkdir dir="${reports.localDir}/behat"/>
<foreach list="${behat.paths}" target="tests:behat:execute" param="behat.path"/>
<phingcall target="tests:selenium:kill"/>
<phingcall target="tests:phantomjs:kill"/>
</target>

<target name="test:behat:check" description="Checks Behat configuration" hidden="true" depends="setup:behat">
Expand Down Expand Up @@ -89,6 +107,7 @@
<not><equals arg1="${behatPass}" arg2="0"/></not>
<then>
<phingcall target="tests:selenium:kill"/>
<phingcall target="tests:phantomjs:kill"/>
<fail message="One or more Behat tests failed." />
</then>
<else>
Expand Down Expand Up @@ -129,9 +148,7 @@
<if>
<equals arg1="${selenium.timedout}" arg2="true"/>
<then>
<fail>
Unable to start Selenium2 standalone server on http://127.0.0.1:4444/wd/hub.
</fail>
<fail>Unable to start Selenium2 standalone server on http://127.0.0.1:4444/wd/hub.</fail>
</then>
</if>
</then>
Expand All @@ -148,6 +165,72 @@
<exec command="pgrep selenium | xargs kill" logoutput="false" level="${blt.exec_level}" passthru="false" checkreturn="false" />
</target>

<target name="tests:phantomjs:launch"
description="Launches a GhostDriver."
hidden="true">

<exec dir="${repo.root}" command="grep 'jakoch/phantomjs-installer' composer.json" logoutput="false" level="${blt.exec_level}" passthru="false" returnProperty="phantom.required"/>
<if>
<isfailure code="${phantom.required}"/>
<then>
<echo level="Warning">behat.launch-phantomjs is true, but jakoch/phantomjs-installer is not required in composer.json.</echo>
<propertyprompt promptText="Do you want to require jakoch/phantomjs-installer via Composer?" propertyName="phantom.do-require" defaultValue="y"/>
<if>
<equals arg1="${phantom.do-require}" arg2="y" casesensitive="false"/>
<then>
<exec dir="${repo.root}" command="composer require jakoch/phantomjs-installer --dev" logoutput="true" level="${blt.exec_level}" passthru="true" />
</then>
<else>
<fail>Cannot launch PhantomJS it is not installed.</fail>
</else>
</if>
</then>
</if>
<exec dir="${repo.root}" command="grep installPhantomJS composer.json" logoutput="false" level="${blt.exec_level}" passthru="false" returnProperty="phantom.scripts"/>
<if>
<isfailure code="${phantom.scripts}"/>
<then>
<echo level="warning">behat.launch-phantomjs is true, but the install-phantomjs script is not defined in composer.json.</echo>
<propertyprompt promptText="Do you want to add an 'install-phantomjs' script to your composer.json?" propertyName="phantom.do-add-script" defaultValue="y"/>
<if>
<equals arg1="${phantom.do-add-script}" arg2="y" casesensitive="false"/>
<then>
<exec command="${composer.bin}/blt-console configure:phantomjs ${repo.root}" logoutput="true" level="${blt.exec_level}" passthru="false" checkreturn="true"/>
</then>
<else>
<fail>Cannot launch PhantomJS because the install-phantomjs script is not present in composer.json. Add it, or use Selenium instead.</fail>
</else>
</if>
</then>
</if>
<if>
<not><available file="${composer.bin}/phantomjs"/></not>
<then>
<exec dir="${repo.root}" command="composer install-phantom" checkreturn="true" logoutput="true" passthru="true" level="${blt.exec_level}"/>
</then>
</if>

<echo message="Launching PhantomJS GhostDriver." />
<phingcall target="tests:phantomjs:kill"/>
<exec command="${composer.bin}/phantomjs --webdriver=4444"
passthru="true"
spawn="true"
checkreturn="true"
level="${blt.exec_level}"/>
<echo message="Waiting 10 seconds for PhantomJS (http://127.0.0.1:4444) to become available."/>
<waitfor maxwait="10" maxwaitunit="second" checkevery="1" checkeveryunit="second">
<http url="http://127.0.0.1:4444/wd/hub"/>
</waitfor>

</target>

<target name="tests:phantomjs:kill"
description="Launches a GhostDriver." hidden="true">
<echo>Killing any PhantomJS processes that are already running.</echo>
<exec command="lsof -ti tcp:4444 | xargs kill" logoutput="false" level="${blt.exec_level}" passthru="false" checkreturn="false" />
<exec command="pgrep phantomjs | xargs kill" logoutput="true" level="${blt.exec_level}" passthru="true" />
</target>

<!-- Execute PHPUnit tests. -->
<target name="tests:phpunit" description="Executes PHPUnit tests against custom code.">
<delete dir="${reports.localDir}/phpunit" quiet="true"/>
Expand Down
2 changes: 2 additions & 0 deletions readme/ci.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ To initialize Pipelines support for your BLT project:

curl -o pipelines https://cloud.acquia.com/pipeline-client/download
chmod a+x pipelines
# Move to a location specified in $PATH. E.g.,
mv pipelines /usr/local/bin

1. [Configure the Pipelines client](https://docs.acquia.com/pipelines/install#authenticate)
1. Initialize Pipelines for your project
Expand Down
2 changes: 1 addition & 1 deletion scripts/pipelines/acquia-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ events:
# The local.hostname must be set to 127.0.0.1:8888 because we are using drush runserver to test the site.
- drupal init
- drupal yaml:update:value blt/project.yml project.local.hostname '127.0.0.1:8888'
- blt -Dbehat.run-server=true -Dcreate_alias=false -Dbehat.launch-selenium=false -Dbehat.tags='~javascript&&~experimental&&~lightningextension' -Dblt.verbose=true ci:build:validate:test
- blt -Dbehat.run-server=true -Dcreate_alias=false -Dbehat.launch-selenium=false -Dbehat.launch-phantomjs=true -Dbehat.tags='~experimental&&~lightningextension' -Dblt.verbose=true ci:build:validate:test

# Generate
- prepare-artifact:
Expand Down
36 changes: 36 additions & 0 deletions src/Console/Command/ConfigurePhantomJsCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace Acquia\Blt\Console\Command;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

class ConfigurePhantomJsCommand extends Command
{
protected function configure()
{
$this
->setName('configure:phantomjs')
->setDescription('Configure PhantomJs')
->addArgument(
'repo-root',
InputArgument::REQUIRED,
'The root directory for the repository.'
)
;
}

protected function execute(InputInterface $input, OutputInterface $output)
{
$repo_root = $input->getArgument('repo-root');
$composer_json = json_decode(file_get_contents($repo_root . '/composer.json'), TRUE);
$composer_json['scripts']['install-phantomjs'] = [
"rm -rf vendor/bin/phantomjs",
"PhantomInstaller\\Installer::installPhantomJS",
];
file_put_contents($repo_root . '/composer.json', json_encode($composer_json, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
}
}
7 changes: 6 additions & 1 deletion template/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"drupal/drupal-extension": "^3.2",
"drupal-composer/drupal-scaffold": "^2.1.0",
"jarnaiz/behat-junit-formatter": "^1.3.2",
"se/selenium-server-standalone": "^2.53"
"se/selenium-server-standalone": "^2.53",
"jakoch/phantomjs-installer": "^2.1.1-p07"
},
"autoload-dev": {
"psr-4": {
Expand Down Expand Up @@ -80,6 +81,10 @@
"rm -rf vendor composer.lock",
"@composer clearcache",
"@composer install"
],
"install-phantomjs": [
"rm -rf vendor/bin/phantomjs",
"PhantomInstaller\\Installer::installPhantomJS"
]
},
"minimum-stability": "dev",
Expand Down