diff options
author | Zarino Zappia <mail@zarino.co.uk> | 2019-06-12 15:25:21 +0100 |
---|---|---|
committer | Matthew Somerville <matthew@mysociety.org> | 2019-06-14 15:19:02 +0100 |
commit | 9a96984a69aae12a9c047a78610b78b12b46f12a (patch) | |
tree | bd8088fd8fbc6b99be8162a496b9cedada77f36c /bin | |
parent | 586f8ee0e0cd629c9b7a24463775e30fd0b77e8a (diff) |
Fix front-end testing script when run with Vagrant
Noticed this week that it’s not been possible to run the cypress browser
tests when you have FMS running in a Vagrant VM (and the tests running
outside on the host) since the FMS Vagrant config was changed to use an
FMS-specific box.
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/browser-tests | 69 |
1 files changed, 37 insertions, 32 deletions
diff --git a/bin/browser-tests b/bin/browser-tests index 37f542c92..59bf970e9 100755 --- a/bin/browser-tests +++ b/bin/browser-tests @@ -2,40 +2,50 @@ use strict; use warnings; +use lib '.'; # For the mock MapIt module + +use Getopt::Long ':config' => qw(pass_through auto_help); + +my ($run_server, $run_cypress, $vagrant, $config_file); +my ($cobrand, $coords, $area_id, $name, $mapit_url); BEGIN { + $config_file = 'conf/general.yml-example'; + $cobrand = [ 'fixmystreet', 'northamptonshire', 'bathnes', 'buckinghamshire' ]; + $coords = '51.532851,-2.284277'; + $area_id = 2608; + $name = 'Borsetshire'; + $mapit_url = 'https://mapit.uk/'; + + GetOptions( + 'config=s' => \$config_file, + 'server' => \$run_server, + 'cypress' => \$run_cypress, + 'vagrant' => \$vagrant, + 'cobrand=s@' => \$cobrand, + 'coords=s' => \$coords, + 'area_id=s' => \$area_id, + 'name=s' => \$name, + 'mapit_url=s' => \$mapit_url, + ); + $cobrand = [ split(',', join(',', @$cobrand)) ]; + + if (!$run_server && !$run_cypress) { + # If asked for neither, run both + $run_server = $run_cypress = 1; + } + use File::Basename qw(dirname); use File::Spec; my $d = dirname(File::Spec->rel2abs($0)); - require "$d/../setenv.pl"; + if (!$vagrant && $run_server) { + require "$d/../setenv.pl"; + } } -use Getopt::Long ':config' => qw(pass_through auto_help); - -my ($run_server, $run_cypress, $vagrant); -my $config_file = 'conf/general.yml-example'; -my $cobrand = [ 'fixmystreet', 'northamptonshire', 'bathnes', 'buckinghamshire' ]; -my $coords = '51.532851,-2.284277'; -my $area_id = 2608; -my $name = 'Borsetshire'; -my $mapit_url = 'https://mapit.uk/'; - -GetOptions( - 'config=s' => \$config_file, - 'server' => \$run_server, - 'cypress' => \$run_cypress, - 'vagrant' => \$vagrant, - 'cobrand=s@' => \$cobrand, - 'coords=s' => \$coords, - 'area_id=s' => \$area_id, - 'name=s' => \$name, - 'mapit_url=s' => \$mapit_url, -); -$cobrand = [ split(',', join(',', @$cobrand)) ]; - if ($vagrant) { # Test inception - system('vagrant ssh -c "cd fixmystreet && bin/browser-tests --server 2>/dev/null" &'); + system('vagrant ssh -- "cd fixmystreet && bin/browser-tests --server 2>/dev/null" &'); require IO::Socket; sub check_connection { @@ -53,15 +63,10 @@ if ($vagrant) { } print " done\n"; system('bin/browser-tests', '--cypress', @ARGV); - system('vagrant', 'ssh', '-c', 'kill $(cat /tmp/cypress-server.pid)'); + system('vagrant', 'ssh', '--', 'kill $(cat /tmp/cypress-server.pid)'); exit; } -if (!$run_server && !$run_cypress) { - # If asked for neither, run both - $run_server = $run_cypress = 1; -} - sub run { my $cmd = shift @ARGV; die "Must specify a cypress command\n" unless $cmd || !$run_cypress; @@ -95,7 +100,7 @@ sub run { kill 'TERM', $pid if $pid; exit $exit >> 8; } else { - use Test::MockModule; + require Test::MockModule; my $c = Test::MockModule->new('FixMyStreet::Cobrand::FixMyStreet'); $c->mock('enable_category_groups', sub { 1 }); # Child, run the server on port 3001 |