Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: move e2e tests to their own package #721

Merged
merged 11 commits into from
Apr 24, 2023
74 changes: 74 additions & 0 deletions .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: e2e

on:
pull_request:
paths:
- ".github/workflows/e2e.yaml"
- "**"
- "lib/**"
- "test/**"
- "pubspec.yaml"
push:
branches:
- main
paths:
- ".github/workflows/e2e.yaml"
- "**"
- "lib/**"
- "test/**"
- "pubspec.yaml"

jobs:
e2e:
runs-on: ubuntu-latest

strategy:
matrix:
flutter-version:
# The version of Flutter to use should use the minimum Dart SDK version supported by the package,
# refer to https://docs.flutter.dev/development/tools/sdk/releases.
- "3.3.0"
test:
# E2E tests for the test command
- test/commands/test/async_main/async_main_test.dart
- test/commands/test/no_project/no_project_test.dart

# E2E tests for the create command
- test/commands/create/flutter_app/core_test.dart
- test/commands/create/dart_cli/dart_cli_test.dart
- test/commands/create/dart_package/dart_pkg_test.dart
- test/commands/create/docs_site/docs_site_test.dart
- test/commands/create/flame_game/flame_game_test.dart
- test/commands/create/flutter_package/flutter_pkg_test.dart
- test/commands/create/flutter_plugin/flutter_plugin_test.dart

# E2E tests for the legacy create command syntax
- test/commands/create/legacy/core_test.dart
- test/commands/create/legacy/dart_cli_test.dart
- test/commands/create/legacy/dart_pkg_test.dart
- test/commands/create/legacy/docs_site_test.dart
- test/commands/create/legacy/flame_game_test.dart
- test/commands/create/legacy/flutter_pkg_test.dart

steps:
- name: 📚 Git Checkout
uses: actions/checkout@v3.1.0

- name: 🐦 Setup Flutter
uses: subosito/flutter-action@v2
with:
flutter-version: ${{ matrix.flutter-version }}

- name: Install LCOV
run: sudo apt-get install -y lcov

- name: 📦 Install Dependencies (root)
run: dart pub get

- name: 📦 Install Dependencies (e2e)
working-directory: e2e
run: dart pub get

- name: 🧪 Run Tests (e2e)
working-directory: e2e
run: dart test ${{ matrix.test }} --run-skipped
48 changes: 0 additions & 48 deletions .github/workflows/very_good_cli.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,54 +45,6 @@ jobs:
- name: Check Code Coverage
uses: VeryGoodOpenSource/very_good_coverage@v2.1.0

e2e:
runs-on: ubuntu-latest

strategy:
matrix:
flutter-version:
# The version of Flutter to use should use the minimum Dart SDK version supported by the package,
# refer to https://docs.flutter.dev/development/tools/sdk/releases.
- "3.3.0"
test:
# E2E tests for the test command
- test/src/commands/test/e2e/

# E2E tests for the create command
- test/src/commands/create/e2e/flutter_app/core_test.dart
- test/src/commands/create/e2e/dart_cli/dart_cli_test.dart
- test/src/commands/create/e2e/dart_package/dart_pkg_test.dart
- test/src/commands/create/e2e/docs_site/docs_site_test.dart
- test/src/commands/create/e2e/flame_game/flame_game_test.dart
- test/src/commands/create/e2e/flutter_package/flutter_pkg_test.dart
- test/src/commands/create/e2e/flutter_plugin/flutter_plugin_test.dart

# E2E tests for the legacy create command syntax
- test/src/commands/create/e2e/legacy/core_test.dart
- test/src/commands/create/e2e/legacy/dart_cli_test.dart
- test/src/commands/create/e2e/legacy/dart_pkg_test.dart
- test/src/commands/create/e2e/legacy/docs_site_test.dart
- test/src/commands/create/e2e/legacy/flame_game_test.dart
- test/src/commands/create/e2e/legacy/flutter_pkg_test.dart

