Skip to content

Commit

Permalink
chore: Update .gitignore and add smoke_test.dart for test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
PlugFox committed May 9, 2024
1 parent c2aa662 commit 5106ed5
Show file tree
Hide file tree
Showing 9 changed files with 375 additions and 73 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ app.*.map.json
log.pana.json

# Test
coverage/
.coverage/
/test/**/*.json
/test/.test_coverage.dart
Expand Down
103 changes: 98 additions & 5 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"version": "0.2.0",
"configurations": [
{
"name": "Example (lcl)",
"name": "[Flutter] Example (Local)",
"request": "launch",
"type": "dart",
"flutterMode": "debug",
Expand All @@ -14,10 +14,12 @@
"console": "debugConsole",
"runTestsOnDevice": false,
"toolArgs": [],
"args": ["--dart-define-from-file=config/local.json"]
"args": [
"--dart-define-from-file=config/local.json"
]
},
{
"name": "Example (dev)",
"name": "[Flutter] Example (Development)",
"request": "launch",
"type": "dart",
"flutterMode": "debug",
Expand All @@ -29,7 +31,98 @@
"console": "debugConsole",
"runTestsOnDevice": false,
"toolArgs": [],
"args": ["--dart-define-from-file=config/development.json"]
"args": [
"--dart-define-from-file=config/development.json"
]
},
// https://pub.dev/packages/test
// dart test test/unit_test.dart --color --platform=vm
{
"name": "[Dart] Unit test (VM)",
"request": "launch",
"type": "dart",
"program": "test/unit_test.dart",
"env": {
"ENVIRONMENT": "test"
},
"console": "debugConsole",
"runTestsOnDevice": false,
"templateFor": "test",
"toolArgs": [
"--color",
"--debug",
"--coverage=coverage",
"--reporter=expanded",
"--platform=vm", // chrome
"--file-reporter=json:coverage/tests.json",
"--timeout=30s",
"--concurrency=12"
/* "--name=handles failed connection attempts" */
],
"args": []
},
// dart test test/unit_test.dart --color --platform=chrome
{
"name": "[Dart] Unit Test (Browser)",
"request": "launch",
"type": "dart",
"program": "test/unit_test.dart",
"env": {
"ENVIRONMENT": "test"
},
"console": "debugConsole",
"runTestsOnDevice": false,
"templateFor": "test",
"toolArgs": [
"--color",
"--debug",
"--coverage=coverage",
"--reporter=expanded",
"--platform=chrome",
"--file-reporter=json:coverage/tests.json",
"--timeout=30s",
"--concurrency=12"
/* "--name=can send binary data" */
],
"args": []
},
// dart test test/smoke_test.dart --color --platform=vm
{
"name": "[Dart] Smoke Test (VM)",
"request": "launch",
"type": "dart",
"program": "test/smoke_test.dart",
"env": {
"ENVIRONMENT": "test"
},
"console": "debugConsole",
"runTestsOnDevice": false,
"templateFor": "test",
"toolArgs": [
"--color",
"--debug",
"--coverage=coverage",
"--reporter=expanded",
"--platform=vm", // chrome
"--file-reporter=json:coverage/tests.json",
"--timeout=30s",
"--concurrency=12"
],
"args": [],
"preLaunchTask": "echo-server:start",
"postDebugTask": "echo-server:stop"
},
// dart run server/bin/server.dart
{
"name": "[Go] Echo Server",
"request": "launch",
"type": "go",
"program": "tool/echo/echo.go",
"cwd": "${workspaceFolder}/tool/echo",
"env": {
"ENVIRONMENT": "WebSocket Server"
},
"console": "internalConsole"
}
]
}
}
86 changes: 47 additions & 39 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"version": "2.0.0",
"tasks": [
{
"label": "Dependencies",
"label": "dart:dependencies",
"type": "shell",
"command": [
"dart pub get"
Expand All @@ -14,30 +14,30 @@
"problemMatcher": []
},
{
"label": "Get protoc plugin",
"label": "dart:get-protoc-plugin",
"detail": "Get protoc plugin",
"type": "shell",
"command": [
"dart pub global activate protoc_plugin"
],
"dependsOn": [
"Dependencies"
],
"dependsOn": [],
"group": {
"kind": "none",
"isDefault": true
},
"problemMatcher": []
},
{
"label": "Generate protobuf",
"label": "dart:generate-protobuf",
"detail": "Generate protobuf files",
"type": "shell",
"command": [
"protoc",
"--proto_path=lib/src/transport/protobuf",
"--dart_out=lib/src/transport/protobuf lib/src/transport/protobuf/client.proto"
],
"dependsOn": [
"Get protoc plugin"
"dart:get-protoc-plugin"
],
"group": {
"kind": "none",
Expand All @@ -46,25 +46,15 @@
"problemMatcher": []
},
{
"label": "Codegenerate",
"label": "dart:codegenerate",
"detail": "Generate code for the project",
"type": "shell",
"command": [
"dart run build_runner build --delete-conflicting-outputs"
],
"dependsOn": [
"Dependencies"
],
"group": {
"kind": "none",
"isDefault": true
},
"problemMatcher": []
},
{
"label": "Format",
"type": "shell",
"command": [
"dart format --fix -l 80 lib/src/model/pubspec.yaml.g.dart lib/src/transport/protobuf/"
"dart:dependencies",
"dart:generate-protobuf"
],
"group": {
"kind": "none",
Expand All @@ -73,18 +63,11 @@
"problemMatcher": []
},
{
"label": "Prepare example",
"label": "dart:format",
"detail": "Format all files in the project",
"type": "shell",
"options": {
"cwd": "${workspaceFolder}/example"
},
"command": [
"dart pub global activate intl_utils",
"dart pub global run intl_utils:generate",
"fvm flutter pub get",
/* "&& fvm flutter gen-l10n --arb-dir lib/src/common/localization --output-dir lib/src/common/localization/generated --template-arb-file intl_en.arb", */
"&& fvm flutter pub run build_runner build --delete-conflicting-outputs",
"&& dart format --fix -l 80 ."
"dart format --fix -l 80 lib test tool example"
],
"group": {
"kind": "none",
Expand All @@ -93,7 +76,8 @@
"problemMatcher": []
},
{
"label": "Start Centrifugo Server",
"label": "centrifugo:start",
"detail": "Start centrifugo server",
"type": "shell",
"windows": {
"command": "docker",
Expand Down Expand Up @@ -160,7 +144,8 @@
}
},
{
"label": "Stop Centrifugo Server",
"label": "centrifugo:stop",
"detail": "Stop centrifugo server",
"type": "shell",
"command": "docker",
"args": [
Expand All @@ -178,7 +163,8 @@
}
},
{
"label": "Generate new user token",
"label": "centrifugo:gentoken",
"detail": "Generate new user token for centrifugo server",
"type": "shell",
"command": "docker",
"args": [
Expand All @@ -204,16 +190,38 @@
}
},
{
"label": "Run echo server",
"label": "echo-server:start",
"type": "shell",
"command": "dart",
"detail": "Start echo server",
"options": {
"cwd": "${workspaceFolder}/tool",
},
"args": [
"run",
"echo_up.dart"
],
"group": {
"kind": "none",
"isDefault": true
},
"problemMatcher": [],
"presentation": {
"reveal": "always",
"panel": "dedicated"
}
},
{
"label": "echo-server:stop",
"type": "shell",
"command": "go",
"detail": "Running echo server",
"command": "dart",
"detail": "Stop echo server",
"options": {
"cwd": "${workspaceFolder}/tool/echo",
"cwd": "${workspaceFolder}/tool",
},
"args": [
"run",
"main.go"
"echo_down.dart"
],
"group": {
"kind": "none",
Expand Down
27 changes: 16 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
.PHONY: format get outdated test publish deploy centrifugo-up centrifugo-down coverage analyze check pana generate
.PHONY: format get outdated test publish deploy echo-up echo-down coverage analyze check pana generate

ifeq ($(OS),Windows_NT)
RM = del /Q
MKDIR = mkdir
PWD = $(shell $(PWD))
else
RM = rm -f
MKDIR = mkdir -p
PWD = pwd
endif

format:
@echo "Formatting the code"
Expand All @@ -12,23 +22,18 @@ outdated:
@dart pub outdated --show-all --dev-dependencies --dependency-overrides --transitive --no-prereleases

test: get
@dart test --debug --coverage=.coverage --platform chrome,vm
@dart test --debug --coverage=coverage --platform chrome,vm test/unit_test.dart

publish: generate
@yes | dart pub publish

deploy: publish

# http://localhost:8000
# https://centrifugal.dev/docs/server/console_commands
centrifugo:
@docker run -it --rm --ulimit nofile=65536:65536 -p 8000:8000 --name centrifugo -v $(PWD)/centrifugo-config.json:/centrifugo/config.json centrifugo/centrifugo:latest centrifugo --client_insecure --admin --admin_insecure --log_level=debug -c config.json
echo-up:
@dart run tool/echo_up.dart

centrifugo-up:
@docker run -d --rm --ulimit nofile=65536:65536 -p 8000:8000 --name centrifugo -v $(PWD)/centrifugo-config.json:/centrifugo/config.json centrifugo/centrifugo:latest centrifugo --client_insecure --admin --admin_insecure --log_level=debug

centrifugo-down:
@docker stop centrifugo
echo-down:
@dart run tool/echo_down.dart

coverage: get
@dart test --concurrency=6 --platform vm --coverage=coverage test/
Expand Down
4 changes: 2 additions & 2 deletions test/smoke/smoke_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import 'package:spinify/spinify.dart';
import 'package:test/test.dart';

void main() {
group('Smoke test', () {
group('Connection', () {
const url = 'ws://localhost:8000/connection/websocket';
test('Connection', () async {
test('Connect_and_disconnect', () async {
final client = Spinify();
await client.connect(url);
expect(client.state, isA<SpinifyState$Connected>());
Expand Down
11 changes: 11 additions & 0 deletions test/smoke_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// ignore_for_file: unnecessary_lambdas

import 'package:test/test.dart';

import 'smoke/smoke_test.dart' as smoke_test;

void main() {
group('Smoke', () {
smoke_test.main();
});
}

0 comments on commit 5106ed5

Please sign in to comment.