Created
May 2, 2010 03:28
-
-
Save clkao/386870 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use warnings; | |
use strict; | |
use Test::TCP (); | |
use Test::More ; | |
use Plack::Request; | |
use Plack::Loader; | |
use Plack::Util; | |
use Data::Dumper; | |
# tport runs the test server (qunit.psgi), which serves js files and | |
# html to run qunit tests. this should probably be a new jifty | |
# instance with some hooks that mount the qunit stuff so we can test | |
# REST api | |
# qport is run by this harness to collect ajax calls by qunit-tap.js | |
# reporting test results. | |
my $tport = $ENV{QUNIT_PORT}; | |
if ($tport && Test::TCP::_check_port($tport)) { | |
test_client($tport); | |
exit; | |
} | |
diag "running qunit.psgi"; | |
Test::TCP::test_tcp( | |
client => \&test_client, | |
server => sub { | |
my $tport = shift; | |
Plack::Loader->load('Standalone', | |
host => '127.0.0.1', | |
port => $tport, | |
)->run( | |
Plack::Util::load_psgi('jt/qunit.psgi')); | |
}); | |
sub test_client { | |
my $tport = shift; | |
my $qport = Test::TCP::empty_port(); | |
diag "hi client $qport"; | |
my $server = Plack::Loader->load('Standalone', | |
host => '127.0.0.1', | |
port => $qport, | |
server_ready => sub { | |
diag 'ready'; | |
my $uri = "http://localhost:$tport/#$qport"; | |
`open -g $uri`; | |
}, | |
); | |
$server->run( | |
sub { | |
my $env = shift; | |
my $req = Plack::Request->new($env); | |
my $param = $req->parameters->mixed; | |
if ($param->{'type'} eq 'one-test') { | |
ok($param->{result} eq 'true', | |
$param->{'message'}); | |
} | |
elsif ($param->{'type'} eq 'done'){ | |
done_testing($param->{total}); | |
exit( $param->{'fail'} ? 1 : 0); | |
} | |
else { | |
diag 'unknown qunit message'; | |
diag Dumper($param); | |
} | |
return [200, [], ['ok']]; | |
} | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment