-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(runtime): Add
setup
parameter to serve
This allows generated backends to provide project-specific configuration at startup.
- Loading branch information
Showing
10 changed files
with
144 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
@TestOn('vm') | ||
library; | ||
|
||
import 'dart:async'; | ||
import 'dart:io'; | ||
|
||
import 'package:celest/src/core/context.dart'; | ||
import 'package:celest/src/runtime/serve.dart'; | ||
import 'package:celest_ast/celest_ast.dart'; | ||
import 'package:pub_semver/pub_semver.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
final config = ResolvedProject( | ||
projectId: 'test', | ||
environmentId: 'local', | ||
sdkConfig: SdkConfiguration( | ||
celest: Version.parse('1.0.0'), | ||
dart: Sdk( | ||
type: SdkType.dart, | ||
version: Version.parse(Platform.version.split(' ').first), | ||
), | ||
), | ||
); | ||
|
||
void main() { | ||
group('serve', () { | ||
test('calls setup', () async { | ||
Context.root = Context.current; | ||
|
||
final setupCompleter = Completer<void>(); | ||
final service = await serve( | ||
config: config, | ||
targets: {}, | ||
setup: setupCompleter.complete, | ||
); | ||
addTearDown(service.close); | ||
expect( | ||
setupCompleter.future.timeout(const Duration(seconds: 1)), | ||
completes, | ||
); | ||
}); | ||
|
||
test('fails to start server if setup fails', () async { | ||
Context.root = Context.current; | ||
|
||
final service = serve( | ||
config: config, | ||
targets: {}, | ||
setup: (_) => throw StateError('Failed to setup'), | ||
); | ||
await expectLater( | ||
service, | ||
throwsA( | ||
isA<StateError>().having( | ||
(e) => e.message, | ||
'message', | ||
'Failed to setup', | ||
), | ||
), | ||
); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters