Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 22 additions & 11 deletions .github/workflows/dart-tests.yaml → .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ env:
jobs:
analyze:
name: Analyze
runs-on: ${{ matrix.os }}
runs-on: ubuntu-latest
strategy:
matrix:
os: [ubuntu-latest]
dart_sdk:
# ${{ env.LOWEST_DART_SDK }} won't work at job level as env context not available for strategy ¯\_(ツ)_/¯
# (see https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/accessing-contextual-information-about-workflow-runs#context-availability)
Expand Down Expand Up @@ -153,19 +152,31 @@ jobs:
if: ${{ matrix.os == 'ubuntu-latest' && matrix.dart_sdk == '3.8.1' && matrix.deps == 'upgrade' }}
run: |
dart pub global activate coverage
for package in packages/relic_core packages/relic_io packages/relic; do
if [ -d "$package/test" ]; then
echo "Running coverage for $package"
(cd "$package" && dart pub global run coverage:test_with_coverage --branch-coverage -- --reporter=failures-only)
fi
done

- name: Upload Coverage
melos run coverage --no-select

- name: Upload Coverage (relic_core)
uses: codecov/codecov-action@v5
if: ${{ matrix.os == 'ubuntu-latest' && matrix.dart_sdk == '3.8.1' && matrix.deps == 'upgrade' && !cancelled() }}
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: packages/relic_core/coverage/lcov.info
flags: relic_core

- name: Upload Coverage (relic_io)
uses: codecov/codecov-action@v5
if: ${{ matrix.os == 'ubuntu-latest' && matrix.dart_sdk == '3.8.1' && matrix.deps == 'upgrade' && !cancelled() }}
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: packages/relic_io/coverage/lcov.info
flags: relic_io

- name: Upload Coverage (relic)
uses: codecov/codecov-action@v5
if: ${{ matrix.os == 'ubuntu-latest' && matrix.dart_sdk == '3.8.1' && matrix.deps == 'upgrade' && !cancelled() }}
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: packages/relic_core/coverage/lcov.info,packages/relic_io/coverage/lcov.info,packages/relic/coverage/lcov.info
files: packages/relic/coverage/lcov.info
flags: relic

docs-markdown-lint:
name: Markdown lint for docs
Expand Down
13 changes: 13 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,22 @@ coverage:
project:
default:
target: auto
paths:
- "packages/relic_core/**"
- "packages/relic_io/**"
- "packages/relic/**"
patch:
default:
target: auto
paths:
- "packages/relic_core/**"
- "packages/relic_io/**"
- "packages/relic/**"

ignore:
- "packages/examples/**"
- "packages/benchmark/**"
- "doc/**"

flag_management:
individual_flags:
Expand Down
6 changes: 4 additions & 2 deletions packages/relic/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@ dev_dependencies:
async: ^2.13.0
http: ^1.5.0
http_parser: ^4.0.2
lints: ">=5.0.0 <7.0.0"
lints: ^6.0.0
meta: ^1.17.0
mime: ">=1.0.6 <3.0.0"
mime: ^2.0.0
mockito: ^5.4.4
path: ^1.8.3
serverpod_lints: ^3.0.0
test: ^1.25.10
test_descriptor: ^2.0.1
test_utils:
path: ../test_utils
vm_service: ^15.0.0
web_socket: ^1.0.1
web_socket_channel: ^3.0.3
Expand Down
3 changes: 1 addition & 2 deletions packages/relic/test/adapter/connection_info_test.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'package:relic/relic.dart';
import 'package:test/test.dart';

import '../util/test_util.dart';
import 'package:test_utils/test_utils.dart';

