Skip to content

Commit

Permalink
JavaScript test plugin: Issue headers that prevent caching, #6218, ad…
Browse files Browse the repository at this point in the history
…ded test for JavaScript test runner
  • Loading branch information
madrobby committed Sep 18, 2006
1 parent fcba328 commit c6e32d3
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG
@@ -1,5 +1,9 @@
*SVN*

* Added test for JavaScript test runner

* Issue headers that prevent caching, #6218 [voidlock]

* Allow for manual execution of tests by manually providing an assets symlink (see README)

* Updated CSS and generator to more Railsy layout and colors, borrowed from Tom Werners' #6036 default error pages patch
Expand Down
21 changes: 19 additions & 2 deletions lib/javascript_test.rb
@@ -1,4 +1,4 @@
require 'rake/tasklib'
#require 'rake/tasklib'
require 'thread'
require 'webrick'

Expand Down Expand Up @@ -125,12 +125,24 @@ def log(level, data)
end
end

class NonCachingFileHandler < WEBrick::HTTPServlet::FileHandler
def do_GET(req, res)
super
res['etag'] = nil
res['last-modified'] = Time.now + 1000
res['Cache-Control'] = 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0"'
res['Pragma'] = 'no-cache'
res['Expires'] = Time.now - 1000
end
end

class JavaScriptTestrunner

def initialize(name=:test)
@name = name
@tests = []
@browsers = []
@result = true

@queue = Queue.new

Expand All @@ -145,6 +157,10 @@ def initialize(name=:test)

define
end

def successful?
@result
end

def define
trap("INT") { @server.shutdown }
Expand All @@ -158,6 +174,7 @@ def define
browser.visit("http://localhost:4711#{test}?resultsURL=http://localhost:4711/results&t=" + ("%.6f" % Time.now.to_f))
result = @queue.pop
puts "#{test} on #{browser}: #{result}"
@result = false unless result == 'SUCCESS'
end
browser.teardown
else
Expand All @@ -173,7 +190,7 @@ def define
def mount(path, dir=nil)
dir ||= (Dir.pwd + path)

@server.mount(path, WEBrick::HTTPServlet::FileHandler, dir)
@server.mount(path, NonCachingFileHandler, dir)
end

# test should be specified as a url
Expand Down
21 changes: 21 additions & 0 deletions test/javascript_test_test.rb
@@ -0,0 +1,21 @@
require 'test/unit'
require 'lib/javascript_test.rb'

# mock RAILS_ROOT required because of file existance check
RAILS_ROOT = File.dirname(File.expand_path(__FILE__));

class JavascriptTestTest < Test::Unit::TestCase

def test_javascript_testrunner
runner = JavaScriptTestrunner.new do |t|
t.mount("/test", RAILS_ROOT+'/test')
t.mount('/test/javascript/assets', RAILS_ROOT+'/../assets')
t.run('test')

t.browser(:firefox)
end

assert runner.successful?
end

end
50 changes: 50 additions & 0 deletions test/test/javascript/test_test.html
@@ -0,0 +1,50 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>JavaScript unit test file</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<script src="assets/prototype.js" type="text/javascript"></script>
<script src="assets/unittest.js" type="text/javascript"></script>
<link rel="stylesheet" href="assets/unittest.css" type="text/css" />
</head>
<body>

<div id="content">

<div id="header">
<h1>JavaScript unit test file</h1>
<p>
This file tests <strong>test.js</strong>.
</p>
</div>

<!-- Log output -->
<div id="testlog"> </div>

</div>

<script type="text/javascript">
// <![CDATA[

new Test.Unit.Runner({

// replace this with your real tests

setup: function() {

},

teardown: function() {

},

testFluxiomObject: function() { with(this) {
assert(true);
}}

}, "testlog");
// ]]>
</script>
</body>
</html>

0 comments on commit c6e32d3

Please sign in to comment.