all:
check:
- $(NITUNIT) .
+ $(NITUNIT) . tests/ examples/
system "curl -s {host}:{port}/not_found" # handled by angular controller
end
- fun test_example_param_route do
+ fun test_example_angular do
var app = new App
app.use("/counter", new CounterAPI)
- app.use("/*", new StaticHandler("../examples/angular/www/", "index.html"))
+ app.use("/*", new StaticHandler(test_path / "../www/", "index.html"))
run_test(app)
end
end
<script src='/javascripts/ng-example.js'></script>
</body>
</html>
+
import pop_tests
import example_post_handler
-class TestExampleQueryString
+class TestExamplePostHandler
super TestPopcorn
redef fun client_test do
system "curl -s {host}:{port}/"
end
- fun test_example_glob_route do
+ fun test_example_post_handler do
var app = new App
app.use("/", new PostHandler)
run_test(app)
Body:
[Client] curl -s localhost:*****/ --data 'user'
-POST Error: user format error on user
URI: /
Body: user
<body>
<h1>404 Not Found</h1>
</body>
- </html>
\ No newline at end of file
+ </html>
system "curl -s {host}:{port}/?items=10\\&order=asc"
end
- fun test_example_glob_route do
+ fun test_example_query_string do
var app = new App
app.use("/", new QueryStringHandler)
run_test(app)
Query string: items=10&order=asc
items: 10
order: asc
+
redef fun all(req, res) do req.timer = new Clock
end
-class LogHandler
+class AdvancedLoggerHandler
super Handler
redef fun all(req, res) do
end
end
-class HelloHandler
+class AnotherHandler
super Handler
redef fun get(req, res) do res.send "Hello World!"
var app = new App
app.use_before("/*", new RequestTimeHandler)
-app.use("/", new HelloHandler)
-app.use_after("/*", new LogHandler)
+app.use("/", new AnotherHandler)
+app.use_after("/*", new AdvancedLoggerHandler)
app.listen("localhost", 3000)
end
end
-class HelloHandler
+class SomeHandler
super Handler
redef fun get(req, res) do res.send "Hello World!"
var app = new App
-app.use("/", new HelloHandler)
+app.use("/", new SomeHandler)
app.use("/*", new SimpleErrorHandler)
app.listen("localhost", 3000)
import popcorn
-class LogHandler
+class SimpleLoggerHandler
super Handler
redef fun all(req, res) do print "Request Logged"
end
-class HelloHandler
+class MyOtherHandler
super Handler
redef fun get(req, res) do res.send "Hello World!"
var app = new App
-app.use_before("/*", new LogHandler)
-app.use("/", new HelloHandler)
+app.use_before("/*", new SimpleLoggerHandler)
+app.use("/", new MyOtherHandler)
app.listen("localhost", 3000)
system "curl -s {host}:{port}/about"
end
- fun test_example_param_route do
+ fun test_example_advanced_logger do
var app = new App
app.use_before("/*", new RequestTimeHandler)
- app.use("/", new HelloHandler)
- app.use_after("/*", new LogHandler)
+ app.use("/", new AnotherHandler)
+ app.use_after("/*", new AdvancedLoggerHandler)
run_test(app)
end
end
<body>
<h1>404 Not Found</h1>
</body>
- </html>
\ No newline at end of file
+ </html>
system "curl -s {host}:{port}/about"
end
- fun test_example_param_route do
+ fun test_example_html_error_handler do
var app = new App
app.use("/*", new HtmlErrorHandler)
run_test(app)
<body>
<h1>404 An error occurred!</h1>
</body>
- </html>
\ No newline at end of file
+ </html>
system "curl -s {host}:{port}/about"
end
- fun test_example_param_route do
+ fun test_example_simple_error_handler do
var app = new App
- app.use("/", new HelloHandler)
+ app.use("/", new SomeHandler)
app.use("/*", new SimpleErrorHandler)
run_test(app)
end
[Client] curl -s localhost:*****/
Hello World!
[Client] curl -s localhost:*****/about
-An error occurred!
\ No newline at end of file
+An error occurred!
system "curl -s {host}:{port}/about"
end
- fun test_example_param_route do
+ fun test_example_simple_logger do
var app = new App
- app.use_before("/*", new LogHandler)
- app.use("/", new HelloHandler)
+ app.use_before("/*", new SimpleLoggerHandler)
+ app.use("/", new MyOtherHandler)
run_test(app)
end
end
<body>
<h1>404 Not Found</h1>
</body>
- </html>
\ No newline at end of file
+ </html>
redef fun all(req, res) do print "User logged"
end
-class UserHome
+class UserHomepage
super Handler
redef fun get(req, res) do res.send "User Home"
var user_router = new Router
user_router.use("/*", new UserLogger)
-user_router.use("/", new UserHome)
+user_router.use("/", new UserHomepage)
user_router.use("/profile", new UserProfile)
var app = new App
fun test_example_router do
var user_router = new Router
user_router.use("/*", new UserLogger)
- user_router.use("/", new UserHome)
+ user_router.use("/", new UserHomepage)
user_router.use("/profile", new UserProfile)
var app = new App
app.use("/", new AppHome)
system "curl -s {host}:{port}/products/not_found"
end
- fun test_example_param_route do
+ fun test_example_session do
var app = new App
app.use("/*", new SessionInit)
app.use("/", new AppLogin)
<body>
<h1>404 Not Found</h1>
</body>
- </html>
\ No newline at end of file
+ </html>
system "curl -s {host}:{port}/not_found.nit"
end
- fun test_example_param_route do
+ fun test_example_static do
var app = new App
- app.use("/", new StaticHandler("../examples/static_files/public/"))
+ app.use("/", new StaticHandler(test_path / "../public/"))
run_test(app)
end
end
<body>
<h1>404 Not Found</h1>
</body>
- </html>
\ No newline at end of file
+ </html>
system "curl -s {host}:{port}/not_found.nit"
end
- fun test_example_param_route do
+ fun test_example_static_default do
var app = new App
- app.use("/", new StaticHandler("../examples/static_files/public/", "default.html"))
+ app.use("/", new StaticHandler(test_path / "../public/", "default.html"))
run_test(app)
end
end
<h1>Default Page</h1>
</body>
</html>
+
system "curl -s {host}:{port}/not_found.nit"
end
- fun test_example_param_route do
+ fun test_example_static_multiple do
var app = new App
- app.use("/", new StaticHandler("../examples/static_files/public/"))
- app.use("/", new StaticHandler("../examples/static_files/files/"))
- app.use("/static", new StaticHandler("../examples/static_files/public/"))
- app.use("/static", new StaticHandler("../examples/static_files/files/"))
+ app.use("/", new StaticHandler(test_path / "../public/"))
+ app.use("/", new StaticHandler(test_path / "../files/"))
+ app.use("/static", new StaticHandler(test_path / "../public/"))
+ app.use("/static", new StaticHandler(test_path / "../files/"))
run_test(app)
end
end
<body>
<h1>404 Not Found</h1>
</body>
- </html>
\ No newline at end of file
+ </html>
# Port used to run App.
var port: Int = test_port
+ # Directory of the current test suite
+ #
+ # Useful when your tested app need to load some external files.
+ var test_path: String = "NIT_TESTING_PATH".environ.dirname
+
# Run the test suite on the App.
fun run_test(app: App) do
var server = new AppThread(host, port, app)