Created
April 9, 2014 10:30
-
-
Save memememomo/10252326 to your computer and use it in GitHub Desktop.
Test::MojoでビルドされたアプリにPhantomJSでアクセスする ref: http://qiita.com/memememomo/items/cc0ae8bb1d82be75315e
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
use strict; | |
use warnings; | |
use File::Basename; | |
use Mojo::Server::Daemon; | |
use Test::TCP; | |
use Test::More; | |
use Test::Mojo; | |
my $t = Test::Mojo->new('SampleApp'); | |
# Webサーバ設定 | |
my $server = Test::TCP->new( | |
code => sub { | |
my $port = shift; | |
my $daemon = Mojo::Server::Daemon->new(listen => ['http://*:'.$port]); | |
$daemon->app($t->app); | |
$daemon->run; | |
} | |
); | |
# サーバのListenポートを取得 | |
my $port = $server->port; | |
# PhantomJSのコマンドを実行 | |
my $file = dirname(__FILE__) . '/scenario1.js'; | |
`phantomjs $file $port`; | |
# 実行後のDBの状態を調べたりしてテストする | |
ok 1; | |
done_testing(); |
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
$ prove -l t/basic.t |
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
var System = require('system'); | |
var port = System.args[1]; | |
var page = require('webpage').create(); | |
page.open('http://127.0.0.1:'+port+'/', function() { | |
page.render('test.png'); | |
phantom.exit(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment