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

chore: Improve testing #1873

Merged
merged 16 commits into from
Aug 2, 2022
Merged
192 changes: 154 additions & 38 deletions .github/workflows/lint.yml

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions .github/workflows/native_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
uses: actions/cache@4504faf7e9bcf8f3ed0bc863c4e1d21499ab8ef8
with:
path: "~/.pub-cache/hosted"
key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:packages/smithy/smithy-packages/smithy/smithy_aws-packages/smithy/smithy_codegen;commands:test_5"
key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:packages/smithy/smithy-packages/smithy/smithy_aws-packages/smithy/smithy_codegen;commands:test_3"
restore-keys: |
os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:packages/smithy/smithy-packages/smithy/smithy_aws-packages/smithy/smithy_codegen
os:ubuntu-latest;pub-cache-hosted;sdk:dev
Expand Down Expand Up @@ -71,7 +71,7 @@ jobs:
uses: actions/cache@4504faf7e9bcf8f3ed0bc863c4e1d21499ab8ef8
with:
path: "~/.pub-cache/hosted"
key: "os:ubuntu-latest;pub-cache-hosted;sdk:stable;packages:packages/smithy/smithy-packages/smithy/smithy_aws-packages/smithy/smithy_codegen;commands:test_5"
key: "os:ubuntu-latest;pub-cache-hosted;sdk:stable;packages:packages/smithy/smithy-packages/smithy/smithy_aws-packages/smithy/smithy_codegen;commands:test_3"
restore-keys: |
os:ubuntu-latest;pub-cache-hosted;sdk:stable;packages:packages/smithy/smithy-packages/smithy/smithy_aws-packages/smithy/smithy_codegen
os:ubuntu-latest;pub-cache-hosted;sdk:stable
Expand Down
1,062 changes: 534 additions & 528 deletions .github/workflows/test.yml

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion packages/aft/pubspec_overrides.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
dependency_overrides:
# Generated with `aft`. Do not modify by hand or check into source control.
dependency_overrides:
amplify_lints:
path: ../amplify_lints
aws_common:
path: ../aws_common
aws_signature_v4:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ import 'package:amplify_authenticator/src/widgets/form.dart';
import 'package:amplify_flutter/amplify_flutter.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:meta/meta.dart';