steps:
- name: 📚 Git Checkout
uses: actions/checkout@v3.1.0

- name: 🐦 Setup Flutter
uses: subosito/flutter-action@v2
with:
flutter-version: ${{ matrix.flutter-version }}

- name: Install LCOV
run: sudo apt-get install -y lcov

- name: 📦 Install Dependencies
run: flutter pub get

- name: Run Tests
run: flutter pub run test ${{ matrix.test }} --run-skipped -t e2e

pana:
runs-on: ubuntu-latest

Expand Down
2 changes: 0 additions & 2 deletions dart_test.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
tags:
pull-request-only:
skip: "Should only be run during pull request"
e2e:
skip: "End to end tests should be run in parallel with other unit tests"
7 changes: 7 additions & 0 deletions e2e/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# See https://www.dartlang.org/guides/libraries/private-files

# Files and directories created by pub
.dart_tool/
.packages
build/
pubspec.lock
1 change: 1 addition & 0 deletions e2e/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include: package:very_good_analysis/analysis_options.3.1.0.yaml
75 changes: 75 additions & 0 deletions e2e/helpers/command_helper.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import 'dart:async';

import 'package:mason/mason.dart';
import 'package:mocktail/mocktail.dart';
import 'package:pub_updater/pub_updater.dart';
import 'package:usage/usage.dart';
import 'package:very_good_cli/src/command_runner.dart';

class _MockAnalytics extends Mock implements Analytics {}

class _MockLogger extends Mock implements Logger {}

class _MockProgress extends Mock implements Progress {}

class _MockPubUpdater extends Mock implements PubUpdater {}

void Function() _overridePrint(void Function(List<String>) fn) {
return () {
final printLogs = <String>[];
final spec = ZoneSpecification(
print: (_, __, ___, String msg) {
printLogs.add(msg);
},
);

return Zone.current
.fork(specification: spec)
.run<void>(() => fn(printLogs));
};
}

void Function() withRunner(
FutureOr<void> Function(
VeryGoodCommandRunner commandRunner,
Logger logger,
PubUpdater pubUpdater,
List<String> printLogs,
)
runnerFn,
) {
return _overridePrint((printLogs) async {
final analytics = _MockAnalytics();
final logger = _MockLogger();
final progress = _MockProgress();
final pubUpdater = _MockPubUpdater();
final progressLogs = <String>[];
final commandRunner = VeryGoodCommandRunner(
analytics: analytics,
logger: logger,
pubUpdater: pubUpdater,
);

when(() => analytics.firstRun).thenReturn(false);
when(() => analytics.enabled).thenReturn(false);
when(
() => analytics.sendEvent(any(), any(), label: any(named: 'label')),
).thenAnswer((_) async {});
when(
() => analytics.waitForLastPing(timeout: any(named: 'timeout')),
).thenAnswer((_) async {});
when(() => progress.complete(any())).thenAnswer((_) {
final message = _.positionalArguments.elementAt(0) as String?;
if (message != null) progressLogs.add(message);
});
when(() => logger.progress(any())).thenReturn(progress);
when(
() => pubUpdater.isUpToDate(
packageName: any(named: 'packageName'),
currentVersion: any(named: 'currentVersion'),
),
).thenAnswer((_) => Future.value(true));

await runnerFn(commandRunner, logger, pubUpdater, printLogs);
});
}
File renamed without changes.
3 changes: 3 additions & 0 deletions e2e/helpers/helpers.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export 'command_helper.dart';
export 'copy_directory.dart';
export 'expect_successful_process_result.dart';
19 changes: 19 additions & 0 deletions e2e/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: very_good_cli_e2e
description: End to End tests for package:very_good_cli
version: 0.1.0+1
publish_to: none

environment:
sdk: ">=2.18.0 <3.0.0"

