server_testing_shelf 0.3.2 copy "server_testing_shelf: ^0.3.2" to clipboard
server_testing_shelf: ^0.3.2 copied to clipboard

Adapter for the Shelf package to use server_testing for HTTP testing.

server_testing_shelf #

Pub Version CI License Sponsor

Shelf adapter for server_testing. It translates between Shelf’s Request / Response objects and the test harness’ RequestHandler interface so you can drive Shelf apps with the fluent assertions from server_testing.

Highlights #

  • Zero-boilerplate adapter – wrap any shelf.Handler with ShelfRequestHandler and instantly gain the testing DSL.
  • In-memory & real sockets – reuse all server_testing transports (e.g. TestClient.inMemory, TransportMode.ephemeralServer).
  • Property-tested translator – byte streams are copied chunk-by-chunk to avoid double-close issues, and the package includes property coverage for the adapter.

Install #

dev_dependencies:
  server_testing: ^0.3.0
  server_testing_shelf: ^0.2.1
  test: ^1.26.0

Example #

import 'dart:io';

import 'package:server_testing/server_testing.dart';
import 'package:server_testing_shelf/server_testing_shelf.dart';
import 'package:shelf/shelf.dart' as shelf;
import 'package:test/test.dart';

void main() {
  final handler = shelf.Pipeline()
      .addMiddleware(shelf.logRequests())
      .addHandler((request) => shelf.Response.ok('ok'));

  serverTest('Shelf ping', (client) async {
    final response = await client.get('/ping');
    response.assertStatus(HttpStatus.ok).assertBodyContains('ok');
  }, handler: ShelfRequestHandler(handler));
}

Funding #

Help keep these adapters maintained by supporting @kingwill101 on Buy Me a Coffee.***

1
likes
160
points
226
downloads

Publisher

verified publisherglenfordwilliams.com

Weekly Downloads

Adapter for the Shelf package to use server_testing for HTTP testing.

Repository (GitHub)
View/report issues

Documentation

API reference

Funding

Consider supporting this project:

www.buymeacoffee.com

License

MIT (license)

Dependencies

meta, server_testing, shelf

More

Packages that depend on server_testing_shelf