export 'package:amplify_auth_cognito/amplify_auth_cognito.dart'
show AuthProvider;
Expand Down
8 changes: 8 additions & 0 deletions packages/amplify_core/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
targets:
$default:
builders:
build_web_compilers:entrypoint:
release_options:
dart2js_args:
- --define=dart.vm.product=true
- --enable-asserts
4 changes: 3 additions & 1 deletion packages/amplify_core/mono_pkg.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ stages:
- format
- analyze: --fatal-infos .
- unit_test:
- command: dart --version
- test:
os:
- windows
- macos
- linux
- test: -p chrome,firefox
- command: dart run build_runner test --delete-conflicting-outputs -- -p chrome,firefox
- command: dart run build_runner test --release --delete-conflicting-outputs -- -p chrome,firefox
2 changes: 2 additions & 0 deletions packages/amplify_core/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ dev_dependencies:
amplify_lints:
path: ../amplify_lints
build_runner: ^2.0.0
build_test: ^2.1.5
build_web_compilers: ^3.2.4
json_serializable: ^6.3.0
path: any
test: ^1.17.0
10 changes: 4 additions & 6 deletions packages/amplify_core/pubspec_overrides.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
# This file is checked in until it can be easily generated locally
# and in CI pipelines, e.g. with melos.
#
# It may cause issues with publishing until https://github.com/dart-lang/pub/pull/3419
# is released in stable.
dependency_overrides:
# Generated with `aft`. Do not modify by hand or check into source control.
dependency_overrides:
amplify_lints:
path: ../amplify_lints
aws_common:
path: ../aws_common
aws_signature_v4:
Expand Down
22 changes: 11 additions & 11 deletions packages/auth/amplify_auth_cognito/example/pubspec_overrides.yaml
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
# This file is checked in until it can be easily generated locally
# and in CI pipelines, e.g. with melos.
#
# It may cause issues with publishing until https://github.com/dart-lang/pub/pull/3419
# is released in stable.
dependency_overrides:
# Generated with `aft`. Do not modify by hand or check into source control.
dependency_overrides:
amplify_api:
path: ../../../api/amplify_api
amplify_api_android:
path: ../../../api/amplify_api_android
amplify_api_ios:
path: ../../../api/amplify_api_ios
amplify_authenticator:
path: ../../../amplify_authenticator
amplify_auth_cognito:
path: ../
path: ..
amplify_auth_cognito_android:
path: ../../amplify_auth_cognito_android
amplify_auth_cognito_dart:
path: ../../amplify_auth_cognito_dart
amplify_auth_cognito_ios:
path: ../../amplify_auth_cognito_ios
amplify_authenticator:
path: ../../../amplify_authenticator
amplify_core:
path: ../../../amplify_core
amplify_datastore_plugin_interface:
path: ../../../amplify_datastore_plugin_interface
amplify_flutter:
path: ../../../amplify/amplify_flutter
amplify_flutter_ios:
path: ../../../amplify/amplify_flutter_ios
amplify_flutter_android:
path: ../../../amplify/amplify_flutter_android
amplify_flutter_ios:
path: ../../../amplify/amplify_flutter_ios
amplify_lints:
path: ../../../amplify_lints
amplify_secure_storage:
path: ../../../secure_storage/amplify_secure_storage
amplify_secure_storage_dart:
path: ../../../secure_storage/amplify_secure_storage_dart
amplify_test:
path: ../../../amplify_test
aws_common:
path: ../../../aws_common
aws_signature_v4:
Expand Down
14 changes: 6 additions & 8 deletions packages/auth/amplify_auth_cognito/pubspec_overrides.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
# This file is checked in until it can be easily generated locally
# and in CI pipelines, e.g. with melos.
#
# It may cause issues with publishing until https://github.com/dart-lang/pub/pull/3419
# is released in stable.
dependency_overrides:
# Generated with `aft`. Do not modify by hand or check into source control.
dependency_overrides:
amplify_auth_cognito_android:
path: ../amplify_auth_cognito_android
amplify_auth_cognito_dart:
Expand All @@ -14,12 +10,14 @@ dependency_overrides:
path: ../../amplify_core
amplify_datastore_plugin_interface:
path: ../../amplify_datastore_plugin_interface
amplify_flutter_android:
path: ../../amplify/amplify_flutter_android
amplify_flutter:
path: ../../amplify/amplify_flutter
amplify_flutter_android:
path: ../../amplify/amplify_flutter_android
amplify_flutter_ios:
path: ../../amplify/amplify_flutter_ios
amplify_lints:
path: ../../amplify_lints
amplify_secure_storage:
path: ../../secure_storage/amplify_secure_storage
amplify_secure_storage_dart:
Expand Down
1 change: 1 addition & 0 deletions packages/auth/amplify_auth_cognito_dart/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ targets:
compiler: dart2js
dart2js_args:
- -O2
- --define=dart.vm.product=true
workers:
auto_apply_builders: false
builders:
Expand Down
7 changes: 7 additions & 0 deletions packages/auth/amplify_auth_cognito_dart/example/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
targets:
$default:
builders:
build_web_compilers:entrypoint:
release_options:
dart2js_args:
- --define=dart.vm.product=true
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Generated with `aft`. Do not modify by hand or check into source control.
dependency_overrides:
amplify_auth_cognito_dart:
path: ..
amplify_core:
path: ../../../amplify_core
amplify_lints:
path: ../../../amplify_lints
amplify_secure_storage_dart:
path: ../../../secure_storage/amplify_secure_storage_dart
aws_common:
path: ../../../aws_common
aws_signature_v4:
path: ../../../aws_signature_v4
example_common:
path: ../../../example_common
smithy:
path: ../../../smithy/smithy
smithy_aws:
path: ../../../smithy/smithy_aws
worker_bee:
path: ../../../worker_bee/worker_bee
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class AmplifyAuthCognitoDart extends AuthPluginInterface

@visibleForTesting
set stateMachine(CognitoAuthStateMachine stateMachine) {
if (!zDebugMode) throw StateError('Can only be called in tests');
if (!zAssertsEnabled) throw StateError('Can only be called in tests');
_stateMachine = stateMachine;
}

Expand Down
7 changes: 1 addition & 6 deletions packages/auth/amplify_auth_cognito_dart/mono_pkg.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,7 @@ stages:
- analyze_and_format:
- group:
- format
- analyze: --fatal-infos lib test
- unit_test:
- group:
- command: dart --version
- test: --exclude-tags=build
- test: -p chrome
- analyze: --fatal-infos lib
- build_test:
- test: --tags=build
sdk:
Expand Down
12 changes: 6 additions & 6 deletions packages/auth/amplify_auth_cognito_dart/pubspec_overrides.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
# This file is checked in until it can be easily generated locally
# and in CI pipelines, e.g. with melos.
#
# It may cause issues with publishing until https://github.com/dart-lang/pub/pull/3419
# is released in stable.
dependency_overrides:
# Generated with `aft`. Do not modify by hand or check into source control.
dependency_overrides:
amplify_core:
path: ../../amplify_core
amplify_lints:
path: ../../amplify_lints
amplify_secure_storage_dart:
path: ../../secure_storage/amplify_secure_storage_dart
aws_common:
Expand All @@ -18,3 +16,5 @@ dependency_overrides:
path: ../../smithy/smithy_aws
worker_bee:
path: ../../worker_bee/worker_bee
worker_bee_builder:
path: ../../worker_bee/worker_bee_builder
6 changes: 6 additions & 0 deletions packages/auth/amplify_auth_cognito_test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Files and directories created by pub.
.dart_tool/
.packages

