-
Notifications
You must be signed in to change notification settings - Fork 2
/
test.pl
executable file
·199 lines (164 loc) · 5.51 KB
/
test.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
#!/usr/bin/perl
package Util;
use strict;
use warnings;
use File::Find qw();
use feature ':5.10';
sub async(&) {
my $block = shift;
if (my $child = fork()) {
return $child;
} else {
$block->();
exit(0);
}
}
sub js_files_in {
my %args = @_;
my $exclusion = $args{exclude} // '^NO EXCLUSIONS$';
my @files;
File::Find::find(sub {
if (/\.js$/ && $File::Find::name !~ /$exclusion/) {
push @files, $File::Find::name;
}
}, $args{include});
return \@files;
}
sub diag {
say("#" . guard(shift));
}
sub guard {
my $msg = shift;
$msg =~ s/\n/\n#/g;
return $msg;
}
package TAP;
use strict;
use warnings;
use feature ':5.10';
use Data::Dumper;
my $test_number = 1;
my $failed = 0;
sub output {
my $message = shift;
given($message) {
when(qr/plan/) {
say("1..$_->{plan}");
}
when(qr/finished/) {
exit($failed);
}
when(qr/failedCount/) {
print "not " if ($_->{failedCount});
say("ok $test_number - " . Util::guard("$_->{suite} - $_->{spec}"));
if ($_->{failedCount}) {
Util::diag(join q(, ), @{ $_->{description} });
$failed += 1;
}
$test_number += 1;
}
when(qr/text/) {
Util::diag($_->{text});
}
default {
say("Bail out! Unknown command: " . Dumper($message));
}
}
}
package Web;
use Mojolicious::Lite;
use feature ':5.10';
websocket '/results' => sub {
my $self = shift;
my $parser = Mojo::JSON->new();
$self->on_message(sub {
my ($self, $json) = @_;
TAP::output($parser->decode($json));
});
};
get '/' => sub {
my $self = shift;
$self->render('test', files => { jasmine => Util::js_files_in(include => 'spec/javascripts/support'),
public => Util::js_files_in(include => 'public/javascripts'),
test => $self->stash('tests') });
};
get '/(*path)' => sub {
my $self = shift;
my $path = $self->stash('path');
$self->render(text => Mojo::Asset::File->new(path => $path)->slurp, format => 'text/javascript');
};
sub startup {
my $spec_scripts = shift // Util::js_files_in(include => 'spec/javascripts', exclude => 'spec/javascripts/support');
app->defaults({ tests => $spec_scripts });
app->start('daemon');
}
package Browser;
use strict;
use warnings;
use File::Temp;
sub open {
my $url = shift;
my $temp = File::Temp->new(TEMPLATE => "$0.XXXXXXX", SUFFIX => ".html");
print $temp "<html><head><meta http-equiv='refresh' content='0;url=$url'></head></html>";
my $safari = Util::async { exec("/Applications/Safari.app/Contents/MacOS/Safari $temp") };
$SIG{INT} = $SIG{HUP} = $SIG{PIPE} = $SIG{TERM} = sub { kill('INT', $safari) and unlink($temp) and exit };
waitpid($safari, 0);
}
package main;
my $spec_scripts = $ARGV[0] ? [$ARGV[0]] : undef;
my $web = Util::async { Web::startup($spec_scripts) };
my $browser = Util::async { Browser::open('http://localhost:3000') };
waitpid($web, 0);
my $exit_status = $? >> 8;
kill('INT', $browser);
wait();
exit($exit_status);
package Web;
__DATA__
@@ test.html.ep
<html>
<head>
<% my $script = begin %>
<% for (@{ $_[0] }) { %>
<script src="<%= $_ %>"></script>
<% } %>
<% end %>
<%== $script->($files->{jasmine}) %>
<%== $script->($files->{public}) %>
<%== $script->($files->{test}) %>
</head>
<body>
<div id="reporting"></div>
</body>
</html>
@@ favicon.ico (base64)
AAABAAEAEBAAAAAAAABoBQAAFgAAACgAAAAQAAAAIAAAAAEACAAAAAAAAAEAAAAA
AAAAAAAAAAEA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