Skip to content

Commit

Permalink
Simplify test suite & move CORS tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kuhnroyal committed Mar 2, 2024
1 parent 6e812bd commit 3c77ae9
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 22 deletions.
10 changes: 3 additions & 7 deletions dio/test/test_suite_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@ import 'package:dio/dio.dart';
import 'package:dio_test/tests.dart';

void main() {
Dio create() => Dio(BaseOptions(baseUrl: 'https://httpbun.com/'));

headerTests(create);
httpMethodTests(create);
redirectTests(create);
parameterTests(create);
statusCodeTests(create);
dioAdapterTestSuite(
() => Dio(BaseOptions(baseUrl: 'https://httpbun.com/')),
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ import 'package:dio/dio.dart';
import 'package:dio_test/util.dart';
import 'package:test/test.dart';

// Test that browsers can correctly classify requests as
// either "simple" or "preflighted". Reference:
// https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS#simple_requests
void main() {
/// Test that browsers can correctly classify requests as
/// either "simple" or "preflighted". Reference:
/// https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS#simple_requests
void corsTests(
Dio Function() create,
) {
late Dio dio;

setUpAll(() {
dio = Dio(BaseOptions(baseUrl: 'https://httpbun.com/'));
setUp(() {
dio = create();
});

group('CORS preflight', () {
Expand Down
22 changes: 22 additions & 0 deletions dio_test/lib/src/test/suite.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import 'package:dio/dio.dart';
import 'package:dio_test/tests.dart';

typedef TestSuiteFunction = void Function(
Dio Function() create,
);

const _tests = [
corsTests,
headerTests,
httpMethodTests,
parameterTests,
redirectTests,
statusCodeTests,
timeoutTests,
];

void dioAdapterTestSuite(
Dio Function() create, {
List<TestSuiteFunction> tests = _tests,
}) =>
tests.forEach((test) => test(create));
2 changes: 2 additions & 0 deletions dio_test/lib/tests.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
export 'src/test/cors_tests.dart';
export 'src/test/headers_tests.dart';
export 'src/test/http_method_tests.dart';
export 'src/test/parameter_tests.dart';
export 'src/test/redirect_tests.dart';
export 'src/test/status_code_tests.dart';
export 'src/test/suite.dart';
export 'src/test/timeout_tests.dart';
13 changes: 4 additions & 9 deletions plugins/http2_adapter/test/test_suite_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,8 @@ import 'package:dio_http2_adapter/dio_http2_adapter.dart';
import 'package:dio_test/tests.dart';

void main() {
Dio create() => Dio(BaseOptions(baseUrl: 'https://httpbun.com/'))
..httpClientAdapter = Http2Adapter(ConnectionManager());

headerTests(create);
httpMethodTests(create);
redirectTests(create);
parameterTests(create);
statusCodeTests(create);
timeoutTests(create);
dioAdapterTestSuite(
() => Dio(BaseOptions(baseUrl: 'https://httpbun.com/'))
..httpClientAdapter = Http2Adapter(ConnectionManager()),
);
}

0 comments on commit 3c77ae9

Please sign in to comment.