Skip to content

Instantly share code, notes, and snippets.

@kyanny

kyanny/01_base.t

Created Feb 9, 2010
Embed
What would you like to do?
JSTAPd study
use JSTAPd::Suite;
sub client_script {
return <<'DONE';
tests(6);
ok(1, 'ok 1');
ok(!0, 'ok 0');
is('test', 'test', 'is');
isnt('test', 'dev', 'isnt');
like('test', new RegExp('es'), 'like');
is(tap$('test').innerHTML, 'DATA', 'getElementById');
DONE
}
sub html_body {
return <<'DONE';
<div id='test'>DATA</div>
DONE
}
use JSTAPd::Suite;
sub client_script {
return <<'DONE';
tests(2);
setTimeout(function(){ ok(1, 'timeout'); }, 200);
function run_test1(){
$.getJSON('/api/get', function(data){
is(data.name, 'yappo', 'test jQuery.getJSON #1');
});
}
run_test1();
var run_test2;
run_test2 = function run_test2(){
$.getJSON('/api/get', function(data){
isnt(data.name, 'yahoo', 'test jQuery.getJSON #2');
});
}
setTimeout(run_test2, 100);
DONE
}
sub html_body {
return <<'DONE';
DONE
}
sub server_api {
my ($self, $global, $req, $method, $path) = @_;
if ($path eq '/api/get' && $method eq 'GET') {
return +{ name => 'yappo' };
}
}
sub include_ex {
'http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js',
\'jquery-jstapd.js',
}
# JSTAPd config
my $config = {
jstapd_prefix => '____jstapd',
apiurl => qr{^/(?!____jstapd(?:__api))},
# apiurl => qr{^/(?!____jstapd(?:__api)|jslib/)},
};
#$config->{urlmap} = [
# { qr!^/jslib/! => '../jslib/' },
#];
# browser auto open
# for run_once mode (prove -vl foo.t or prove -vlr jstap/)
# this example for Mac OS X
# $config->{auto_open_command} = 'open -a Safari %s';
# or $ENV{JSTAP_AUTO_OPEN_COMMAND} = 'open -a Safari %s';
$config->{auto_open_command} = 'open -a Safari %s';
$config;
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>index</title>
$HEAD
</head>
<body id="body">
$BODY
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment