aboutsummaryrefslogtreecommitdiffstats
path: root/bin/browser-tests
diff options
context:
space:
mode:
authorMarius Halden <marius.h@lden.org>2021-10-07 13:32:40 +0200
committerMarius Halden <marius.h@lden.org>2021-10-07 13:32:40 +0200
commit09dacfc6b8bf62addeee16c20b1d90c2a256da96 (patch)
tree7caa2bf9e92227ab74448f9b746dd28bbcb81b2a /bin/browser-tests
parent585e57484f9c6332668bf1ac0a6a3b39dbe32223 (diff)
parentcea89fb87a96943708a1db0f646492fbfaaf000f (diff)
Merge tag 'v3.1' into fiksgatami-devfiksgatami-dev
Diffstat (limited to 'bin/browser-tests')
-rwxr-xr-xbin/browser-tests60
1 files changed, 56 insertions, 4 deletions
diff --git a/bin/browser-tests b/bin/browser-tests
index c7e5df27c..bfbe4e51d 100755
--- a/bin/browser-tests
+++ b/bin/browser-tests
@@ -7,11 +7,23 @@ 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);
+my ($cobrand, $coords, $area_id, $name, $mapit_url, $coverage);
BEGIN {
$config_file = 'conf/general.yml-example';
- $cobrand = [ 'borsetshire', 'fixmystreet', 'northamptonshire', 'bathnes', 'buckinghamshire', 'hounslow', 'isleofwight', 'peterborough', 'tfl' ];
+ $cobrand = [qw(
+ bathnes
+ borsetshire
+ buckinghamshire
+ fixmystreet
+ hackney
+ hounslow
+ isleofwight
+ northamptonshire
+ oxfordshire
+ peterborough
+ tfl
+ )];
$coords = '51.532851,-2.284277';
$area_id = 2608;
$name = 'Borsetshire';
@@ -19,6 +31,7 @@ BEGIN {
$node = 'C:\Program Files\nodejs\node.exe';
GetOptions(
+ 'coverage' => \$coverage,
'config=s' => \$config_file,
'server' => \$run_server,
'cypress' => \$run_cypress,
@@ -38,6 +51,11 @@ BEGIN {
exit 1;
}
+ if ($coverage && (system('git', 'diff', '--quiet', 'web') >> 8)) {
+ print 'Do not run coverage with changes in web, they will be lost';
+ exit 1;
+ }
+
if (!$run_server && !$run_cypress) {
# If asked for neither, run both
$run_server = $run_cypress = 1;
@@ -75,6 +93,35 @@ if ($vagrant) {
exit;
}
+BEGIN {
+ # setenv.pl above unloads File:: modules but we need them
+ use File::Path qw(remove_tree);
+}
+
+sub coverage_setup {
+ # Add instrumentation to all JS files under web/
+ if (system('nyc', 'instrument', '--exclude', 'vendor', '--compact', 'false', 'web', 'webO') >> 8) {
+ print 'Could not instrument JS files - are @cypress/code-coverage and nyc installed?';
+ exit 1;
+ }
+
+ # Move the instrumented files on top of the originals
+ while (glob("webO/js/*.js webO/cobrands/*/*.js")) {
+ (my $new = $_) =~ s/webO/web/;
+ rename $_, $new;
+ }
+
+ remove_tree('webO', { safe => 1 }); # Remove anything else left
+}
+
+sub coverage_teardown {
+ remove_tree('.nyc_output', '.cypress/coverage', { safe => 1 }); # Remove old data and incorrect report
+ rename '.cypress/.nyc_output', './.nyc_output'; # Move to top level so nyc can find JS files
+ system('git', 'checkout', 'web'); # Remove instrumented JS files
+ system('nyc', 'report', '--reporter=lcov'); # Generate correct report
+ print "The JS coverage report is at coverage/lcov-report/index.html\n";
+}
+
sub run {
my $cmd = shift @ARGV;
die "Must specify a cypress command\n" unless $cmd || !$run_cypress;
@@ -113,8 +160,12 @@ sub run {
if ($wsl) {
@cypress = ('cmd.exe', '/c', $node, $wsl);
}
- my $exit = system(@cypress, $cmd, '--config', 'pluginsFile=false,supportFile=false', '--project', '.cypress', @ARGV);
+ my @config = $coverage ? () : ('--config', 'pluginsFile=false,supportFile=false');
+ my $exit = system(@cypress, $cmd, @config, '--project', '.cypress', @ARGV);
kill 'TERM', $pid if $pid;
+
+ coverage_teardown() if $coverage;
+
exit $exit >> 8;
} else {
# Child, run the server on port 3001
@@ -128,6 +179,7 @@ sub run {
}
}
+coverage_setup() if $coverage;
run();
@@ -150,7 +202,7 @@ browser-tests [running options] [fixture options] [cypress options]
--help this help message
Fixture option:
- --cobrand Cobrand(s) to use, default is fixmystreet,northamptonshire,bathnes,buckinghamshire,isleofwight,peterborough,tfl
+ --cobrand Cobrand(s) to use, default is fixmystreet,northamptonshire,bathnes,buckinghamshire,isleofwight,peterborough,tfl,hackney,oxfordshire
--coords Default co-ordinates for created reports
--area_id Area ID to use for created body
--name Name to use for created body