Skip to content

Commit

Permalink
refactor: Simplify logger method in smoke_test.dart
Browse files Browse the repository at this point in the history
  • Loading branch information
PlugFox committed Jul 17, 2024
1 parent b9394d6 commit 494af50
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 16 deletions.
4 changes: 2 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@
"--concurrency=12"
],
"args": [],
"preLaunchTask": "echo:start",
"postDebugTask": "echo:stop"
/* "preLaunchTask": "echo:start",
"postDebugTask": "echo:stop" */
},
{
"name": "[Dart] Smoke Test (dart2js)",
Expand Down
2 changes: 1 addition & 1 deletion lib/src/protobuf/protobuf_codec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ final class ProtobufReplyDecoder extends Converter<pb.Reply, SpinifyReply> {
Refresh refresh = 12;
*/
static SpinifyReply _decodePush(pb.Push push) {
final channel = push.channel;
final channel = push.hasChannel() ? push.channel : '';
final now = DateTime.now();
final SpinifyChannelEvent event;
if (push.hasPub()) {
Expand Down
2 changes: 1 addition & 1 deletion lib/src/transport_ws_pb_js.dart
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ final class SpinifyTransport$WS$PB$JS implements ISpinifyTransport {
SpinifyPush(
timestamp: timestamp,
event: SpinifyDisconnect(
channel: '',
channel: '', // empty channel
timestamp: timestamp,
code: code,
reason: reason,
Expand Down
2 changes: 1 addition & 1 deletion lib/src/transport_ws_pb_vm.dart
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ final class SpinifyTransport$WS$PB$VM implements ISpinifyTransport {
SpinifyPush(
timestamp: timestamp,
event: SpinifyDisconnect(
channel: '',
channel: '', // empty channel
timestamp: timestamp,
code: code,
reason: reason,
Expand Down
20 changes: 9 additions & 11 deletions test/smoke/smoke_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ extension type _SpinifyChannelEventView(SpinifyChannelEvent event) {}

void main() {
const url = 'ws://localhost:8000/connection/websocket';
final enablePrint = false; // ignore: prefer_const_declarations
const enablePrint =
bool.fromEnvironment('TEST_ENABLE_PRINT', defaultValue: false);
final logBuffer = SpinifyLogBuffer(size: 100);

void loggerPrint(SpinifyLogLevel level, String event, String message,
Expand All @@ -23,8 +24,7 @@ void main() {
expect(
event,
isA<SpinifyChannelEvent>()
.having((s) => s.channel, 'channel', isNotEmpty)
.having((s) => s.type, 'type', isNotEmpty)
.having((s) => s.channel, 'channel', isNotNull)
.having((s) => s.type, 'type', isNotEmpty)
.having((s) => s.toString(), 'toString()', isNotEmpty)
.having(
Expand All @@ -48,21 +48,19 @@ void main() {
isTrue,
);
if ($prevEvent != null) {
expect(event, isNot(equals($prevEvent)));
expect(event.compareTo($prevEvent!), isPositive);
expect(() => event == $prevEvent, returnsNormally);
expect(event.compareTo($prevEvent!), isNonNegative);
}
$prevEvent = event;
}
}

void logger(SpinifyLogLevel level, String event, String message,
Map<String, Object?> context) {
// ignore: dead_code
if (enablePrint) {
Function.apply(loggerPrint, [level, event, message, context]);
}
Function.apply(logBuffer.add, [level, event, message, context]);
Function.apply(loggerCheckEvents, [level, event, message, context]);
final args = [level, event, message, context];
if (enablePrint) Function.apply(loggerPrint, args);
Function.apply(logBuffer.add, args);
Function.apply(loggerCheckEvents, args);
}

ISpinify createClient() => Spinify(
Expand Down

0 comments on commit 494af50

Please sign in to comment.