dev_dependencies:
mason: ^0.1.0-dev.41
mocktail: ^0.3.0
path: ^1.8.0
pub_updater: ^0.2.4
test: ^1.19.2
universal_io: ^2.0.4
usage: ^4.0.2
very_good_analysis: ^3.1.0
very_good_cli:
path: ../
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
@Tags(['e2e'])
library dart_cli_test;

import 'package:mason/mason.dart';
import 'package:path/path.dart' as path;
import 'package:test/test.dart';
import 'package:universal_io/io.dart';

import '../../../../../helpers/helpers.dart';
import '../../../../helpers/helpers.dart';

void main() {
test(
Expand Down Expand Up @@ -39,7 +36,7 @@ void main() {

await expectSuccessfulProcessResult(
'dart',
['format', '--set-exit-if-changed', '.'],
['format'],
workingDirectory: workingDirectory,
);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
@Tags(['e2e'])
library dart_pkg_test;

import 'package:mason/mason.dart';
import 'package:path/path.dart' as path;
import 'package:test/test.dart';
import 'package:universal_io/io.dart';

import '../../../../../helpers/helpers.dart';
import '../../../../helpers/helpers.dart';

void main() {
test(
Expand All @@ -32,7 +29,7 @@ void main() {

await expectSuccessfulProcessResult(
'dart',
['format', '--set-exit-if-changed', '.'],
['format'],
workingDirectory: workingDirectory,
);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
@Tags(['e2e'])
library docs_site_test;

import 'package:mason/mason.dart';
import 'package:path/path.dart' as path;
import 'package:test/test.dart';
import 'package:universal_io/io.dart';

import '../../../../../helpers/helpers.dart';
import '../../../../helpers/helpers.dart';

void main() {
test(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
@Tags(['e2e'])
library flame_game_test;

import 'package:mason/mason.dart';
import 'package:path/path.dart' as path;
import 'package:test/test.dart';
import 'package:universal_io/io.dart';

import '../../../../../helpers/helpers.dart';
import '../../../../helpers/helpers.dart';

void main() {
test(
Expand Down Expand Up @@ -34,7 +31,7 @@ void main() {

await expectSuccessfulProcessResult(
'dart',
['format', '--set-exit-if-changed', '.'],
['format'],
workingDirectory: workingDirectory,
);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
@Tags(['e2e'])
library core_test;

import 'package:mason/mason.dart';
import 'package:path/path.dart' as path;
import 'package:test/test.dart';
import 'package:universal_io/io.dart';

import '../../../../../helpers/helpers.dart';
import '../../../../helpers/helpers.dart';

void main() {
test(
Expand All @@ -25,7 +22,7 @@ void main() {

await expectSuccessfulProcessResult(
'dart',
['format', '--set-exit-if-changed', '.'],
['format'],
workingDirectory: workingDirectory,
);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
@Tags(['e2e'])
library flutter_pkg_test;

import 'package:mason/mason.dart';
import 'package:path/path.dart' as path;
import 'package:test/test.dart';
import 'package:universal_io/io.dart';

import '../../../../../helpers/helpers.dart';
import '../../../../helpers/helpers.dart';

void main() {
test(
Expand All @@ -32,7 +29,7 @@ void main() {

await expectSuccessfulProcessResult(
'dart',
['format', '--set-exit-if-changed', '.'],
['format'],
workingDirectory: workingDirectory,
);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
@Tags(['e2e'])
library flutter_plugin_test;

import 'package:mason/mason.dart';
import 'package:path/path.dart' as path;
import 'package:test/test.dart';
import 'package:universal_io/io.dart';

import '../../../../../helpers/helpers.dart';
import '../../../../helpers/helpers.dart';

void main() {
test(
Expand All @@ -30,7 +27,7 @@ void main() {

await expectSuccessfulProcessResult(
'dart',
['format', '--set-exit-if-changed', '.'],
['format'],
workingDirectory: pluginDirectory,
);

Expand Down
Loading