void main() {
group('SocketAddress', () {
Expand Down
2 changes: 1 addition & 1 deletion packages/relic/test/headers/basic/host_header_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ library;

import 'package:relic/relic.dart';
import 'package:test/test.dart';
import 'package:test_utils/test_utils.dart';

import '../../util/test_util.dart';
import '../headers_test_utils.dart';

/// Reference: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Host
Expand Down
2 changes: 1 addition & 1 deletion packages/relic/test/headers/header_test.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:relic/relic.dart';
import 'package:test/test.dart';
import 'package:test_utils/test_utils.dart';

import '../util/test_util.dart';
import 'headers_test_utils.dart';

void main() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import 'dart:convert';

import 'package:relic/relic.dart';
import 'package:test/test.dart';
import 'package:test_utils/test_utils.dart';

import '../../util/test_util.dart';
import '../docs/strict_validation_docs.dart';
import '../headers_test_utils.dart';

Expand Down
3 changes: 1 addition & 2 deletions packages/relic/test/message/apply_headers_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import 'package:http_parser/http_parser.dart';
import 'package:mockito/mockito.dart';
import 'package:relic/relic.dart';
import 'package:test/test.dart';

import '../util/test_util.dart';
import 'package:test_utils/test_utils.dart';

class HttpHeadersMock extends Mock implements HttpHeaders {
final Map<String, List<String>> _headers = {};
Expand Down
3 changes: 1 addition & 2 deletions packages/relic/test/path/path_param_test.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'package:relic/relic.dart';
import 'package:test/test.dart';

import '../util/test_util.dart';
import 'package:test_utils/test_utils.dart';

/// Tests for PathParam and PathParameters.
///
Expand Down
3 changes: 1 addition & 2 deletions packages/relic/test/relic_server_connections_info_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import 'dart:io';
import 'package:http/http.dart' as http;
import 'package:relic/relic.dart';
import 'package:test/test.dart';

import 'util/test_util.dart';
import 'package:test_utils/test_utils.dart';

Handler _createDelayedHandler() {
return (final req) async {
Expand Down
1 change: 1 addition & 0 deletions packages/relic/test/relic_server_serve_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:http/http.dart' as http;
import 'package:http_parser/http_parser.dart' as parser;
import 'package:relic/relic.dart';
import 'package:test/test.dart';
import 'package:test_utils/test_utils.dart';
import 'package:web_socket/web_socket.dart';

import 'headers/headers_test_utils.dart';
Expand Down
2 changes: 1 addition & 1 deletion packages/relic/test/relic_server_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import 'dart:io';
import 'package:http/http.dart' as http;
import 'package:relic/relic.dart';
import 'package:test/test.dart';
import 'package:test_utils/test_utils.dart';

import 'headers/headers_test_utils.dart';
import 'util/test_util.dart';

void main() {
// Use concrete type to ensure extensions are applied
Expand Down
3 changes: 1 addition & 2 deletions packages/relic/test/router/router_methods_test.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'package:relic/relic.dart';
import 'package:test/test.dart';

import '../util/test_util.dart';
import 'package:test_utils/test_utils.dart';

void main() {
group('Router Method Specific Tests', () {
Expand Down
144 changes: 0 additions & 144 deletions packages/relic/test/util/test_util.dart
Original file line number Diff line number Diff line change
@@ -1,65 +1,6 @@
import 'dart:async';
import 'dart:convert';
import 'dart:io';

import 'package:meta/meta.dart';
import 'package:relic/relic.dart';
import 'package:test/test.dart';

final helloBytes = utf8.encode('hello,');

final worldBytes = utf8.encode(' world');

typedef SyncHandler = Result Function(Request);

/// A simple, synchronous handler.
///
/// By default, replies with a status code 200, empty headers, and
/// `Hello from ${req.url.path}`.
SyncHandler createSyncHandler({
final int statusCode = 200,
final Headers? headers,
final Body? body,
}) {
return (final Request req) {
return Response(
statusCode,
headers: headers ?? Headers.empty(),
body: body ?? Body.fromString('Hello from ${req.url.path}'),
);
};
}

final SyncHandler syncHandler = createSyncHandler();

/// Calls [createSyncHandler] and wraps the response in a [Future].
Future<Result> asyncHandler(final Request req) async {
return syncHandler(req);
}

/// Makes a simple GET request to [handler] and returns the result.
Future<Response> makeSimpleRequest(
final Handler handler, [
final Request? request,
]) async {
final newCtx = await handler((request ?? _defaultRequest));
if (newCtx is! Response) throw ArgumentError(newCtx);
return newCtx;
}

final _defaultRequest = RequestInternal.create(
Method.get,
localhostUri,
Object(),
);

final localhostUri = Uri.parse('http://localhost/');

final isOhNoStateError = isA<StateError>().having(
(final e) => e.message,
'message',
'oh no',
);

Future<RelicServer> testServe(
final Handler handler, {
Expand All @@ -72,88 +13,3 @@ Future<RelicServer> testServe(
await server.mountAndStart(handler);
return server;
}

/// Like [group], but takes a [variants] argument and creates a group for each
/// variant.
///
/// Setup multiple groups of tests where each group gets a different parameter
/// value. The [descriptionBuilder] is used to produce a description for each
/// group based on the [variants]. For each variant the [body] is executed to
/// setup tests and sub-groups.
///
/// This is useful for running the same tests against multiple configurations,
/// implementations, or inputs.
///
/// Example:
/// ```dart
/// parameterizedGroup<String>(
/// (protocol) => 'Testing protocol: $protocol',
/// (protocol) {
/// test('connects successfully', () {
/// // Test using the protocol parameter
/// });
/// },
/// variants: ['http', 'https', 'ws'],
/// );
/// ```
@isTestGroup
void parameterizedGroup<T>(
final String Function(T) descriptionBuilder,
final void Function(T) body, {
required final Iterable<T> variants,
}) {
for (final v in variants) {
group(descriptionBuilder(v), () => body(v));
}
}

/// Like [test,] but takes a [variants] argument and creates a test-case
/// for each variant.
///
/// Setup multiple test cases where each test case gets a different parameter
/// value. The [descriptionBuilder] is used to produce a description for each
/// test case based on the [variants]. For each variant the [body] is executed.
///
/// This is useful for testing the same functionality against multiple inputs
/// or configurations.
///
/// Example:
/// ```dart
/// parameterizedTest<int>(
/// (value) => 'Test with value: $value',
/// (value) {
/// expect(value * 2, greaterThan(value));
/// },
/// variants: [1, 2, 3, 4, 5],
/// );
/// ```
@isTest
void parameterizedTest<T>(
final String Function(T) descriptionBuilder,
final void Function(T) body, {
required final Iterable<T> variants,
}) {
for (final v in variants) {
test(descriptionBuilder(v), () => body(v));
}
}

/// Creates a [test] with a single [expect].
///
/// A convenience method that creates a test with a [description] that
/// validates the single expectation that [actual] matches [expected].
///
/// Example:
/// ```dart
/// singleTest('1 + 1 equals 2', 1 + 1, 2);
/// ```
@isTest
void singleTest(
final String description,
final dynamic actual,
final dynamic expected,
) {
test(description, () {
expect(actual, expected);
});
}
6 changes: 4 additions & 2 deletions packages/relic_core/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ dependencies:
crypto: ^3.0.0
http_parser: ^4.0.2
meta: ^1.17.0
mime: ">=1.0.6 <3.0.0"
mime: ^2.0.0
path: ^1.8.3
stack_trace: ^1.10.0
stream_channel: ^2.1.1
Expand All @@ -30,7 +30,9 @@ dependencies:
web_socket_channel: ^3.0.3

dev_dependencies:
lints: ">=5.0.0 <7.0.0"
lints: ^6.0.0
mockito: ^5.4.4
serverpod_lints: ^3.0.0
test: ^1.25.10
test_utils:
path: ../test_utils
Loading