I have created a simple REST Api using aqueduct and dart and I am attempting to run unit tests. However, I get the following error when trying to do so:
Failed to load "test\example_test.dart":
Unable to spawn isolate: Error: Cannot run with sound null safety, because the following dependencies
don't support null safety:
- package:test_core
- package:test_api
- package:aqueduct_test
- package:test
- package:aqueduct
- package:boolean_selector
- package:logging
- package:safe_config
- package:matcher
- package:crypto
- package:password_hash
- package:open_api
- package:yaml
- package:postgres
- package:convert
- package:codable
- package:pub_semver
My Code is as follows:
channel.dart
Controller get entryPoint {
final router = Router();
// Prefer to use `link` instead of `linkFunction`.
// See: https://aqueduct.io/docs/http/request_controller/
router.route("/example").linkFunction((request) async {
return Response.ok({"key": "value"});
});
example_test.dart
import 'harness/app.dart';
Future main() async {
final harness = Harness()..install();
test("GET /example returns 200 {'key': 'value'}", () async {
expectResponse(await harness.agent.get("/example"), 200, body: {"key": "value"});
});
}
Any help is appreciated
Seems like your Dart version is >2.12
Aqueduct does not support null safety. So basically you cannot go about it as it is. You need to install dart version which is lower than 2.12. I would suggest 2.7.2 as there were some breaking changes from 2.8 and above which mess things up in Aqueduct.
A better solution is to install dart 2.7.2 inside a docker container and use VS code for development.
And also it is better to note that Stabelkernel has discontinued development of Aqueduct and it wont be supported.
There is a community effort to fork aqueduct and rebrand it as Conduit. Hopefully a null safe initial release of Conduit is around the corner. So an eye for that too.