# Conventional directory for build output.
build/
11 changes: 11 additions & 0 deletions packages/auth/amplify_auth_cognito_test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Tests for the [`amplify_auth_cognito_dart`](../amplify_auth_cognito_dart) package separated out so that they can be easily tested using `build_runner`.

## Testing

To run tests:

```sh
$ dart test
$ dart run build_runner test --delete-conflicting-outputs -- -p chrome,firefox
$ dart run build_runner test --release --delete-conflicting-outputs -- -p chrome,firefox
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this work with Edge, like Flutter tests? If so, might be worth noting somewhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah, I forget about edge 😂 I'll see if we can get it running on windows

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like it's not supported yet, unfortunately: dart-lang/test#1142. The Flutter team jumped through some hoops to get it to work (flutter/engine#15641) and I'm not sure if that effort is worth it right now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, sounds good

```
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
include: package:amplify_lints/library.yaml

analyzer:
errors:
invalid_use_of_internal_member: ignore
exclude:
- '**/*.g.dart'
8 changes: 8 additions & 0 deletions packages/auth/amplify_auth_cognito_test/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
targets:
$default:
builders:
build_web_compilers:entrypoint:
release_options:
dart2js_args:
- --define=dart.vm.product=true
- --enable-asserts
8 changes: 8 additions & 0 deletions packages/auth/amplify_auth_cognito_test/dart_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
override_platforms:
firefox:
settings:
arguments: -headless
on_platform:
# Tests with workers seems to be really slow on browsers
browser:
timeout: 2x
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/// Tests for the `amplify_auth_cognito_dart` package.
library amplify_auth_cognito_test;
22 changes: 22 additions & 0 deletions packages/auth/amplify_auth_cognito_test/mono_pkg.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
sdk:
- stable
- dev

stages:
- analyze_and_format:
- group:
- format
- analyze: --fatal-infos .
- unit_test:
- command: dart --version
- test:
os:
- windows
- macos
- linux
- command: dart run build_runner test --delete-conflicting-outputs -- -p chrome,firefox
sdk:
- stable
# TODO(dnys1): https://github.com/dart-lang/sdk/issues/49474
# - dev
- command: dart run build_runner test --release --delete-conflicting-outputs -- -p chrome,firefox
46 changes: 46 additions & 0 deletions packages/auth/amplify_auth_cognito_test/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: amplify_auth_cognito_test
description: Tests for the amplify_auth_cognito_dart package.
publish_to: none

environment:
sdk: '>=2.17.0 <3.0.0'

dependency_overrides:
amplify_core:
path: ../../amplify_core
amplify_secure_storage_dart:
path: ../../secure_storage/amplify_secure_storage_dart
aws_common:
path: ../../aws_common
aws_signature_v4:
path: ../../aws_signature_v4
worker_bee:
path: ../../worker_bee/worker_bee

dev_dependencies:
amplify_auth_cognito_dart:
path: ../amplify_auth_cognito_dart
amplify_core:
path: ../../amplify_core
amplify_lints:
path: ../../amplify_lints
amplify_secure_storage_dart:
path: ../../secure_storage/amplify_secure_storage_dart
build_runner: ^2.0.0
build_test: ^2.0.0
build_web_compilers: ^3.2.2
built_collection: ^5.0.0
built_value: ^8.0.0
convert: ^3.0.0
http: ^0.13.0
mockito: ^5.0.0
smithy:
hosted: https://pub.dillonnys.com
version: ^0.5.0
smithy_aws:
hosted: https://pub.dillonnys.com
version: ^0.5.0
stream_transform: ^2.0.0
test: ^1.16.0
worker_bee:
path: ../../worker_bee/worker_bee
20 changes: 20 additions & 0 deletions packages/auth/amplify_auth_cognito_test/pubspec_overrides.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Generated with `aft`. Do not modify by hand or check into source control.
dependency_overrides:
amplify_auth_cognito_dart:
path: ../amplify_auth_cognito_dart
amplify_core:
path: ../../amplify_core
amplify_lints:
path: ../../amplify_lints
amplify_secure_storage_dart:
path: ../../secure_storage/amplify_secure_storage_dart
aws_common:
path: ../../aws_common
aws_signature_v4:
path: ../../aws_signature_v4
smithy:
path: ../../smithy/smithy
smithy_aws:
path: ../../smithy/smithy_aws
worker_bee:
path: ../../worker_bee/worker_bee
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.

@OnPlatform({
'chrome': Skip('TODO(dnys1): Failing in CI'),
})

import 'dart:async';

import 'package:amplify_auth_cognito_dart/src/flows/constants.dart';
Expand Down
Loading