diff options
author | Marius Halden <marius.h@lden.org> | 2020-09-29 14:23:52 +0200 |
---|---|---|
committer | Marius Halden <marius.h@lden.org> | 2020-09-29 14:23:52 +0200 |
commit | a27ce1524d801d2742a2bdb6ec1da45126d64353 (patch) | |
tree | 64123c4e17dc1776aa0a7cd65ee01d49d3e7d978 /bin/browser-tests | |
parent | 377bd96aab7cad3434185c30eb908c9da447fe40 (diff) | |
parent | 2773c60226b9370fe8ee00f7b205b571bb87c3b5 (diff) |
Merge tag 'v3.0.1' into fiksgatami-dev
Diffstat (limited to 'bin/browser-tests')
-rwxr-xr-x | bin/browser-tests | 101 |
1 files changed, 62 insertions, 39 deletions
diff --git a/bin/browser-tests b/bin/browser-tests index c663e56af..c7e5df27c 100755 --- a/bin/browser-tests +++ b/bin/browser-tests @@ -2,39 +2,58 @@ 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, $wsl, $node, $config_file); +my ($cobrand, $coords, $area_id, $name, $mapit_url); BEGIN { + $config_file = 'conf/general.yml-example'; + $cobrand = [ 'borsetshire', 'fixmystreet', 'northamptonshire', 'bathnes', 'buckinghamshire', 'hounslow', 'isleofwight', 'peterborough', 'tfl' ]; + $coords = '51.532851,-2.284277'; + $area_id = 2608; + $name = 'Borsetshire'; + $mapit_url = 'https://mapit.uk/'; + $node = 'C:\Program Files\nodejs\node.exe'; + + GetOptions( + 'config=s' => \$config_file, + 'server' => \$run_server, + 'cypress' => \$run_cypress, + 'vagrant' => \$vagrant, + 'wsl=s' => \$wsl, + 'node=s' => \$node, + '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 && $wsl) { + print 'You cannot use both --vagrant and --wsl'; + exit 1; + } + + 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'; -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, -); - 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 { @@ -52,15 +71,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; @@ -71,15 +85,20 @@ sub run { my $config_out = FixMyStreet::TestAppProve->get_config({ config_file => $config_file, # Want this to be like .com - ALLOWED_COBRANDS => [ $cobrand ], + ALLOWED_COBRANDS => $cobrand, MAPIT_URL => $mapit_url, - BASE_URL => 'http://localhost:3001', + BASE_URL => 'http://fixmystreet.localhost:3001', + STAGING_FLAGS => { skip_checks => 1 }, + COBRAND_FEATURES => { + category_groups => { map { $_ => 1 } @$cobrand }, + suggest_duplicates => { map { $_ => 1 } @$cobrand }, + } }); $ENV{FMS_OVERRIDE_CONFIG} = $config_out; # Set up, and load in some data - system('bin/make_css', 'fixmystreet.com'); - system('bin/fixmystreet.com/fixture', '--nonrandom', '--coords', $coords, '--name', $name, '--area-id', $area_id, '--commit'); + system('bin/make_css', map { $_ eq 'fixmystreet' ? 'fixmystreet.com' : $_ } @$cobrand); + system('bin/fixmystreet.com/fixture', '--test_fixtures', '--nonrandom', '--coords', $coords, '--name', $name, '--area-id', $area_id, '--commit'); } my $pid; @@ -90,14 +109,16 @@ sub run { if (($run_cypress && !$run_server) || $pid) { # Parent, run the test runner (then kill the child) - my $exit = system("cypress", $cmd, '--config', 'pluginsFile=false,supportFile=false,blacklistHosts=[gaze.mysociety.org,*.openstreetmap.org]', '--project', '.cypress', '--env', "cobrand=$cobrand", @ARGV); + my @cypress = ('cypress'); + if ($wsl) { + @cypress = ('cmd.exe', '/c', $node, $wsl); + } + my $exit = system(@cypress, $cmd, '--config', 'pluginsFile=false,supportFile=false', '--project', '.cypress', @ARGV); kill 'TERM', $pid if $pid; exit $exit >> 8; } else { - use Test::MockModule; - my $c = Test::MockModule->new('FixMyStreet::Cobrand::FixMyStreet'); - $c->mock('enable_category_groups', sub { 1 }); # Child, run the server on port 3001 + require FixMyStreet; FixMyStreet->test_mode(1); # So email doesn't try to send local $ENV{FIXMYSTREET_APP_DEBUG} = 0; require Plack::Runner; @@ -125,10 +146,11 @@ browser-tests [running options] [fixture options] [cypress options] --server only run the test server, not cypress --cypress only run cypress, not the test server --vagrant run test server inside Vagrant, cypress outside + --wsl provide path to cypress node script, to run test server inside WSL, cypress outside --help this help message Fixture option: - --cobrand Cobrand to use, default 'fixmystreet' + --cobrand Cobrand(s) to use, default is fixmystreet,northamptonshire,bathnes,buckinghamshire,isleofwight,peterborough,tfl --coords Default co-ordinates for created reports --area_id Area ID to use for created body --name Name to use for created body @@ -143,6 +165,7 @@ server in the VM and Cypress outside of it. $ browser-tests run # run headlessly $ browser-tests run --record --key # record and upload a run $ browser-tests --vagrant run # run if you use Vagrant + $ browser-tests --wsl ..cypress run # run if you use WSL You need to have installed cypress already using npm, and it needs to be on your PATH. |