Plummbur Kruk

A “real fake” HTTP server specially designed to support browsers tests that make HTTP requests.

Build Status

Getting Started

You'll need Dart.

Install this from pub as plummbur_kruk.

To start the plummbur_kruk server, use the script:

# Start the test server

The test server runs on port 31337.

To stop the server, use the script:

# Stop the server

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 script, be sure to allow to run before exiting on failure:

# Start the test server
echo "starting test server"

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

# check to see if DumpRenderTree tests
# fails, since it always returns 0
if [[ "$results" == *"Some tests failed"* ]]; then
    exit 1

if [[ "$results" == *"Exception: "* ]]; then
    exit 1

Address Already in Use

Sometimes it is possible for things to go quite wrong. If the 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*               LISTEN      2879/dart
$ kill 2879


This software is licensed under the MIT License. See LICENSE for details.