plummbur_kruk 0.1.2 plummbur_kruk: ^0.1.2 copied to clipboard
A real pretend server for testing.
Plummbur Kruk #
A “real fake” HTTP server specially designed to support browsers tests that make HTTP requests.
Getting Started #
You'll need Dart.
Install this from pub as plummbur_kruk
.
To start the plummbur_kruk server, use the start.sh
script:
# Start the test server
packages/plummbur_kruk/start.sh
The test server runs on port 31337
.
To stop the server, use the stop.sh
script:
# Stop the server
packages/plummbur_kruk/stop.sh
Using with dart:html #
A REST-like API is available at http://localhost:31337/widgets
. The most common REST verbs will work: GET, POST, PUT, DELETE.
When testing browser code, it is not possible to access a running server. The Kruk server can be controlled through a simple client-side API.
To create a record, use:
static Future<HttpRequest> create(String json)
For example:
var id;
setUp(() {
return Kruk.
create('{"foo": 42}').
then((res) {
id = JSON.parse(res.responseText)['id'];
});
});
If you would like a one-request alias for /widgets
, use Kruk.alias()
:
static Future<HttpRequest> alias(String old_url, {as: String})
To delete all record, use Kruk.deleteAll()
:
static Future<HttpRequest> deleteAll()
This is especially useful when deleting records in a unittest tearDown()
:
tearDown(()=> Kruk.deleteAll());
As Part of a Test Runner #
In a test_runner.sh
script, be sure to allow stop.sh
to run before exiting on failure:
# Start the test server
echo "starting test server"
packages/plummbur_kruk/start.sh
echo "content_shell --dump-render-tree test/index.html"
results=`content_shell --dump-render-tree test/index.html 2>&1`
echo "$results"
# Stop the server
packages/plummbur_kruk/stop.sh
# check to see if DumpRenderTree tests
# fails, since it always returns 0
if [[ "$results" == *"Some tests failed"* ]]; then
exit 1
fi
if [[ "$results" == *"Exception: "* ]]; then
exit 1
fi
Address Already in Use #
Sometimes it is possible for things to go quite wrong. If the kruk.pid
file is deleted before the server shuts down, it needs to be stopped manually. The netstat
command is your friend:
$ sudo netstat -nlp | grep 31337
tcp 0 0 127.0.0.1:31337 0.0.0.0:* LISTEN 2879/dart
$ kill 2879
License #
This software is licensed under the MIT License. See LICENSE for details.