diff options
Diffstat (limited to 'bin/browser-tests')
-rwxr-xr-x | bin/browser-tests | 83 |
1 files changed, 51 insertions, 32 deletions
diff --git a/bin/browser-tests b/bin/browser-tests index da6db6737..b5241490e 100755 --- a/bin/browser-tests +++ b/bin/browser-tests @@ -2,40 +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 = [ 'fixmystreet', 'northamptonshire', 'bathnes', 'buckinghamshire' ]; + $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', '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 +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; @@ -94,7 +107,11 @@ 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', '--project', '.cypress', @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 { @@ -127,6 +144,7 @@ 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: @@ -145,6 +163,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. |