From f45fd0b50d02d0caad512e09f84c929165cbd6fa Mon Sep 17 00:00:00 2001 From: Anna Gringauze Date: Fri, 27 Jan 2023 12:02:54 -0800 Subject: [PATCH 01/15] Validate only needed summaries in expression_compiler_service From 2fab3a05ccf5591c91fb1f5c6e434ba460fc45f5 Mon Sep 17 00:00:00 2001 From: Anna Gringauze Date: Wed, 8 Feb 2023 11:01:32 -0800 Subject: [PATCH 02/15] Move shared test functionality into test_common package --- .github/workflows/dart.yml | 407 +++++++++++++----- dwds/CHANGELOG.md | 1 + dwds/lib/src/version.dart | 2 +- dwds/pubspec.yaml | 4 +- dwds/test/build_daemon_callstack_test.dart | 2 +- dwds/test/chrome_proxy_service_test.dart | 2 +- dwds/test/dart_uri_test.dart | 2 +- dwds/test/evaluate_circular_common.dart | 2 +- dwds/test/evaluate_common.dart | 2 +- dwds/test/events_test.dart | 2 +- .../expression_compiler_service_test.dart | 8 +- dwds/test/fixtures/context.dart | 5 +- .../test/frontend_server_breakpoint_test.dart | 2 +- dwds/test/frontend_server_callstack_test.dart | 2 +- dwds/test/handlers/asset_handler_test.dart | 2 +- dwds/test/records_test.dart | 2 +- dwds/test/reload_test.dart | 2 +- dwds/test/restore_breakpoints_test.dart | 2 +- frontend_server_common/lib/src/devfs.dart | 55 +-- .../lib/src/frontend_server_client.dart | 9 +- .../lib/src/resident_runner.dart | 18 +- frontend_server_common/pubspec.yaml | 2 + test_common/analysis_options.yaml | 13 + test_common/dart_test.yaml | 3 + .../fixtures => test_common/lib}/logging.dart | 0 .../lib}/sdk_asset_generator.dart | 1 + test_common/lib/sdk_layout.dart | 194 +++++++++ test_common/mono_pkg.yaml | 27 ++ test_common/pubspec.yaml | 18 + .../test/sdk_asset_generator_test.dart | 7 +- tool/ci.sh | 6 +- 31 files changed, 605 insertions(+), 199 deletions(-) create mode 100644 test_common/analysis_options.yaml create mode 100644 test_common/dart_test.yaml rename {dwds/test/fixtures => test_common/lib}/logging.dart (100%) rename {dwds/test/fixtures => test_common/lib}/sdk_asset_generator.dart (99%) create mode 100644 test_common/lib/sdk_layout.dart create mode 100644 test_common/mono_pkg.yaml create mode 100644 test_common/pubspec.yaml rename {dwds => test_common}/test/sdk_asset_generator_test.dart (97%) diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index 70e0a5a64..00dd0792e 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -1,4 +1,4 @@ -# Created with package:mono_repo v6.5.0 +# Created with package:mono_repo v6.4.3 name: Dart CI on: push: @@ -22,7 +22,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@627f0f41f6904a5b1efbaed9f96d9eb58e92e920 + uses: actions/cache@4723a57e26efda3a62cbde1812113b730952852d with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:stable" @@ -30,14 +30,14 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@a57a6c04cf7d4840e88432aad6281d1e125f0d46 + uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d with: sdk: stable - id: checkout name: Checkout repository - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c + uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b - name: mono_repo self validate - run: dart pub global activate mono_repo 6.5.0 + run: dart pub global activate mono_repo 6.4.3 - name: mono_repo self validate run: dart pub global run mono_repo generate --validate job_002: @@ -45,7 +45,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@627f0f41f6904a5b1efbaed9f96d9eb58e92e920 + uses: actions/cache@4723a57e26efda3a62cbde1812113b730952852d with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:dwds;commands:format-analyze_0-test_0" @@ -55,12 +55,12 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@a57a6c04cf7d4840e88432aad6281d1e125f0d46 + uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d with: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c + uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b - id: dwds_pub_upgrade name: dwds; dart pub upgrade run: dart pub upgrade @@ -79,26 +79,26 @@ jobs: if: "always() && steps.dwds_pub_upgrade.conclusion == 'success'" working-directory: dwds job_003: - name: "analyzer_and_format; linux; Dart dev; PKGS: example, fixtures/_webdevSoundSmoke, frontend_server_client, frontend_server_common; `dart format --output=none --set-exit-if-changed .`, `dart analyze --fatal-infos .`" + name: "analyzer_and_format; linux; Dart dev; PKGS: example, fixtures/_webdevSoundSmoke, frontend_server_client, frontend_server_common, test_common; `dart format --output=none --set-exit-if-changed .`, `dart analyze --fatal-infos .`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@627f0f41f6904a5b1efbaed9f96d9eb58e92e920 + uses: actions/cache@4723a57e26efda3a62cbde1812113b730952852d with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:example-fixtures/_webdevSoundSmoke-frontend_server_client-frontend_server_common;commands:format-analyze_0" + key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:example-fixtures/_webdevSoundSmoke-frontend_server_client-frontend_server_common-test_common;commands:format-analyze_0" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:example-fixtures/_webdevSoundSmoke-frontend_server_client-frontend_server_common + os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:example-fixtures/_webdevSoundSmoke-frontend_server_client-frontend_server_common-test_common os:ubuntu-latest;pub-cache-hosted;sdk:dev os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@a57a6c04cf7d4840e88432aad6281d1e125f0d46 + uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d with: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c + uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b - id: example_pub_upgrade name: example; dart pub upgrade run: dart pub upgrade @@ -151,27 +151,40 @@ jobs: run: dart analyze --fatal-infos . if: "always() && steps.frontend_server_common_pub_upgrade.conclusion == 'success'" working-directory: frontend_server_common + - id: test_common_pub_upgrade + name: test_common; dart pub upgrade + run: dart pub upgrade + if: "always() && steps.checkout.conclusion == 'success'" + working-directory: test_common + - name: "test_common; dart format --output=none --set-exit-if-changed ." + run: "dart format --output=none --set-exit-if-changed ." + if: "always() && steps.test_common_pub_upgrade.conclusion == 'success'" + working-directory: test_common + - name: "test_common; dart analyze --fatal-infos ." + run: dart analyze --fatal-infos . + if: "always() && steps.test_common_pub_upgrade.conclusion == 'success'" + working-directory: test_common job_004: name: "analyzer_and_format; linux; Dart dev; PKG: webdev; `dart format --output=none --set-exit-if-changed .`, `dart analyze --fatal-infos .`, `dart test test/build/ensure_build_test.dart`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@627f0f41f6904a5b1efbaed9f96d9eb58e92e920 + uses: actions/cache@4723a57e26efda3a62cbde1812113b730952852d with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:webdev;commands:format-analyze_0-test_6" + key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:webdev;commands:format-analyze_0-test_7" restore-keys: | os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:webdev os:ubuntu-latest;pub-cache-hosted;sdk:dev os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@a57a6c04cf7d4840e88432aad6281d1e125f0d46 + uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d with: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c + uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b - id: webdev_pub_upgrade name: webdev; dart pub upgrade run: dart pub upgrade @@ -194,7 +207,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@627f0f41f6904a5b1efbaed9f96d9eb58e92e920 + uses: actions/cache@4723a57e26efda3a62cbde1812113b730952852d with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:dwds;commands:command-test_1" @@ -204,12 +217,12 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@a57a6c04cf7d4840e88432aad6281d1e125f0d46 + uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d with: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c + uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b - id: dwds_pub_upgrade name: dwds; dart pub upgrade run: dart pub upgrade @@ -233,7 +246,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@627f0f41f6904a5b1efbaed9f96d9eb58e92e920 + uses: actions/cache@4723a57e26efda3a62cbde1812113b730952852d with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:dwds;commands:test_2" @@ -243,12 +256,12 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@a57a6c04cf7d4840e88432aad6281d1e125f0d46 + uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d with: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c + uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b - id: dwds_pub_upgrade name: dwds; dart pub upgrade run: dart pub upgrade @@ -268,7 +281,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@627f0f41f6904a5b1efbaed9f96d9eb58e92e920 + uses: actions/cache@4723a57e26efda3a62cbde1812113b730952852d with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:dwds;commands:test_3" @@ -278,12 +291,12 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@a57a6c04cf7d4840e88432aad6281d1e125f0d46 + uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d with: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c + uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b - id: dwds_pub_upgrade name: dwds; dart pub upgrade run: dart pub upgrade @@ -303,7 +316,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@627f0f41f6904a5b1efbaed9f96d9eb58e92e920 + uses: actions/cache@4723a57e26efda3a62cbde1812113b730952852d with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:dwds;commands:test_4" @@ -313,12 +326,12 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@a57a6c04cf7d4840e88432aad6281d1e125f0d46 + uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d with: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c + uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b - id: dwds_pub_upgrade name: dwds; dart pub upgrade run: dart pub upgrade @@ -338,7 +351,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@627f0f41f6904a5b1efbaed9f96d9eb58e92e920 + uses: actions/cache@4723a57e26efda3a62cbde1812113b730952852d with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:frontend_server_client;commands:test_5" @@ -348,12 +361,12 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@a57a6c04cf7d4840e88432aad6281d1e125f0d46 + uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d with: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c + uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b - id: frontend_server_client_pub_upgrade name: frontend_server_client; dart pub upgrade run: dart pub upgrade @@ -369,11 +382,50 @@ jobs: - job_003 - job_004 job_010: + name: "unit_test; linux; Dart dev; PKG: test_common; `Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &`, `dart test`" + runs-on: ubuntu-latest + steps: + - name: Cache Pub hosted dependencies + uses: actions/cache@4723a57e26efda3a62cbde1812113b730952852d + with: + path: "~/.pub-cache/hosted" + key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:test_common;commands:command-test_6" + restore-keys: | + os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:test_common + os:ubuntu-latest;pub-cache-hosted;sdk:dev + os:ubuntu-latest;pub-cache-hosted + os:ubuntu-latest + - name: Setup Dart SDK + uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d + with: + sdk: dev + - id: checkout + name: Checkout repository + uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b + - id: test_common_pub_upgrade + name: test_common; dart pub upgrade + run: dart pub upgrade + if: "always() && steps.checkout.conclusion == 'success'" + working-directory: test_common + - name: "test_common; Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &" + run: "Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &" + if: "always() && steps.test_common_pub_upgrade.conclusion == 'success'" + working-directory: test_common + - name: test_common; dart test + run: dart test + if: "always() && steps.test_common_pub_upgrade.conclusion == 'success'" + working-directory: test_common + needs: + - job_001 + - job_002 + - job_003 + - job_004 + job_011: name: "unit_test; linux; Dart dev; PKG: webdev; `Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &`, `dart test -j 1`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@627f0f41f6904a5b1efbaed9f96d9eb58e92e920 + uses: actions/cache@4723a57e26efda3a62cbde1812113b730952852d with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:webdev;commands:command-test_5" @@ -383,12 +435,12 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@a57a6c04cf7d4840e88432aad6281d1e125f0d46 + uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d with: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c + uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b - id: webdev_pub_upgrade name: webdev; dart pub upgrade run: dart pub upgrade @@ -407,12 +459,12 @@ jobs: - job_002 - job_003 - job_004 - job_011: + job_012: name: "unit_test; linux; Dart main; PKG: dwds; `Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &`, `dart test --tags=extension`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@627f0f41f6904a5b1efbaed9f96d9eb58e92e920 + uses: actions/cache@4723a57e26efda3a62cbde1812113b730952852d with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:main;packages:dwds;commands:command-test_1" @@ -422,12 +474,12 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@a57a6c04cf7d4840e88432aad6281d1e125f0d46 + uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d with: sdk: main - id: checkout name: Checkout repository - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c + uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b - id: dwds_pub_upgrade name: dwds; dart pub upgrade run: dart pub upgrade @@ -446,12 +498,12 @@ jobs: - job_002 - job_003 - job_004 - job_012: + job_013: name: "unit_test; linux; Dart main; PKG: dwds; `dart test --total-shards 3 --shard-index 0 --exclude-tags=extension`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@627f0f41f6904a5b1efbaed9f96d9eb58e92e920 + uses: actions/cache@4723a57e26efda3a62cbde1812113b730952852d with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:main;packages:dwds;commands:test_2" @@ -461,12 +513,12 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@a57a6c04cf7d4840e88432aad6281d1e125f0d46 + uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d with: sdk: main - id: checkout name: Checkout repository - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c + uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b - id: dwds_pub_upgrade name: dwds; dart pub upgrade run: dart pub upgrade @@ -481,12 +533,12 @@ jobs: - job_002 - job_003 - job_004 - job_013: + job_014: name: "unit_test; linux; Dart main; PKG: dwds; `dart test --total-shards 3 --shard-index 1 --exclude-tags=extension`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@627f0f41f6904a5b1efbaed9f96d9eb58e92e920 + uses: actions/cache@4723a57e26efda3a62cbde1812113b730952852d with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:main;packages:dwds;commands:test_3" @@ -496,12 +548,12 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@a57a6c04cf7d4840e88432aad6281d1e125f0d46 + uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d with: sdk: main - id: checkout name: Checkout repository - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c + uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b - id: dwds_pub_upgrade name: dwds; dart pub upgrade run: dart pub upgrade @@ -516,12 +568,12 @@ jobs: - job_002 - job_003 - job_004 - job_014: + job_015: name: "unit_test; linux; Dart main; PKG: dwds; `dart test --total-shards 3 --shard-index 2 --exclude-tags=extension`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@627f0f41f6904a5b1efbaed9f96d9eb58e92e920 + uses: actions/cache@4723a57e26efda3a62cbde1812113b730952852d with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:main;packages:dwds;commands:test_4" @@ -531,12 +583,12 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@a57a6c04cf7d4840e88432aad6281d1e125f0d46 + uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d with: sdk: main - id: checkout name: Checkout repository - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c + uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b - id: dwds_pub_upgrade name: dwds; dart pub upgrade run: dart pub upgrade @@ -551,12 +603,12 @@ jobs: - job_002 - job_003 - job_004 - job_015: + job_016: name: "unit_test; linux; Dart main; PKG: frontend_server_client; `dart test -j 1`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@627f0f41f6904a5b1efbaed9f96d9eb58e92e920 + uses: actions/cache@4723a57e26efda3a62cbde1812113b730952852d with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:main;packages:frontend_server_client;commands:test_5" @@ -566,12 +618,12 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@a57a6c04cf7d4840e88432aad6281d1e125f0d46 + uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d with: sdk: main - id: checkout name: Checkout repository - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c + uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b - id: frontend_server_client_pub_upgrade name: frontend_server_client; dart pub upgrade run: dart pub upgrade @@ -586,12 +638,51 @@ jobs: - job_002 - job_003 - job_004 - job_016: + job_017: + name: "unit_test; linux; Dart main; PKG: test_common; `Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &`, `dart test`" + runs-on: ubuntu-latest + steps: + - name: Cache Pub hosted dependencies + uses: actions/cache@4723a57e26efda3a62cbde1812113b730952852d + with: + path: "~/.pub-cache/hosted" + key: "os:ubuntu-latest;pub-cache-hosted;sdk:main;packages:test_common;commands:command-test_6" + restore-keys: | + os:ubuntu-latest;pub-cache-hosted;sdk:main;packages:test_common + os:ubuntu-latest;pub-cache-hosted;sdk:main + os:ubuntu-latest;pub-cache-hosted + os:ubuntu-latest + - name: Setup Dart SDK + uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d + with: + sdk: main + - id: checkout + name: Checkout repository + uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b + - id: test_common_pub_upgrade + name: test_common; dart pub upgrade + run: dart pub upgrade + if: "always() && steps.checkout.conclusion == 'success'" + working-directory: test_common + - name: "test_common; Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &" + run: "Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &" + if: "always() && steps.test_common_pub_upgrade.conclusion == 'success'" + working-directory: test_common + - name: test_common; dart test + run: dart test + if: "always() && steps.test_common_pub_upgrade.conclusion == 'success'" + working-directory: test_common + needs: + - job_001 + - job_002 + - job_003 + - job_004 + job_018: name: "unit_test; linux; Dart main; PKG: webdev; `Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &`, `dart test -j 1`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@627f0f41f6904a5b1efbaed9f96d9eb58e92e920 + uses: actions/cache@4723a57e26efda3a62cbde1812113b730952852d with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:main;packages:webdev;commands:command-test_5" @@ -601,12 +692,12 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@a57a6c04cf7d4840e88432aad6281d1e125f0d46 + uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d with: sdk: main - id: checkout name: Checkout repository - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c + uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b - id: webdev_pub_upgrade name: webdev; dart pub upgrade run: dart pub upgrade @@ -625,17 +716,17 @@ jobs: - job_002 - job_003 - job_004 - job_017: + job_019: name: "unit_test; windows; Dart dev; PKG: dwds; `dart test --tags=extension`" runs-on: windows-latest steps: - name: Setup Dart SDK - uses: dart-lang/setup-dart@a57a6c04cf7d4840e88432aad6281d1e125f0d46 + uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d with: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c + uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b - id: dwds_pub_upgrade name: dwds; dart pub upgrade run: dart pub upgrade @@ -650,17 +741,17 @@ jobs: - job_002 - job_003 - job_004 - job_018: + job_020: name: "unit_test; windows; Dart dev; PKG: dwds; `dart test --total-shards 3 --shard-index 0 --exclude-tags=extension`" runs-on: windows-latest steps: - name: Setup Dart SDK - uses: dart-lang/setup-dart@a57a6c04cf7d4840e88432aad6281d1e125f0d46 + uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d with: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c + uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b - id: dwds_pub_upgrade name: dwds; dart pub upgrade run: dart pub upgrade @@ -675,17 +766,17 @@ jobs: - job_002 - job_003 - job_004 - job_019: + job_021: name: "unit_test; windows; Dart dev; PKG: dwds; `dart test --total-shards 3 --shard-index 1 --exclude-tags=extension`" runs-on: windows-latest steps: - name: Setup Dart SDK - uses: dart-lang/setup-dart@a57a6c04cf7d4840e88432aad6281d1e125f0d46 + uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d with: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c + uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b - id: dwds_pub_upgrade name: dwds; dart pub upgrade run: dart pub upgrade @@ -700,17 +791,17 @@ jobs: - job_002 - job_003 - job_004 - job_020: + job_022: name: "unit_test; windows; Dart dev; PKG: dwds; `dart test --total-shards 3 --shard-index 2 --exclude-tags=extension`" runs-on: windows-latest steps: - name: Setup Dart SDK - uses: dart-lang/setup-dart@a57a6c04cf7d4840e88432aad6281d1e125f0d46 + uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d with: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c + uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b - id: dwds_pub_upgrade name: dwds; dart pub upgrade run: dart pub upgrade @@ -725,17 +816,17 @@ jobs: - job_002 - job_003 - job_004 - job_021: + job_023: name: "unit_test; windows; Dart dev; PKG: frontend_server_client; `dart test -j 1`" runs-on: windows-latest steps: - name: Setup Dart SDK - uses: dart-lang/setup-dart@a57a6c04cf7d4840e88432aad6281d1e125f0d46 + uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d with: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c + uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b - id: frontend_server_client_pub_upgrade name: frontend_server_client; dart pub upgrade run: dart pub upgrade @@ -750,17 +841,17 @@ jobs: - job_002 - job_003 - job_004 - job_022: + job_024: name: "unit_test; windows; Dart dev; PKG: webdev; `dart test -j 1`" runs-on: windows-latest steps: - name: Setup Dart SDK - uses: dart-lang/setup-dart@a57a6c04cf7d4840e88432aad6281d1e125f0d46 + uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d with: sdk: dev - id: checkout name: Checkout repository - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c + uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b - id: webdev_pub_upgrade name: webdev; dart pub upgrade run: dart pub upgrade @@ -775,17 +866,42 @@ jobs: - job_002 - job_003 - job_004 - job_023: + job_025: + name: "unit_test; windows; Dart dev; PKG: test_common; `dart test`" + runs-on: windows-latest + steps: + - name: Setup Dart SDK + uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d + with: + sdk: dev + - id: checkout + name: Checkout repository + uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b + - id: test_common_pub_upgrade + name: test_common; dart pub upgrade + run: dart pub upgrade + if: "always() && steps.checkout.conclusion == 'success'" + working-directory: test_common + - name: test_common; dart test + run: dart test + if: "always() && steps.test_common_pub_upgrade.conclusion == 'success'" + working-directory: test_common + needs: + - job_001 + - job_002 + - job_003 + - job_004 + job_026: name: "unit_test; windows; Dart main; PKG: dwds; `dart test --tags=extension`" runs-on: windows-latest steps: - name: Setup Dart SDK - uses: dart-lang/setup-dart@a57a6c04cf7d4840e88432aad6281d1e125f0d46 + uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d with: sdk: main - id: checkout name: Checkout repository - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c + uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b - id: dwds_pub_upgrade name: dwds; dart pub upgrade run: dart pub upgrade @@ -800,17 +916,17 @@ jobs: - job_002 - job_003 - job_004 - job_024: + job_027: name: "unit_test; windows; Dart main; PKG: dwds; `dart test --total-shards 3 --shard-index 0 --exclude-tags=extension`" runs-on: windows-latest steps: - name: Setup Dart SDK - uses: dart-lang/setup-dart@a57a6c04cf7d4840e88432aad6281d1e125f0d46 + uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d with: sdk: main - id: checkout name: Checkout repository - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c + uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b - id: dwds_pub_upgrade name: dwds; dart pub upgrade run: dart pub upgrade @@ -825,17 +941,17 @@ jobs: - job_002 - job_003 - job_004 - job_025: + job_028: name: "unit_test; windows; Dart main; PKG: dwds; `dart test --total-shards 3 --shard-index 1 --exclude-tags=extension`" runs-on: windows-latest steps: - name: Setup Dart SDK - uses: dart-lang/setup-dart@a57a6c04cf7d4840e88432aad6281d1e125f0d46 + uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d with: sdk: main - id: checkout name: Checkout repository - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c + uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b - id: dwds_pub_upgrade name: dwds; dart pub upgrade run: dart pub upgrade @@ -850,17 +966,17 @@ jobs: - job_002 - job_003 - job_004 - job_026: + job_029: name: "unit_test; windows; Dart main; PKG: dwds; `dart test --total-shards 3 --shard-index 2 --exclude-tags=extension`" runs-on: windows-latest steps: - name: Setup Dart SDK - uses: dart-lang/setup-dart@a57a6c04cf7d4840e88432aad6281d1e125f0d46 + uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d with: sdk: main - id: checkout name: Checkout repository - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c + uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b - id: dwds_pub_upgrade name: dwds; dart pub upgrade run: dart pub upgrade @@ -875,17 +991,17 @@ jobs: - job_002 - job_003 - job_004 - job_027: + job_030: name: "unit_test; windows; Dart main; PKG: frontend_server_client; `dart test -j 1`" runs-on: windows-latest steps: - name: Setup Dart SDK - uses: dart-lang/setup-dart@a57a6c04cf7d4840e88432aad6281d1e125f0d46 + uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d with: sdk: main - id: checkout name: Checkout repository - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c + uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b - id: frontend_server_client_pub_upgrade name: frontend_server_client; dart pub upgrade run: dart pub upgrade @@ -900,17 +1016,17 @@ jobs: - job_002 - job_003 - job_004 - job_028: + job_031: name: "unit_test; windows; Dart main; PKG: webdev; `dart test -j 1`" runs-on: windows-latest steps: - name: Setup Dart SDK - uses: dart-lang/setup-dart@a57a6c04cf7d4840e88432aad6281d1e125f0d46 + uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d with: sdk: main - id: checkout name: Checkout repository - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c + uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b - id: webdev_pub_upgrade name: webdev; dart pub upgrade run: dart pub upgrade @@ -925,13 +1041,38 @@ jobs: - job_002 - job_003 - job_004 - job_029: + job_032: + name: "unit_test; windows; Dart main; PKG: test_common; `dart test`" + runs-on: windows-latest + steps: + - name: Setup Dart SDK + uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d + with: + sdk: main + - id: checkout + name: Checkout repository + uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b + - id: test_common_pub_upgrade + name: test_common; dart pub upgrade + run: dart pub upgrade + if: "always() && steps.checkout.conclusion == 'success'" + working-directory: test_common + - name: test_common; dart test + run: dart test + if: "always() && steps.test_common_pub_upgrade.conclusion == 'success'" + working-directory: test_common + needs: + - job_001 + - job_002 + - job_003 + - job_004 + job_033: name: "beta_cron; linux; Dart beta; PKG: dwds; `Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &`, `dart test -j 1`" runs-on: ubuntu-latest if: "github.event_name == 'schedule'" steps: - name: Cache Pub hosted dependencies - uses: actions/cache@627f0f41f6904a5b1efbaed9f96d9eb58e92e920 + uses: actions/cache@4723a57e26efda3a62cbde1812113b730952852d with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:beta;packages:dwds;commands:command-test_5" @@ -941,12 +1082,12 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@a57a6c04cf7d4840e88432aad6281d1e125f0d46 + uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d with: sdk: beta - id: checkout name: Checkout repository - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c + uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b - id: dwds_pub_upgrade name: dwds; dart pub upgrade run: dart pub upgrade @@ -989,13 +1130,17 @@ jobs: - job_026 - job_027 - job_028 - job_030: + - job_029 + - job_030 + - job_031 + - job_032 + job_034: name: "beta_cron; linux; Dart beta; PKG: webdev; `Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &`, `dart test -j 1`" runs-on: ubuntu-latest if: "github.event_name == 'schedule'" steps: - name: Cache Pub hosted dependencies - uses: actions/cache@627f0f41f6904a5b1efbaed9f96d9eb58e92e920 + uses: actions/cache@4723a57e26efda3a62cbde1812113b730952852d with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:beta;packages:webdev;commands:command-test_5" @@ -1005,12 +1150,12 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@a57a6c04cf7d4840e88432aad6281d1e125f0d46 + uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d with: sdk: beta - id: checkout name: Checkout repository - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c + uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b - id: webdev_pub_upgrade name: webdev; dart pub upgrade run: dart pub upgrade @@ -1053,13 +1198,17 @@ jobs: - job_026 - job_027 - job_028 - job_031: + - job_029 + - job_030 + - job_031 + - job_032 + job_035: name: "beta_cron; linux; Dart beta; PKG: dwds; `dart analyze .`" runs-on: ubuntu-latest if: "github.event_name == 'schedule'" steps: - name: Cache Pub hosted dependencies - uses: actions/cache@627f0f41f6904a5b1efbaed9f96d9eb58e92e920 + uses: actions/cache@4723a57e26efda3a62cbde1812113b730952852d with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:beta;packages:dwds;commands:analyze_1" @@ -1069,12 +1218,12 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@a57a6c04cf7d4840e88432aad6281d1e125f0d46 + uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d with: sdk: beta - id: checkout name: Checkout repository - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c + uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b - id: dwds_pub_upgrade name: dwds; dart pub upgrade run: dart pub upgrade @@ -1113,13 +1262,17 @@ jobs: - job_026 - job_027 - job_028 - job_032: + - job_029 + - job_030 + - job_031 + - job_032 + job_036: name: "beta_cron; linux; Dart beta; PKG: webdev; `dart analyze .`" runs-on: ubuntu-latest if: "github.event_name == 'schedule'" steps: - name: Cache Pub hosted dependencies - uses: actions/cache@627f0f41f6904a5b1efbaed9f96d9eb58e92e920 + uses: actions/cache@4723a57e26efda3a62cbde1812113b730952852d with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:beta;packages:webdev;commands:analyze_1" @@ -1129,12 +1282,12 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@a57a6c04cf7d4840e88432aad6281d1e125f0d46 + uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d with: sdk: beta - id: checkout name: Checkout repository - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c + uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b - id: webdev_pub_upgrade name: webdev; dart pub upgrade run: dart pub upgrade @@ -1173,18 +1326,22 @@ jobs: - job_026 - job_027 - job_028 - job_033: + - job_029 + - job_030 + - job_031 + - job_032 + job_037: name: "beta_cron; windows; Dart beta; PKG: dwds; `dart test -j 1`" runs-on: windows-latest if: "github.event_name == 'schedule'" steps: - name: Setup Dart SDK - uses: dart-lang/setup-dart@a57a6c04cf7d4840e88432aad6281d1e125f0d46 + uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d with: sdk: beta - id: checkout name: Checkout repository - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c + uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b - id: dwds_pub_upgrade name: dwds; dart pub upgrade run: dart pub upgrade @@ -1223,18 +1380,22 @@ jobs: - job_026 - job_027 - job_028 - job_034: + - job_029 + - job_030 + - job_031 + - job_032 + job_038: name: "beta_cron; windows; Dart beta; PKG: webdev; `dart test -j 1`" runs-on: windows-latest if: "github.event_name == 'schedule'" steps: - name: Setup Dart SDK - uses: dart-lang/setup-dart@a57a6c04cf7d4840e88432aad6281d1e125f0d46 + uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d with: sdk: beta - id: checkout name: Checkout repository - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c + uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b - id: webdev_pub_upgrade name: webdev; dart pub upgrade run: dart pub upgrade @@ -1273,7 +1434,11 @@ jobs: - job_026 - job_027 - job_028 - job_035: + - job_029 + - job_030 + - job_031 + - job_032 + job_039: name: Notify failure runs-on: ubuntu-latest if: "(github.event_name == 'push' || github.event_name == 'schedule') && failure()" @@ -1319,3 +1484,7 @@ jobs: - job_032 - job_033 - job_034 + - job_035 + - job_036 + - job_037 + - job_038 diff --git a/dwds/CHANGELOG.md b/dwds/CHANGELOG.md index 6dcf8613d..09fb15e34 100644 --- a/dwds/CHANGELOG.md +++ b/dwds/CHANGELOG.md @@ -10,6 +10,7 @@ - Fill `BoundField.name` for records. - Display records as a container of fields. - Remove test-only code from `sdk_configuration.dart`. +- Move shared test-only code to a new `test_common` package. **Breaking changes** - Require `sdkConfigurationProvider` in `ExpressionCompilerService` diff --git a/dwds/lib/src/version.dart b/dwds/lib/src/version.dart index 378dae623..98abd762f 100644 --- a/dwds/lib/src/version.dart +++ b/dwds/lib/src/version.dart @@ -1,2 +1,2 @@ // Generated code. Do not modify. -const packageVersion = '18.0.0-dev'; +const packageVersion = '17.0.1-dev'; diff --git a/dwds/pubspec.yaml b/dwds/pubspec.yaml index 43119a178..6476c158c 100644 --- a/dwds/pubspec.yaml +++ b/dwds/pubspec.yaml @@ -1,6 +1,6 @@ name: dwds # Every time this changes you need to run `dart run build_runner build`. -version: 18.0.0-dev +version: 17.0.1-dev description: >- A service that proxies between the Chrome debug protocol and the Dart VM service protocol. @@ -55,4 +55,6 @@ dev_dependencies: puppeteer: ^2.19.0 stream_channel: ^2.1.0 test: ^1.21.1 + test_common: + path: ../test_common webdriver: ^3.0.0 diff --git a/dwds/test/build_daemon_callstack_test.dart b/dwds/test/build_daemon_callstack_test.dart index ba4f584e9..eee6161cc 100644 --- a/dwds/test/build_daemon_callstack_test.dart +++ b/dwds/test/build_daemon_callstack_test.dart @@ -9,11 +9,11 @@ import 'dart:async'; import 'package:dwds/src/connections/debug_connection.dart'; import 'package:dwds/src/services/chrome_proxy_service.dart'; import 'package:test/test.dart'; +import 'package:test_common/logging.dart'; import 'package:vm_service/vm_service.dart'; import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart'; import 'fixtures/context.dart'; -import 'fixtures/logging.dart'; class TestSetup { static final contextUnsound = TestContext.withWeakNullSafety( diff --git a/dwds/test/chrome_proxy_service_test.dart b/dwds/test/chrome_proxy_service_test.dart index ec87588b8..8ffb75a36 100644 --- a/dwds/test/chrome_proxy_service_test.dart +++ b/dwds/test/chrome_proxy_service_test.dart @@ -16,11 +16,11 @@ import 'package:dwds/src/utilities/shared.dart'; import 'package:http/http.dart' as http; import 'package:path/path.dart' as path; import 'package:test/test.dart'; +import 'package:test_common/logging.dart'; import 'package:vm_service/vm_service.dart'; import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart'; import 'fixtures/context.dart'; -import 'fixtures/logging.dart'; final context = TestContext.withSoundNullSafety(); diff --git a/dwds/test/dart_uri_test.dart b/dwds/test/dart_uri_test.dart index 91bedf364..5e061bcea 100644 --- a/dwds/test/dart_uri_test.dart +++ b/dwds/test/dart_uri_test.dart @@ -8,9 +8,9 @@ import 'package:dwds/src/loaders/strategy.dart'; import 'package:dwds/src/utilities/dart_uri.dart'; import 'package:test/test.dart'; +import 'package:test_common/logging.dart'; import 'fixtures/fakes.dart'; -import 'fixtures/logging.dart'; class TestStrategy extends FakeStrategy { @override diff --git a/dwds/test/evaluate_circular_common.dart b/dwds/test/evaluate_circular_common.dart index 87bc97370..f7a0a450b 100644 --- a/dwds/test/evaluate_circular_common.dart +++ b/dwds/test/evaluate_circular_common.dart @@ -9,11 +9,11 @@ import 'dart:async'; import 'package:dwds/src/connections/debug_connection.dart'; import 'package:dwds/src/services/chrome_proxy_service.dart'; import 'package:test/test.dart'; +import 'package:test_common/logging.dart'; import 'package:vm_service/vm_service.dart'; import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart'; import 'fixtures/context.dart'; -import 'fixtures/logging.dart'; class TestSetup { static TestContext contextUnsound(String index) => diff --git a/dwds/test/evaluate_common.dart b/dwds/test/evaluate_common.dart index 982aaf00d..7da5c2606 100644 --- a/dwds/test/evaluate_common.dart +++ b/dwds/test/evaluate_common.dart @@ -9,11 +9,11 @@ import 'dart:async'; import 'package:dwds/src/connections/debug_connection.dart'; import 'package:dwds/src/services/chrome_proxy_service.dart'; import 'package:test/test.dart'; +import 'package:test_common/logging.dart'; import 'package:vm_service/vm_service.dart'; import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart'; import 'fixtures/context.dart'; -import 'fixtures/logging.dart'; class TestSetup { static TestContext contextUnsound(String index) => diff --git a/dwds/test/events_test.dart b/dwds/test/events_test.dart index 8e8ad5399..4453a2444 100644 --- a/dwds/test/events_test.dart +++ b/dwds/test/events_test.dart @@ -11,12 +11,12 @@ import 'package:dwds/src/events.dart'; import 'package:dwds/src/services/chrome_proxy_service.dart'; import 'package:dwds/src/utilities/server.dart'; import 'package:test/test.dart'; +import 'package:test_common/logging.dart'; import 'package:vm_service/vm_service.dart'; import 'package:webdriver/async_core.dart'; import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart'; import 'fixtures/context.dart'; -import 'fixtures/logging.dart'; ChromeProxyService get service => fetchChromeProxyService(context.debugConnection); diff --git a/dwds/test/expression_compiler_service_test.dart b/dwds/test/expression_compiler_service_test.dart index 75eb4aa96..f63f31444 100644 --- a/dwds/test/expression_compiler_service_test.dart +++ b/dwds/test/expression_compiler_service_test.dart @@ -9,14 +9,13 @@ import 'dart:convert'; import 'dart:io'; import 'package:dwds/expression_compiler.dart'; +import 'package:dwds/sdk_configuration.dart'; import 'package:dwds/src/services/expression_compiler_service.dart'; -import 'package:dwds/src/utilities/sdk_configuration.dart'; import 'package:dwds/src/utilities/server.dart'; import 'package:logging/logging.dart'; import 'package:shelf/shelf.dart'; import 'package:test/test.dart'; - -import 'fixtures/logging.dart'; +import 'package:test_common/logging.dart'; ExpressionCompilerService get service => _service!; late ExpressionCompilerService? _service; @@ -50,7 +49,10 @@ void main() async { final executable = Platform.resolvedExecutable; final dartdevc = SdkConfiguration.defaultConfiguration.compilerWorkerPath!; +<<<<<<< HEAD +======= +>>>>>>> af0c65ab91 (Changed accidentally renamed fields back) // redirect logs for testing _output = StreamController.broadcast(); output.stream.listen(printOnFailure); diff --git a/dwds/test/fixtures/context.dart b/dwds/test/fixtures/context.dart index 9eca00156..ad42e8b21 100644 --- a/dwds/test/fixtures/context.dart +++ b/dwds/test/fixtures/context.dart @@ -31,12 +31,13 @@ import 'package:path/path.dart' as p; import 'package:shelf/shelf.dart'; import 'package:shelf_proxy/shelf_proxy.dart'; import 'package:test/test.dart'; +import 'package:test_common/logging.dart'; +import 'package:test_common/sdk_layout.dart'; import 'package:vm_service/vm_service.dart'; // ignore: deprecated_member_use import 'package:webdriver/io.dart'; import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart'; -import 'logging.dart'; import 'server.dart'; import 'test_sdk_configuration.dart'; import 'utilities.dart'; @@ -205,6 +206,7 @@ class TestContext { // Generate missing SDK assets if needed. final sdkConfigurationProvider = TestSdkConfigurationProvider(verboseCompiler: verboseCompiler); + final sdkLayout = sdkConfigurationProvider.sdkLayout; final configuration = await sdkConfigurationProvider.configuration; configuration.validate(); @@ -335,6 +337,7 @@ class TestContext { soundNullSafety: nullSafety == NullSafety.sound, experiments: experiments, verbose: verboseCompiler, + sdkLayout: sdkLayout, ); final assetServerPort = await findUnusedPort(); diff --git a/dwds/test/frontend_server_breakpoint_test.dart b/dwds/test/frontend_server_breakpoint_test.dart index 4b11784fc..f9498a353 100644 --- a/dwds/test/frontend_server_breakpoint_test.dart +++ b/dwds/test/frontend_server_breakpoint_test.dart @@ -9,11 +9,11 @@ import 'dart:async'; import 'package:dwds/src/connections/debug_connection.dart'; import 'package:dwds/src/services/chrome_proxy_service.dart'; import 'package:test/test.dart'; +import 'package:test_common/logging.dart'; import 'package:vm_service/vm_service.dart'; import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart'; import 'fixtures/context.dart'; -import 'fixtures/logging.dart'; final context = TestContext.withWeakNullSafety( packageName: '_testPackage', diff --git a/dwds/test/frontend_server_callstack_test.dart b/dwds/test/frontend_server_callstack_test.dart index f2f837204..ec6566dfb 100644 --- a/dwds/test/frontend_server_callstack_test.dart +++ b/dwds/test/frontend_server_callstack_test.dart @@ -9,11 +9,11 @@ import 'dart:async'; import 'package:dwds/src/connections/debug_connection.dart'; import 'package:dwds/src/services/chrome_proxy_service.dart'; import 'package:test/test.dart'; +import 'package:test_common/logging.dart'; import 'package:vm_service/vm_service.dart'; import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart'; import 'fixtures/context.dart'; -import 'fixtures/logging.dart'; class TestSetup { static final contextUnsound = TestContext.withWeakNullSafety( diff --git a/dwds/test/handlers/asset_handler_test.dart b/dwds/test/handlers/asset_handler_test.dart index 7cb468193..57484c31b 100644 --- a/dwds/test/handlers/asset_handler_test.dart +++ b/dwds/test/handlers/asset_handler_test.dart @@ -6,9 +6,9 @@ import 'package:shelf/shelf.dart'; import 'package:test/test.dart'; +import 'package:test_common/logging.dart'; import '../fixtures/context.dart'; -import '../fixtures/logging.dart'; void main() { group('Asset handler', () { diff --git a/dwds/test/records_test.dart b/dwds/test/records_test.dart index cb090b1bd..57bd2da7b 100644 --- a/dwds/test/records_test.dart +++ b/dwds/test/records_test.dart @@ -8,10 +8,10 @@ import 'package:dwds/src/connections/debug_connection.dart'; import 'package:dwds/src/services/chrome_proxy_service.dart'; import 'package:test/test.dart'; +import 'package:test_common/logging.dart'; import 'package:vm_service/vm_service.dart'; import 'fixtures/context.dart'; -import 'fixtures/logging.dart'; class TestSetup { TestContext context; diff --git a/dwds/test/reload_test.dart b/dwds/test/reload_test.dart index d9052e314..6ae7d608e 100644 --- a/dwds/test/reload_test.dart +++ b/dwds/test/reload_test.dart @@ -6,10 +6,10 @@ @Timeout(Duration(minutes: 5)) import 'package:dwds/src/loaders/strategy.dart'; import 'package:test/test.dart'; +import 'package:test_common/logging.dart'; import 'package:vm_service/vm_service.dart'; import 'fixtures/context.dart'; -import 'fixtures/logging.dart'; import 'fixtures/utilities.dart'; final context = TestContext.withSoundNullSafety( diff --git a/dwds/test/restore_breakpoints_test.dart b/dwds/test/restore_breakpoints_test.dart index e21c3e35a..d9313ce15 100644 --- a/dwds/test/restore_breakpoints_test.dart +++ b/dwds/test/restore_breakpoints_test.dart @@ -9,11 +9,11 @@ import 'dart:async'; import 'package:dwds/src/connections/debug_connection.dart'; import 'package:dwds/src/services/chrome_proxy_service.dart'; import 'package:test/test.dart'; +import 'package:test_common/logging.dart'; import 'package:vm_service/vm_service.dart'; import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart'; import 'fixtures/context.dart'; -import 'fixtures/logging.dart'; final context = TestContext.withSoundNullSafety(); ChromeProxyService get service => diff --git a/frontend_server_common/lib/src/devfs.dart b/frontend_server_common/lib/src/devfs.dart index fd00c052f..d672810a3 100644 --- a/frontend_server_common/lib/src/devfs.dart +++ b/frontend_server_common/lib/src/devfs.dart @@ -7,13 +7,11 @@ import 'package:dwds/asset_reader.dart'; import 'package:file/file.dart'; import 'package:path/path.dart' as p; +import 'package:test_common/sdk_layout.dart'; import 'asset_server.dart'; import 'bootstrap.dart'; import 'frontend_server_client.dart'; -import 'utilities.dart'; - -final String dartWebSdkPath = p.join(dartSdkPath, 'lib', 'dev_compiler'); class WebDevFS { WebDevFS({ @@ -25,6 +23,7 @@ class WebDevFS { required this.index, required this.soundNullSafety, this.urlTunneler, + required this.sdkLayout, }); final FileSystem fileSystem; @@ -36,6 +35,7 @@ class WebDevFS { final String index; final UrlEncoder? urlTunneler; final bool soundNullSafety; + final TestSdkLayout sdkLayout; late final Directory _savedCurrentDirectory; Future create() async { @@ -85,9 +85,9 @@ class WebDevFS { assetServer.writeFile('main_module.digests', '{}'); - var sdk = soundNullSafety ? dartSdkSound : dartSdk; + var sdk = soundNullSafety ? dartSdk : dartSdkWeak; var sdkSourceMap = - soundNullSafety ? dartSdkSourcemapSound : dartSdkSourcemap; + soundNullSafety ? dartSdkSourcemap : dartSdkSourcemapWeak; assetServer.writeFile('dart_sdk.js', sdk.readAsStringSync()); assetServer.writeFile('dart_sdk.js.map', sdkSourceMap.readAsStringSync()); @@ -129,45 +129,12 @@ class WebDevFS { )..invalidatedModules = modules; } - File get requireJS => fileSystem.file(fileSystem.path.join( - dartWebSdkPath, - 'amd', - 'require.js', - )); - - File get dartSdk => fileSystem.file(fileSystem.path.join( - dartWebSdkPath, - 'kernel', - 'amd', - 'dart_sdk_unsound.js', - )); - - File get dartSdkSound => fileSystem.file(fileSystem.path.join( - dartWebSdkPath, - 'kernel', - 'amd', - 'dart_sdk.js', - )); - - File get dartSdkSourcemap => fileSystem.file(fileSystem.path.join( - dartWebSdkPath, - 'kernel', - 'amd', - 'dart_sdk_unsound.js.map', - )); - - File get dartSdkSourcemapSound => fileSystem.file(fileSystem.path.join( - dartWebSdkPath, - 'kernel', - 'amd', - 'dart_sdk.js.map', - )); - - File get stackTraceMapper => fileSystem.file(fileSystem.path.join( - dartWebSdkPath, - 'web', - 'dart_stack_trace_mapper.js', - )); + File get requireJS => fileSystem.file(sdkLayout.requireJsPath); + File get dartSdkWeak => fileSystem.file(sdkLayout.weakJsPath); + File get dartSdk => fileSystem.file(sdkLayout.soundJsPath); + File get dartSdkSourcemapWeak => fileSystem.file(sdkLayout.weakJsMapPath); + File get dartSdkSourcemap => fileSystem.file(sdkLayout.soundJsMapPath); + File get stackTraceMapper => fileSystem.file(sdkLayout.stackTraceMapperPath); } class UpdateFSReport { diff --git a/frontend_server_common/lib/src/frontend_server_client.dart b/frontend_server_common/lib/src/frontend_server_client.dart index 911937704..533beaa12 100644 --- a/frontend_server_common/lib/src/frontend_server_client.dart +++ b/frontend_server_common/lib/src/frontend_server_client.dart @@ -11,7 +11,7 @@ import 'dart:io'; import 'package:dwds/expression_compiler.dart'; import 'package:logging/logging.dart'; import 'package:package_config/package_config.dart'; -import 'package:path/path.dart' as p; +import 'package:test_common/sdk_layout.dart'; import 'package:usage/uuid/uuid.dart'; import 'utilities.dart'; @@ -24,9 +24,6 @@ void defaultConsumer(String message, {StackTrace? stackTrace}) => ? _serverLogger.info(message) : _serverLogger.severe(message, null, stackTrace); -String get frontendServerExecutable => - p.join(dartSdkPath, 'bin', 'snapshots', 'frontend_server.dart.snapshot'); - typedef CompilerMessageConsumer = void Function(String message, {StackTrace stackTrace}); @@ -261,6 +258,7 @@ class ResidentCompiler { required this.platformDill, required this.soundNullSafety, this.experiments = const [], + required this.sdkLayout, this.verbose = false, CompilerMessageConsumer compilerMessageConsumer = defaultConsumer, }) : _stdoutHandler = StdoutHandler(consumer: compilerMessageConsumer); @@ -273,6 +271,7 @@ class ResidentCompiler { final String platformDill; final bool soundNullSafety; final List experiments; + final TestSdkLayout sdkLayout; final bool verbose; /// The path to the root of the Dart SDK used to compile. @@ -362,7 +361,7 @@ class ResidentCompiler { Future _compile( String scriptUri, String outputFilePath) async { - var frontendServer = frontendServerExecutable; + var frontendServer = sdkLayout.frontendServerSnapshotPath; var args = [ frontendServer, '--sdk-root', diff --git a/frontend_server_common/lib/src/resident_runner.dart b/frontend_server_common/lib/src/resident_runner.dart index 99b1ed81c..964015d52 100644 --- a/frontend_server_common/lib/src/resident_runner.dart +++ b/frontend_server_common/lib/src/resident_runner.dart @@ -11,17 +11,12 @@ import 'package:dwds/asset_reader.dart'; import 'package:dwds/expression_compiler.dart'; import 'package:file/file.dart'; import 'package:logging/logging.dart'; -import 'package:path/path.dart' as p; +import 'package:test_common/sdk_layout.dart'; import 'devfs.dart'; import 'frontend_server_client.dart'; import 'utilities.dart'; -final Uri summaryDillUnsound = Uri.file( - p.join(dartSdkPath, 'lib', '_internal', 'ddc_outline_unsound.dill')); -final Uri summaryDillSound = - Uri.file(p.join(dartSdkPath, 'lib', '_internal', 'ddc_outline.dill')); - class ResidentWebRunner { final _logger = Logger('ResidentWebRunner'); @@ -36,19 +31,24 @@ class ResidentWebRunner { required this.outputPath, required this.soundNullSafety, this.experiments = const [], + required this.sdkLayout, bool verbose = false, }) { + final platformDillUri = Uri.file(soundNullSafety + ? sdkLayout.soundSummaryPath + : sdkLayout.weakSummaryPath); + generator = ResidentCompiler( dartSdkPath, projectDirectory: projectDirectory, packageConfigFile: packageConfigFile, useDebuggerModuleNames: packageUriMapper.useDebuggerModuleNames, - platformDill: - soundNullSafety ? '$summaryDillSound' : '$summaryDillUnsound', + platformDill: '$platformDillUri', fileSystemRoots: fileSystemRoots, fileSystemScheme: fileSystemScheme, soundNullSafety: soundNullSafety, experiments: experiments, + sdkLayout: sdkLayout, verbose: verbose, ); expressionCompiler = TestExpressionCompiler(generator); @@ -64,6 +64,7 @@ class ResidentWebRunner { final String fileSystemScheme; final bool soundNullSafety; final List experiments; + final TestSdkLayout sdkLayout; late ResidentCompiler generator; late ExpressionCompiler expressionCompiler; @@ -82,6 +83,7 @@ class ResidentWebRunner { index: index, urlTunneler: urlTunneler, soundNullSafety: soundNullSafety, + sdkLayout: sdkLayout, ); uri = await devFS.create(); diff --git a/frontend_server_common/pubspec.yaml b/frontend_server_common/pubspec.yaml index e410d6886..d9ed20682 100644 --- a/frontend_server_common/pubspec.yaml +++ b/frontend_server_common/pubspec.yaml @@ -16,4 +16,6 @@ dependencies: package_config: ^2.0.0 path: ^1.8.0 pub_semver: ^2.1.1 + test_common: + path: ../test_common usage: ^4.0.0 diff --git a/test_common/analysis_options.yaml b/test_common/analysis_options.yaml new file mode 100644 index 000000000..64d22c080 --- /dev/null +++ b/test_common/analysis_options.yaml @@ -0,0 +1,13 @@ +# This file contains the analysis options used for code in the webdev +# repository. + +include: package:lints/recommended.yaml + +analyzer: + +linter: + rules: + - always_use_package_imports + - directives_ordering + - prefer_final_locals + - unawaited_futures diff --git a/test_common/dart_test.yaml b/test_common/dart_test.yaml new file mode 100644 index 000000000..94245ee9a --- /dev/null +++ b/test_common/dart_test.yaml @@ -0,0 +1,3 @@ +concurrency: 1 +retry: 3 + diff --git a/dwds/test/fixtures/logging.dart b/test_common/lib/logging.dart similarity index 100% rename from dwds/test/fixtures/logging.dart rename to test_common/lib/logging.dart diff --git a/dwds/test/fixtures/sdk_asset_generator.dart b/test_common/lib/sdk_asset_generator.dart similarity index 99% rename from dwds/test/fixtures/sdk_asset_generator.dart rename to test_common/lib/sdk_asset_generator.dart index 83f977ab6..a51859ad0 100644 --- a/dwds/test/fixtures/sdk_asset_generator.dart +++ b/test_common/lib/sdk_asset_generator.dart @@ -5,6 +5,7 @@ import 'package:file/file.dart'; import 'package:file/local.dart'; import 'package:logging/logging.dart'; import 'package:path/path.dart' as p; +import 'package:test_common/sdk_layout.dart'; import 'test_sdk_layout.dart'; diff --git a/test_common/lib/sdk_layout.dart b/test_common/lib/sdk_layout.dart new file mode 100644 index 000000000..357fd66df --- /dev/null +++ b/test_common/lib/sdk_layout.dart @@ -0,0 +1,194 @@ +// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +import 'package:dwds/sdk_configuration.dart'; +import 'package:path/path.dart' as p; +import 'package:test_common/sdk_asset_generator.dart'; + +/// Test Dart SDK layout. +/// +/// Contains definition of the default SDK layout required for tests. +/// We keep all the path constants in one place for ease of update. +class TestSdkLayout { + static final defaultSdkDirectory = SdkLayout.defaultSdkDirectory; + static TestSdkLayout defaultSdkLayout = + TestSdkLayout.createDefault(defaultSdkDirectory); + static SdkConfiguration defaultSdkConfiguration = + createConfiguration(defaultSdkLayout); + + factory TestSdkLayout.createDefault(String sdkDirectory) => + TestSdkLayout.createDefaultFromSdkLayout( + SdkLayout.createDefault(sdkDirectory)); + + factory TestSdkLayout.createDefaultFromSdkLayout(SdkLayout sdkLayout) => + TestSdkLayout( + sdkDirectory: sdkLayout.sdkDirectory, + soundSummaryPath: sdkLayout.soundSummaryPath, + soundFullDillPath: p.join( + sdkLayout.sdkDirectory, + 'lib', + '_internal', + 'ddc_platform.dill', + ), + soundJsPath: p.join( + sdkLayout.sdkDirectory, + 'lib', + 'dev_compiler', + 'kernel', + 'amd', + 'dart_sdk.js', + ), + soundJsMapPath: p.join( + sdkLayout.sdkDirectory, + 'lib', + 'dev_compiler', + 'kernel', + 'amd', + 'dart_sdk.js.map', + ), + weakSummaryPath: sdkLayout.weakSummaryPath, + weakFullDillPath: p.join( + sdkLayout.sdkDirectory, + 'lib', + '_internal', + 'ddc_platform_unsound.dill', + ), + weakJsPath: p.join( + sdkLayout.sdkDirectory, + 'lib', + 'dev_compiler', + 'kernel', + 'amd', + 'dart_sdk_unsound.js', + ), + weakJsMapPath: p.join( + sdkLayout.sdkDirectory, + 'lib', + 'dev_compiler', + 'kernel', + 'amd', + 'dart_sdk_unsound.js.map', + ), + requireJsPath: p.join( + sdkLayout.sdkDirectory, + 'lib', + 'dev_compiler', + 'amd', + 'require.js', + ), + stackTraceMapperPath: p.join( + sdkLayout.sdkDirectory, + 'lib', + 'dev_compiler', + 'web', + 'dart_stack_trace_mapper.js', + ), + dartPath: p.join(sdkLayout.sdkDirectory, 'bin', 'dart'), + frontendServerSnapshotPath: p.join( + sdkLayout.sdkDirectory, + 'bin', + 'snapshots', + 'frontend_server.dart.snapshot', + ), + dartdevcSnapshotPath: sdkLayout.dartdevcSnapshotPath, + kernelWorkerSnapshotPath: p.join( + sdkLayout.sdkDirectory, + 'bin', + 'snapshots', + 'kernel_worker.dart.snapshot', + ), + ); + + final String sdkDirectory; + + String get soundJsFileName => p.basename(soundJsPath); + String get soundJsMapFileName => p.basename(soundJsMapPath); + String get soundSummaryFileName => p.basename(soundSummaryPath); + String get soundFullDillFileName => p.basename(soundFullDillPath); + + final String soundJsPath; + final String soundJsMapPath; + final String soundSummaryPath; + final String soundFullDillPath; + + String get weakJsFileName => p.basename(weakJsPath); + String get weakJsMapFileName => p.basename(weakJsMapPath); + String get weakSummaryFileName => p.basename(weakSummaryPath); + String get weakFullDillFileName => p.basename(weakFullDillPath); + + final String weakJsPath; + final String weakJsMapPath; + final String weakSummaryPath; + final String weakFullDillPath; + + final String requireJsPath; + final String stackTraceMapperPath; + + final String dartPath; + final String frontendServerSnapshotPath; + final String dartdevcSnapshotPath; + final String kernelWorkerSnapshotPath; + + const TestSdkLayout({ + required this.sdkDirectory, + required this.soundJsPath, + required this.soundJsMapPath, + required this.soundSummaryPath, + required this.soundFullDillPath, + required this.weakJsPath, + required this.weakJsMapPath, + required this.weakSummaryPath, + required this.weakFullDillPath, + required this.requireJsPath, + required this.stackTraceMapperPath, + required this.dartPath, + required this.frontendServerSnapshotPath, + required this.dartdevcSnapshotPath, + required this.kernelWorkerSnapshotPath, + }); + + /// Creates configuration from sdk layout. + static SdkConfiguration createConfiguration(TestSdkLayout sdkLayout) => + SdkConfiguration( + sdkDirectory: sdkLayout.sdkDirectory, + weakSdkSummaryPath: sdkLayout.weakSummaryPath, + soundSdkSummaryPath: sdkLayout.soundSummaryPath, + compilerWorkerPath: sdkLayout.dartdevcSnapshotPath, + ); +} + +/// Implementation for SDK configuration for tests that can generate +/// missing assets. +/// +/// - Generate SDK js, source map, and full dill for weak and sound +/// modes (normally included in flutter SDK or produced by build). +/// - Need to generate SDK summary for weak null safety mode as it +/// is not provided by the SDK installation. +/// +/// TODO(annagrin): update to only generating missing sound artifacts +/// for frontend server after we have no uses of weak null safety. +class TestSdkConfigurationProvider extends SdkConfigurationProvider { + final bool _verboseCompiler; + SdkConfiguration? _configuration; + + final sdkLayout = TestSdkLayout.defaultSdkLayout; + + TestSdkConfigurationProvider({bool verboseCompiler = false}) + : _verboseCompiler = verboseCompiler; + + @override + Future get configuration async => + _configuration ??= await _create(); + + /// Generate missing assets in the default SDK layout. + Future _create() async { + final assetGenerator = SdkAssetGenerator( + sdkLayout: sdkLayout, + verboseCompiler: _verboseCompiler, + ); + + await assetGenerator.generateSdkAssets(); + return TestSdkLayout.defaultSdkConfiguration; + } +} diff --git a/test_common/mono_pkg.yaml b/test_common/mono_pkg.yaml new file mode 100644 index 000000000..6528b9008 --- /dev/null +++ b/test_common/mono_pkg.yaml @@ -0,0 +1,27 @@ +# See https://pub.dev/packages/mono_repo for details +stages: + - analyzer_and_format: + - group: + - format + - analyze: --fatal-infos . + sdk: dev + - unit_test: + # Linux tests: + # Note: `Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &` must be + # run first for Linux. + - group: + - command: Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 & + - test: + sdk: + - dev + - main + os: + - linux + # Windows tests: + - group: + - test: + sdk: + - dev + - main + os: + - windows diff --git a/test_common/pubspec.yaml b/test_common/pubspec.yaml new file mode 100644 index 000000000..adaae0e27 --- /dev/null +++ b/test_common/pubspec.yaml @@ -0,0 +1,18 @@ +name: test_common +publish_to: none +description: >- + Common test functionality. +environment: + sdk: ">=3.0.0-134.0.dev <4.0.0" + +dependencies: + dwds: + path: ../dwds + file: ^6.1.3 + logging: ^1.0.1 + path: ^1.8.1 + test: ^1.21.1 + +dev_dependencies: + lints: ^2.0.0 + diff --git a/dwds/test/sdk_asset_generator_test.dart b/test_common/test/sdk_asset_generator_test.dart similarity index 97% rename from dwds/test/sdk_asset_generator_test.dart rename to test_common/test/sdk_asset_generator_test.dart index 833f9a420..54978e781 100644 --- a/dwds/test/sdk_asset_generator_test.dart +++ b/test_common/test/sdk_asset_generator_test.dart @@ -9,10 +9,9 @@ import 'dart:io'; import 'package:path/path.dart' as p; import 'package:test/test.dart'; - -import 'fixtures/logging.dart'; -import 'fixtures/sdk_asset_generator.dart'; -import 'fixtures/test_sdk_layout.dart'; +import 'package:test_common/logging.dart'; +import 'package:test_common/sdk_asset_generator.dart'; +import 'package:test_common/sdk_layout.dart'; void main() { group('SDK asset generator', () { diff --git a/tool/ci.sh b/tool/ci.sh index 9c13f0f80..783882300 100755 --- a/tool/ci.sh +++ b/tool/ci.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Created with package:mono_repo v6.5.0 +# Created with package:mono_repo v6.4.3 # Support built in commands on windows out of the box. # When it is a flutter repo (check the pubspec.yaml for "sdk: flutter") @@ -108,6 +108,10 @@ for PKG in ${PKGS}; do dart test -j 1 || EXIT_CODE=$? ;; test_6) + echo 'dart test' + dart test || EXIT_CODE=$? + ;; + test_7) echo 'dart test test/build/ensure_build_test.dart' dart test test/build/ensure_build_test.dart || EXIT_CODE=$? ;; From e781731124191b7d95004db90c78806daf3ea424 Mon Sep 17 00:00:00 2001 From: Anna Gringauze Date: Mon, 13 Feb 2023 18:36:11 -0800 Subject: [PATCH 03/15] Rebase on master --- .../expression_compiler_service_test.dart | 4 --- dwds/test/fixtures/context.dart | 3 +- frontend_server_common/lib/src/devfs.dart | 2 +- .../lib/src/frontend_server_client.dart | 2 +- .../lib/src/resident_runner.dart | 2 +- test_common/lib/sdk_asset_generator.dart | 4 +-- .../lib}/test_sdk_configuration.dart | 6 ++-- .../{sdk_layout.dart => test_sdk_layout.dart} | 36 ------------------- .../test/sdk_asset_generator_test.dart | 2 +- 9 files changed, 9 insertions(+), 52 deletions(-) rename {dwds/test/fixtures => test_common/lib}/test_sdk_configuration.dart (90%) rename test_common/lib/{sdk_layout.dart => test_sdk_layout.dart} (79%) diff --git a/dwds/test/expression_compiler_service_test.dart b/dwds/test/expression_compiler_service_test.dart index f63f31444..90f9d311a 100644 --- a/dwds/test/expression_compiler_service_test.dart +++ b/dwds/test/expression_compiler_service_test.dart @@ -49,10 +49,6 @@ void main() async { final executable = Platform.resolvedExecutable; final dartdevc = SdkConfiguration.defaultConfiguration.compilerWorkerPath!; -<<<<<<< HEAD - -======= ->>>>>>> af0c65ab91 (Changed accidentally renamed fields back) // redirect logs for testing _output = StreamController.broadcast(); output.stream.listen(printOnFailure); diff --git a/dwds/test/fixtures/context.dart b/dwds/test/fixtures/context.dart index ad42e8b21..3fcd2a836 100644 --- a/dwds/test/fixtures/context.dart +++ b/dwds/test/fixtures/context.dart @@ -32,14 +32,13 @@ import 'package:shelf/shelf.dart'; import 'package:shelf_proxy/shelf_proxy.dart'; import 'package:test/test.dart'; import 'package:test_common/logging.dart'; -import 'package:test_common/sdk_layout.dart'; +import 'package:test_common/test_sdk_configuration.dart'; import 'package:vm_service/vm_service.dart'; // ignore: deprecated_member_use import 'package:webdriver/io.dart'; import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart'; import 'server.dart'; -import 'test_sdk_configuration.dart'; import 'utilities.dart'; final _exeExt = Platform.isWindows ? '.exe' : ''; diff --git a/frontend_server_common/lib/src/devfs.dart b/frontend_server_common/lib/src/devfs.dart index d672810a3..9bd7c9cbc 100644 --- a/frontend_server_common/lib/src/devfs.dart +++ b/frontend_server_common/lib/src/devfs.dart @@ -7,7 +7,7 @@ import 'package:dwds/asset_reader.dart'; import 'package:file/file.dart'; import 'package:path/path.dart' as p; -import 'package:test_common/sdk_layout.dart'; +import 'package:test_common/test_sdk_layout.dart'; import 'asset_server.dart'; import 'bootstrap.dart'; diff --git a/frontend_server_common/lib/src/frontend_server_client.dart b/frontend_server_common/lib/src/frontend_server_client.dart index 533beaa12..5aa733b32 100644 --- a/frontend_server_common/lib/src/frontend_server_client.dart +++ b/frontend_server_common/lib/src/frontend_server_client.dart @@ -11,7 +11,7 @@ import 'dart:io'; import 'package:dwds/expression_compiler.dart'; import 'package:logging/logging.dart'; import 'package:package_config/package_config.dart'; -import 'package:test_common/sdk_layout.dart'; +import 'package:test_common/test_sdk_layout.dart'; import 'package:usage/uuid/uuid.dart'; import 'utilities.dart'; diff --git a/frontend_server_common/lib/src/resident_runner.dart b/frontend_server_common/lib/src/resident_runner.dart index 964015d52..1c9af81d1 100644 --- a/frontend_server_common/lib/src/resident_runner.dart +++ b/frontend_server_common/lib/src/resident_runner.dart @@ -11,7 +11,7 @@ import 'package:dwds/asset_reader.dart'; import 'package:dwds/expression_compiler.dart'; import 'package:file/file.dart'; import 'package:logging/logging.dart'; -import 'package:test_common/sdk_layout.dart'; +import 'package:test_common/test_sdk_layout.dart'; import 'devfs.dart'; import 'frontend_server_client.dart'; diff --git a/test_common/lib/sdk_asset_generator.dart b/test_common/lib/sdk_asset_generator.dart index a51859ad0..21bcf55ec 100644 --- a/test_common/lib/sdk_asset_generator.dart +++ b/test_common/lib/sdk_asset_generator.dart @@ -5,9 +5,7 @@ import 'package:file/file.dart'; import 'package:file/local.dart'; import 'package:logging/logging.dart'; import 'package:path/path.dart' as p; -import 'package:test_common/sdk_layout.dart'; - -import 'test_sdk_layout.dart'; +import 'package:test_common/test_sdk_layout.dart'; /// Generates sdk.js, sdk.map, sdk full dill, and sdk summary files. /// diff --git a/dwds/test/fixtures/test_sdk_configuration.dart b/test_common/lib/test_sdk_configuration.dart similarity index 90% rename from dwds/test/fixtures/test_sdk_configuration.dart rename to test_common/lib/test_sdk_configuration.dart index 29c35bb6d..f93fe691d 100644 --- a/dwds/test/fixtures/test_sdk_configuration.dart +++ b/test_common/lib/test_sdk_configuration.dart @@ -3,10 +3,10 @@ // BSD-style license that can be found in the LICENSE file. // TODO:(annagrin) Move to a test_common package. -import 'package:dwds/src/utilities/sdk_configuration.dart'; +import 'package:dwds/sdk_configuration.dart'; -import 'sdk_asset_generator.dart'; -import 'test_sdk_layout.dart'; +import 'package:test_common/sdk_asset_generator.dart'; +import 'package:test_common/test_sdk_layout.dart'; /// Implementation for SDK configuration for tests that can generate /// missing assets. diff --git a/test_common/lib/sdk_layout.dart b/test_common/lib/test_sdk_layout.dart similarity index 79% rename from test_common/lib/sdk_layout.dart rename to test_common/lib/test_sdk_layout.dart index 357fd66df..78a00c1d4 100644 --- a/test_common/lib/sdk_layout.dart +++ b/test_common/lib/test_sdk_layout.dart @@ -4,7 +4,6 @@ import 'package:dwds/sdk_configuration.dart'; import 'package:path/path.dart' as p; -import 'package:test_common/sdk_asset_generator.dart'; /// Test Dart SDK layout. /// @@ -157,38 +156,3 @@ class TestSdkLayout { compilerWorkerPath: sdkLayout.dartdevcSnapshotPath, ); } - -/// Implementation for SDK configuration for tests that can generate -/// missing assets. -/// -/// - Generate SDK js, source map, and full dill for weak and sound -/// modes (normally included in flutter SDK or produced by build). -/// - Need to generate SDK summary for weak null safety mode as it -/// is not provided by the SDK installation. -/// -/// TODO(annagrin): update to only generating missing sound artifacts -/// for frontend server after we have no uses of weak null safety. -class TestSdkConfigurationProvider extends SdkConfigurationProvider { - final bool _verboseCompiler; - SdkConfiguration? _configuration; - - final sdkLayout = TestSdkLayout.defaultSdkLayout; - - TestSdkConfigurationProvider({bool verboseCompiler = false}) - : _verboseCompiler = verboseCompiler; - - @override - Future get configuration async => - _configuration ??= await _create(); - - /// Generate missing assets in the default SDK layout. - Future _create() async { - final assetGenerator = SdkAssetGenerator( - sdkLayout: sdkLayout, - verboseCompiler: _verboseCompiler, - ); - - await assetGenerator.generateSdkAssets(); - return TestSdkLayout.defaultSdkConfiguration; - } -} diff --git a/test_common/test/sdk_asset_generator_test.dart b/test_common/test/sdk_asset_generator_test.dart index 54978e781..5a7cad7aa 100644 --- a/test_common/test/sdk_asset_generator_test.dart +++ b/test_common/test/sdk_asset_generator_test.dart @@ -11,7 +11,7 @@ import 'package:path/path.dart' as p; import 'package:test/test.dart'; import 'package:test_common/logging.dart'; import 'package:test_common/sdk_asset_generator.dart'; -import 'package:test_common/sdk_layout.dart'; +import 'package:test_common/test_sdk_layout.dart'; void main() { group('SDK asset generator', () { From 15b0837a475444436bf153a1de5573168f66fd78 Mon Sep 17 00:00:00 2001 From: Anna Gringauze Date: Mon, 13 Feb 2023 19:08:57 -0800 Subject: [PATCH 04/15] Fix bad merge --- dwds/lib/src/version.dart | 2 +- dwds/pubspec.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dwds/lib/src/version.dart b/dwds/lib/src/version.dart index 98abd762f..378dae623 100644 --- a/dwds/lib/src/version.dart +++ b/dwds/lib/src/version.dart @@ -1,2 +1,2 @@ // Generated code. Do not modify. -const packageVersion = '17.0.1-dev'; +const packageVersion = '18.0.0-dev'; diff --git a/dwds/pubspec.yaml b/dwds/pubspec.yaml index 6476c158c..af0f93ec0 100644 --- a/dwds/pubspec.yaml +++ b/dwds/pubspec.yaml @@ -1,6 +1,6 @@ name: dwds # Every time this changes you need to run `dart run build_runner build`. -version: 17.0.1-dev +version: 18.0.0-dev description: >- A service that proxies between the Chrome debug protocol and the Dart VM service protocol. From 6647335918ba2b05c6be6b88654f7c7e8a8fe68a Mon Sep 17 00:00:00 2001 From: Anna Gringauze Date: Mon, 13 Feb 2023 20:06:24 -0800 Subject: [PATCH 05/15] Re-enable webdev weak null safety e2e tests --- webdev/pubspec.yaml | 2 ++ webdev/test/e2e_test.dart | 6 ++---- webdev/test/test_utils.dart | 5 +++++ 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/webdev/pubspec.yaml b/webdev/pubspec.yaml index b131612c1..d6f991faa 100644 --- a/webdev/pubspec.yaml +++ b/webdev/pubspec.yaml @@ -45,6 +45,8 @@ dev_dependencies: build_verify: ^3.0.0 build_version: ^2.1.1 test: ^1.21.1 + test_common: + path: ../test_common test_descriptor: ^2.0.0 test_process: ^2.0.2 webdriver: ^3.0.0 diff --git a/webdev/test/e2e_test.dart b/webdev/test/e2e_test.dart index afdecc708..8d706a434 100644 --- a/webdev/test/e2e_test.dart +++ b/webdev/test/e2e_test.dart @@ -180,8 +180,7 @@ void main() { await process.shouldExit(0); await d.file('main.unsound.ddc.js', isNotEmpty).validate(); - // 'https://github.com/dart-lang/webdev/issues/1892' - }, skip: true); + }); }); group('should build with --output=NONE', () { @@ -507,8 +506,7 @@ void main() { } }, timeout: const Timeout.factor(2)); }); - // 'https://github.com/dart-lang/webdev/issues/1892' - }, skip: !soundNullSafety); + }); } }); } diff --git a/webdev/test/test_utils.dart b/webdev/test/test_utils.dart index 56c207dcc..67ee55813 100644 --- a/webdev/test/test_utils.dart +++ b/webdev/test/test_utils.dart @@ -7,13 +7,18 @@ import 'dart:io'; import 'package:path/path.dart' as p; import 'package:test/test.dart'; +import 'package:test_common/test_sdk_configuration.dart'; import 'package:test_process/test_process.dart'; import 'package:webdev/src/util.dart'; final _webdevBin = p.absolute(p.join('bin', 'webdev.dart')); +final _sdkConfigurationProvider = TestSdkConfigurationProvider(); Future runWebDev(List args, {String? workingDirectory}) async { + // Generate missing test assets in the SDK. + await _sdkConfigurationProvider.configuration; + var fullArgs = [_webdevBin, ...args]; return TestProcess.start(dartPath, fullArgs, From 4ddc0e4054ccb4b92fbef78e2cfd36f24c8cb52d Mon Sep 17 00:00:00 2001 From: Anna Gringauze Date: Tue, 14 Feb 2023 10:44:07 -0800 Subject: [PATCH 06/15] Create copy of the SDK for tests --- .../expression_compiler_service_test.dart | 5 +- dwds/test/fixtures/context.dart | 27 ++- dwds/test/fixtures/test_sdk_layout.dart | 159 ------------------ dwds/test/fixtures/utilities.dart | 4 +- .../frontend_server_asset_reader_test.dart | 4 +- dwds/test/sdk_configuration_test.dart | 14 +- .../lib/src/frontend_server_client.dart | 2 +- test_common/lib/test_sdk_configuration.dart | 8 +- test_common/lib/test_sdk_layout.dart | 19 +++ .../test/sdk_asset_generator_test.dart | 19 +-- 10 files changed, 66 insertions(+), 195 deletions(-) delete mode 100644 dwds/test/fixtures/test_sdk_layout.dart diff --git a/dwds/test/expression_compiler_service_test.dart b/dwds/test/expression_compiler_service_test.dart index 90f9d311a..5e0a03b78 100644 --- a/dwds/test/expression_compiler_service_test.dart +++ b/dwds/test/expression_compiler_service_test.dart @@ -46,6 +46,9 @@ void main() async { final source = outputDir.uri.resolve('try.dart'); final packages = outputDir.uri.resolve('package_config.json'); final kernel = outputDir.uri.resolve('try.full.dill'); + // Expression compiler service does not need any extra assets + // generated in the SDK, so we use the current SDK layout and + // configuration. final executable = Platform.resolvedExecutable; final dartdevc = SdkConfiguration.defaultConfiguration.compilerWorkerPath!; @@ -74,7 +77,7 @@ void main() async { sdkConfigurationProvider: DefaultSdkConfigurationProvider(), ); - await service.initialize(moduleFormat: 'amd'); + await service.initialize(moduleFormat: 'amd', soundNullSafety: true); // setup asset server serveHttpRequests(server, assetHandler, (e, s) { diff --git a/dwds/test/fixtures/context.dart b/dwds/test/fixtures/context.dart index 3fcd2a836..e47eee110 100644 --- a/dwds/test/fixtures/context.dart +++ b/dwds/test/fixtures/context.dart @@ -33,6 +33,7 @@ import 'package:shelf_proxy/shelf_proxy.dart'; import 'package:test/test.dart'; import 'package:test_common/logging.dart'; import 'package:test_common/test_sdk_configuration.dart'; +import 'package:test_common/test_sdk_layout.dart'; import 'package:vm_service/vm_service.dart'; // ignore: deprecated_member_use import 'package:webdriver/io.dart'; @@ -61,6 +62,7 @@ class TestContext { final String dartEntryFileName; final String htmlEntryFileName; final NullSafety nullSafety; + late final Directory sdkDirectory; /// Top level directory in which we run the test server, e.g. /// "/workstation/webdev/fixtures/_testSound". @@ -182,6 +184,22 @@ class TestContext { _logger.info('Entry: $_dartEntryFilePath'); } + void setUpAll() { + final systemTempDir = Directory.systemTemp; + sdkDirectory = systemTempDir.createTempSync('sdk copy'); + copyDirectory(TestSdkLayout.defaultSdkDirectory, sdkDirectory.path); + } + + void tearDownAll() { + try { + if (sdkDirectory.existsSync()) { + sdkDirectory.deleteSync(recursive: true); + } + } catch(e) { + _logger.warning('Failed to delete sdk directory copy: ${sdkDirectory.path}'); + } + } + Future setUp({ ReloadConfiguration reloadConfiguration = ReloadConfiguration.none, bool serveDevTools = false, @@ -204,7 +222,10 @@ class TestContext { }) async { // Generate missing SDK assets if needed. final sdkConfigurationProvider = - TestSdkConfigurationProvider(verboseCompiler: verboseCompiler); + TestSdkConfigurationProvider( + sdkDirectory: sdkDirectory.path, + verboseCompiler: verboseCompiler); + final sdkLayout = sdkConfigurationProvider.sdkLayout; final configuration = await sdkConfigurationProvider.configuration; configuration.validate(); @@ -249,7 +270,7 @@ class TestContext { 'Could not start ChromeDriver. Is it installed?\nError: $e'); } - await Process.run(dartPath, ['pub', 'upgrade'], + await Process.run(sdkLayout.dartPath, ['pub', 'upgrade'], workingDirectory: workingDirectory); ExpressionCompiler? expressionCompiler; @@ -272,7 +293,7 @@ class TestContext { '--verbose', ]; _daemonClient = - await connectClient(workingDirectory, options, (log) { + await connectClient(sdkLayout.dartPath, workingDirectory, options, (log) { final record = log.toLogRecord(); final name = record.loggerName == '' ? '' : '${record.loggerName}: '; diff --git a/dwds/test/fixtures/test_sdk_layout.dart b/dwds/test/fixtures/test_sdk_layout.dart deleted file mode 100644 index 488fdd009..000000000 --- a/dwds/test/fixtures/test_sdk_layout.dart +++ /dev/null @@ -1,159 +0,0 @@ -// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -// TODO:(annagrin) Move to a test_common package. -import 'package:dwds/src/utilities/sdk_configuration.dart'; -import 'package:path/path.dart' as p; - -/// Test Dart SDK layout. -/// -/// Contains definition of the default SDK layout required for tests. -/// We keep all the path constants in one place for ease of update. -class TestSdkLayout { - static final defaultSdkDirectory = SdkLayout.defaultSdkDirectory; - static TestSdkLayout defaultSdkLayout = - TestSdkLayout.createDefault(defaultSdkDirectory); - static SdkConfiguration defaultSdkConfiguration = - createConfiguration(defaultSdkLayout); - - factory TestSdkLayout.createDefault(String sdkDirectory) => - TestSdkLayout.createDefaultFromSdkLayout( - SdkLayout.createDefault(sdkDirectory)); - - factory TestSdkLayout.createDefaultFromSdkLayout(SdkLayout sdkLayout) => - TestSdkLayout( - sdkDirectory: sdkLayout.sdkDirectory, - soundSummaryPath: sdkLayout.soundSummaryPath, - soundFullDillPath: p.join( - sdkLayout.sdkDirectory, - 'lib', - '_internal', - 'ddc_platform.dill', - ), - soundJsPath: p.join( - sdkLayout.sdkDirectory, - 'lib', - 'dev_compiler', - 'kernel', - 'amd', - 'dart_sdk.js', - ), - soundJsMapPath: p.join( - sdkLayout.sdkDirectory, - 'lib', - 'dev_compiler', - 'kernel', - 'amd', - 'dart_sdk.js.map', - ), - weakSummaryPath: sdkLayout.weakSummaryPath, - weakFullDillPath: p.join( - sdkLayout.sdkDirectory, - 'lib', - '_internal', - 'ddc_platform_unsound.dill', - ), - weakJsPath: p.join( - sdkLayout.sdkDirectory, - 'lib', - 'dev_compiler', - 'kernel', - 'amd', - 'dart_sdk_unsound.js', - ), - weakJsMapPath: p.join( - sdkLayout.sdkDirectory, - 'lib', - 'dev_compiler', - 'kernel', - 'amd', - 'dart_sdk_unsound.js.map', - ), - requireJsPath: p.join( - sdkLayout.sdkDirectory, - 'lib', - 'dev_compiler', - 'amd', - 'require.js', - ), - stackTraceMapperPath: p.join( - sdkLayout.sdkDirectory, - 'lib', - 'dev_compiler', - 'web', - 'dart_stack_trace_mapper.js', - ), - dartPath: p.join(sdkLayout.sdkDirectory, 'bin', 'dart'), - frontendServerSnapshotPath: p.join( - sdkLayout.sdkDirectory, - 'bin', - 'snapshots', - 'frontend_server.dart.snapshot', - ), - dartdevcSnapshotPath: sdkLayout.dartdevcSnapshotPath, - kernelWorkerSnapshotPath: p.join( - sdkLayout.sdkDirectory, - 'bin', - 'snapshots', - 'kernel_worker.dart.snapshot', - ), - ); - - final String sdkDirectory; - - String get soundJsFileName => p.basename(soundJsPath); - String get soundJsMapFileName => p.basename(soundJsMapPath); - String get soundSummaryFileName => p.basename(soundSummaryPath); - String get soundFullDillFileName => p.basename(soundFullDillPath); - - final String soundJsPath; - final String soundJsMapPath; - final String soundSummaryPath; - final String soundFullDillPath; - - String get weakJsFileName => p.basename(weakJsPath); - String get weakJsMapFileName => p.basename(weakJsMapPath); - String get weakSummaryFileName => p.basename(weakSummaryPath); - String get weakFullDillFileName => p.basename(weakFullDillPath); - - final String weakJsPath; - final String weakJsMapPath; - final String weakSummaryPath; - final String weakFullDillPath; - - final String requireJsPath; - final String stackTraceMapperPath; - - final String dartPath; - final String frontendServerSnapshotPath; - final String dartdevcSnapshotPath; - final String kernelWorkerSnapshotPath; - - const TestSdkLayout({ - required this.sdkDirectory, - required this.soundJsPath, - required this.soundJsMapPath, - required this.soundSummaryPath, - required this.soundFullDillPath, - required this.weakJsPath, - required this.weakJsMapPath, - required this.weakSummaryPath, - required this.weakFullDillPath, - required this.requireJsPath, - required this.stackTraceMapperPath, - required this.dartPath, - required this.frontendServerSnapshotPath, - required this.dartdevcSnapshotPath, - required this.kernelWorkerSnapshotPath, - }); - - /// Creates configuration from sdk layout. - static SdkConfiguration createConfiguration(TestSdkLayout sdkLayout) => - SdkConfiguration( - sdkDirectory: sdkLayout.sdkDirectory, - weakSdkSummaryPath: sdkLayout.weakSummaryPath, - soundSdkSummaryPath: sdkLayout.soundSummaryPath, - compilerWorkerPath: sdkLayout.dartdevcSnapshotPath, - ); -} diff --git a/dwds/test/fixtures/utilities.dart b/dwds/test/fixtures/utilities.dart index 1f153da02..021b0b140 100644 --- a/dwds/test/fixtures/utilities.dart +++ b/dwds/test/fixtures/utilities.dart @@ -68,7 +68,7 @@ String absolutePath({ } /// Connects to the `build_runner` daemon. -Future connectClient(String workingDirectory, +Future connectClient(String dartPath, String workingDirectory, List options, Function(ServerLog) logHandler) => BuildDaemonClient.connect(workingDirectory, [dartPath, 'run', 'build_runner', 'daemon', ...options], @@ -84,7 +84,7 @@ final String _sdkDir = (() { })(); final String dartSdkPath = _sdkDir; -final String dartPath = p.join(_sdkDir, 'bin', 'dart'); +//final String dartPath = p.join(_sdkDir, 'bin', 'dart'); final String devToolsPath = p.join(_sdkDir, 'bin', 'resources', 'devtools'); /// Returns the port of the daemon asset server. diff --git a/dwds/test/readers/frontend_server_asset_reader_test.dart b/dwds/test/readers/frontend_server_asset_reader_test.dart index 619038873..4b1ae75b0 100644 --- a/dwds/test/readers/frontend_server_asset_reader_test.dart +++ b/dwds/test/readers/frontend_server_asset_reader_test.dart @@ -9,6 +9,7 @@ import 'dart:io'; import 'package:dwds/src/readers/frontend_server_asset_reader.dart'; import 'package:path/path.dart' as p; import 'package:test/test.dart'; +import 'package:test_common/test_sdk_layout.dart'; import '../fixtures/utilities.dart'; @@ -32,7 +33,8 @@ void main() { } setUpAll(() async { - await Process.run(dartPath, ['pub', 'upgrade'], + final sdkLayout = TestSdkLayout.defaultSdkLayout; + await Process.run(sdkLayout.dartPath, ['pub', 'upgrade'], workingDirectory: packagesDir); }); diff --git a/dwds/test/sdk_configuration_test.dart b/dwds/test/sdk_configuration_test.dart index 22ae6023f..8717b2601 100644 --- a/dwds/test/sdk_configuration_test.dart +++ b/dwds/test/sdk_configuration_test.dart @@ -49,8 +49,8 @@ void main() { await DefaultSdkConfigurationProvider().configuration; final sdkDirectory = outputDir.path; - final sdkLayout = TestSdkLayout(sdkDirectory); - final sdkConfiguration = TestSdkLayout.createConfiguration(sdkLayout); + final sdkLayout = FakeSdkLayout(sdkDirectory); + final sdkConfiguration = FakeSdkLayout.createConfiguration(sdkLayout); final weakSdkSummaryPath = sdkLayout.weakSummaryPath; final soundSdkSummaryPath = sdkLayout.soundSummaryPath; @@ -81,8 +81,8 @@ void main() { test('Cannot validate non-existing configuration layout', () async { final sdkDirectory = outputDir.path; - final sdkLayout = TestSdkLayout(sdkDirectory); - final sdkConfiguration = TestSdkLayout.createConfiguration(sdkLayout); + final sdkLayout = FakeSdkLayout(sdkDirectory); + final sdkConfiguration = FakeSdkLayout.createConfiguration(sdkLayout); sdkConfiguration.validateSdkDir(); expect(() => sdkConfiguration.validate(), _throwsDoesNotExistException); @@ -121,10 +121,10 @@ void main() { }); } -class TestSdkLayout { +class FakeSdkLayout { final String sdkDirectory; - static SdkConfiguration createConfiguration(TestSdkLayout sdkLayout) => + static SdkConfiguration createConfiguration(FakeSdkLayout sdkLayout) => SdkConfiguration( sdkDirectory: sdkLayout.sdkDirectory, soundSdkSummaryPath: sdkLayout.soundSummaryPath, @@ -132,7 +132,7 @@ class TestSdkLayout { compilerWorkerPath: sdkLayout.compilerWorkerPath, ); - TestSdkLayout(this.sdkDirectory); + FakeSdkLayout(this.sdkDirectory); String get weakSummaryPath => p.join(sdkDirectory, 'summaries', 'unsound.dill'); diff --git a/frontend_server_common/lib/src/frontend_server_client.dart b/frontend_server_common/lib/src/frontend_server_client.dart index 5aa733b32..3a5300d23 100644 --- a/frontend_server_common/lib/src/frontend_server_client.dart +++ b/frontend_server_common/lib/src/frontend_server_client.dart @@ -396,7 +396,7 @@ class ResidentCompiler { _logger.info(args.join(' ')); final workingDirectory = projectDirectory.toFilePath(); - _server = await Process.start(Platform.resolvedExecutable, args, + _server = await Process.start(sdkLayout.dartPath, args, workingDirectory: workingDirectory); var server = _server!; diff --git a/test_common/lib/test_sdk_configuration.dart b/test_common/lib/test_sdk_configuration.dart index f93fe691d..a289ef9b0 100644 --- a/test_common/lib/test_sdk_configuration.dart +++ b/test_common/lib/test_sdk_configuration.dart @@ -19,13 +19,15 @@ import 'package:test_common/test_sdk_layout.dart'; /// TODO(annagrin): update to only generating missing sound artifacts /// for frontend server after we have no uses of weak null safety. class TestSdkConfigurationProvider extends SdkConfigurationProvider { + late final String _sdkDirectory; final bool _verboseCompiler; SdkConfiguration? _configuration; - final sdkLayout = TestSdkLayout.defaultSdkLayout; + late final sdkLayout = TestSdkLayout.createDefault(_sdkDirectory); - TestSdkConfigurationProvider({bool verboseCompiler = false}) - : _verboseCompiler = verboseCompiler; + TestSdkConfigurationProvider({String? sdkDirectory, bool verboseCompiler = false}) + : _sdkDirectory = sdkDirectory?? SdkLayout.defaultSdkDirectory, + _verboseCompiler = verboseCompiler; @override Future get configuration async => diff --git a/test_common/lib/test_sdk_layout.dart b/test_common/lib/test_sdk_layout.dart index 78a00c1d4..3fb2d358c 100644 --- a/test_common/lib/test_sdk_layout.dart +++ b/test_common/lib/test_sdk_layout.dart @@ -2,6 +2,8 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. +import 'dart:io'; + import 'package:dwds/sdk_configuration.dart'; import 'package:path/path.dart' as p; @@ -156,3 +158,20 @@ class TestSdkLayout { compilerWorkerPath: sdkLayout.dartdevcSnapshotPath, ); } + +// Update modified files. +Future copyDirectory(String from, String to) async { + if (!Directory(from).existsSync()) return; + await Directory(to).create(recursive: true); + + await for (final file in Directory(from).list()) { + final copyTo = p.join(to, p.relative(file.path, from: from)); + if (file is Directory) { + await copyDirectory(file.path, copyTo); + } else if (file is File) { + await File(file.path).copy(copyTo); + } else if (file is Link) { + await Link(copyTo).create(await file.target(), recursive: true); + } + } +} \ No newline at end of file diff --git a/test_common/test/sdk_asset_generator_test.dart b/test_common/test/sdk_asset_generator_test.dart index 5a7cad7aa..5075e107a 100644 --- a/test_common/test/sdk_asset_generator_test.dart +++ b/test_common/test/sdk_asset_generator_test.dart @@ -7,7 +7,6 @@ import 'dart:io'; -import 'package:path/path.dart' as p; import 'package:test/test.dart'; import 'package:test_common/logging.dart'; import 'package:test_common/sdk_asset_generator.dart'; @@ -44,7 +43,7 @@ void main() { compilerWorkerPath = copySdkLayout.dartdevcSnapshotPath; // Copy the SDK directory into a temp directory. - await _copy(TestSdkLayout.defaultSdkDirectory, sdkDirectory); + await copyDirectory(TestSdkLayout.defaultSdkDirectory, sdkDirectory); // Simulate missing sound assets. soundSdkFullDillPath = copySdkLayout.soundFullDillPath; @@ -121,19 +120,3 @@ void _deleteIfExists(String path) { } } -// Update modified files. -Future _copy(String from, String to) async { - if (!Directory(from).existsSync()) return; - await Directory(to).create(recursive: true); - - await for (final file in Directory(from).list()) { - final copyTo = p.join(to, p.relative(file.path, from: from)); - if (file is Directory) { - await _copy(file.path, copyTo); - } else if (file is File) { - await File(file.path).copy(copyTo); - } else if (file is Link) { - await Link(copyTo).create(await file.target(), recursive: true); - } - } -} From f890bfa39a28945cda85ecdfb0125b821d398b0f Mon Sep 17 00:00:00 2001 From: Anna Gringauze Date: Wed, 15 Feb 2023 14:59:17 -0800 Subject: [PATCH 07/15] Modify tests to run with sdk copy --- dwds/test/build_daemon_breakpoint_test.dart | 20 +- dwds/test/build_daemon_callstack_test.dart | 46 +- .../build_daemon_circular_evaluate_test.dart | 5 + dwds/test/build_daemon_evaluate_test.dart | 5 + dwds/test/chrome_proxy_service_test.dart | 614 +++++++++--------- dwds/test/dart_uri_file_uri_test.dart | 20 +- dwds/test/debug_extension_test.dart | 22 +- dwds/test/debug_service_test.dart | 8 +- dwds/test/debugger_test.dart | 2 - dwds/test/devtools_test.dart | 8 +- dwds/test/evaluate_circular_common.dart | 74 +-- dwds/test/evaluate_common.dart | 177 ++--- dwds/test/events_test.dart | 28 +- dwds/test/fixtures/context.dart | 139 ++-- dwds/test/fixtures/server.dart | 6 +- dwds/test/fixtures/utilities.dart | 20 +- .../test/frontend_server_breakpoint_test.dart | 22 +- dwds/test/frontend_server_callstack_test.dart | 49 +- ...rontend_server_circular_evaluate_test.dart | 13 +- .../frontend_server_evaluate_sound_test.dart | 5 + .../frontend_server_evaluate_weak_test.dart | 5 + dwds/test/handlers/asset_handler_test.dart | 4 +- dwds/test/inspector_test.dart | 17 +- dwds/test/instance_test.dart | 17 +- dwds/test/listviews_test.dart | 9 +- dwds/test/puppeteer/extension_test.dart | 10 +- dwds/test/puppeteer/lifeline_test.dart | 8 +- .../proxy_server_asset_reader_test.dart | 12 +- dwds/test/records_test.dart | 39 +- dwds/test/refresh_test.dart | 16 +- dwds/test/reload_test.dart | 44 +- dwds/test/restore_breakpoints_test.dart | 24 +- dwds/test/run_request_test.dart | 15 +- dwds/test/screenshot_test.dart | 8 +- dwds/test/variable_scope_test.dart | 20 +- .../lib/src/asset_server.dart | 17 +- frontend_server_common/lib/src/devfs.dart | 2 +- .../lib/src/resident_runner.dart | 3 +- frontend_server_common/lib/src/utilities.dart | 14 - test_common/lib/sdk_asset_generator.dart | 11 +- test_common/lib/test_sdk_configuration.dart | 48 +- test_common/lib/test_sdk_layout.dart | 6 +- .../test/sdk_asset_generator_test.dart | 1 - webdev/test/daemon/app_domain_test.dart | 38 +- webdev/test/daemon/daemon_domain_test.dart | 18 +- webdev/test/daemon/launch_app_test.dart | 9 +- webdev/test/daemon/utils.dart | 22 +- webdev/test/e2e_test.dart | 43 +- webdev/test/integration_test.dart | 33 +- webdev/test/readme_test.dart | 12 +- webdev/test/test_utils.dart | 50 +- 51 files changed, 942 insertions(+), 916 deletions(-) diff --git a/dwds/test/build_daemon_breakpoint_test.dart b/dwds/test/build_daemon_breakpoint_test.dart index 8dd6fe192..cbb1fe3ff 100644 --- a/dwds/test/build_daemon_breakpoint_test.dart +++ b/dwds/test/build_daemon_breakpoint_test.dart @@ -6,26 +6,18 @@ @Timeout(Duration(minutes: 2)) import 'dart:async'; -import 'package:dwds/src/connections/debug_connection.dart'; -import 'package:dwds/src/services/chrome_proxy_service.dart'; import 'package:test/test.dart'; +import 'package:test_common/test_sdk_configuration.dart'; import 'package:vm_service/vm_service.dart'; -import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart'; import 'fixtures/context.dart'; -final context = TestContext.withSoundNullSafety( - packageName: '_testPackageSound', - webAssetsPath: 'web', - dartEntryFileName: 'main.dart', - htmlEntryFileName: 'index.html', -); +void main() { + final provider = TestSdkConfigurationProvider(); + tearDownAll(provider.dispose); -ChromeProxyService get service => - fetchChromeProxyService(context.debugConnection); -WipConnection get tabConnection => context.tabConnection; + final context = TestContext.testPackageWithSoundNullSafety(provider); -void main() { group('shared context', () { setUpAll(() async { await context.setUp(); @@ -43,8 +35,10 @@ void main() { late ScriptRef mainScript; late String mainScriptUri; late Stream stream; + late VmServiceInterface service; setUp(() async { + service = context.service; vm = await service.getVM(); isolate = await service.getIsolate(vm.isolates!.first.id!); isolateId = isolate.id!; diff --git a/dwds/test/build_daemon_callstack_test.dart b/dwds/test/build_daemon_callstack_test.dart index eee6161cc..7b4018888 100644 --- a/dwds/test/build_daemon_callstack_test.dart +++ b/dwds/test/build_daemon_callstack_test.dart @@ -6,42 +6,17 @@ @Timeout(Duration(minutes: 2)) import 'dart:async'; -import 'package:dwds/src/connections/debug_connection.dart'; -import 'package:dwds/src/services/chrome_proxy_service.dart'; import 'package:test/test.dart'; import 'package:test_common/logging.dart'; +import 'package:test_common/test_sdk_configuration.dart'; import 'package:vm_service/vm_service.dart'; -import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart'; import 'fixtures/context.dart'; -class TestSetup { - static final contextUnsound = TestContext.withWeakNullSafety( - packageName: '_testPackage', - webAssetsPath: 'web', - dartEntryFileName: 'main.dart', - htmlEntryFileName: 'index.html', - ); - - static final contextSound = TestContext.withSoundNullSafety( - packageName: '_testPackageSound', - webAssetsPath: 'web', - dartEntryFileName: 'main.dart', - htmlEntryFileName: 'index.html', - ); - - TestContext context; - - TestSetup.sound() : context = contextSound; - - TestSetup.unsound() : context = contextUnsound; - - ChromeProxyService get service => - fetchChromeProxyService(context.debugConnection); - WipConnection get tabConnection => context.tabConnection; -} - void main() { + final provider = TestSdkConfigurationProvider(); + tearDownAll(provider.dispose); + group( 'shared context |', () { @@ -51,9 +26,8 @@ void main() { for (var nullSafety in NullSafety.values) { group('${nullSafety.name} null safety |', () { final soundNullSafety = nullSafety == NullSafety.sound; - final setup = - soundNullSafety ? TestSetup.sound() : TestSetup.unsound(); - final context = setup.context; + final context = TestContext.testPackage( + provider: provider, nullSafety: nullSafety); setUpAll(() async { setCurrentLogWriter(debug: debug); @@ -69,7 +43,7 @@ void main() { }); group('callStack |', () { - late ChromeProxyService service; + late VmServiceInterface service; VM vm; late Isolate isolate; ScriptList scripts; @@ -79,7 +53,7 @@ void main() { setUp(() async { setCurrentLogWriter(debug: debug); - service = setup.service; + service = context.service; vm = await service.getVM(); isolate = await service.getIsolate(vm.isolates!.first.id!); scripts = await service.getScripts(isolate.id!); @@ -108,7 +82,7 @@ void main() { final script = breakpoint.script; final line = await context.findBreakpointLine(bpId, isolate.id!, script); - bp = await setup.service + bp = await context.service .addBreakpointWithScriptUri(isolate.id!, script.uri!, line); expect(bp, isNotNull); @@ -121,7 +95,7 @@ void main() { } finally { // Remove breakpoint so it doesn't impact other tests or retries. if (bp != null) { - await setup.service.removeBreakpoint(isolate.id!, bp.id!); + await context.service.removeBreakpoint(isolate.id!, bp.id!); } } } diff --git a/dwds/test/build_daemon_circular_evaluate_test.dart b/dwds/test/build_daemon_circular_evaluate_test.dart index 2be53bb26..bc952c000 100644 --- a/dwds/test/build_daemon_circular_evaluate_test.dart +++ b/dwds/test/build_daemon_circular_evaluate_test.dart @@ -6,6 +6,7 @@ @Timeout(Duration(minutes: 2)) import 'package:test/test.dart'; +import 'package:test_common/test_sdk_configuration.dart'; import 'evaluate_circular_common.dart'; import 'fixtures/context.dart'; @@ -14,9 +15,13 @@ void main() async { // Enable verbose logging for debugging. final debug = false; + final provider = TestSdkConfigurationProvider(verbose: debug); + tearDownAll(provider.dispose); + for (var nullSafety in NullSafety.values) { group('${nullSafety.name} null safety |', () { testAll( + provider: provider, compilationMode: CompilationMode.buildDaemon, nullSafety: nullSafety, debug: debug, diff --git a/dwds/test/build_daemon_evaluate_test.dart b/dwds/test/build_daemon_evaluate_test.dart index 06cdb5a8f..e50406849 100644 --- a/dwds/test/build_daemon_evaluate_test.dart +++ b/dwds/test/build_daemon_evaluate_test.dart @@ -6,6 +6,7 @@ @Timeout(Duration(minutes: 2)) import 'package:test/test.dart'; +import 'package:test_common/test_sdk_configuration.dart'; import 'evaluate_common.dart'; import 'fixtures/context.dart'; @@ -14,9 +15,13 @@ void main() async { // Enable verbose logging for debugging. final debug = false; + final provider = TestSdkConfigurationProvider(verbose: debug); + tearDownAll(provider.dispose); + for (var nullSafety in NullSafety.values) { group('${nullSafety.name} null safety |', () { testAll( + provider: provider, compilationMode: CompilationMode.buildDaemon, nullSafety: nullSafety, debug: debug, diff --git a/dwds/test/chrome_proxy_service_test.dart b/dwds/test/chrome_proxy_service_test.dart index 8ffb75a36..146daf229 100644 --- a/dwds/test/chrome_proxy_service_test.dart +++ b/dwds/test/chrome_proxy_service_test.dart @@ -8,30 +8,28 @@ import 'dart:async'; import 'dart:convert'; import 'dart:io'; -import 'package:dwds/src/connections/debug_connection.dart'; import 'package:dwds/src/loaders/strategy.dart'; -import 'package:dwds/src/services/chrome_proxy_service.dart'; import 'package:dwds/src/utilities/dart_uri.dart'; import 'package:dwds/src/utilities/shared.dart'; import 'package:http/http.dart' as http; import 'package:path/path.dart' as path; import 'package:test/test.dart'; import 'package:test_common/logging.dart'; +import 'package:test_common/test_sdk_configuration.dart'; import 'package:vm_service/vm_service.dart'; import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart'; import 'fixtures/context.dart'; -final context = TestContext.withSoundNullSafety(); - -ChromeProxyService get service => - fetchChromeProxyService(context.debugConnection); - -WipConnection get tabConnection => context.tabConnection; - void main() { // Change to true to see verbose output from the tests. final debug = false; + + final provider = TestSdkConfigurationProvider(verbose: debug); + tearDownAll(provider.dispose); + + final context = TestContext.testWithSoundNullSafety(provider); + group('shared context', () { setUpAll(() async { setCurrentLogWriter(debug: debug); @@ -54,33 +52,30 @@ void main() { setUp(() async { setCurrentLogWriter(debug: debug); - vm = await fetchChromeProxyService(context.debugConnection).getVM(); - isolate = await fetchChromeProxyService(context.debugConnection) - .getIsolate(vm.isolates!.first.id!); - scripts = await fetchChromeProxyService(context.debugConnection) - .getScripts(isolate.id!); + vm = await context.service.getVM(); + isolate = await context.service.getIsolate(vm.isolates!.first.id!); + scripts = await context.service.getScripts(isolate.id!); mainScript = scripts.scripts! .firstWhere((each) => each.uri!.contains('main.dart')); }); test('addBreakpoint', () async { - // TODO: Much more testing. final line = await context.findBreakpointLine( 'printHelloWorld', isolate.id!, mainScript); - final firstBp = - await service.addBreakpoint(isolate.id!, mainScript.id!, line); + final firstBp = await context.service + .addBreakpoint(isolate.id!, mainScript.id!, line); expect(firstBp, isNotNull); expect(firstBp.id, isNotNull); - final secondBp = - await service.addBreakpoint(isolate.id!, mainScript.id!, line); + final secondBp = await context.service + .addBreakpoint(isolate.id!, mainScript.id!, line); expect(secondBp, isNotNull); expect(secondBp.id, isNotNull); expect(firstBp.id, equals(secondBp.id)); // Remove breakpoint so it doesn't impact other tests. - await service.removeBreakpoint(isolate.id!, firstBp.id!); + await context.service.removeBreakpoint(isolate.id!, firstBp.id!); }); test('addBreakpoint succeeds when sending the same breakpoint twice', @@ -88,40 +83,44 @@ void main() { final line = await context.findBreakpointLine( 'printHelloWorld', isolate.id!, mainScript); final firstBp = - service.addBreakpoint(isolate.id!, mainScript.id!, line); + context.service.addBreakpoint(isolate.id!, mainScript.id!, line); final secondBp = - service.addBreakpoint(isolate.id!, mainScript.id!, line); + context.service.addBreakpoint(isolate.id!, mainScript.id!, line); // Remove breakpoint so it doesn't impact other tests. - await service.removeBreakpoint(isolate.id!, (await firstBp).id!); + await context.service + .removeBreakpoint(isolate.id!, (await firstBp).id!); expect((await firstBp).id, equals((await secondBp).id)); }); test('addBreakpoint in nonsense location throws', () async { - expect(service.addBreakpoint(isolate.id!, mainScript.id!, 200000), + expect( + context.service.addBreakpoint(isolate.id!, mainScript.id!, 200000), throwsA(predicate((dynamic e) => e is RPCError && e.code == 102))); }); test('addBreakpoint on a part file', () async { final partScript = scripts.scripts! .firstWhere((script) => script.uri!.contains('part.dart')); - final bp = await service.addBreakpoint(isolate.id!, partScript.id!, 10); + final bp = await context.service + .addBreakpoint(isolate.id!, partScript.id!, 10); // Remove breakpoint so it doesn't impact other tests. - await service.removeBreakpoint(isolate.id!, bp.id!); + await context.service.removeBreakpoint(isolate.id!, bp.id!); expect(bp.id, isNotNull); }); test('addBreakpointAtEntry', () async { - await expectLater(service.addBreakpointAtEntry('', ''), throwsRPCError); + await expectLater( + context.service.addBreakpointAtEntry('', ''), throwsRPCError); }); test('addBreakpointWithScriptUri', () async { final line = await context.findBreakpointLine( 'printHelloWorld', isolate.id!, mainScript); - final bp = await service.addBreakpointWithScriptUri( - isolate.id!, mainScript.uri!, line); + final bp = await context.service + .addBreakpointWithScriptUri(isolate.id!, mainScript.uri!, line); // Remove breakpoint so it doesn't impact other tests. - await service.removeBreakpoint(isolate.id!, bp.id!); + await context.service.removeBreakpoint(isolate.id!, bp.id!); expect(bp.id, isNotNull); }); @@ -133,45 +132,45 @@ void main() { final fileUri = Uri.file(fullPath); final line = await context.findBreakpointLine( 'printHelloWorld', isolate.id!, mainScript); - final bp = await service.addBreakpointWithScriptUri( - isolate.id!, '$fileUri', line); + final bp = await context.service + .addBreakpointWithScriptUri(isolate.id!, '$fileUri', line); // Remove breakpoint so it doesn't impact other tests. - await service.removeBreakpoint(isolate.id!, bp.id!); + await context.service.removeBreakpoint(isolate.id!, bp.id!); expect(bp.id, isNotNull); }); test('removeBreakpoint null arguments', () async { await expectLater( - service.removeBreakpoint('', ''), throwsSentinelException); + context.service.removeBreakpoint('', ''), throwsSentinelException); await expectLater( - service.removeBreakpoint(isolate.id!, ''), throwsRPCError); + context.service.removeBreakpoint(isolate.id!, ''), throwsRPCError); }); test("removeBreakpoint that doesn't exist fails", () async { - await expectLater( - service.removeBreakpoint(isolate.id!, '1234'), throwsRPCError); + await expectLater(context.service.removeBreakpoint(isolate.id!, '1234'), + throwsRPCError); }); test('add and remove breakpoint', () async { final line = await context.findBreakpointLine( 'printHelloWorld', isolate.id!, mainScript); - final bp = - await service.addBreakpoint(isolate.id!, mainScript.id!, line); + final bp = await context.service + .addBreakpoint(isolate.id!, mainScript.id!, line); expect(isolate.breakpoints, [bp]); - await service.removeBreakpoint(isolate.id!, bp.id!); + await context.service.removeBreakpoint(isolate.id!, bp.id!); expect(isolate.breakpoints, isEmpty); }); }); - group('callServiceExtension', () { + group('callcontext.serviceExtension', () { setUp(() { setCurrentLogWriter(debug: debug); }); test('success', () async { - final serviceMethod = 'ext.test.callServiceExtension'; - await tabConnection.runtime - .evaluate('registerExtension("$serviceMethod");'); + final serviceMethod = 'ext.test.callcontext.serviceExtension'; + await context.tabConnection.runtime + .evaluate('registerExtension("$context.serviceMethod");'); // The non-string keys/values get auto json-encoded to match the vm // behavior. @@ -185,8 +184,8 @@ void main() { false: true, }; - final result = - await service.callServiceExtension(serviceMethod, args: args); + final result = await context.service + .callServiceExtension(serviceMethod, args: args); expect( result.json, args.map((k, v) => MapEntry(k is String ? k : jsonEncode(k), @@ -196,13 +195,13 @@ void main() { }); test('failure', () async { - final serviceMethod = 'ext.test.callServiceExtensionWithError'; - await tabConnection.runtime + final serviceMethod = 'ext.test.callcontext.serviceExtensionWithError'; + await context.tabConnection.runtime .evaluate('registerExtensionWithError("$serviceMethod");'); final errorDetails = {'intentional': 'error'}; expect( - service.callServiceExtension(serviceMethod, args: { + context.service.callServiceExtension(serviceMethod, args: { 'code': '-32001', 'details': jsonEncode(errorDetails), }), @@ -221,32 +220,33 @@ void main() { }); test('clearVMTimeline', () async { - await expectLater(service.clearVMTimeline(), throwsRPCError); + await expectLater(context.service.clearVMTimeline(), throwsRPCError); }); test('getVMTimelineMicros', () async { - await expectLater(service.getVMTimelineMicros(), throwsRPCError); + await expectLater( + context.service.getVMTimelineMicros(), throwsRPCError); }); test('getVMTimeline', () async { - await expectLater(service.getVMTimeline(), throwsRPCError); + await expectLater(context.service.getVMTimeline(), throwsRPCError); }); test('getVMTimelineFlags', () async { - await expectLater(service.getVMTimelineFlags(), throwsRPCError); + await expectLater(context.service.getVMTimelineFlags(), throwsRPCError); }); test('setVMTimelineFlags', () async { await expectLater( - service.setVMTimelineFlags([]), throwsRPCError); + context.service.setVMTimelineFlags([]), throwsRPCError); }); }); test('getMemoryUsage', () async { - final vm = await service.getVM(); - final isolate = await service.getIsolate(vm.isolates!.first.id!); + final vm = await context.service.getVM(); + final isolate = await context.service.getIsolate(vm.isolates!.first.id!); - final memoryUsage = await service.getMemoryUsage(isolate.id!); + final memoryUsage = await context.service.getMemoryUsage(isolate.id!); expect(memoryUsage.heapUsage, isNotNull); expect(memoryUsage.heapUsage, greaterThan(0)); @@ -260,8 +260,8 @@ void main() { setUpAll(() async { setCurrentLogWriter(debug: debug); - final vm = await service.getVM(); - isolate = await service.getIsolate(vm.isolates!.first.id!); + final vm = await context.service.getVM(); + isolate = await context.service.getIsolate(vm.isolates!.first.id!); bootstrap = isolate.rootLib; }); @@ -272,7 +272,7 @@ void main() { test('can return strings', () async { expect( - await service.evaluate( + await context.service.evaluate( isolate.id!, bootstrap!.id!, "helloString('world')"), const TypeMatcher().having( (instance) => instance.valueAsString, 'value', 'world')); @@ -280,15 +280,15 @@ void main() { test('can return bools', () async { expect( - await service.evaluate( - isolate.id!, bootstrap!.id!, 'helloBool(true)'), + await context.service + .evaluate(isolate.id!, bootstrap!.id!, 'helloBool(true)'), const TypeMatcher().having( (instance) => instance.valueAsString, 'valueAsString', 'true')); expect( - await service.evaluate( - isolate.id!, bootstrap!.id!, 'helloBool(false)'), + await context.service + .evaluate(isolate.id!, bootstrap!.id!, 'helloBool(false)'), const TypeMatcher().having( (instance) => instance.valueAsString, 'valueAsString', @@ -297,13 +297,13 @@ void main() { test('can return nums', () async { expect( - await service.evaluate( - isolate.id!, bootstrap!.id!, 'helloNum(42.0)'), + await context.service + .evaluate(isolate.id!, bootstrap!.id!, 'helloNum(42.0)'), const TypeMatcher().having( (instance) => instance.valueAsString, 'valueAsString', '42')); expect( - await service.evaluate( - isolate.id!, bootstrap!.id!, 'helloNum(42.2)'), + await context.service + .evaluate(isolate.id!, bootstrap!.id!, 'helloNum(42.2)'), const TypeMatcher().having( (instance) => instance.valueAsString, 'valueAsString', @@ -311,8 +311,8 @@ void main() { }); test('can return objects with ids', () async { - final object = await service.evaluate( - isolate.id!, bootstrap!.id!, 'createObject("cool")'); + final object = await context.service + .evaluate(isolate.id!, bootstrap!.id!, 'createObject("cool")'); expect( object, const TypeMatcher() @@ -327,14 +327,14 @@ void main() { }); Future createRemoteObject(String message) async { - return await service.evaluate( + return await context.service.evaluate( isolate.id!, bootstrap!.id!, 'createObject("$message")') as InstanceRef; } test('single scope object', () async { final instance = await createRemoteObject('A'); - final result = await service.evaluate( + final result = await context.service.evaluate( isolate.id!, bootstrap!.id!, 'messageFor(arg1)', scope: {'arg1': instance.id!}); expect( @@ -348,7 +348,7 @@ void main() { test('multiple scope objects', () async { final instance1 = await createRemoteObject('A'); final instance2 = await createRemoteObject('B'); - final result = await service.evaluate( + final result = await context.service.evaluate( isolate.id!, bootstrap!.id!, 'messagesCombined(arg1, arg2)', scope: {'arg1': instance1.id!, 'arg2': instance2.id!}); expect( @@ -364,23 +364,25 @@ void main() { test('evaluateInFrame', () async { await expectLater( - service.evaluateInFrame('', 0, ''), throwsSentinelException); + context.service.evaluateInFrame('', 0, ''), throwsSentinelException); }); test('getAllocationProfile', () async { - await expectLater(service.getAllocationProfile(''), throwsRPCError); + await expectLater( + context.service.getAllocationProfile(''), throwsRPCError); }); test('getClassList', () async { - await expectLater(service.getClassList(''), throwsRPCError); + await expectLater(context.service.getClassList(''), throwsRPCError); }); test('getFlagList', () async { - expect(await service.getFlagList(), isA()); + expect(await context.service.getFlagList(), isA()); }); test('getInstances', () async { - await expectLater(service.getInstances('', '', 0), throwsRPCError); + await expectLater( + context.service.getInstances('', '', 0), throwsRPCError); }); group('getIsolate', () { @@ -389,8 +391,8 @@ void main() { }); test('works for existing isolates', () async { - final vm = await service.getVM(); - final result = await service.getIsolate(vm.isolates!.first.id!); + final vm = await context.service.getVM(); + final result = await context.service.getIsolate(vm.isolates!.first.id!); expect(result, const TypeMatcher()); final isolate = result; expect(isolate.name, contains('main')); @@ -408,7 +410,7 @@ void main() { }); test('throws for invalid ids', () async { - expect(service.getIsolate('bad'), throwsSentinelException); + expect(context.service.getIsolate('bad'), throwsSentinelException); }); }); @@ -420,11 +422,11 @@ void main() { setUpAll(() async { setCurrentLogWriter(debug: debug); - final vm = await service.getVM(); - isolate = await service.getIsolate(vm.isolates!.first.id!); + final vm = await context.service.getVM(); + isolate = await context.service.getIsolate(vm.isolates!.first.id!); bootstrap = isolate.rootLib; - rootLibrary = - await service.getObject(isolate.id!, bootstrap!.id!) as Library; + rootLibrary = await context.service + .getObject(isolate.id!, bootstrap!.id!) as Library; }); setUp(() { @@ -441,8 +443,8 @@ void main() { }); test('Library only contains included scripts', () async { - final library = - await service.getObject(isolate.id!, rootLibrary!.id!) as Library; + final library = await context.service + .getObject(isolate.id!, rootLibrary!.id!) as Library; expect(library.scripts, hasLength(2)); expect( library.scripts, @@ -456,8 +458,8 @@ void main() { test('Can get the same library in parallel', () async { final futures = [ - service.getObject(isolate.id!, rootLibrary!.id!), - service.getObject(isolate.id!, rootLibrary!.id!), + context.service.getObject(isolate.id!, rootLibrary!.id!), + context.service.getObject(isolate.id!, rootLibrary!.id!), ]; final results = await Future.wait(futures); final library1 = results[0] as Library; @@ -466,8 +468,8 @@ void main() { }); test('Classes', () async { - final testClass = await service.getObject( - isolate.id!, rootLibrary!.classes!.first.id!) as Class; + final testClass = await context.service + .getObject(isolate.id!, rootLibrary!.classes!.first.id!) as Class; expect( testClass.functions, unorderedEquals([ @@ -507,21 +509,21 @@ void main() { }); test('Runtime classes', () async { - final testClass = await service.getObject( - isolate.id!, 'classes|dart:_runtime|_Type') as Class; + final testClass = await context.service + .getObject(isolate.id!, 'classes|dart:_runtime|_Type') as Class; expect(testClass.name, '_Type'); }); test('String', () async { - final worldRef = await service.evaluate( + final worldRef = await context.service.evaluate( isolate.id!, bootstrap!.id!, "helloString('world')") as InstanceRef; - final world = - await service.getObject(isolate.id!, worldRef.id!) as Instance; + final world = await context.service.getObject(isolate.id!, worldRef.id!) + as Instance; expect(world.valueAsString, 'world'); }); test('Large strings not truncated', () async { - final largeString = await service.evaluate( + final largeString = await context.service.evaluate( isolate.id!, bootstrap!.id!, "helloString('${'abcde' * 250}')") as InstanceRef; expect(largeString.valueAsStringIsTruncated, isNot(isTrue)); @@ -538,7 +540,7 @@ void main() { list[4] = 100; return list; })()'''; - return service.inspector.jsEvaluate(expr); + return context.service.inspector.jsEvaluate(expr); } /// Helper to create a LinkedHashMap with 1001 entries, doing a direct JS eval. @@ -554,13 +556,13 @@ void main() { const linkedMap = sdk.dart.dsend(sdk.collection.LinkedHashMap, "from", [map]); return linkedMap; })()'''; - return service.inspector.jsEvaluate(expr); + return context.service.inspector.jsEvaluate(expr); } test('Lists', () async { final list = await createList(); - final inst = - await service.getObject(isolate.id!, list.objectId!) as Instance; + final inst = await context.service + .getObject(isolate.id!, list.objectId!) as Instance; expect(inst.length, 1001); expect(inst.offset, null); expect(inst.count, null); @@ -573,8 +575,8 @@ void main() { test('Maps', () async { final map = await createMap(); - final inst = - await service.getObject(isolate.id!, map.objectId!) as Instance; + final inst = await context.service.getObject(isolate.id!, map.objectId!) + as Instance; expect(inst.length, 1001); expect(inst.offset, null); expect(inst.count, null); @@ -588,29 +590,31 @@ void main() { }); test('bool', () async { - final ref = await service.evaluate( + final ref = await context.service.evaluate( isolate.id!, bootstrap!.id!, 'helloBool(true)') as InstanceRef; - final obj = await service.getObject(isolate.id!, ref.id!) as Instance; + final obj = + await context.service.getObject(isolate.id!, ref.id!) as Instance; expect(obj.kind, InstanceKind.kBool); expect(obj.classRef!.name, 'Bool'); expect(obj.valueAsString, 'true'); }); test('num', () async { - final ref = await service.evaluate( + final ref = await context.service.evaluate( isolate.id!, bootstrap!.id!, 'helloNum(42)') as InstanceRef; - final obj = await service.getObject(isolate.id!, ref.id!) as Instance; + final obj = + await context.service.getObject(isolate.id!, ref.id!) as Instance; expect(obj.kind, InstanceKind.kDouble); expect(obj.classRef!.name, 'Double'); expect(obj.valueAsString, '42'); }); test('Scripts', () async { - final scripts = await service.getScripts(isolate.id!); + final scripts = await context.service.getScripts(isolate.id!); assert(scripts.scripts!.isNotEmpty); for (var scriptRef in scripts.scripts!) { - final script = - await service.getObject(isolate.id!, scriptRef.id!) as Script; + final script = await context.service + .getObject(isolate.id!, scriptRef.id!) as Script; final serverPath = DartUri(script.uri!, 'hello_world/').serverPath; final result = await http .get(Uri.parse('http://localhost:${context.port}/$serverPath')); @@ -623,7 +627,7 @@ void main() { group('getObject called with offset/count parameters', () { test('Lists with null offset and count are not truncated', () async { final list = await createList(); - final inst = await service.getObject( + final inst = await context.service.getObject( isolate.id!, list.objectId!, count: null, @@ -641,7 +645,7 @@ void main() { test('Lists with null count are not truncated', () async { final list = await createList(); - final inst = await service.getObject( + final inst = await context.service.getObject( isolate.id!, list.objectId!, count: null, @@ -661,7 +665,7 @@ void main() { 'Lists with null count and offset greater than 0 are ' 'truncated from offset to end of list', () async { final list = await createList(); - final inst = await service.getObject( + final inst = await context.service.getObject( isolate.id!, list.objectId!, count: null, @@ -677,7 +681,7 @@ void main() { test('Lists with offset/count are truncated', () async { final list = await createList(); - final inst = await service.getObject( + final inst = await context.service.getObject( isolate.id!, list.objectId!, count: 7, @@ -696,7 +700,7 @@ void main() { test('Lists are truncated to the end if offset/count runs off the end', () async { final list = await createList(); - final inst = await service.getObject( + final inst = await context.service.getObject( isolate.id!, list.objectId!, count: 5, @@ -713,7 +717,7 @@ void main() { test('Lists are truncated to empty if offset runs off the end', () async { final list = await createList(); - final inst = await service.getObject( + final inst = await context.service.getObject( isolate.id!, list.objectId!, count: 5, @@ -729,7 +733,7 @@ void main() { test('Lists are truncated to empty with 0 count and null offset', () async { final list = await createList(); - final inst = await service.getObject( + final inst = await context.service.getObject( isolate.id!, list.objectId!, count: 0, @@ -744,7 +748,7 @@ void main() { test('Maps with null offset/count are not truncated', () async { final map = await createMap(); - final inst = await service.getObject( + final inst = await context.service.getObject( isolate.id!, map.objectId!, count: null, @@ -766,7 +770,7 @@ void main() { 'Maps with null count and offset greater than 0 are ' 'truncated from offset to end of map', () async { final list = await createMap(); - final inst = await service.getObject( + final inst = await context.service.getObject( isolate.id!, list.objectId!, count: null, @@ -783,7 +787,7 @@ void main() { test('Maps with null count are not truncated', () async { final map = await createMap(); - final inst = await service.getObject( + final inst = await context.service.getObject( isolate.id!, map.objectId!, count: null, @@ -803,7 +807,7 @@ void main() { test('Maps with offset/count are truncated', () async { final map = await createMap(); - final inst = await service.getObject( + final inst = await context.service.getObject( isolate.id!, map.objectId!, count: 7, @@ -824,7 +828,7 @@ void main() { test('Maps are truncated to the end if offset/count runs off the end', () async { final map = await createMap(); - final inst = await service.getObject( + final inst = await context.service.getObject( isolate.id!, map.objectId!, count: 5, @@ -842,7 +846,7 @@ void main() { test('Maps are truncated to empty if offset runs off the end', () async { final list = await createMap(); - final inst = await service.getObject( + final inst = await context.service.getObject( isolate.id!, list.objectId!, count: 5, @@ -856,10 +860,10 @@ void main() { }); test('Strings with offset/count are truncated', () async { - final worldRef = await service.evaluate( - isolate.id!, bootstrap!.id!, "helloString('world')") + final worldRef = await context.service + .evaluate(isolate.id!, bootstrap!.id!, "helloString('world')") as InstanceRef; - final world = await service.getObject( + final world = await context.service.getObject( isolate.id!, worldRef.id!, count: 2, @@ -874,7 +878,7 @@ void main() { test('Maps are truncated to empty if offset runs off the end', () async { final list = await createMap(); - final inst = await service.getObject( + final inst = await context.service.getObject( isolate.id!, list.objectId!, count: 5, @@ -890,7 +894,7 @@ void main() { test('Maps are truncated to empty with 0 count and null offset', () async { final list = await createMap(); - final inst = await service.getObject( + final inst = await context.service.getObject( isolate.id!, list.objectId!, count: 0, @@ -906,10 +910,10 @@ void main() { test( 'Strings are truncated to the end if offset/count runs off the end', () async { - final worldRef = await service.evaluate( - isolate.id!, bootstrap!.id!, "helloString('world')") + final worldRef = await context.service + .evaluate(isolate.id!, bootstrap!.id!, "helloString('world')") as InstanceRef; - final world = await service.getObject( + final world = await context.service.getObject( isolate.id!, worldRef.id!, count: 5, @@ -922,7 +926,7 @@ void main() { }); test('offset/count parameters are ignored for Classes', () async { - final testClass = await service.getObject( + final testClass = await context.service.getObject( isolate.id!, rootLibrary!.classes!.first.id!, offset: 100, @@ -969,9 +973,9 @@ void main() { }); test('offset/count parameters are ignored for bools', () async { - final ref = await service.evaluate( + final ref = await context.service.evaluate( isolate.id!, bootstrap!.id!, 'helloBool(true)') as InstanceRef; - final obj = await service.getObject( + final obj = await context.service.getObject( isolate.id!, ref.id!, offset: 100, @@ -983,9 +987,9 @@ void main() { }); test('offset/count parameters are ignored for nums', () async { - final ref = await service.evaluate( + final ref = await context.service.evaluate( isolate.id!, bootstrap!.id!, 'helloNum(42)') as InstanceRef; - final obj = await service.getObject( + final obj = await context.service.getObject( isolate.id!, ref.id!, offset: 100, @@ -997,9 +1001,9 @@ void main() { }); test('offset/count parameters are ignored for null', () async { - final ref = await service.evaluate( + final ref = await context.service.evaluate( isolate.id!, bootstrap!.id!, 'helloNum(null)') as InstanceRef; - final obj = await service.getObject( + final obj = await context.service.getObject( isolate.id!, ref.id!, offset: 100, @@ -1013,9 +1017,9 @@ void main() { }); test('getScripts', () async { - final vm = await service.getVM(); + final vm = await context.service.getVM(); final isolateId = vm.isolates!.first.id!; - final scripts = await service.getScripts(isolateId); + final scripts = await context.service.getScripts(isolateId); expect(scripts, isNotNull); expect(scripts.scripts, isNotEmpty); @@ -1040,39 +1044,41 @@ void main() { }); test('Coverage report', () async { - final vm = await service.getVM(); + final vm = await context.service.getVM(); final isolateId = vm.isolates!.first.id!; await expectLater( - service.getSourceReport(isolateId, ['Coverage']), throwsRPCError); + context.service.getSourceReport(isolateId, ['Coverage']), + throwsRPCError); }); test('Coverage report', () async { - final vm = await service.getVM(); + final vm = await context.service.getVM(); final isolateId = vm.isolates!.first.id!; await expectLater( - service.getSourceReport(isolateId, ['Coverage'], + context.service.getSourceReport(isolateId, ['Coverage'], libraryFilters: ['foo']), throwsRPCError); }); test('report type not understood', () async { - final vm = await service.getVM(); + final vm = await context.service.getVM(); final isolateId = vm.isolates!.first.id!; await expectLater( - service.getSourceReport(isolateId, ['FooBar']), throwsRPCError); + context.service.getSourceReport(isolateId, ['FooBar']), + throwsRPCError); }); test('PossibleBreakpoints report', () async { - final vm = await service.getVM(); + final vm = await context.service.getVM(); final isolateId = vm.isolates!.first.id!; - final scripts = await service.getScripts(isolateId); + final scripts = await context.service.getScripts(isolateId); final mainScript = scripts.scripts! .firstWhere((script) => script.uri!.contains('main.dart')); - final sourceReport = await service.getSourceReport( + final sourceReport = await context.service.getSourceReport( isolateId, ['PossibleBreakpoints'], scriptId: mainScript.id, @@ -1094,11 +1100,11 @@ void main() { setUp(() async { setCurrentLogWriter(debug: debug); - final vm = await service.getVM(); + final vm = await context.service.getVM(); isolateId = vm.isolates!.first.id; - scripts = await service.getScripts(isolateId!); - await service.streamListen('Debug'); - stream = service.onEvent('Debug'); + scripts = await context.service.getScripts(isolateId!); + await context.service.streamListen('Debug'); + stream = context.service.onEvent('Debug'); mainScript = scripts.scripts! .firstWhere((script) => script.uri!.contains('main.dart')); }); @@ -1106,19 +1112,19 @@ void main() { test('at breakpoints sets pauseBreakPoints', () async { final line = await context.findBreakpointLine( 'callPrintCount', isolateId!, mainScript); - final bp = - await service.addBreakpoint(isolateId!, mainScript.id!, line); + final bp = await context.service + .addBreakpoint(isolateId!, mainScript.id!, line); final event = await stream .firstWhere((event) => event.kind == EventKind.kPauseBreakpoint); final pauseBreakpoints = event.pauseBreakpoints!; expect(pauseBreakpoints, hasLength(1)); expect(pauseBreakpoints.first.id, bp.id); - await service.removeBreakpoint(isolateId!, bp.id!); + await context.service.removeBreakpoint(isolateId!, bp.id!); }); tearDown(() async { // Resume execution to not impact other tests. - await service.resume(isolateId!); + await context.service.resume(isolateId!); }); }); @@ -1130,34 +1136,34 @@ void main() { setUp(() async { setCurrentLogWriter(debug: debug); - final vm = await service.getVM(); + final vm = await context.service.getVM(); isolateId = vm.isolates!.first.id; - scripts = await service.getScripts(isolateId!); - await service.streamListen('Debug'); - stream = service.onEvent('Debug'); + scripts = await context.service.getScripts(isolateId!); + await context.service.streamListen('Debug'); + stream = context.service.onEvent('Debug'); mainScript = scripts.scripts! .firstWhere((script) => script.uri!.contains('main.dart')); final line = await context.findBreakpointLine( 'callPrintCount', isolateId!, mainScript); - final bp = - await service.addBreakpoint(isolateId!, mainScript.id!, line); + final bp = await context.service + .addBreakpoint(isolateId!, mainScript.id!, line); // Wait for breakpoint to trigger. await stream .firstWhere((event) => event.kind == EventKind.kPauseBreakpoint); - await service.removeBreakpoint(isolateId!, bp.id!); + await context.service.removeBreakpoint(isolateId!, bp.id!); }); tearDown(() async { // Resume execution to not impact other tests. - await service.resume(isolateId!); + await context.service.resume(isolateId!); }); test('Into goes to the next Dart location', () async { - await service.resume(isolateId!, step: 'Into'); + await context.service.resume(isolateId!, step: 'Into'); // Wait for the step to actually occur. await stream .firstWhere((event) => event.kind == EventKind.kPauseInterrupted); - final stack = await service.getStack(isolateId!); + final stack = await context.service.getStack(isolateId!); expect(stack, isNotNull); final first = stack.frames!.first; expect(first.kind, 'Regular'); @@ -1166,11 +1172,11 @@ void main() { }); test('Over goes to the next Dart location', () async { - await service.resume(isolateId!, step: 'Over'); + await context.service.resume(isolateId!, step: 'Over'); // Wait for the step to actually occur. await stream .firstWhere((event) => event.kind == EventKind.kPauseInterrupted); - final stack = await service.getStack(isolateId!); + final stack = await context.service.getStack(isolateId!); expect(stack, isNotNull); final first = stack.frames!.first; expect(first.kind, 'Regular'); @@ -1179,11 +1185,11 @@ void main() { }); test('Out goes to the next Dart location', () async { - await service.resume(isolateId!, step: 'Out'); + await context.service.resume(isolateId!, step: 'Out'); // Wait for the step to actually occur. await stream .firstWhere((event) => event.kind == EventKind.kPauseInterrupted); - final stack = await service.getStack(isolateId!); + final stack = await context.service.getStack(isolateId!); expect(stack, isNotNull); final first = stack.frames!.first; expect(first.kind, 'Regular'); @@ -1200,17 +1206,17 @@ void main() { setUp(() async { setCurrentLogWriter(debug: debug); - final vm = await service.getVM(); + final vm = await context.service.getVM(); isolateId = vm.isolates!.first.id; - scripts = await service.getScripts(isolateId!); - await service.streamListen('Debug'); - stream = service.onEvent('Debug'); + scripts = await context.service.getScripts(isolateId!); + await context.service.streamListen('Debug'); + stream = context.service.onEvent('Debug'); mainScript = scripts.scripts! .firstWhere((each) => each.uri!.contains('main.dart')); }); test('throws if not paused', () async { - await expectLater(service.getStack(isolateId!), throwsRPCError); + await expectLater(context.service.getStack(isolateId!), throwsRPCError); }, skip: Platform .isWindows); // Issue: https://github.com/dart-lang/webdev/issues/1749 @@ -1221,17 +1227,18 @@ void main() { breakpointId, isolateId!, mainScript); Breakpoint? bp; try { - bp = await service.addBreakpoint(isolateId!, mainScript.id!, line); + bp = await context.service + .addBreakpoint(isolateId!, mainScript.id!, line); // Wait for breakpoint to trigger. await stream .firstWhere((event) => event.kind == EventKind.kPauseBreakpoint); - return await service.getStack(isolateId!, limit: limit); + return await context.service.getStack(isolateId!, limit: limit); } finally { // Remove breakpoint and resume so it doesn't impact other tests. if (bp != null) { - await service.removeBreakpoint(isolateId!, bp.id!); + await context.service.removeBreakpoint(isolateId!, bp.id!); } - await service.resume(isolateId!); + await context.service.resume(isolateId!); } } @@ -1307,8 +1314,8 @@ void main() { test('break on exceptions with setIsolatePauseMode', () async { final oldPauseMode = - (await service.getIsolate(isolateId!)).exceptionPauseMode; - await service.setIsolatePauseMode(isolateId!, + (await context.service.getIsolate(isolateId!)).exceptionPauseMode; + await context.service.setIsolatePauseMode(isolateId!, exceptionPauseMode: ExceptionPauseMode.kAll); // Wait for pausing to actually propagate. final event = await stream @@ -1318,27 +1325,27 @@ void main() { // TODO(https://github.com/dart-lang/webdev/issues/1821) Uncomment. // expect(event.exception!.valueAsString, contains('main.dart')); - final stack = await service.getStack(isolateId!); + final stack = await context.service.getStack(isolateId!); expect(stack, isNotNull); - await service.setIsolatePauseMode(isolateId!, - exceptionPauseMode: oldPauseMode); - await service.resume(isolateId!); + await context.service + .setIsolatePauseMode(isolateId!, exceptionPauseMode: oldPauseMode); + await context.service.resume(isolateId!); }); test('returns non-null stack when paused', () async { - await service.pause(isolateId!); + await context.service.pause(isolateId!); // Wait for pausing to actually propagate. await stream .firstWhere((event) => event.kind == EventKind.kPauseInterrupted); - expect(await service.getStack(isolateId!), isNotNull); + expect(await context.service.getStack(isolateId!), isNotNull); // Resume the isolate to not impact other tests. - await service.resume(isolateId!); + await context.service.resume(isolateId!); }); }); test('getVM', () async { - final vm = await service.getVM(); + final vm = await context.service.getVM(); expect(vm.name, isNotNull); expect(vm.version, Platform.version); expect(vm.isolates, hasLength(1)); @@ -1349,7 +1356,7 @@ void main() { }); test('getVersion', () async { - final version = await service.getVersion(); + final version = await context.service.getVersion(); expect(version, isNotNull); expect(version.major, greaterThan(0)); }); @@ -1362,11 +1369,11 @@ void main() { setUp(() async { setCurrentLogWriter(debug: debug); - vm = await service.getVM(); - isolate = await service.getIsolate(vm.isolates!.first.id!); + vm = await context.service.getVM(); + isolate = await context.service.getIsolate(vm.isolates!.first.id!); bootstrap = isolate.rootLib; - testInstance = await service.evaluate( - isolate.id!, bootstrap!.id!, 'myInstance') as InstanceRef; + testInstance = await context.service + .evaluate(isolate.id!, bootstrap!.id!, 'myInstance') as InstanceRef; }); test('rootLib', () async { @@ -1377,8 +1384,8 @@ void main() { }); test('toString()', () async { - final remote = - await service.invoke(isolate.id!, testInstance.id!, 'toString', []); + final remote = await context.service + .invoke(isolate.id!, testInstance.id!, 'toString', []); expect( remote, const TypeMatcher().having( @@ -1388,8 +1395,8 @@ void main() { }); test('hello()', () async { - final remote = - await service.invoke(isolate.id!, testInstance.id!, 'hello', []); + final remote = await context.service + .invoke(isolate.id!, testInstance.id!, 'hello', []); expect( remote, const TypeMatcher().having( @@ -1397,7 +1404,7 @@ void main() { }); test('helloString', () async { - final remote = await service.invoke(isolate.id!, bootstrap!.id!, + final remote = await context.service.invoke(isolate.id!, bootstrap!.id!, 'helloString', ['#StringInstanceRef#abc']); expect( remote, @@ -1410,7 +1417,7 @@ void main() { }); test('null argument', () async { - final remote = await service.invoke( + final remote = await context.service.invoke( isolate.id!, bootstrap!.id!, 'helloString', ['objects/null']); expect( remote, @@ -1423,7 +1430,7 @@ void main() { }); test('helloBool', () async { - final remote = await service.invoke( + final remote = await context.service.invoke( isolate.id!, bootstrap!.id!, 'helloBool', ['objects/bool-true']); expect( remote, @@ -1436,7 +1443,7 @@ void main() { }); test('helloNum', () async { - final remote = await service.invoke( + final remote = await context.service.invoke( isolate.id!, bootstrap!.id!, 'helloNum', ['objects/int-123']); expect( remote, @@ -1449,7 +1456,7 @@ void main() { }); test('two object arguments', () async { - final remote = await service.invoke(isolate.id!, bootstrap!.id!, + final remote = await context.service.invoke(isolate.id!, bootstrap!.id!, 'messagesCombined', [testInstance.id, testInstance.id]); expect( remote, @@ -1465,35 +1472,37 @@ void main() { }); test('kill', () async { - await expectLater(service.kill(''), throwsRPCError); + await expectLater(context.service.kill(''), throwsRPCError); }); test('onEvent', () async { - expect(() => service.onEvent(''), throwsRPCError); + expect(() => context.service.onEvent(''), throwsRPCError); }); test('pause / resume', () async { - await service.streamListen('Debug'); - final stream = service.onEvent('Debug'); - final vm = await service.getVM(); + await context.service.streamListen('Debug'); + final stream = context.service.onEvent('Debug'); + final vm = await context.service.getVM(); final isolateId = vm.isolates!.first.id!; final pauseCompleter = Completer(); - final pauseSub = tabConnection.debugger.onPaused.listen((_) { + final pauseSub = context.tabConnection.debugger.onPaused.listen((_) { pauseCompleter.complete(); }); final resumeCompleter = Completer(); - final resumeSub = tabConnection.debugger.onResumed.listen((_) { + final resumeSub = context.tabConnection.debugger.onResumed.listen((_) { resumeCompleter.complete(); }); - expect(await service.pause(isolateId), const TypeMatcher()); + expect( + await context.service.pause(isolateId), const TypeMatcher()); await stream .firstWhere((event) => event.kind == EventKind.kPauseInterrupted); - expect((await service.getIsolate(isolateId)).pauseEvent!.kind, + expect((await context.service.getIsolate(isolateId)).pauseEvent!.kind, EventKind.kPauseInterrupted); await pauseCompleter.future; - expect(await service.resume(isolateId), const TypeMatcher()); + expect(await context.service.resume(isolateId), + const TypeMatcher()); await stream.firstWhere((event) => event.kind == EventKind.kResume); - expect((await service.getIsolate(isolateId)).pauseEvent!.kind, + expect((await context.service.getIsolate(isolateId)).pauseEvent!.kind, EventKind.kResume); await resumeCompleter.future; await pauseSub.cancel(); @@ -1502,22 +1511,23 @@ void main() { test('getInboundReferences', () async { await expectLater( - service.getInboundReferences('', '', 0), throwsRPCError); + context.service.getInboundReferences('', '', 0), throwsRPCError); }); test('getRetainingPath', () async { - await expectLater(service.getRetainingPath('', '', 0), throwsRPCError); + await expectLater( + context.service.getRetainingPath('', '', 0), throwsRPCError); }); test('lookupResolvedPackageUris converts package and org-dartlang-app uris', () async { - final vm = await service.getVM(); + final vm = await context.service.getVM(); final isolateId = vm.isolates!.first.id!; - final scriptList = await service.getScripts(isolateId); + final scriptList = await context.service.getScripts(isolateId); final uris = scriptList.scripts!.map((e) => e.uri!).toList(); final resolvedUris = - await service.lookupResolvedPackageUris(isolateId, uris); + await context.service.lookupResolvedPackageUris(isolateId, uris); expect( resolvedUris.uris, @@ -1530,10 +1540,11 @@ void main() { test('lookupResolvedPackageUris does not translate non-existent paths', () async { - final vm = await service.getVM(); + final vm = await context.service.getVM(); final isolateId = vm.isolates!.first.id!; - final resolvedUris = await service.lookupResolvedPackageUris(isolateId, [ + final resolvedUris = + await context.service.lookupResolvedPackageUris(isolateId, [ 'package:does/not/exist.dart', 'dart:does_not_exist', 'file:///does_not_exist.dart', @@ -1542,10 +1553,11 @@ void main() { }); test('lookupResolvedPackageUris translates dart uris', () async { - final vm = await service.getVM(); + final vm = await context.service.getVM(); final isolateId = vm.isolates!.first.id!; - final resolvedUris = await service.lookupResolvedPackageUris(isolateId, [ + final resolvedUris = + await context.service.lookupResolvedPackageUris(isolateId, [ 'dart:html', 'dart:async', ]); @@ -1558,16 +1570,16 @@ void main() { test('lookupPackageUris finds package and org-dartlang-app paths', () async { - final vm = await service.getVM(); + final vm = await context.service.getVM(); final isolateId = vm.isolates!.first.id!; - final scriptList = await service.getScripts(isolateId); + final scriptList = await context.service.getScripts(isolateId); final uris = scriptList.scripts!.map((e) => e.uri!).toList(); final resolvedUris = - await service.lookupResolvedPackageUris(isolateId, uris); + await context.service.lookupResolvedPackageUris(isolateId, uris); - final packageUris = await service.lookupPackageUris( - isolateId, List.from(resolvedUris.uris!)); + final packageUris = await context.service + .lookupPackageUris(isolateId, List.from(resolvedUris.uris!)); expect( packageUris.uris, containsAll([ @@ -1578,15 +1590,15 @@ void main() { }); test('lookupPackageUris ignores local parameter', () async { - final vm = await service.getVM(); + final vm = await context.service.getVM(); final isolateId = vm.isolates!.first.id!; - final scriptList = await service.getScripts(isolateId); + final scriptList = await context.service.getScripts(isolateId); final uris = scriptList.scripts!.map((e) => e.uri!).toList(); - final resolvedUrisWithLocal = - await service.lookupResolvedPackageUris(isolateId, uris, local: true); + final resolvedUrisWithLocal = await context.service + .lookupResolvedPackageUris(isolateId, uris, local: true); - final packageUrisWithLocal = await service.lookupPackageUris( + final packageUrisWithLocal = await context.service.lookupPackageUris( isolateId, List.from(resolvedUrisWithLocal.uris!)); expect( packageUrisWithLocal.uris, @@ -1596,10 +1608,10 @@ void main() { 'package:path/src/path_set.dart', ])); - final resolvedUrisWithoutLocal = - await service.lookupResolvedPackageUris(isolateId, uris, local: true); + final resolvedUrisWithoutLocal = await context.service + .lookupResolvedPackageUris(isolateId, uris, local: true); - final packageUrisWithoutLocal = await service.lookupPackageUris( + final packageUrisWithoutLocal = await context.service.lookupPackageUris( isolateId, List.from(resolvedUrisWithoutLocal.uris!)); expect( packageUrisWithoutLocal.uris, @@ -1611,10 +1623,10 @@ void main() { }); test('lookupPackageUris does not translate non-existent paths', () async { - final vm = await service.getVM(); + final vm = await context.service.getVM(); final isolateId = vm.isolates!.first.id!; - final resolvedUris = await service.lookupPackageUris(isolateId, [ + final resolvedUris = await context.service.lookupPackageUris(isolateId, [ 'org-dartlang-sdk:///sdk/does/not/exist.dart', 'does_not_exist.dart', 'file:///does_not_exist.dart', @@ -1623,10 +1635,10 @@ void main() { }); test('lookupPackageUris translates dart uris', () async { - final vm = await service.getVM(); + final vm = await context.service.getVM(); final isolateId = vm.isolates!.first.id!; - final resolvedUris = await service.lookupPackageUris(isolateId, [ + final resolvedUris = await context.service.lookupPackageUris(isolateId, [ 'org-dartlang-sdk:///sdk/lib/html/dart2js/html_dart2js.dart', 'org-dartlang-sdk:///sdk/lib/async/async.dart', ]); @@ -1637,62 +1649,64 @@ void main() { ]); }, skip: 'https://github.com/dart-lang/webdev/issues/1584'); - test('registerService', () async { + test('registercontext.service', () async { await expectLater( - service.registerService('ext.foo.bar', ''), throwsRPCError); + context.service.registerService('ext.foo.bar', ''), throwsRPCError); }); test('reloadSources', () async { - await expectLater(service.reloadSources(''), throwsRPCError); + await expectLater(context.service.reloadSources(''), throwsRPCError); }); test('setIsolatePauseMode', () async { - final vm = await service.getVM(); + final vm = await context.service.getVM(); final isolateId = vm.isolates!.first.id!; - expect(await service.setIsolatePauseMode(isolateId), _isSuccess); + expect(await context.service.setIsolatePauseMode(isolateId), _isSuccess); expect( - await service.setIsolatePauseMode(isolateId, + await context.service.setIsolatePauseMode(isolateId, exceptionPauseMode: ExceptionPauseMode.kAll), _isSuccess); expect( - await service.setIsolatePauseMode(isolateId, + await context.service.setIsolatePauseMode(isolateId, exceptionPauseMode: ExceptionPauseMode.kUnhandled), _isSuccess); // Make sure this is the last one - or future tests might hang. expect( - await service.setIsolatePauseMode(isolateId, + await context.service.setIsolatePauseMode(isolateId, exceptionPauseMode: ExceptionPauseMode.kNone), _isSuccess); await expectLater( - service.setIsolatePauseMode(isolateId, exceptionPauseMode: 'invalid'), + context.service + .setIsolatePauseMode(isolateId, exceptionPauseMode: 'invalid'), throwsRPCError); }); test('setFlag', () async { - await expectLater(service.setFlag('', ''), throwsRPCError); + await expectLater(context.service.setFlag('', ''), throwsRPCError); }); test('setLibraryDebuggable', () async { await expectLater( - service.setLibraryDebuggable('', '', false), throwsRPCError); + context.service.setLibraryDebuggable('', '', false), throwsRPCError); }); test('setName', () async { - final vm = await service.getVM(); + final vm = await context.service.getVM(); final isolateId = vm.isolates!.first.id!; - expect(service.setName(isolateId, 'test'), completion(_isSuccess)); - final isolate = await service.getIsolate(isolateId); + expect( + context.service.setName(isolateId, 'test'), completion(_isSuccess)); + final isolate = await context.service.getIsolate(isolateId); expect(isolate.name, 'test'); }); test('setVMName', () async { - expect(service.setVMName('foo'), completion(_isSuccess)); - final vm = await service.getVM(); + expect(context.service.setVMName('foo'), completion(_isSuccess)); + final vm = await context.service.getVM(); expect(vm.name, 'foo'); }); test('streamCancel', () async { - await expectLater(service.streamCancel(''), throwsRPCError); + await expectLater(context.service.streamCancel(''), throwsRPCError); }); group('streamListen/onEvent', () { @@ -1701,20 +1715,20 @@ void main() { setUp(() async { setCurrentLogWriter(debug: debug); - expect(await service.streamListen('Debug'), + expect(await context.service.streamListen('Debug'), const TypeMatcher()); - eventStream = service.onEvent('Debug'); + eventStream = context.service.onEvent('Debug'); }); test('basic Pause/Resume', () async { - expect(service.streamListen('Debug'), completion(_isSuccess)); - final stream = service.onEvent('Debug'); - safeUnawaited(tabConnection.debugger.pause()); + expect(context.service.streamListen('Debug'), completion(_isSuccess)); + final stream = context.service.onEvent('Debug'); + safeUnawaited(context.tabConnection.debugger.pause()); await expectLater( stream, emitsThrough(const TypeMatcher() .having((e) => e.kind, 'kind', EventKind.kPauseInterrupted))); - safeUnawaited(tabConnection.debugger.resume()); + safeUnawaited(context.tabConnection.debugger.resume()); expect( eventStream, emitsThrough(const TypeMatcher() @@ -1733,7 +1747,7 @@ void main() { .having((instance) => instance.id, 'id', isNotNull) .having((instance) => instance.kind, 'inspectee.kind', InstanceKind.kPlainInstance)))); - await tabConnection.runtime.evaluate('inspectInstance()'); + await context.tabConnection.runtime.evaluate('inspectInstance()'); }); }); @@ -1742,9 +1756,9 @@ void main() { setUp(() async { setCurrentLogWriter(debug: debug); - expect(await service.streamListen('Extension'), + expect(await context.service.streamListen('Extension'), const TypeMatcher()); - eventStream = service.onEvent('Extension'); + eventStream = context.service.onEvent('Extension'); }); test('Custom debug event', () async { @@ -1755,7 +1769,8 @@ void main() { event.kind == EventKind.kExtension && event.extensionKind == eventKind && event.extensionData!.data['example'] == 'data'))); - await tabConnection.runtime.evaluate("postEvent('$eventKind');"); + await context.tabConnection.runtime + .evaluate("postEvent('$eventKind');"); }); test('Batched debug events from injected client', () async { @@ -1788,40 +1803,41 @@ void main() { ])); for (var data in batch1) { - await tabConnection.runtime.evaluate(emitDebugEvent(data)); + await context.tabConnection.runtime.evaluate(emitDebugEvent(data)); } await Future.delayed(delay); for (var data in batch2) { - await tabConnection.runtime.evaluate(emitDebugEvent(data)); + await context.tabConnection.runtime.evaluate(emitDebugEvent(data)); } }); }); test('GC', () async { - expect(service.streamListen('GC'), completion(_isSuccess)); + expect(context.service.streamListen('GC'), completion(_isSuccess)); }); group('Isolate', () { late Stream isolateEventStream; setUp(() async { - expect(await service.streamListen(EventStreams.kIsolate), _isSuccess); - isolateEventStream = service.onEvent(EventStreams.kIsolate); + expect(await context.service.streamListen(EventStreams.kIsolate), + _isSuccess); + isolateEventStream = context.service.onEvent(EventStreams.kIsolate); }); - test('ServiceExtensionAdded', () async { + test('context.serviceExtensionAdded', () async { final extensionMethod = 'ext.foo.bar'; expect( isolateEventStream, emitsThrough(predicate((Event event) => event.kind == EventKind.kServiceExtensionAdded && event.extensionRPC == extensionMethod))); - await tabConnection.runtime + await context.tabConnection.runtime .evaluate("registerExtension('$extensionMethod');"); }); test('lifecycle events', () async { - final vm = await service.getVM(); + final vm = await context.service.getVM(); final initialIsolateId = vm.isolates!.first.id; final eventsDone = expectLater( isolateEventStream, @@ -1836,10 +1852,10 @@ void main() { event.kind == EventKind.kIsolateRunnable && event.isolate!.id != initialIsolateId), ]))); - service.destroyIsolate(); - await service.createIsolate(context.appConnection); + context.service.destroyIsolate(); + await context.service.createIsolate(context.appConnection); await eventsDone; - expect((await service.getVM()).isolates!.first.id, + expect((await context.service.getVM()).isolates!.first.id, isNot(initialIsolateId)); }); @@ -1858,69 +1874,73 @@ void main() { expect( isolateEventStream, emitsInOrder(extensions.map(eventMatcher))); for (var extension in extensions) { - await tabConnection.runtime.evaluate(emitRegisterEvent(extension)); + await context.tabConnection.runtime + .evaluate(emitRegisterEvent(extension)); } }); }); test('Timeline', () async { - expect(service.streamListen('Timeline'), completion(_isSuccess)); + expect( + context.service.streamListen('Timeline'), completion(_isSuccess)); }); test('Stdout', () async { - expect(service.streamListen('Stdout'), completion(_isSuccess)); + expect(context.service.streamListen('Stdout'), completion(_isSuccess)); expect( - service.onEvent('Stdout'), + context.service.onEvent('Stdout'), emitsThrough(predicate((Event event) => event.kind == EventKind.kWriteEvent && String.fromCharCodes(base64.decode(event.bytes!)) .contains('hello')))); - await tabConnection.runtime.evaluate('console.log("hello");'); + await context.tabConnection.runtime.evaluate('console.log("hello");'); }); test('Stderr', () async { - expect(service.streamListen('Stderr'), completion(_isSuccess)); - final stderrStream = service.onEvent('Stderr'); + expect(context.service.streamListen('Stderr'), completion(_isSuccess)); + final stderrStream = context.service.onEvent('Stderr'); expect( stderrStream, emitsThrough(predicate((Event event) => event.kind == EventKind.kWriteEvent && String.fromCharCodes(base64.decode(event.bytes!)) .contains('Error')))); - await tabConnection.runtime.evaluate('console.error("Error");'); + await context.tabConnection.runtime.evaluate('console.error("Error");'); }); test('exception stack trace mapper', () async { - expect(service.streamListen('Stderr'), completion(_isSuccess)); - final stderrStream = service.onEvent('Stderr'); + expect(context.service.streamListen('Stderr'), completion(_isSuccess)); + final stderrStream = context.service.onEvent('Stderr'); expect( stderrStream, emitsThrough(predicate((Event event) => event.kind == EventKind.kWriteEvent && String.fromCharCodes(base64.decode(event.bytes!)) .contains('main.dart')))); - await tabConnection.runtime.evaluate('throwUncaughtException();'); + await context.tabConnection.runtime + .evaluate('throwUncaughtException();'); }); test('VM', () async { - final status = await service.streamListen('VM'); + final status = await context.service.streamListen('VM'); expect(status, _isSuccess); - final stream = service.onEvent('VM'); + final stream = context.service.onEvent('VM'); expect( stream, emitsThrough(predicate((Event e) => e.kind == EventKind.kVMUpdate && e.vm!.name == 'test'))); - await service.setVMName('test'); + await context.service.setVMName('test'); }); }); test('Logging', () async { - expect( - service.streamListen(EventStreams.kLogging), completion(_isSuccess)); - final stream = service.onEvent(EventStreams.kLogging); + expect(context.service.streamListen(EventStreams.kLogging), + completion(_isSuccess)); + final stream = context.service.onEvent(EventStreams.kLogging); final message = 'myMessage'; - safeUnawaited(tabConnection.runtime.evaluate("sendLog('$message');")); + safeUnawaited( + context.tabConnection.runtime.evaluate("sendLog('$message');")); final event = await stream.first; expect(event.kind, EventKind.kLogging); diff --git a/dwds/test/dart_uri_file_uri_test.dart b/dwds/test/dart_uri_file_uri_test.dart index fc35f6d2b..18204002c 100644 --- a/dwds/test/dart_uri_file_uri_test.dart +++ b/dwds/test/dart_uri_file_uri_test.dart @@ -8,17 +8,11 @@ import 'package:dwds/src/utilities/dart_uri.dart'; import 'package:path/path.dart' as p; import 'package:test/test.dart'; +import 'package:test_common/test_sdk_configuration.dart'; import 'fixtures/context.dart'; import 'fixtures/utilities.dart'; -final context = TestContext.withWeakNullSafety( - packageName: '_testPackage', - webAssetsPath: 'web', - dartEntryFileName: 'main.dart', - htmlEntryFileName: 'index.html', -); - /// The directory for the general _test package. final testDir = absolutePath(pathFromFixtures: p.join('_test')); @@ -33,6 +27,10 @@ final testPackageDir = absolutePath(pathFromFixtures: p.join('_testPackage')); // TODO(https://github.com/dart-lang/webdev/issues/1818): Switch test over for // testing sound null-safety. void main() { + final provider = TestSdkConfigurationProvider(); + tearDownAll(provider.dispose); + final context = TestContext.testWithSoundNullSafety(provider); + for (final compilationMode in CompilationMode.values) { group('$compilationMode |', () { for (final useDebuggerModuleNames in [false, true]) { @@ -45,14 +43,14 @@ void main() { final serverPath = compilationMode == CompilationMode.frontendServer && useDebuggerModuleNames - ? 'packages/_testPackage/lib/test_library.dart' - : 'packages/_test_package/test_library.dart'; + ? 'packages/_testPackageSound/lib/test_library.dart' + : 'packages/_test_package_sound/test_library.dart'; final anotherServerPath = compilationMode == CompilationMode.frontendServer && useDebuggerModuleNames - ? 'packages/_test/lib/library.dart' - : 'packages/_test/library.dart'; + ? 'packages/_testSound/lib/library.dart' + : 'packages/_test_sound/library.dart'; setUpAll(() async { await context.setUp( diff --git a/dwds/test/debug_extension_test.dart b/dwds/test/debug_extension_test.dart index cadc04d90..1bd4cf7ab 100644 --- a/dwds/test/debug_extension_test.dart +++ b/dwds/test/debug_extension_test.dart @@ -14,6 +14,7 @@ import 'package:dwds/src/connections/debug_connection.dart'; import 'package:dwds/src/handlers/injector.dart'; import 'package:http/http.dart' as http; import 'package:test/test.dart'; +import 'package:test_common/test_sdk_configuration.dart'; // ignore: deprecated_member_use import 'package:webdriver/io.dart'; @@ -30,9 +31,12 @@ import 'fixtures/utilities.dart'; // Remove the key before pushing code to GitHub. // See go/extension-identification. -final context = TestContext.withSoundNullSafety(); - void main() async { + final provider = TestSdkConfigurationProvider(); + tearDownAll(provider.dispose); + + final context = TestContext.testWithSoundNullSafety(provider); + Future waitForDartDevToolsWithRetry({ int retryCount = 6, Duration retryWait = const Duration(seconds: 1), @@ -204,18 +208,14 @@ void main() async { } group('With encoding', () { - final context = TestContext.withSoundNullSafety(); - setUp(() async { + final context = TestContext.testWithSoundNullSafety(provider); + setUpAll(() async { await context.setUp( enableDebugExtension: true, urlEncoder: (url) async => url.endsWith(r'/$debug') ? 'http://some-encoded-url:8081/' : url); }); - tearDown(() async { - await context.tearDown(); - }); - test('uses the encoded URI', () async { final result = await http.get(Uri.parse( 'http://localhost:${context.port}/hello_world/main.dart$bootstrapJsExtension')); @@ -225,14 +225,14 @@ void main() async { }); group('With "any" hostname', () { - final context = TestContext.withSoundNullSafety(); + final context = TestContext.testWithSoundNullSafety(provider); final uriPattern = RegExp(r'dartExtensionUri = "([^"]+)";'); - setUp(() async { + setUpAll(() async { await context.setUp(enableDebugExtension: true, hostname: 'any'); }); - tearDown(() async { + tearDownAll(() async { await context.tearDown(); }); diff --git a/dwds/test/debug_service_test.dart b/dwds/test/debug_service_test.dart index 4fd90cb93..768b3a7d2 100644 --- a/dwds/test/debug_service_test.dart +++ b/dwds/test/debug_service_test.dart @@ -9,12 +9,16 @@ import 'dart:convert'; import 'dart:io'; import 'package:test/test.dart'; +import 'package:test_common/test_sdk_configuration.dart'; import 'fixtures/context.dart'; -final context = TestContext.withSoundNullSafety(); - void main() { + final provider = TestSdkConfigurationProvider(); + tearDownAll(provider.dispose); + + final context = TestContext.testWithSoundNullSafety(provider); + setUpAll(() async { // Disable DDS as we're testing DWDS behavior. await context.setUp(spawnDds: false); diff --git a/dwds/test/debugger_test.dart b/dwds/test/debugger_test.dart index 4585404a8..c6514e4aa 100644 --- a/dwds/test/debugger_test.dart +++ b/dwds/test/debugger_test.dart @@ -18,11 +18,9 @@ import 'package:vm_service/vm_service.dart' hide LogRecord; import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart' show CallFrame, DebuggerPausedEvent, StackTrace, WipCallFrame, WipScript; -import 'fixtures/context.dart'; import 'fixtures/debugger_data.dart'; import 'fixtures/fakes.dart'; -final context = TestContext.withSoundNullSafety(); late AppInspector inspector; late Debugger debugger; late FakeWebkitDebugger webkitDebugger; diff --git a/dwds/test/devtools_test.dart b/dwds/test/devtools_test.dart index 56d01c8fb..8912ed3ce 100644 --- a/dwds/test/devtools_test.dart +++ b/dwds/test/devtools_test.dart @@ -7,14 +7,13 @@ import 'dart:io'; import 'package:test/test.dart'; +import 'package:test_common/test_sdk_configuration.dart'; import 'package:vm_service/vm_service.dart'; // ignore: deprecated_member_use import 'package:webdriver/io.dart'; import 'fixtures/context.dart'; -final context = TestContext.withSoundNullSafety(); - Future _waitForPageReady(TestContext context) async { var attempt = 100; while (attempt-- > 0) { @@ -26,6 +25,11 @@ Future _waitForPageReady(TestContext context) async { } void main() { + final provider = TestSdkConfigurationProvider(); + tearDownAll(provider.dispose); + + final context = TestContext.testWithSoundNullSafety(provider); + group('Injected client', () { setUp(() async { await context.setUp( diff --git a/dwds/test/evaluate_circular_common.dart b/dwds/test/evaluate_circular_common.dart index f7a0a450b..49b744a43 100644 --- a/dwds/test/evaluate_circular_common.dart +++ b/dwds/test/evaluate_circular_common.dart @@ -6,54 +6,15 @@ @Timeout(Duration(minutes: 2)) import 'dart:async'; -import 'package:dwds/src/connections/debug_connection.dart'; -import 'package:dwds/src/services/chrome_proxy_service.dart'; import 'package:test/test.dart'; import 'package:test_common/logging.dart'; +import 'package:test_common/test_sdk_configuration.dart'; import 'package:vm_service/vm_service.dart'; -import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart'; import 'fixtures/context.dart'; -class TestSetup { - static TestContext contextUnsound(String index) => - TestContext.withWeakNullSafety( - packageName: '_testCircular2', - webAssetsPath: 'web', - dartEntryFileName: 'main.dart', - htmlEntryFileName: index, - ); - - static TestContext contextSound(String index) => - TestContext.withSoundNullSafety( - packageName: '_testCircular2Sound', - webAssetsPath: 'web', - dartEntryFileName: 'main.dart', - htmlEntryFileName: index, - ); - - TestContext context; - - TestSetup.sound(IndexBaseMode baseMode) - : context = contextSound(_index(baseMode)); - - TestSetup.unsound(IndexBaseMode baseMode) - : context = contextUnsound(_index(baseMode)); - - factory TestSetup.create(NullSafety? nullSafety, IndexBaseMode baseMode) => - nullSafety == NullSafety.sound - ? TestSetup.sound(baseMode) - : TestSetup.unsound(baseMode); - - ChromeProxyService get service => - fetchChromeProxyService(context.debugConnection); - WipConnection get tabConnection => context.tabConnection; - - static String _index(IndexBaseMode baseMode) => - baseMode == IndexBaseMode.base ? 'base_index.html' : 'index.html'; -} - void testAll({ + required TestSdkConfigurationProvider provider, CompilationMode compilationMode = CompilationMode.buildDaemon, IndexBaseMode indexBaseMode = IndexBaseMode.noBase, NullSafety nullSafety = NullSafety.sound, @@ -65,22 +26,25 @@ void testAll({ throw StateError( 'build daemon scenario does not support non-empty base in index file'); } - final setup = TestSetup.create(nullSafety, indexBaseMode); - final context = setup.context; + final context = TestContext.testCircular( + provider: provider, + nullSafety: nullSafety, + baseMode: indexBaseMode, + ); Future onBreakPoint(String isolate, ScriptRef script, String breakPointId, Future Function() body) async { + final service = context.service; Breakpoint? bp; try { final line = await context.findBreakpointLine(breakPointId, isolate, script); - bp = await setup.service - .addBreakpointWithScriptUri(isolate, script.uri!, line); + bp = await service.addBreakpointWithScriptUri(isolate, script.uri!, line); await body(); } finally { // Remove breakpoint so it doesn't impact other tests or retries. if (bp != null) { - await setup.service.removeBreakpoint(isolate, bp.id!); + await service.removeBreakpoint(isolate, bp.id!); } } } @@ -103,6 +67,7 @@ void testAll({ setUp(() => setCurrentLogWriter(debug: debug)); group('evaluateInFrame', () { + late VmServiceInterface service; VM vm; late Isolate isolate; late String isolateId; @@ -113,13 +78,14 @@ void testAll({ setUp(() async { setCurrentLogWriter(debug: debug); - vm = await setup.service.getVM(); - isolate = await setup.service.getIsolate(vm.isolates!.first.id!); + service = context.service; + vm = await service.getVM(); + isolate = await service.getIsolate(vm.isolates!.first.id!); isolateId = isolate.id!; - scripts = await setup.service.getScripts(isolateId); + scripts = await service.getScripts(isolateId); - await setup.service.streamListen('Debug'); - stream = setup.service.onEvent('Debug'); + await service.streamListen('Debug'); + stream = service.onEvent('Debug'); final soundNullSafety = nullSafety == NullSafety.sound; final test1 = @@ -134,7 +100,7 @@ void testAll({ }); tearDown(() async { - await setup.service.resume(isolateId); + await service.resume(isolateId); }); test('evaluate expression in _test_circular1/library', () async { @@ -143,7 +109,7 @@ void testAll({ final event = await stream .firstWhere((event) => event.kind == EventKind.kPauseBreakpoint); - final result = await setup.service + final result = await context.service .evaluateInFrame(isolateId, event.topFrame!.index!, 'a'); expect( @@ -160,7 +126,7 @@ void testAll({ final event = await stream .firstWhere((event) => event.kind == EventKind.kPauseBreakpoint); - final result = await setup.service + final result = await context.service .evaluateInFrame(isolateId, event.topFrame!.index!, 'true'); expect( diff --git a/dwds/test/evaluate_common.dart b/dwds/test/evaluate_common.dart index 7da5c2606..25322abb5 100644 --- a/dwds/test/evaluate_common.dart +++ b/dwds/test/evaluate_common.dart @@ -6,54 +6,15 @@ @Timeout(Duration(minutes: 2)) import 'dart:async'; -import 'package:dwds/src/connections/debug_connection.dart'; -import 'package:dwds/src/services/chrome_proxy_service.dart'; import 'package:test/test.dart'; import 'package:test_common/logging.dart'; +import 'package:test_common/test_sdk_configuration.dart'; import 'package:vm_service/vm_service.dart'; -import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart'; import 'fixtures/context.dart'; -class TestSetup { - static TestContext contextUnsound(String index) => - TestContext.withWeakNullSafety( - packageName: '_testPackage', - webAssetsPath: 'web', - dartEntryFileName: 'main.dart', - htmlEntryFileName: index, - ); - - static TestContext contextSound(String index) => - TestContext.withSoundNullSafety( - packageName: '_testPackageSound', - webAssetsPath: 'web', - dartEntryFileName: 'main.dart', - htmlEntryFileName: index, - ); - - TestContext context; - - TestSetup.sound(IndexBaseMode baseMode) - : context = contextSound(_index(baseMode)); - - TestSetup.unsound(IndexBaseMode baseMode) - : context = contextUnsound(_index(baseMode)); - - factory TestSetup.create(NullSafety? nullSafety, IndexBaseMode baseMode) => - nullSafety == NullSafety.sound - ? TestSetup.sound(baseMode) - : TestSetup.unsound(baseMode); - - ChromeProxyService get service => - fetchChromeProxyService(context.debugConnection); - WipConnection get tabConnection => context.tabConnection; - - static String _index(IndexBaseMode baseMode) => - baseMode == IndexBaseMode.base ? 'base_index.html' : 'index.html'; -} - void testAll({ + required TestSdkConfigurationProvider provider, CompilationMode compilationMode = CompilationMode.buildDaemon, IndexBaseMode indexBaseMode = IndexBaseMode.noBase, NullSafety nullSafety = NullSafety.sound, @@ -65,27 +26,27 @@ void testAll({ throw StateError( 'build daemon scenario does not support non-empty base in index file'); } - final setup = TestSetup.create(nullSafety, indexBaseMode); - final context = setup.context; + final context = TestContext.testPackage( + provider: provider, nullSafety: nullSafety, baseMode: indexBaseMode); Future onBreakPoint(String isolate, ScriptRef script, String breakPointId, Future Function() body) async { + final service = context.service; Breakpoint? bp; try { final line = await context.findBreakpointLine(breakPointId, isolate, script); - bp = await setup.service - .addBreakpointWithScriptUri(isolate, script.uri!, line); + bp = await service.addBreakpointWithScriptUri(isolate, script.uri!, line); await body(); } finally { // Remove breakpoint so it doesn't impact other tests or retries. if (bp != null) { - await setup.service.removeBreakpoint(isolate, bp.id!); + await service.removeBreakpoint(isolate, bp.id!); } } } - group('shared context with evaluation |', () { + group('with evaluation |', () { setUpAll(() async { setCurrentLogWriter(debug: debug); await context.setUp( @@ -103,6 +64,7 @@ void testAll({ setUp(() => setCurrentLogWriter(debug: debug)); group('evaluateInFrame |', () { + late VmServiceInterface service; VM vm; late Isolate isolate; late String isolateId; @@ -115,13 +77,14 @@ void testAll({ setUp(() async { setCurrentLogWriter(debug: debug); - vm = await setup.service.getVM(); - isolate = await setup.service.getIsolate(vm.isolates!.first.id!); + service = context.service; + vm = await service.getVM(); + isolate = await service.getIsolate(vm.isolates!.first.id!); isolateId = isolate.id!; - scripts = await setup.service.getScripts(isolateId); + scripts = await service.getScripts(isolateId); - await setup.service.streamListen('Debug'); - stream = setup.service.onEvent('Debug'); + await service.streamListen('Debug'); + stream = service.onEvent('Debug'); final soundNullSafety = nullSafety == NullSafety.sound; final testPackage = @@ -138,7 +101,7 @@ void testAll({ }); tearDown(() async { - await setup.service.resume(isolateId); + await service.resume(isolateId); }); test('uses correct null safety mode', () async { @@ -148,7 +111,7 @@ void testAll({ final isNullSafetyEnabled = '() { const sound = !([] is List); return sound; } ()'; - final result = await setup.service.evaluateInFrame( + final result = await service.evaluateInFrame( isolateId, event.topFrame!.index!, isNullSafetyEnabled); expect( @@ -163,10 +126,10 @@ void testAll({ final event = await stream .firstWhere((event) => event.kind == EventKind.kPauseBreakpoint); - final result = await setup.service + final result = await context.service .evaluateInFrame(isolateId, event.topFrame!.index!, 'stream'); final instanceId = (result as InstanceRef).id!; - final instance = await setup.service.getObject(isolateId, instanceId); + final instance = await service.getObject(isolateId, instanceId); expect( instance, @@ -180,11 +143,11 @@ void testAll({ final event = await stream .firstWhere((event) => event.kind == EventKind.kPauseBreakpoint); - final object = await setup.service.evaluateInFrame( + final object = await service.evaluateInFrame( isolateId, event.topFrame!.index!, 'MainClass(0)'); final param = object as InstanceRef; - final result = await setup.service.evaluateInFrame( + final result = await service.evaluateInFrame( isolateId, event.topFrame!.index!, 't.toString()', @@ -206,7 +169,7 @@ void testAll({ final event = await stream .firstWhere((event) => event.kind == EventKind.kPauseBreakpoint); - final result = await setup.service + final result = await context.service .evaluateInFrame(isolateId, event.topFrame!.index!, 'local'); expect( @@ -219,7 +182,7 @@ void testAll({ test('Type does not show native JavaScript object fields', () async { await onBreakPoint(isolateId, mainScript, 'printLocal', () async { Future getInstance(InstanceRef ref) async { - final result = await setup.service.getObject(isolateId, ref.id!); + final result = await service.getObject(isolateId, ref.id!); expect(result, isA()); return result as Instance; } @@ -227,7 +190,7 @@ void testAll({ final event = await stream .firstWhere((event) => event.kind == EventKind.kPauseBreakpoint); - final result = await setup.service + final result = await context.service .evaluateInFrame(isolateId, event.topFrame!.index!, 'Type'); expect(result, isA()); final instanceRef = result as InstanceRef; @@ -265,7 +228,7 @@ void testAll({ final event = await stream .firstWhere((event) => event.kind == EventKind.kPauseBreakpoint); - final result = await setup.service.evaluateInFrame( + final result = await service.evaluateInFrame( isolateId, event.topFrame!.index!, 'instance.field'); expect( @@ -281,7 +244,7 @@ void testAll({ final event = await stream .firstWhere((event) => event.kind == EventKind.kPauseBreakpoint); - final result = await setup.service.evaluateInFrame( + final result = await service.evaluateInFrame( isolateId, event.topFrame!.index!, 'instance._field'); expect( @@ -296,7 +259,7 @@ void testAll({ final event = await stream .firstWhere((event) => event.kind == EventKind.kPauseBreakpoint); - final result = await setup.service.evaluateInFrame( + final result = await service.evaluateInFrame( isolateId, event.topFrame!.index!, 'instance._field'); expect( @@ -312,10 +275,10 @@ void testAll({ final event = await stream .firstWhere((event) => event.kind == EventKind.kPauseBreakpoint); - final instanceRef = await setup.service.evaluateInFrame( + final instanceRef = await service.evaluateInFrame( isolateId, event.topFrame!.index!, 'instance') as InstanceRef; - final instance = await setup.service + final instance = await context.service .getObject(isolateId, instanceRef.id!) as Instance; final field = instance.fields!.firstWhere( @@ -333,7 +296,7 @@ void testAll({ final event = await stream .firstWhere((event) => event.kind == EventKind.kPauseBreakpoint); - final result = await setup.service.evaluateInFrame( + final result = await service.evaluateInFrame( isolateId, event.topFrame!.index!, 'testLibraryValue'); expect( @@ -348,7 +311,7 @@ void testAll({ final event = await stream .firstWhere((event) => event.kind == EventKind.kPauseBreakpoint); - final result = await setup.service.evaluateInFrame( + final result = await service.evaluateInFrame( isolateId, event.topFrame!.index!, 'print(local)'); expect( @@ -363,7 +326,7 @@ void testAll({ final event = await stream .firstWhere((event) => event.kind == EventKind.kPauseBreakpoint); - final result = await setup.service.evaluateInFrame( + final result = await service.evaluateInFrame( isolateId, event.topFrame!.index!, 'testLibraryFunction(42)'); expect( @@ -378,7 +341,7 @@ void testAll({ final event = await stream .firstWhere((event) => event.kind == EventKind.kPauseBreakpoint); - final result = await setup.service.evaluateInFrame( + final result = await service.evaluateInFrame( isolateId, event.topFrame!.index!, 'testLibraryFunction(local)'); expect( @@ -393,7 +356,7 @@ void testAll({ final event = await stream .firstWhere((event) => event.kind == EventKind.kPauseBreakpoint); - final result = await setup.service.evaluateInFrame( + final result = await service.evaluateInFrame( isolateId, event.topFrame!.index!, 'testLibraryPartFunction(42)'); expect( @@ -408,7 +371,7 @@ void testAll({ final event = await stream .firstWhere((event) => event.kind == EventKind.kPauseBreakpoint); - final result = await setup.service.evaluateInFrame(isolateId, + final result = await service.evaluateInFrame(isolateId, event.topFrame!.index!, 'testLibraryPartFunction(local)'); expect( @@ -424,7 +387,7 @@ void testAll({ final event = await stream .firstWhere((event) => event.kind == EventKind.kPauseBreakpoint); - final result = await setup.service + final result = await context.service .evaluateInFrame(isolateId, event.topFrame!.index!, 'item'); expect( @@ -440,7 +403,7 @@ void testAll({ final event = await stream .firstWhere((event) => event.kind == EventKind.kPauseBreakpoint); - final result = await setup.service + final result = await context.service .evaluateInFrame(isolateId, event.topFrame!.index!, 'formal'); expect( @@ -457,8 +420,8 @@ void testAll({ final event = await stream .firstWhere((event) => event.kind == EventKind.kPauseBreakpoint); - final result = await setup.service - .evaluateInFrame(isolateId, event.topFrame!.index!, 'this.field'); + final result = await service.evaluateInFrame( + isolateId, event.topFrame!.index!, 'this.field'); expect( result, @@ -475,8 +438,8 @@ void testAll({ final event = await stream .firstWhere((event) => event.kind == EventKind.kPauseBreakpoint); - final result = await setup.service - .evaluateInFrame(isolateId, event.topFrame!.index!, 'this.field'); + final result = await service.evaluateInFrame( + isolateId, event.topFrame!.index!, 'this.field'); expect( result, @@ -491,8 +454,8 @@ void testAll({ final event = await stream .firstWhere((event) => event.kind == EventKind.kPauseBreakpoint); - final result = await setup.service - .evaluateInFrame(isolateId, event.topFrame!.index! + 1, 'local'); + final result = await service.evaluateInFrame( + isolateId, event.topFrame!.index! + 1, 'local'); expect( result, @@ -506,7 +469,7 @@ void testAll({ final event = await stream .firstWhere((event) => event.kind == EventKind.kPauseBreakpoint); - final result = await setup.service + final result = await context.service .evaluateInFrame(isolateId, event.topFrame!.index!, 'a'); expect( @@ -521,7 +484,7 @@ void testAll({ final event = await stream .firstWhere((event) => event.kind == EventKind.kPauseBreakpoint); - final error = await setup.service + final error = await context.service .evaluateInFrame(isolateId, event.topFrame!.index!, 'typo'); expect( @@ -536,7 +499,7 @@ void testAll({ final event = await stream .firstWhere((event) => event.kind == EventKind.kPauseBreakpoint); - final error = await setup.service.evaluateInFrame( + final error = await service.evaluateInFrame( isolateId, event.topFrame!.index!, 'd.deferredPrintLocal()'); expect( @@ -552,7 +515,7 @@ void testAll({ .firstWhere((event) => event.kind == EventKind.kPauseBreakpoint); await expectLater( - setup.service + context.service .evaluateInFrame('bad', event.topFrame!.index!, 'local'), throwsSentinelException); }); @@ -560,26 +523,28 @@ void testAll({ }); group('evaluate |', () { + late VmServiceInterface service; VM vm; late Isolate isolate; late String isolateId; setUp(() async { setCurrentLogWriter(debug: debug); - vm = await setup.service.getVM(); - isolate = await setup.service.getIsolate(vm.isolates!.first.id!); + service = context.service; + vm = await service.getVM(); + isolate = await service.getIsolate(vm.isolates!.first.id!); isolateId = isolate.id!; - await setup.service.streamListen('Debug'); + await service.streamListen('Debug'); }); tearDown(() async {}); test('in parallel (in a batch)', () async { final library = isolate.rootLib!; - final evaluation1 = setup.service + final evaluation1 = context.service .evaluate(isolateId, library.id!, 'MainClass(0).toString()'); - final evaluation2 = setup.service + final evaluation2 = context.service .evaluate(isolateId, library.id!, 'MainClass(1).toString()'); final results = await Future.wait([evaluation1, evaluation2]); @@ -597,9 +562,9 @@ void testAll({ test('in parallel (in a batch) handles errors', () async { final library = isolate.rootLib!; final missingLibId = ''; - final evaluation1 = setup.service + final evaluation1 = context.service .evaluate(isolateId, missingLibId, 'MainClass(0).toString()'); - final evaluation2 = setup.service + final evaluation2 = context.service .evaluate(isolateId, library.id!, 'MainClass(1).toString()'); final results = await Future.wait([evaluation1, evaluation2]); @@ -622,11 +587,11 @@ void testAll({ test('with scope override', () async { final library = isolate.rootLib!; - final object = await setup.service + final object = await context.service .evaluate(isolateId, library.id!, 'MainClass(0)'); final param = object as InstanceRef; - final result = await setup.service.evaluate( + final result = await service.evaluate( isolateId, library.id!, 't.toString()', scope: {'t': param.id!}); @@ -638,7 +603,7 @@ void testAll({ test('uses symbol from the same library', () async { final library = isolate.rootLib!; - final result = await setup.service + final result = await context.service .evaluate(isolateId, library.id!, 'MainClass(0).toString()'); expect( @@ -649,7 +614,7 @@ void testAll({ test('uses symbol from another library', () async { final library = isolate.rootLib!; - final result = await setup.service.evaluate( + final result = await service.evaluate( isolateId, library.id!, 'TestLibraryClass(0,1).toString()'); expect( @@ -662,7 +627,7 @@ void testAll({ test('closure call', () async { final library = isolate.rootLib!; - final result = await setup.service + final result = await context.service .evaluate(isolateId, library.id!, '(() => 42)()'); expect( @@ -673,7 +638,7 @@ void testAll({ }); }, timeout: const Timeout.factor(2)); - group('shared context with no evaluation |', () { + group('with no evaluation |', () { setUpAll(() async { setCurrentLogWriter(debug: debug); await context.setUp( @@ -690,6 +655,7 @@ void testAll({ setUp(() => setCurrentLogWriter(debug: debug)); group('evaluateInFrame |', () { + late VmServiceInterface service; VM vm; late Isolate isolate; late String isolateId; @@ -698,20 +664,21 @@ void testAll({ late Stream stream; setUp(() async { - vm = await setup.service.getVM(); - isolate = await setup.service.getIsolate(vm.isolates!.first.id!); + service = context.service; + vm = await service.getVM(); + isolate = await service.getIsolate(vm.isolates!.first.id!); isolateId = isolate.id!; - scripts = await setup.service.getScripts(isolateId); + scripts = await service.getScripts(isolateId); - await setup.service.streamListen('Debug'); - stream = setup.service.onEvent('Debug'); + await service.streamListen('Debug'); + stream = service.onEvent('Debug'); mainScript = scripts.scripts! .firstWhere((each) => each.uri!.contains('main.dart')); }); tearDown(() async { - await setup.service.resume(isolateId); + await service.resume(isolateId); }); test('cannot evaluate expression', () async { @@ -720,8 +687,8 @@ void testAll({ .firstWhere((event) => event.kind == EventKind.kPauseBreakpoint); await expectLater( - setup.service - .evaluateInFrame(isolateId, event.topFrame!.index!, 'local'), + service.evaluateInFrame( + isolateId, event.topFrame!.index!, 'local'), throwsRPCError); }); }); diff --git a/dwds/test/events_test.dart b/dwds/test/events_test.dart index 4453a2444..386b7e982 100644 --- a/dwds/test/events_test.dart +++ b/dwds/test/events_test.dart @@ -6,26 +6,22 @@ import 'dart:async'; import 'dart:io'; -import 'package:dwds/src/connections/debug_connection.dart'; import 'package:dwds/src/events.dart'; -import 'package:dwds/src/services/chrome_proxy_service.dart'; import 'package:dwds/src/utilities/server.dart'; import 'package:test/test.dart'; import 'package:test_common/logging.dart'; +import 'package:test_common/test_sdk_configuration.dart'; import 'package:vm_service/vm_service.dart'; import 'package:webdriver/async_core.dart'; -import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart'; import 'fixtures/context.dart'; -ChromeProxyService get service => - fetchChromeProxyService(context.debugConnection); - -WipConnection get tabConnection => context.tabConnection; +void main() { + final provider = TestSdkConfigurationProvider(); + tearDownAll(provider.dispose); -final context = TestContext.withSoundNullSafety(); + final context = TestContext.testWithSoundNullSafety(provider); -void main() { group('serve requests', () { late HttpServer server; @@ -172,11 +168,13 @@ void main() { }); group('evaluate', () { + late VmServiceInterface service; late String isolateId; late String bootstrapId; setUpAll(() async { setCurrentLogWriter(); + service = context.service; final vm = await service.getVM(); final isolate = await service.getIsolate(vm.isolates!.first.id!); isolateId = isolate.id!; @@ -216,12 +214,14 @@ void main() { }); group('evaluateInFrame', () { + late VmServiceInterface service; late String isolateId; late Stream stream; late ScriptRef mainScript; setUpAll(() async { setCurrentLogWriter(); + service = context.service; final vm = await service.getVM(); isolateId = vm.isolates!.first.id!; @@ -306,11 +306,13 @@ void main() { }); group('getSourceReport', () { + late VmServiceInterface service; late String isolateId; late ScriptRef mainScript; setUp(() async { setCurrentLogWriter(); + service = context.service; final vm = await service.getVM(); isolateId = vm.isolates!.first.id!; final scriptList = await service.getScripts(isolateId); @@ -331,10 +333,12 @@ void main() { }); group('getSripts', () { + late VmServiceInterface service; late String isolateId; setUp(() async { setCurrentLogWriter(); + service = context.service; final vm = await service.getVM(); isolateId = vm.isolates!.first.id!; }); @@ -349,10 +353,12 @@ void main() { }); group('getIsolate', () { + late VmServiceInterface service; late String isolateId; setUp(() async { setCurrentLogWriter(); + service = context.service; final vm = await service.getVM(); isolateId = vm.isolates!.first.id!; }); @@ -376,7 +382,7 @@ void main() { matchesEvent(DwdsEventKind.getVM, { 'elapsedMilliseconds': isNotNull, }), - () => service.getVM()); + () => context.service.getVM()); }); }); @@ -397,10 +403,12 @@ void main() { }); group('resume', () { + late VmServiceInterface service; late String isolateId; setUp(() async { setCurrentLogWriter(); + service = context.service; final vm = await service.getVM(); isolateId = vm.isolates!.first.id!; await service.streamListen('Debug'); diff --git a/dwds/test/fixtures/context.dart b/dwds/test/fixtures/context.dart index e47eee110..84ffe619a 100644 --- a/dwds/test/fixtures/context.dart +++ b/dwds/test/fixtures/context.dart @@ -19,6 +19,7 @@ import 'package:dwds/src/loaders/frontend_server_require.dart'; import 'package:dwds/src/loaders/require.dart'; import 'package:dwds/src/loaders/strategy.dart'; import 'package:dwds/src/readers/proxy_server_asset_reader.dart'; +import 'package:dwds/src/services/chrome_proxy_service.dart'; import 'package:dwds/src/services/expression_compiler_service.dart'; import 'package:dwds/src/utilities/dart_uri.dart'; import 'package:dwds/src/utilities/server.dart'; @@ -33,10 +34,8 @@ import 'package:shelf_proxy/shelf_proxy.dart'; import 'package:test/test.dart'; import 'package:test_common/logging.dart'; import 'package:test_common/test_sdk_configuration.dart'; -import 'package:test_common/test_sdk_layout.dart'; import 'package:vm_service/vm_service.dart'; -// ignore: deprecated_member_use -import 'package:webdriver/io.dart'; +import 'package:webdriver/async_io.dart'; import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart'; import 'server.dart'; @@ -62,7 +61,9 @@ class TestContext { final String dartEntryFileName; final String htmlEntryFileName; final NullSafety nullSafety; - late final Directory sdkDirectory; + + final TestSdkConfigurationProvider sdkConfigurationProvider; + // late TestSdkLayout sdkLayout; /// Top level directory in which we run the test server, e.g. /// "/workstation/webdev/fixtures/_testSound". @@ -137,30 +138,84 @@ class TestContext { final _logger = logging.Logger('Context'); - TestContext.withSoundNullSafety({ - String packageName = '_testSound', - String webAssetsPath = 'example/hello_world', - String dartEntryFileName = 'main.dart', - String htmlEntryFileName = 'index.html', + static String _index(IndexBaseMode baseMode) => + baseMode == IndexBaseMode.base ? 'base_index.html' : 'index.html'; + + TestContext.testPackage({ + required TestSdkConfigurationProvider provider, + required NullSafety nullSafety, + IndexBaseMode baseMode = IndexBaseMode.noBase, }) : this._( - nullSafety: NullSafety.sound, - packageName: packageName, - webAssetsPath: webAssetsPath, - dartEntryFileName: dartEntryFileName, - htmlEntryFileName: htmlEntryFileName, + packageName: nullSafety == NullSafety.sound + ? '_testPackageSound' + : '_testPackage', + webAssetsPath: 'web', + dartEntryFileName: 'main.dart', + htmlEntryFileName: _index(baseMode), + nullSafety: nullSafety, + sdkConfigurationProvider: provider, ); - TestContext.withWeakNullSafety({ - String packageName = '_test', - String webAssetsPath = 'example/hello_world', - String dartEntryFileName = 'main.dart', - String htmlEntryFileName = 'index.html', + TestContext.testPackageWithSoundNullSafety( + TestSdkConfigurationProvider provider) + : this.testPackage(provider: provider, nullSafety: NullSafety.sound); + + TestContext.testCircular({ + required TestSdkConfigurationProvider provider, + required NullSafety nullSafety, + IndexBaseMode baseMode = IndexBaseMode.noBase, }) : this._( - nullSafety: NullSafety.weak, - packageName: packageName, - webAssetsPath: webAssetsPath, - dartEntryFileName: dartEntryFileName, - htmlEntryFileName: htmlEntryFileName, + packageName: nullSafety == NullSafety.sound + ? '_testCircular2Sound' + : '_testCircular2', + webAssetsPath: 'web', + dartEntryFileName: 'main.dart', + htmlEntryFileName: _index(baseMode), + nullSafety: nullSafety, + sdkConfigurationProvider: provider, + ); + + TestContext.testWithSoundNullSafety(TestSdkConfigurationProvider provider) + : this._( + packageName: '_testSound', + webAssetsPath: 'example/hello_world', + dartEntryFileName: 'main.dart', + htmlEntryFileName: 'index.html', + nullSafety: NullSafety.sound, + sdkConfigurationProvider: provider, + ); + + TestContext.testScopesWithSoundNullSafety( + TestSdkConfigurationProvider provider) + : this._( + packageName: '_testSound', + webAssetsPath: webCompatiblePath(['example', 'scopes']), + dartEntryFileName: 'main.dart', + htmlEntryFileName: 'scopes.html', + nullSafety: NullSafety.sound, + sdkConfigurationProvider: provider, + ); + + TestContext.testAppendBodyWithSoundNullSafety( + TestSdkConfigurationProvider provider) + : this._( + packageName: '_testSound', + webAssetsPath: webCompatiblePath(['example', 'append_body']), + dartEntryFileName: 'main.dart', + htmlEntryFileName: 'index.html', + nullSafety: NullSafety.sound, + sdkConfigurationProvider: provider, + ); + + TestContext.testExperimentWithSoundNullSafety( + TestSdkConfigurationProvider provider) + : this._( + packageName: '_experimentSound', + webAssetsPath: 'web', + dartEntryFileName: 'main.dart', + htmlEntryFileName: 'index.html', + nullSafety: NullSafety.sound, + sdkConfigurationProvider: provider, ); TestContext._({ @@ -169,6 +224,7 @@ class TestContext { required this.dartEntryFileName, required this.htmlEntryFileName, required this.nullSafety, + required this.sdkConfigurationProvider, }) { // Verify that the test fixtures package matches the null-safety mode: final isSoundPackage = packageName.toLowerCase().contains('sound'); @@ -184,22 +240,6 @@ class TestContext { _logger.info('Entry: $_dartEntryFilePath'); } - void setUpAll() { - final systemTempDir = Directory.systemTemp; - sdkDirectory = systemTempDir.createTempSync('sdk copy'); - copyDirectory(TestSdkLayout.defaultSdkDirectory, sdkDirectory.path); - } - - void tearDownAll() { - try { - if (sdkDirectory.existsSync()) { - sdkDirectory.deleteSync(recursive: true); - } - } catch(e) { - _logger.warning('Failed to delete sdk directory copy: ${sdkDirectory.path}'); - } - } - Future setUp({ ReloadConfiguration reloadConfiguration = ReloadConfiguration.none, bool serveDevTools = false, @@ -220,17 +260,13 @@ class TestContext { bool isInternalBuild = false, List experiments = const [], }) async { - // Generate missing SDK assets if needed. - final sdkConfigurationProvider = - TestSdkConfigurationProvider( - sdkDirectory: sdkDirectory.path, - verboseCompiler: verboseCompiler); - final sdkLayout = sdkConfigurationProvider.sdkLayout; - final configuration = await sdkConfigurationProvider.configuration; - configuration.validate(); try { + // Make sure configuration was created correctly. + final configuration = await sdkConfigurationProvider.configuration; + configuration.validate(); + DartUri.currentDirectory = workingDirectory; configureLogWriter(); @@ -292,8 +328,8 @@ class TestContext { '--enable-experiment=$experiment', '--verbose', ]; - _daemonClient = - await connectClient(sdkLayout.dartPath, workingDirectory, options, (log) { + _daemonClient = await connectClient( + sdkLayout.dartPath, workingDirectory, options, (log) { final record = log.toLogRecord(); final name = record.loggerName == '' ? '' : '${record.loggerName}: '; @@ -437,6 +473,7 @@ class TestContext { ddcService, isFlutterApp, isInternalBuild, + sdkLayout, ); _appUrl = basePath.isEmpty @@ -471,6 +508,8 @@ class TestContext { } } + ChromeProxyService get service => fetchChromeProxyService(debugConnection); + Future startDebugging() async { debugConnection = await testServer.dwds.debugConnection(appConnection); _webkitDebugger = WebkitDebugger(WipDebugger(tabConnection)); diff --git a/dwds/test/fixtures/server.dart b/dwds/test/fixtures/server.dart index 9c17b9567..8eaa4def7 100644 --- a/dwds/test/fixtures/server.dart +++ b/dwds/test/fixtures/server.dart @@ -16,10 +16,9 @@ import 'package:dwds/src/services/expression_compiler_service.dart'; import 'package:dwds/src/utilities/server.dart'; import 'package:logging/logging.dart'; import 'package:shelf/shelf.dart'; +import 'package:test_common/test_sdk_layout.dart'; import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart'; -import 'utilities.dart'; - Logger _logger = Logger('TestServer'); Handler _interceptFavicon(Handler handler) { @@ -82,6 +81,7 @@ class TestServer { ExpressionCompilerService? ddcService, bool isFlutterApp, bool isInternalBuild, + TestSdkLayout sdkLayout, ) async { var pipeline = const Pipeline(); @@ -122,7 +122,7 @@ class TestServer { final server = await DevToolsServer().serveDevTools( hostname: hostname, enableStdinCommands: false, - customDevToolsPath: devToolsPath, + customDevToolsPath: sdkLayout.devToolsPath, ); if (server == null) { throw StateError('DevTools server could not be started.'); diff --git a/dwds/test/fixtures/utilities.dart b/dwds/test/fixtures/utilities.dart index 021b0b140..4c5db3f5b 100644 --- a/dwds/test/fixtures/utilities.dart +++ b/dwds/test/fixtures/utilities.dart @@ -68,25 +68,15 @@ String absolutePath({ } /// Connects to the `build_runner` daemon. -Future connectClient(String dartPath, String workingDirectory, - List options, Function(ServerLog) logHandler) => +Future connectClient( + String dartPath, + String workingDirectory, + List options, + Function(ServerLog) logHandler) => BuildDaemonClient.connect(workingDirectory, [dartPath, 'run', 'build_runner', 'daemon', ...options], logHandler: logHandler); -/// The path to the root directory of the SDK. -final String _sdkDir = (() { - // The Dart executable is in "/path/to/sdk/bin/dart", so two levels up is - // "/path/to/sdk". - final aboveExecutable = p.dirname(p.dirname(Platform.resolvedExecutable)); - assert(FileSystemEntity.isFileSync(p.join(aboveExecutable, 'version'))); - return aboveExecutable; -})(); - -final String dartSdkPath = _sdkDir; -//final String dartPath = p.join(_sdkDir, 'bin', 'dart'); -final String devToolsPath = p.join(_sdkDir, 'bin', 'resources', 'devtools'); - /// Returns the port of the daemon asset server. int daemonPort(String workingDirectory) { final portFile = File(_assetServerPortFilePath(workingDirectory)); diff --git a/dwds/test/frontend_server_breakpoint_test.dart b/dwds/test/frontend_server_breakpoint_test.dart index f9498a353..3216f8ff9 100644 --- a/dwds/test/frontend_server_breakpoint_test.dart +++ b/dwds/test/frontend_server_breakpoint_test.dart @@ -6,30 +6,22 @@ @Timeout(Duration(minutes: 2)) import 'dart:async'; -import 'package:dwds/src/connections/debug_connection.dart'; -import 'package:dwds/src/services/chrome_proxy_service.dart'; import 'package:test/test.dart'; import 'package:test_common/logging.dart'; +import 'package:test_common/test_sdk_configuration.dart'; import 'package:vm_service/vm_service.dart'; -import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart'; import 'fixtures/context.dart'; -final context = TestContext.withWeakNullSafety( - packageName: '_testPackage', - webAssetsPath: 'web', - dartEntryFileName: 'main.dart', - htmlEntryFileName: 'index.html', -); - -ChromeProxyService get service => - fetchChromeProxyService(context.debugConnection); -WipConnection get tabConnection => context.tabConnection; - void main() { // Enable verbose logging for debugging. final debug = false; + final provider = TestSdkConfigurationProvider(verbose: debug); + tearDownAll(provider.dispose); + + final context = TestContext.testPackageWithSoundNullSafety(provider); + // Change to 'true' to print expression compiler messages to console. // // Note: expression compiler runs in an isolate, so its output is not @@ -50,6 +42,7 @@ void main() { }); group('breakpoint', () { + late VmServiceInterface service; VM vm; late Isolate isolate; late String isolateId; @@ -59,6 +52,7 @@ void main() { late Stream stream; setUp(() async { + service = context.service; setCurrentLogWriter(debug: debug); vm = await service.getVM(); isolate = await service.getIsolate(vm.isolates!.first.id!); diff --git a/dwds/test/frontend_server_callstack_test.dart b/dwds/test/frontend_server_callstack_test.dart index ec6566dfb..30332e057 100644 --- a/dwds/test/frontend_server_callstack_test.dart +++ b/dwds/test/frontend_server_callstack_test.dart @@ -6,51 +6,26 @@ @Timeout(Duration(minutes: 2)) import 'dart:async'; -import 'package:dwds/src/connections/debug_connection.dart'; -import 'package:dwds/src/services/chrome_proxy_service.dart'; import 'package:test/test.dart'; import 'package:test_common/logging.dart'; +import 'package:test_common/test_sdk_configuration.dart'; import 'package:vm_service/vm_service.dart'; -import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart'; import 'fixtures/context.dart'; -class TestSetup { - static final contextUnsound = TestContext.withWeakNullSafety( - packageName: '_testPackage', - webAssetsPath: 'web', - dartEntryFileName: 'main.dart', - htmlEntryFileName: 'index.html', - ); - - static final contextSound = TestContext.withSoundNullSafety( - packageName: '_testPackageSound', - webAssetsPath: 'web', - dartEntryFileName: 'main.dart', - htmlEntryFileName: 'index.html', - ); - - TestContext context; - - TestSetup.sound() : context = contextSound; - - TestSetup.unsound() : context = contextUnsound; +void main() { + // Enable verbose logging for debugging. + final debug = false; - ChromeProxyService get service => - fetchChromeProxyService(context.debugConnection); - WipConnection get tabConnection => context.tabConnection; -} + final provider = TestSdkConfigurationProvider(verbose: debug); + tearDownAll(provider.dispose); -void main() { group('shared context |', () { - // Enable verbose logging for debugging. - final debug = false; - for (var nullSafety in NullSafety.values) { group('${nullSafety.name} null safety |', () { final soundNullSafety = nullSafety == NullSafety.sound; - final setup = soundNullSafety ? TestSetup.sound() : TestSetup.unsound(); - final context = setup.context; + final context = + TestContext.testPackage(provider: provider, nullSafety: nullSafety); setUpAll(() async { setCurrentLogWriter(debug: debug); @@ -65,7 +40,7 @@ void main() { }); group('callStack |', () { - late ChromeProxyService service; + late VmServiceInterface service; VM vm; late Isolate isolate; late String isolateId; @@ -76,7 +51,7 @@ void main() { setUp(() async { setCurrentLogWriter(debug: debug); - service = setup.service; + service = context.service; vm = await service.getVM(); isolate = await service.getIsolate(vm.isolates!.first.id!); isolateId = isolate.id!; @@ -106,7 +81,7 @@ void main() { final script = breakpoint.script; final line = await context.findBreakpointLine(bpId, isolateId, script); - bp = await setup.service + bp = await context.service .addBreakpointWithScriptUri(isolateId, script.uri!, line); expect(bp, isNotNull); @@ -119,7 +94,7 @@ void main() { } finally { // Remove breakpoint so it doesn't impact other tests or retries. if (bp != null) { - await setup.service.removeBreakpoint(isolateId, bp.id!); + await context.service.removeBreakpoint(isolateId, bp.id!); } } } diff --git a/dwds/test/frontend_server_circular_evaluate_test.dart b/dwds/test/frontend_server_circular_evaluate_test.dart index 896e6f4c3..db453a5c7 100644 --- a/dwds/test/frontend_server_circular_evaluate_test.dart +++ b/dwds/test/frontend_server_circular_evaluate_test.dart @@ -7,8 +7,8 @@ import 'dart:io'; -import 'package:pub_semver/pub_semver.dart'; import 'package:test/test.dart'; +import 'package:test_common/test_sdk_configuration.dart'; import 'evaluate_circular_common.dart'; import 'fixtures/context.dart'; @@ -17,10 +17,8 @@ void main() async { // Enable verbose logging for debugging. final debug = false; - // TODO(annagrin): Remove when 2.19.0-150.0.dev is in stable. - final debuggerModuleNamesSupported = - Version.parse(Platform.version.split(' ').first) >= - Version.parse('2.19.0-150.0.dev'); + final provider = TestSdkConfigurationProvider(verbose: debug); + tearDownAll(provider.dispose); group('Context with circular dependencies |', () { for (var nullSafety in NullSafety.values) { @@ -28,6 +26,7 @@ void main() async { for (var indexBaseMode in IndexBaseMode.values) { group('with ${indexBaseMode.name} |', () { testAll( + provider: provider, compilationMode: CompilationMode.frontendServer, indexBaseMode: indexBaseMode, nullSafety: nullSafety, @@ -37,9 +36,7 @@ void main() async { }, skip: // https://github.com/dart-lang/sdk/issues/49277 - indexBaseMode == IndexBaseMode.base && Platform.isWindows || - // Needs debugger module names change in the SDK to work. - !debuggerModuleNamesSupported); + indexBaseMode == IndexBaseMode.base && Platform.isWindows); } }); } diff --git a/dwds/test/frontend_server_evaluate_sound_test.dart b/dwds/test/frontend_server_evaluate_sound_test.dart index 6877c481e..8ac2462cf 100644 --- a/dwds/test/frontend_server_evaluate_sound_test.dart +++ b/dwds/test/frontend_server_evaluate_sound_test.dart @@ -8,6 +8,7 @@ import 'dart:io'; import 'package:test/test.dart'; +import 'package:test_common/test_sdk_configuration.dart'; import 'evaluate_common.dart'; import 'fixtures/context.dart'; @@ -16,6 +17,9 @@ void main() async { // Enable verbose logging for debugging. final debug = false; + final provider = TestSdkConfigurationProvider(verbose: debug); + tearDownAll(provider.dispose); + for (var useDebuggerModuleNames in [false, true]) { group('Debugger module names: $useDebuggerModuleNames |', () { final nullSafety = NullSafety.sound; @@ -23,6 +27,7 @@ void main() async { for (var indexBaseMode in IndexBaseMode.values) { group('with ${indexBaseMode.name} |', () { testAll( + provider: provider, compilationMode: CompilationMode.frontendServer, indexBaseMode: indexBaseMode, nullSafety: nullSafety, diff --git a/dwds/test/frontend_server_evaluate_weak_test.dart b/dwds/test/frontend_server_evaluate_weak_test.dart index 113dea4d3..284672cf2 100644 --- a/dwds/test/frontend_server_evaluate_weak_test.dart +++ b/dwds/test/frontend_server_evaluate_weak_test.dart @@ -8,6 +8,7 @@ import 'dart:io'; import 'package:test/test.dart'; +import 'package:test_common/test_sdk_configuration.dart'; import 'evaluate_common.dart'; import 'fixtures/context.dart'; @@ -16,6 +17,9 @@ void main() async { // Enable verbose logging for debugging. final debug = false; + final provider = TestSdkConfigurationProvider(verbose: debug); + tearDownAll(provider.dispose); + for (var useDebuggerModuleNames in [false, true]) { group('Debugger module names: $useDebuggerModuleNames |', () { final nullSafety = NullSafety.weak; @@ -23,6 +27,7 @@ void main() async { for (var indexBaseMode in IndexBaseMode.values) { group('with ${indexBaseMode.name} |', () { testAll( + provider: provider, compilationMode: CompilationMode.frontendServer, indexBaseMode: indexBaseMode, nullSafety: nullSafety, diff --git a/dwds/test/handlers/asset_handler_test.dart b/dwds/test/handlers/asset_handler_test.dart index 57484c31b..17a0d4eed 100644 --- a/dwds/test/handlers/asset_handler_test.dart +++ b/dwds/test/handlers/asset_handler_test.dart @@ -7,12 +7,14 @@ import 'package:shelf/shelf.dart'; import 'package:test/test.dart'; import 'package:test_common/logging.dart'; +import 'package:test_common/test_sdk_configuration.dart'; import '../fixtures/context.dart'; void main() { group('Asset handler', () { - final context = TestContext.withSoundNullSafety(); + final provider = TestSdkConfigurationProvider(); + final context = TestContext.testWithSoundNullSafety(provider); setUpAll(() async { setCurrentLogWriter(); diff --git a/dwds/test/inspector_test.dart b/dwds/test/inspector_test.dart index 10100f93b..2fb8db312 100644 --- a/dwds/test/inspector_test.dart +++ b/dwds/test/inspector_test.dart @@ -6,33 +6,28 @@ @Timeout(Duration(minutes: 2)) import 'package:dwds/dwds.dart'; -import 'package:dwds/src/connections/debug_connection.dart'; import 'package:dwds/src/debugging/debugger.dart'; import 'package:dwds/src/debugging/inspector.dart'; import 'package:dwds/src/loaders/strategy.dart'; import 'package:dwds/src/utilities/conversions.dart'; import 'package:test/test.dart'; +import 'package:test_common/test_sdk_configuration.dart'; import 'package:vm_service/vm_service.dart'; import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart'; import 'fixtures/context.dart'; -import 'fixtures/utilities.dart'; - -final context = TestContext.withSoundNullSafety( - webAssetsPath: webCompatiblePath(['example', 'scopes']), - dartEntryFileName: 'main.dart', - htmlEntryFileName: 'scopes.html', -); - -WipConnection get tabConnection => context.tabConnection; void main() { + final provider = TestSdkConfigurationProvider(); + tearDownAll(provider.dispose); + + final context = TestContext.testScopesWithSoundNullSafety(provider); late AppInspector inspector; late Debugger debugger; setUpAll(() async { await context.setUp(); - final service = fetchChromeProxyService(context.debugConnection); + final service = context.service; inspector = service.inspector; debugger = await service.debuggerFuture; }); diff --git a/dwds/test/instance_test.dart b/dwds/test/instance_test.dart index c5f279703..896afa803 100644 --- a/dwds/test/instance_test.dart +++ b/dwds/test/instance_test.dart @@ -5,32 +5,27 @@ @Timeout(Duration(minutes: 2)) import 'dart:async'; -import 'package:dwds/src/connections/debug_connection.dart'; import 'package:dwds/src/debugging/debugger.dart'; import 'package:dwds/src/debugging/inspector.dart'; import 'package:dwds/src/loaders/strategy.dart'; import 'package:test/test.dart'; +import 'package:test_common/test_sdk_configuration.dart'; import 'package:vm_service/vm_service.dart'; import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart'; import 'fixtures/context.dart'; -import 'fixtures/utilities.dart'; - -final context = TestContext.withSoundNullSafety( - webAssetsPath: webCompatiblePath(['example', 'scopes']), - dartEntryFileName: 'main.dart', - htmlEntryFileName: 'scopes.html', -); - -WipConnection get tabConnection => context.tabConnection; void main() { + final provider = TestSdkConfigurationProvider(); + tearDownAll(provider.dispose); + + final context = TestContext.testScopesWithSoundNullSafety(provider); late AppInspector inspector; late Debugger debugger; setUpAll(() async { await context.setUp(); - final chromeProxyService = fetchChromeProxyService(context.debugConnection); + final chromeProxyService = context.service; inspector = chromeProxyService.inspector; debugger = await chromeProxyService.debuggerFuture; }); diff --git a/dwds/test/listviews_test.dart b/dwds/test/listviews_test.dart index db3c5b1fd..92a42c896 100644 --- a/dwds/test/listviews_test.dart +++ b/dwds/test/listviews_test.dart @@ -5,12 +5,15 @@ @Timeout(Duration(minutes: 2)) import 'package:test/test.dart'; +import 'package:test_common/test_sdk_configuration.dart'; import 'fixtures/context.dart'; -final context = TestContext.withSoundNullSafety(); - void main() { + final provider = TestSdkConfigurationProvider(); + tearDownAll(provider.dispose); + + final context = TestContext.testWithSoundNullSafety(provider); setUpAll(() async { await context.setUp(); }); @@ -42,7 +45,5 @@ void main() { expect(result.json, expected); }, - // TODO(https://github.com/dart-lang/webdev/issues/1741): Re-enable when resolved. - skip: true, ); } diff --git a/dwds/test/puppeteer/extension_test.dart b/dwds/test/puppeteer/extension_test.dart index f1cc393f7..6f0d48117 100644 --- a/dwds/test/puppeteer/extension_test.dart +++ b/dwds/test/puppeteer/extension_test.dart @@ -18,6 +18,7 @@ import 'package:dwds/data/debug_info.dart'; import 'package:path/path.dart' as p; import 'package:puppeteer/puppeteer.dart'; import 'package:test/test.dart'; +import 'package:test_common/test_sdk_configuration.dart'; import '../../debug_extension_mv3/web/data_serializers.dart'; import '../../debug_extension_mv3/web/data_types.dart'; @@ -25,18 +26,20 @@ import '../fixtures/context.dart'; import '../fixtures/utilities.dart'; import 'test_utils.dart'; -final context = TestContext.withSoundNullSafety(); - enum Panel { debugger, inspector } void main() async { group('MV3 Debug Extension', () { + final provider = TestSdkConfigurationProvider(); + final context = TestContext.testWithSoundNullSafety(provider); late String extensionPath; setUpAll(() async { extensionPath = await buildDebugExtension(); }); + tearDownAll(provider.dispose); + for (var useSse in [true, false]) { group(useSse ? 'connected with SSE:' : 'connected with WebSockets:', () { late Browser browser; @@ -65,6 +68,7 @@ void main() async { tearDownAll(() async { await browser.close(); + await context.tearDown(); }); test('the debug info for a Dart app is saved in session storage', @@ -350,6 +354,7 @@ void main() async { tearDownAll(() async { await browser.close(); + await context.tearDown(); }); test( 'isFlutterApp=$isFlutterApp and isInternalBuild=false are saved in storage', @@ -441,6 +446,7 @@ void main() async { tearDownAll(() async { await browser.close(); + await context.tearDown(); }); test( 'isFlutterApp=$isFlutterApp and isInternalBuild=true are saved in storage', diff --git a/dwds/test/puppeteer/lifeline_test.dart b/dwds/test/puppeteer/lifeline_test.dart index bd920dcc6..5bb5061dd 100644 --- a/dwds/test/puppeteer/lifeline_test.dart +++ b/dwds/test/puppeteer/lifeline_test.dart @@ -8,19 +8,22 @@ import 'dart:async'; import 'package:puppeteer/puppeteer.dart'; import 'package:test/test.dart'; +import 'package:test_common/test_sdk_configuration.dart'; import '../fixtures/context.dart'; import 'test_utils.dart'; -final context = TestContext.withSoundNullSafety(); - void main() async { + final provider = TestSdkConfigurationProvider(); + final context = TestContext.testWithSoundNullSafety(provider); late Worker worker; late Browser browser; late String extensionPath; int connectionCount = 0; + tearDownAll(provider.dispose); + group('MV3 Debug Extension Lifeline Connection', () { setUpAll(() async { extensionPath = await buildDebugExtension(); @@ -34,6 +37,7 @@ void main() async { tearDownAll(() async { await browser.close(); + await context.tearDown(); }); test('connects to a lifeline port', () async { diff --git a/dwds/test/readers/proxy_server_asset_reader_test.dart b/dwds/test/readers/proxy_server_asset_reader_test.dart index eade1e6b0..235e71ac2 100644 --- a/dwds/test/readers/proxy_server_asset_reader_test.dart +++ b/dwds/test/readers/proxy_server_asset_reader_test.dart @@ -6,17 +6,27 @@ import 'package:dwds/src/readers/proxy_server_asset_reader.dart'; import 'package:test/test.dart'; +import 'package:test_common/test_sdk_configuration.dart'; import '../fixtures/context.dart'; void main() { group('ProxyServerAssetReader', () { - final context = TestContext.withWeakNullSafety(); + final provider = TestSdkConfigurationProvider(); + tearDownAll(provider.dispose); + + final context = TestContext.testWithSoundNullSafety(provider); + late ProxyServerAssetReader assetReader; setUpAll(() async { await context.setUp(); assetReader = context.testServer.assetReader as ProxyServerAssetReader; }); + + tearDownAll(() async { + await context.tearDown(); + }); + test('returns null if the dart path does not exist', () async { final result = await assetReader.dartSourceContents('some/path/foo.dart'); expect(result, isNull); diff --git a/dwds/test/records_test.dart b/dwds/test/records_test.dart index 57bd2da7b..a9af7459f 100644 --- a/dwds/test/records_test.dart +++ b/dwds/test/records_test.dart @@ -5,35 +5,23 @@ @TestOn('vm') @Timeout(Duration(minutes: 2)) -import 'package:dwds/src/connections/debug_connection.dart'; -import 'package:dwds/src/services/chrome_proxy_service.dart'; import 'package:test/test.dart'; import 'package:test_common/logging.dart'; +import 'package:test_common/test_sdk_configuration.dart'; import 'package:vm_service/vm_service.dart'; import 'fixtures/context.dart'; -class TestSetup { - TestContext context; - - TestSetup.sound() - : context = TestContext.withSoundNullSafety( - packageName: '_experimentSound', - webAssetsPath: 'web', - dartEntryFileName: 'main.dart', - htmlEntryFileName: 'index.html', - ); - - ChromeProxyService get service => - fetchChromeProxyService(context.debugConnection); -} - void main() async { // Enable verbose logging for debugging. final debug = false; + final provider = TestSdkConfigurationProvider(verbose: debug); + tearDownAll(provider.dispose); + for (var compilationMode in CompilationMode.values) { await _runTests( + provider: provider, compilationMode: compilationMode, debug: debug, ); @@ -41,18 +29,18 @@ void main() async { } Future _runTests({ + required TestSdkConfigurationProvider provider, required CompilationMode compilationMode, required bool debug, }) async { - final setup = TestSetup.sound(); - final context = setup.context; + final context = TestContext.testExperimentWithSoundNullSafety(provider); late VmServiceInterface service; late Stream stream; late String isolateId; late ScriptRef mainScript; onBreakPoint(breakPointId, body) => - _onBreakPoint(setup, stream, isolateId, mainScript, breakPointId, body); + _onBreakPoint(context, stream, isolateId, mainScript, breakPointId, body); getInstance(frame, expression) => _getInstance(service, isolateId, frame, expression); @@ -74,7 +62,7 @@ Future _runTests({ verboseCompiler: debug, experiments: ['records'], ); - service = setup.service; + service = context.service; final vm = await service.getVM(); isolateId = vm.isolates!.first.id!; @@ -87,7 +75,9 @@ Future _runTests({ .firstWhere((each) => each.uri!.contains('main.dart')); }); - tearDownAll(context.tearDown); + tearDownAll(() async { + await context.tearDown(); + }); setUp(() => setCurrentLogWriter(debug: debug)); tearDown(() => service.resume(isolateId)); @@ -405,15 +395,14 @@ Future _runTests({ } Future _onBreakPoint( - TestSetup setup, + TestContext context, Stream stream, String isolateId, ScriptRef script, String breakPointId, Future Function(Event event) body, ) async { - final context = setup.context; - final service = setup.service; + final service = context.service; Breakpoint? bp; try { diff --git a/dwds/test/refresh_test.dart b/dwds/test/refresh_test.dart index 2fc125b9e..2db21c90b 100644 --- a/dwds/test/refresh_test.dart +++ b/dwds/test/refresh_test.dart @@ -10,24 +10,24 @@ library refresh_test; import 'dart:async'; -import 'package:dwds/src/connections/debug_connection.dart'; -import 'package:dwds/src/services/chrome_proxy_service.dart'; import 'package:test/test.dart'; +import 'package:test_common/test_sdk_configuration.dart'; import 'package:vm_service/vm_service.dart'; -import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart'; import 'fixtures/context.dart'; -final context = TestContext.withSoundNullSafety(); -ChromeProxyService get service => - fetchChromeProxyService(context.debugConnection); -WipConnection get tabConnection => context.tabConnection; - void main() { + final provider = TestSdkConfigurationProvider(); + tearDownAll(provider.dispose); + + final context = TestContext.testWithSoundNullSafety(provider); + group('fresh context', () { + late VmServiceInterface service; late VM vm; setUpAll(() async { await context.setUp(); + service = context.service; vm = await service.getVM(); }); diff --git a/dwds/test/reload_test.dart b/dwds/test/reload_test.dart index 6ae7d608e..4f2891f15 100644 --- a/dwds/test/reload_test.dart +++ b/dwds/test/reload_test.dart @@ -7,16 +7,10 @@ import 'package:dwds/src/loaders/strategy.dart'; import 'package:test/test.dart'; import 'package:test_common/logging.dart'; +import 'package:test_common/test_sdk_configuration.dart'; import 'package:vm_service/vm_service.dart'; import 'fixtures/context.dart'; -import 'fixtures/utilities.dart'; - -final context = TestContext.withSoundNullSafety( - webAssetsPath: webCompatiblePath(['example', 'append_body']), - dartEntryFileName: 'main.dart', - htmlEntryFileName: 'index.html', -); const originalString = 'Hello World!'; const newString = 'Bonjour le monde!'; @@ -24,6 +18,27 @@ const newString = 'Bonjour le monde!'; void main() { // set to true for debug logging. final debug = false; + + final provider = TestSdkConfigurationProvider(verbose: debug); + tearDownAll(provider.dispose); + + final context = TestContext.testAppendBodyWithSoundNullSafety(provider); + + Future makeEditAndWaitForRebuild() async { + context.makeEditToDartEntryFile( + toReplace: originalString, + replaceWith: newString, + ); + await context.waitForSuccessfulBuild(propagateToBrowser: true); + } + + void undoEdit() { + context.makeEditToDartEntryFile( + toReplace: newString, + replaceWith: originalString, + ); + } + group('Injected client with live reload', () { group('and with debugging', () { setUp(() async { @@ -441,20 +456,5 @@ void main() { }); } -Future makeEditAndWaitForRebuild() async { - context.makeEditToDartEntryFile( - toReplace: originalString, - replaceWith: newString, - ); - await context.waitForSuccessfulBuild(propagateToBrowser: true); -} - -void undoEdit() { - context.makeEditToDartEntryFile( - toReplace: newString, - replaceWith: originalString, - ); -} - TypeMatcher _hasKind(String kind) => isA().having((e) => e.kind, 'kind', kind); diff --git a/dwds/test/restore_breakpoints_test.dart b/dwds/test/restore_breakpoints_test.dart index d9313ce15..15fe61567 100644 --- a/dwds/test/restore_breakpoints_test.dart +++ b/dwds/test/restore_breakpoints_test.dart @@ -6,21 +6,19 @@ @Timeout(Duration(minutes: 2)) import 'dart:async'; -import 'package:dwds/src/connections/debug_connection.dart'; -import 'package:dwds/src/services/chrome_proxy_service.dart'; import 'package:test/test.dart'; import 'package:test_common/logging.dart'; +import 'package:test_common/test_sdk_configuration.dart'; import 'package:vm_service/vm_service.dart'; -import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart'; import 'fixtures/context.dart'; -final context = TestContext.withSoundNullSafety(); -ChromeProxyService get service => - fetchChromeProxyService(context.debugConnection); -WipConnection get tabConnection => context.tabConnection; - void main() { + final provider = TestSdkConfigurationProvider(); + tearDownAll(provider.dispose); + + final context = TestContext.testWithSoundNullSafety(provider); + setUpAll(() async { setCurrentLogWriter(); await context.setUp(); @@ -31,6 +29,7 @@ void main() { }); group('breakpoints', () { + late VmServiceInterface service; VM vm; late Isolate isolate; ScriptList scripts; @@ -39,11 +38,10 @@ void main() { setUp(() async { setCurrentLogWriter(); - vm = await fetchChromeProxyService(context.debugConnection).getVM(); - isolate = await fetchChromeProxyService(context.debugConnection) - .getIsolate(vm.isolates!.first.id!); - scripts = await fetchChromeProxyService(context.debugConnection) - .getScripts(isolate.id!); + service = context.service; + vm = await service.getVM(); + isolate = await service.getIsolate(vm.isolates!.first.id!); + scripts = await service.getScripts(isolate.id!); mainScript = scripts.scripts! .firstWhere((each) => each.uri!.contains('main.dart')); isolateEventStream = service.onEvent('Isolate'); diff --git a/dwds/test/run_request_test.dart b/dwds/test/run_request_test.dart index 5b461bdf7..57d8042c1 100644 --- a/dwds/test/run_request_test.dart +++ b/dwds/test/run_request_test.dart @@ -5,22 +5,23 @@ @Timeout(Duration(minutes: 2)) import 'dart:async'; -import 'package:dwds/src/connections/debug_connection.dart'; -import 'package:dwds/src/services/chrome_proxy_service.dart'; import 'package:test/test.dart'; +import 'package:test_common/test_sdk_configuration.dart'; import 'package:vm_service/vm_service.dart'; import 'fixtures/context.dart'; -final context = TestContext.withSoundNullSafety(); +void main() { + final provider = TestSdkConfigurationProvider(); + tearDownAll(provider.dispose); -ChromeProxyService get service => - fetchChromeProxyService(context.debugConnection); + final context = TestContext.testWithSoundNullSafety(provider); -void main() { group('while debugger is attached', () { + late VmServiceInterface service; setUp(() async { await context.setUp(autoRun: false); + service = context.service; }); tearDown(() async { @@ -57,8 +58,10 @@ void main() { }); group('while debugger is not attached', () { + late VmServiceInterface service; setUp(() async { await context.setUp(autoRun: false, waitToDebug: true); + service = context.service; }); tearDown(() async { diff --git a/dwds/test/screenshot_test.dart b/dwds/test/screenshot_test.dart index 9410abf1e..0ef06aca4 100644 --- a/dwds/test/screenshot_test.dart +++ b/dwds/test/screenshot_test.dart @@ -5,12 +5,16 @@ @Timeout(Duration(minutes: 2)) import 'package:test/test.dart'; +import 'package:test_common/test_sdk_configuration.dart'; import 'fixtures/context.dart'; -final context = TestContext.withSoundNullSafety(); - void main() { + final provider = TestSdkConfigurationProvider(); + tearDownAll(provider.dispose); + + final context = TestContext.testWithSoundNullSafety(provider); + setUpAll(() async { await context.setUp(); }); diff --git a/dwds/test/variable_scope_test.dart b/dwds/test/variable_scope_test.dart index 19a7c7eb6..621e7d56b 100644 --- a/dwds/test/variable_scope_test.dart +++ b/dwds/test/variable_scope_test.dart @@ -4,26 +4,20 @@ @TestOn('vm') @Timeout(Duration(minutes: 2)) -import 'package:dwds/src/connections/debug_connection.dart'; import 'package:dwds/src/debugging/dart_scope.dart'; import 'package:dwds/src/services/chrome_proxy_service.dart'; import 'package:test/test.dart'; +import 'package:test_common/test_sdk_configuration.dart'; import 'package:vm_service/vm_service.dart'; -import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart'; import 'fixtures/context.dart'; -import 'fixtures/utilities.dart'; - -final context = TestContext.withSoundNullSafety( - webAssetsPath: webCompatiblePath(['example', 'scopes']), - dartEntryFileName: 'main.dart', - htmlEntryFileName: 'scopes.html', -); -ChromeProxyService get service => - fetchChromeProxyService(context.debugConnection); -WipConnection get tabConnection => context.tabConnection; void main() { + final provider = TestSdkConfigurationProvider(); + tearDownAll(provider.dispose); + + final context = TestContext.testScopesWithSoundNullSafety(provider); + setUpAll(() async { await context.setUp(); }); @@ -52,6 +46,7 @@ void main() { }); group('variable scope', () { + late ChromeProxyService service; VM vm; String? isolateId; late Stream stream; @@ -112,6 +107,7 @@ void main() { } setUp(() async { + service = context.service; vm = await service.getVM(); isolateId = vm.isolates!.first.id; scripts = await service.getScripts(isolateId!); diff --git a/frontend_server_common/lib/src/asset_server.dart b/frontend_server_common/lib/src/asset_server.dart index 6e56e9478..2731d1d30 100644 --- a/frontend_server_common/lib/src/asset_server.dart +++ b/frontend_server_common/lib/src/asset_server.dart @@ -14,8 +14,7 @@ import 'package:file/file.dart'; import 'package:logging/logging.dart'; import 'package:mime/mime.dart' as mime; import 'package:shelf/shelf.dart' as shelf; - -import 'utilities.dart'; +import 'package:test_common/test_sdk_layout.dart'; class TestAssetServer implements AssetReader { late final String basePath; @@ -34,6 +33,7 @@ class TestAssetServer implements AssetReader { late String _mergedMetadata; final PackageUriMapper _packageUriMapper; final InternetAddress internetAddress; + final TestSdkLayout _sdkLayout; TestAssetServer( this.index, @@ -41,6 +41,7 @@ class TestAssetServer implements AssetReader { this._packageUriMapper, this.internetAddress, this._fileSystem, + this._sdkLayout, ) { basePath = _parseBasePathFromIndexHtml(index); } @@ -59,6 +60,7 @@ class TestAssetServer implements AssetReader { /// Unhandled exceptions will throw a exception with the error and stack /// trace. static Future start( + String sdkDirectory, FileSystem fileSystem, String index, String hostname, @@ -66,10 +68,11 @@ class TestAssetServer implements AssetReader { UrlEncoder? urlTunneler, PackageUriMapper packageUriMapper, ) async { - var address = (await InternetAddress.lookup(hostname)).first; - var httpServer = await HttpServer.bind(address, port); - var server = TestAssetServer( - index, httpServer, packageUriMapper, address, fileSystem); + final address = (await InternetAddress.lookup(hostname)).first; + final httpServer = await HttpServer.bind(address, port); + final sdkLayout = TestSdkLayout.createDefault(sdkDirectory); + final server = TestAssetServer( + index, httpServer, packageUriMapper, address, fileSystem, sdkLayout); return server; } @@ -257,7 +260,7 @@ class TestAssetServer implements AssetReader { } // Otherwise it must be a Dart SDK source. - var dartSdkParent = _fileSystem.directory(dartSdkPath).parent; + var dartSdkParent = _fileSystem.directory(_sdkLayout.sdkDirectory).parent; var dartSdkFile = _fileSystem.file( _fileSystem.path.joinAll([dartSdkParent.path, ...segments])); return dartSdkFile; diff --git a/frontend_server_common/lib/src/devfs.dart b/frontend_server_common/lib/src/devfs.dart index 9bd7c9cbc..1c1c71db5 100644 --- a/frontend_server_common/lib/src/devfs.dart +++ b/frontend_server_common/lib/src/devfs.dart @@ -43,7 +43,7 @@ class WebDevFS { fileSystem.currentDirectory = projectDirectory.toFilePath(); - assetServer = await TestAssetServer.start( + assetServer = await TestAssetServer.start(sdkLayout.sdkDirectory, fileSystem, index, hostname, port, urlTunneler, packageUriMapper); return Uri.parse('http://$hostname:$port'); } diff --git a/frontend_server_common/lib/src/resident_runner.dart b/frontend_server_common/lib/src/resident_runner.dart index 1c9af81d1..826fc6a38 100644 --- a/frontend_server_common/lib/src/resident_runner.dart +++ b/frontend_server_common/lib/src/resident_runner.dart @@ -15,7 +15,6 @@ import 'package:test_common/test_sdk_layout.dart'; import 'devfs.dart'; import 'frontend_server_client.dart'; -import 'utilities.dart'; class ResidentWebRunner { final _logger = Logger('ResidentWebRunner'); @@ -39,7 +38,7 @@ class ResidentWebRunner { : sdkLayout.weakSummaryPath); generator = ResidentCompiler( - dartSdkPath, + sdkLayout.sdkDirectory, projectDirectory: projectDirectory, packageConfigFile: packageConfigFile, useDebuggerModuleNames: packageUriMapper.useDebuggerModuleNames, diff --git a/frontend_server_common/lib/src/utilities.dart b/frontend_server_common/lib/src/utilities.dart index 1c68b52e6..eddc3b40a 100644 --- a/frontend_server_common/lib/src/utilities.dart +++ b/frontend_server_common/lib/src/utilities.dart @@ -2,21 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -import 'dart:io'; - import 'package:file/file.dart' as fs; import 'package:file/local.dart'; -import 'package:path/path.dart' as p; - -/// The path to the root directory of the SDK. -final String _sdkDir = (() { - // The Dart executable is in "/path/to/sdk/bin/dart", so two levels up is - // "/path/to/sdk". - var aboveExecutable = p.dirname(p.dirname(Platform.resolvedExecutable)); - assert(FileSystemEntity.isFileSync(p.join(aboveExecutable, 'version'))); - return aboveExecutable; -})(); - -final String dartSdkPath = _sdkDir; const fs.FileSystem localFileSystem = LocalFileSystem(); diff --git a/test_common/lib/sdk_asset_generator.dart b/test_common/lib/sdk_asset_generator.dart index 21bcf55ec..5d6061137 100644 --- a/test_common/lib/sdk_asset_generator.dart +++ b/test_common/lib/sdk_asset_generator.dart @@ -13,7 +13,7 @@ import 'package:test_common/test_sdk_layout.dart'; /// - sound null safety: js, source map, full dill. /// - weak null safety: js, source map, full dill, summary. class SdkAssetGenerator { - static bool _sdkAssetsGenerated = false; + bool _sdkAssetsGenerated = false; final _logger = Logger('SdkAssetGenerator'); final FileSystem fileSystem; @@ -88,10 +88,7 @@ class SdkAssetGenerator { 'org-dartlang-sdk:///lib/libraries.json', '--modules', 'amd', - if (soundNullSafety) - '--sound-null-safety' - else - '--no-sound-null-safety', + soundNullSafety ? '--sound-null-safety' : '--no-sound-null-safety', 'dart:core', '-o', jsPath, @@ -99,7 +96,7 @@ class SdkAssetGenerator { final output = []; _logger.fine('Executing dart ${args.join(' ')}'); - final process = await Process.start(Platform.resolvedExecutable, args, + final process = await Process.start(sdkLayout.dartPath, args, workingDirectory: sdkLayout.sdkDirectory); process.stdout @@ -187,7 +184,7 @@ class SdkAssetGenerator { ]; _logger.fine('Executing dart ${args.join(' ')}'); - final process = await Process.start(Platform.resolvedExecutable, args, + final process = await Process.start(sdkLayout.dartPath, args, workingDirectory: sdkLayout.sdkDirectory); final output = []; diff --git a/test_common/lib/test_sdk_configuration.dart b/test_common/lib/test_sdk_configuration.dart index a289ef9b0..e90c19b96 100644 --- a/test_common/lib/test_sdk_configuration.dart +++ b/test_common/lib/test_sdk_configuration.dart @@ -2,7 +2,8 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO:(annagrin) Move to a test_common package. +import 'dart:io'; + import 'package:dwds/sdk_configuration.dart'; import 'package:test_common/sdk_asset_generator.dart'; @@ -19,28 +20,49 @@ import 'package:test_common/test_sdk_layout.dart'; /// TODO(annagrin): update to only generating missing sound artifacts /// for frontend server after we have no uses of weak null safety. class TestSdkConfigurationProvider extends SdkConfigurationProvider { - late final String _sdkDirectory; - final bool _verboseCompiler; + final bool _verbose; + late final Directory _sdkDirectory; SdkConfiguration? _configuration; - late final sdkLayout = TestSdkLayout.createDefault(_sdkDirectory); + late final TestSdkLayout sdkLayout; - TestSdkConfigurationProvider({String? sdkDirectory, bool verboseCompiler = false}) - : _sdkDirectory = sdkDirectory?? SdkLayout.defaultSdkDirectory, - _verboseCompiler = verboseCompiler; + TestSdkConfigurationProvider({bool verbose = false}) : _verbose = verbose { + _sdkDirectory = Directory.systemTemp.createTempSync('sdk copy'); + sdkLayout = TestSdkLayout.createDefault(_sdkDirectory.path); + } @override Future get configuration async => _configuration ??= await _create(); /// Generate missing assets in the default SDK layout. + /// + /// Creates a copy of the SDK directory where all the missing assets + /// are generated. Tests using this configuration run using the copy + /// sdk layout to make sure the actual SDK is not modified. Future _create() async { - final assetGenerator = SdkAssetGenerator( - sdkLayout: sdkLayout, - verboseCompiler: _verboseCompiler, - ); + try { + await copyDirectory( + TestSdkLayout.defaultSdkDirectory, _sdkDirectory.path); + + final assetGenerator = SdkAssetGenerator( + sdkLayout: sdkLayout, + verboseCompiler: _verbose, + ); + + await assetGenerator.generateSdkAssets(); + return TestSdkLayout.createConfiguration(sdkLayout); + } catch (_) { + dispose(); + rethrow; + } + } - await assetGenerator.generateSdkAssets(); - return TestSdkLayout.defaultSdkConfiguration; + void dispose() { + try { + if (_sdkDirectory.existsSync()) { + _sdkDirectory.deleteSync(recursive: true); + } + } catch (_) {} } } diff --git a/test_common/lib/test_sdk_layout.dart b/test_common/lib/test_sdk_layout.dart index 3fb2d358c..8a46f1056 100644 --- a/test_common/lib/test_sdk_layout.dart +++ b/test_common/lib/test_sdk_layout.dart @@ -99,6 +99,8 @@ class TestSdkLayout { 'snapshots', 'kernel_worker.dart.snapshot', ), + devToolsPath: + p.join(sdkLayout.sdkDirectory, 'bin', 'resources', 'devtools'), ); final String sdkDirectory; @@ -130,6 +132,7 @@ class TestSdkLayout { final String frontendServerSnapshotPath; final String dartdevcSnapshotPath; final String kernelWorkerSnapshotPath; + final String devToolsPath; const TestSdkLayout({ required this.sdkDirectory, @@ -147,6 +150,7 @@ class TestSdkLayout { required this.frontendServerSnapshotPath, required this.dartdevcSnapshotPath, required this.kernelWorkerSnapshotPath, + required this.devToolsPath, }); /// Creates configuration from sdk layout. @@ -174,4 +178,4 @@ Future copyDirectory(String from, String to) async { await Link(copyTo).create(await file.target(), recursive: true); } } -} \ No newline at end of file +} diff --git a/test_common/test/sdk_asset_generator_test.dart b/test_common/test/sdk_asset_generator_test.dart index 5075e107a..d4b23a7c8 100644 --- a/test_common/test/sdk_asset_generator_test.dart +++ b/test_common/test/sdk_asset_generator_test.dart @@ -119,4 +119,3 @@ void _deleteIfExists(String path) { file.deleteSync(); } } - diff --git a/webdev/test/daemon/app_domain_test.dart b/webdev/test/daemon/app_domain_test.dart index ad6f6735e..546172400 100644 --- a/webdev/test/daemon/app_domain_test.dart +++ b/webdev/test/daemon/app_domain_test.dart @@ -14,39 +14,43 @@ import 'utils.dart'; void main() { late String exampleDirectory; + final testRunner = TestRunner(); setUpAll(() async { - exampleDirectory = await prepareWorkspace(); + await testRunner.setUpAll(); + exampleDirectory = await testRunner.prepareWorkspace(); }); + tearDownAll(testRunner.tearDownAll); + group('AppDomain', () { group('Events', () { test('.start', () async { - var webdev = - await runWebDev(['daemon'], workingDirectory: exampleDirectory); + var webdev = await testRunner + .runWebDev(['daemon'], workingDirectory: exampleDirectory); await expectLater( webdev.stdout, emitsThrough(startsWith('[{"event":"app.start"'))); await exitWebdev(webdev); }); test('.started', () async { - var webdev = - await runWebDev(['daemon'], workingDirectory: exampleDirectory); + var webdev = await testRunner + .runWebDev(['daemon'], workingDirectory: exampleDirectory); await expectLater( webdev.stdout, emitsThrough(startsWith('[{"event":"app.started"'))); await exitWebdev(webdev); }); test('.debugPort', () async { - var webdev = - await runWebDev(['daemon'], workingDirectory: exampleDirectory); + var webdev = await testRunner + .runWebDev(['daemon'], workingDirectory: exampleDirectory); await expectLater(webdev.stdout, emitsThrough(startsWith('[{"event":"app.debugPort"'))); await exitWebdev(webdev); }); test('.log', () async { - var webdev = - await runWebDev(['daemon'], workingDirectory: exampleDirectory); + var webdev = await testRunner + .runWebDev(['daemon'], workingDirectory: exampleDirectory); var appId = await waitForAppId(webdev); // The example app does an initial print. await expectLater( @@ -60,8 +64,8 @@ void main() { group('Methods', () { test('.callServiceExtension', () async { - var webdev = - await runWebDev(['daemon'], workingDirectory: exampleDirectory); + var webdev = await testRunner + .runWebDev(['daemon'], workingDirectory: exampleDirectory); var appId = await waitForAppId(webdev); if (Platform.isWindows) { // Windows takes a bit longer to run the application and register @@ -81,8 +85,8 @@ void main() { }); test('.reload', () async { - var webdev = - await runWebDev(['daemon'], workingDirectory: exampleDirectory); + var webdev = await testRunner + .runWebDev(['daemon'], workingDirectory: exampleDirectory); var appId = await waitForAppId(webdev); var extensionCall = '[{"method":"app.restart","id":0,' '"params" : { "appId" : "$appId", "fullRestart" : false}}]'; @@ -97,8 +101,8 @@ void main() { }); test('.restart', () async { - var webdev = - await runWebDev(['daemon'], workingDirectory: exampleDirectory); + var webdev = await testRunner + .runWebDev(['daemon'], workingDirectory: exampleDirectory); var appId = await waitForAppId(webdev); var extensionCall = '[{"method":"app.restart","id":0,' '"params" : { "appId" : "$appId", "fullRestart" : true}}]'; @@ -117,8 +121,8 @@ void main() { }); test('.stop', () async { - var webdev = - await runWebDev(['daemon'], workingDirectory: exampleDirectory); + var webdev = await testRunner + .runWebDev(['daemon'], workingDirectory: exampleDirectory); var appId = await waitForAppId(webdev); var stopCall = '[{"method":"app.stop","id":0,' '"params" : { "appId" : "$appId"}}]'; diff --git a/webdev/test/daemon/daemon_domain_test.dart b/webdev/test/daemon/daemon_domain_test.dart index a7102a622..45cfdf07d 100644 --- a/webdev/test/daemon/daemon_domain_test.dart +++ b/webdev/test/daemon/daemon_domain_test.dart @@ -14,15 +14,19 @@ import 'utils.dart'; void main() { late String exampleDirectory; + final testRunner = TestRunner(); setUpAll(() async { - exampleDirectory = await prepareWorkspace(); + await testRunner.setUpAll(); + exampleDirectory = await testRunner.prepareWorkspace(); }); + tearDownAll(testRunner.tearDownAll); + group('Daemon', () { group('Events', () { test('.connected', () async { - var webdev = - await runWebDev(['daemon'], workingDirectory: exampleDirectory); + var webdev = await testRunner + .runWebDev(['daemon'], workingDirectory: exampleDirectory); await expectLater( webdev.stdout, emits(startsWith('[{"event":"daemon.connected"'))); await exitWebdev(webdev); @@ -31,8 +35,8 @@ void main() { group('Methods', () { test('.version', () async { - var webdev = - await runWebDev(['daemon'], workingDirectory: exampleDirectory); + var webdev = await testRunner + .runWebDev(['daemon'], workingDirectory: exampleDirectory); webdev.stdin.add(utf8.encode('[{"method":"daemon.version","id":0}]\n')); await expectLater( webdev.stdout, emitsThrough(equals('[{"id":0,"result":"0.4.2"}]'))); @@ -40,8 +44,8 @@ void main() { }); test('.shutdown', () async { - var webdev = - await runWebDev(['daemon'], workingDirectory: exampleDirectory); + var webdev = await testRunner + .runWebDev(['daemon'], workingDirectory: exampleDirectory); webdev.stdin .add(utf8.encode('[{"method":"daemon.shutdown","id":0}]\n')); await expectLater(webdev.stdout, emitsThrough(equals('[{"id":0}]'))); diff --git a/webdev/test/daemon/launch_app_test.dart b/webdev/test/daemon/launch_app_test.dart index 9818e7ba9..54e40ee50 100644 --- a/webdev/test/daemon/launch_app_test.dart +++ b/webdev/test/daemon/launch_app_test.dart @@ -11,12 +11,17 @@ import 'utils.dart'; void main() { late String exampleDirectory; + final testRunner = TestRunner(); setUpAll(() async { - exampleDirectory = await prepareWorkspace(); + await testRunner.setUpAll(); + exampleDirectory = await testRunner.prepareWorkspace(); }); + tearDownAll(testRunner.tearDownAll); + test('--launch-app launches the specified app', () async { - var webdev = await runWebDev(['daemon', '--launch-app=web/scopes.html'], + var webdev = await testRunner.runWebDev( + ['daemon', '--launch-app=web/scopes.html'], workingDirectory: exampleDirectory); var appId = await waitForAppId(webdev); diff --git a/webdev/test/daemon/utils.dart b/webdev/test/daemon/utils.dart index f124a2fcd..fc9f100a2 100644 --- a/webdev/test/daemon/utils.dart +++ b/webdev/test/daemon/utils.dart @@ -5,13 +5,13 @@ import 'dart:async'; import 'dart:convert'; -import 'package:path/path.dart' as p; +//import 'package:path/path.dart' as p; import 'package:test/test.dart'; import 'package:test_process/test_process.dart'; import 'package:vm_service/vm_service.dart'; -import 'package:webdev/src/util.dart'; +//import 'package:webdev/src/util.dart'; -import '../test_utils.dart'; +//import '../test_utils.dart'; const isRPCError = TypeMatcher(); @@ -37,16 +37,16 @@ Future waitForAppId(TestProcess webdev) async { return appId; } -Future prepareWorkspace() async { - var exampleDirectory = - p.absolute(p.join(p.current, '..', 'fixtures', '_webdevSoundSmoke')); +// Future prepareWorkspace() async { +// var exampleDirectory = +// p.absolute(p.join(p.current, '..', 'fixtures', '_webdevSoundSmoke')); - var process = await TestProcess.start(dartPath, ['pub', 'upgrade'], - workingDirectory: exampleDirectory, environment: getPubEnvironment()); +// var process = await TestProcess.start(dartPath, ['pub', 'upgrade'], +// workingDirectory: exampleDirectory, environment: getPubEnvironment()); - await process.shouldExit(0); - return exampleDirectory; -} +// await process.shouldExit(0); +// return exampleDirectory; +// } String? getDebugServiceUri(String line) { var regex = RegExp(r'Debug service listening on (?[^\s^\\]*)'); diff --git a/webdev/test/e2e_test.dart b/webdev/test/e2e_test.dart index 8d706a434..6c6d09248 100644 --- a/webdev/test/e2e_test.dart +++ b/webdev/test/e2e_test.dart @@ -36,10 +36,12 @@ void main() { // Change to true for debugging. final debug = false; + final testRunner = TestRunner(); late String exampleDirectory; late String soundExampleDirectory; setUpAll(() async { configureLogWriter(debug); + await testRunner.setUpAll(); exampleDirectory = p.absolute(p.join(p.current, '..', 'fixtures', '_webdevSmoke')); soundExampleDirectory = @@ -62,6 +64,8 @@ void main() { await d.file('pubspec.lock', isNotEmpty).validate(soundExampleDirectory); }); + tearDownAll(testRunner.tearDownAll); + test('smoke test is configured properly', () async { var smokeYaml = loadYaml( await File('$soundExampleDirectory/pubspec.yaml').readAsString()) @@ -81,8 +85,8 @@ void main() { var args = ['build', '-o', 'web:${d.sandbox}']; - var process = - await runWebDev(args, workingDirectory: soundExampleDirectory); + var process = await testRunner.runWebDev(args, + workingDirectory: soundExampleDirectory); // NOTE: We'd like this to be more useful // See https://github.com/dart-lang/build/issues/1283 @@ -109,8 +113,8 @@ void main() { '--delete-conflicting-outputs' ]; - var process = - await runWebDev(args, workingDirectory: soundExampleDirectory); + var process = await testRunner.runWebDev(args, + workingDirectory: soundExampleDirectory); await checkProcessStdout(process, ['Succeeded']); await process.shouldExit(0); @@ -124,8 +128,8 @@ void main() { args.add('--no-release'); } - var process = - await runWebDev(args, workingDirectory: soundExampleDirectory); + var process = await testRunner.runWebDev(args, + workingDirectory: soundExampleDirectory); var expectedItems = ['Succeeded']; @@ -152,8 +156,8 @@ void main() { '--null-safety=sound' ]; - var process = - await runWebDev(args, workingDirectory: soundExampleDirectory); + var process = await testRunner.runWebDev(args, + workingDirectory: soundExampleDirectory); var expectedItems = ['Succeeded']; @@ -172,7 +176,8 @@ void main() { '--null-safety=unsound' ]; - var process = await runWebDev(args, workingDirectory: exampleDirectory); + var process = + await testRunner.runWebDev(args, workingDirectory: exampleDirectory); var expectedItems = ['Succeeded']; @@ -191,8 +196,8 @@ void main() { args.add('--no-release'); } - var process = - await runWebDev(args, workingDirectory: soundExampleDirectory); + var process = await testRunner.runWebDev(args, + workingDirectory: soundExampleDirectory); var expectedItems = ['Succeeded']; @@ -214,8 +219,8 @@ void main() { args.add('--release'); } - var process = - await runWebDev(args, workingDirectory: soundExampleDirectory); + var process = await testRunner.runWebDev(args, + workingDirectory: soundExampleDirectory); var hostUrl = 'http://localhost:$openPort'; @@ -256,8 +261,8 @@ void main() { if (command == 'build') '--output=$dir:foo' else dir ]; - var process = - await runWebDev(args, workingDirectory: soundExampleDirectory); + var process = await testRunner.runWebDev(args, + workingDirectory: soundExampleDirectory); await expectLater( process.stdout, emitsThrough(contains( @@ -294,7 +299,7 @@ void main() { '--null-safety=$nullSafetyOption', '--verbose', ]; - var process = await runWebDev(args, + var process = await testRunner.runWebDev(args, workingDirectory: soundNullSafety ? soundExampleDirectory : exampleDirectory); VmService? vmService; @@ -360,7 +365,7 @@ void main() { '--enable-expression-evaluation', '--verbose', ]; - var process = await runWebDev(args, + var process = await testRunner.runWebDev(args, workingDirectory: soundNullSafety ? soundExampleDirectory : exampleDirectory); VmService? vmService; @@ -418,7 +423,7 @@ void main() { '--no-enable-expression-evaluation', '--verbose', ]; - var process = await runWebDev(args, + var process = await testRunner.runWebDev(args, workingDirectory: soundNullSafety ? soundExampleDirectory : exampleDirectory); VmService? vmService; @@ -473,7 +478,7 @@ void main() { '--no-enable-expression-evaluation', '--verbose', ]; - var process = await runWebDev(args, + var process = await testRunner.runWebDev(args, workingDirectory: soundNullSafety ? soundExampleDirectory : exampleDirectory); VmService? vmService; diff --git a/webdev/test/integration_test.dart b/webdev/test/integration_test.dart index 2e9154388..6739b8bdf 100644 --- a/webdev/test/integration_test.dart +++ b/webdev/test/integration_test.dart @@ -18,8 +18,12 @@ void main() { var pubCommand = sdkVersion.compareTo(firstSdkVersionWithoutPub) < 0 ? 'pub' : 'dart pub'; + final testRunner = TestRunner(); + setUpAll(testRunner.setUpAll); + tearDownAll(testRunner.tearDownAll); + test('non-existant commands create errors', () async { - var process = await runWebDev(['monkey']); + var process = await testRunner.runWebDev(['monkey']); await expectLater( process.stdout, emits('Could not find a command named "monkey".')); @@ -28,7 +32,7 @@ void main() { }); test('passing extra args to build fails with bad usage', () async { - var process = await runWebDev(['build', 'extra', 'args']); + var process = await testRunner.runWebDev(['build', 'extra', 'args']); await expectLater(process.stdout, emits('Arguments were provided that are not supported: "extra args".')); @@ -55,7 +59,8 @@ name: sample await d.file('.dart_tool/package_config.json', ''' ''').create(); - var process = await runWebDev(['serve'], workingDirectory: d.sandbox); + var process = + await testRunner.runWebDev(['serve'], workingDirectory: d.sandbox); var output = await process.stdout.rest.toList(); @@ -87,7 +92,8 @@ name: sample await d.file('.dart_tool/package_config.json', ''' ''').create(); - var process = await runWebDev([command], workingDirectory: d.sandbox); + var process = await testRunner + .runWebDev([command], workingDirectory: d.sandbox); await checkProcessStdout(process, [ 'webdev could not run for this project.', @@ -110,7 +116,8 @@ name: sample await d.file('.dart_tool/package_config.json', ''' ''').create(); - var process = await runWebDev(['serve'], workingDirectory: d.sandbox); + var process = await testRunner + .runWebDev(['serve'], workingDirectory: d.sandbox); await checkProcessStdout(process, [ 'webdev could not run for this project.', @@ -138,7 +145,8 @@ name: sample // Required for webdev to not complain about nothing to serve. await d.dir('web').create(); - var process = await runWebDev(['serve', '--no-build-web-compilers'], + var process = await testRunner.runWebDev( + ['serve', '--no-build-web-compilers'], workingDirectory: d.sandbox); // Fails since this is a fake package @@ -187,8 +195,8 @@ name: sample await d.file('.dart_tool/package_config.json', ''' ''').create(); - var process = - await runWebDev(['serve'], workingDirectory: d.sandbox); + var process = await testRunner + .runWebDev(['serve'], workingDirectory: d.sandbox); if (entry.key == 'build_daemon') { await checkProcessStdout(process, [ @@ -212,7 +220,8 @@ name: sample } test('no pubspec.yaml', () async { - var process = await runWebDev(['serve'], workingDirectory: d.sandbox); + var process = + await testRunner.runWebDev(['serve'], workingDirectory: d.sandbox); await checkProcessStdout(process, [ 'webdev could not run for this project.', @@ -226,7 +235,8 @@ name: sample name: sample ''').create(); - var process = await runWebDev(['serve'], workingDirectory: d.sandbox); + var process = + await testRunner.runWebDev(['serve'], workingDirectory: d.sandbox); await checkProcessStdout(process, [ 'webdev could not run for this project.', @@ -250,7 +260,8 @@ dependencies: args: ^1.0.0 ''').create(); - var process = await runWebDev(['serve'], workingDirectory: d.sandbox); + var process = + await testRunner.runWebDev(['serve'], workingDirectory: d.sandbox); await checkProcessStdout(process, [ 'webdev could not run for this project.', diff --git a/webdev/test/readme_test.dart b/webdev/test/readme_test.dart index 0f57f0f96..77def258a 100644 --- a/webdev/test/readme_test.dart +++ b/webdev/test/readme_test.dart @@ -15,14 +15,18 @@ import 'package:test/test.dart'; import 'test_utils.dart'; void main() { - test('help build', () => _readmeCheck(['help', 'build'])); - test('help serve', () => _readmeCheck(['help', 'serve'])); + final testRunner = TestRunner(); + setUpAll(testRunner.setUpAll); + tearDownAll(testRunner.tearDownAll); + + test('help build', () => _readmeCheck(testRunner, ['help', 'build'])); + test('help serve', () => _readmeCheck(testRunner, ['help', 'serve'])); } final _readmeContents = File('README.md').readAsStringSync(); -Future _readmeCheck(List args) async { - var process = await runWebDev(args); +Future _readmeCheck(TestRunner testRunner, List args) async { + var process = await testRunner.runWebDev(args); var output = (await process.stdoutStream().map((line) => line.trimRight()).join('\n')) .trim(); diff --git a/webdev/test/test_utils.dart b/webdev/test/test_utils.dart index 67ee55813..0b8615dde 100644 --- a/webdev/test/test_utils.dart +++ b/webdev/test/test_utils.dart @@ -8,21 +8,53 @@ import 'dart:io'; import 'package:path/path.dart' as p; import 'package:test/test.dart'; import 'package:test_common/test_sdk_configuration.dart'; +import 'package:test_common/test_sdk_layout.dart'; import 'package:test_process/test_process.dart'; -import 'package:webdev/src/util.dart'; final _webdevBin = p.absolute(p.join('bin', 'webdev.dart')); -final _sdkConfigurationProvider = TestSdkConfigurationProvider(); -Future runWebDev(List args, - {String? workingDirectory}) async { - // Generate missing test assets in the SDK. - await _sdkConfigurationProvider.configuration; +class TestRunner { + late TestSdkConfigurationProvider sdkConfigurationProvider; + late TestSdkLayout sdkLayout; - var fullArgs = [_webdevBin, ...args]; + Future setUpAll({bool verbose = false}) async { + // Generate missing SDK assets if needed. + sdkConfigurationProvider = TestSdkConfigurationProvider(verbose: verbose); + sdkLayout = sdkConfigurationProvider.sdkLayout; - return TestProcess.start(dartPath, fullArgs, - workingDirectory: workingDirectory); + try { + // Make sure configuration was created correctly. + final configuration = await sdkConfigurationProvider.configuration; + configuration.validate(); + } catch (_) { + tearDownAll(); + rethrow; + } + } + + void tearDownAll() { + sdkConfigurationProvider.dispose(); + } + + Future runWebDev(List args, + {String? workingDirectory}) async { + var fullArgs = [_webdevBin, ...args]; + + return TestProcess.start(sdkLayout.dartPath, fullArgs, + workingDirectory: workingDirectory); + } + + Future prepareWorkspace() async { + var exampleDirectory = + p.absolute(p.join(p.current, '..', 'fixtures', '_webdevSoundSmoke')); + + var process = await TestProcess.start( + sdkLayout.dartPath, ['pub', 'upgrade'], + workingDirectory: exampleDirectory, environment: getPubEnvironment()); + + await process.shouldExit(0); + return exampleDirectory; + } } Future checkProcessStdout(TestProcess process, List items) async { From d431a3eb72598519890c567a8c2860c87808f5fc Mon Sep 17 00:00:00 2001 From: Anna Gringauze Date: Wed, 15 Feb 2023 15:14:54 -0800 Subject: [PATCH 08/15] Cleanup --- dwds/test/evaluate_circular_common.dart | 6 +++--- dwds/test/records_test.dart | 7 +++---- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/dwds/test/evaluate_circular_common.dart b/dwds/test/evaluate_circular_common.dart index 49b744a43..03d727ab9 100644 --- a/dwds/test/evaluate_circular_common.dart +++ b/dwds/test/evaluate_circular_common.dart @@ -34,17 +34,17 @@ void testAll({ Future onBreakPoint(String isolate, ScriptRef script, String breakPointId, Future Function() body) async { - final service = context.service; Breakpoint? bp; try { final line = await context.findBreakpointLine(breakPointId, isolate, script); - bp = await service.addBreakpointWithScriptUri(isolate, script.uri!, line); + bp = await context.service + .addBreakpointWithScriptUri(isolate, script.uri!, line); await body(); } finally { // Remove breakpoint so it doesn't impact other tests or retries. if (bp != null) { - await service.removeBreakpoint(isolate, bp.id!); + await context.service.removeBreakpoint(isolate, bp.id!); } } } diff --git a/dwds/test/records_test.dart b/dwds/test/records_test.dart index a9af7459f..4396b383f 100644 --- a/dwds/test/records_test.dart +++ b/dwds/test/records_test.dart @@ -402,13 +402,12 @@ Future _onBreakPoint( String breakPointId, Future Function(Event event) body, ) async { - final service = context.service; - Breakpoint? bp; try { final line = await context.findBreakpointLine(breakPointId, isolateId, script); - bp = await service.addBreakpointWithScriptUri(isolateId, script.uri!, line); + bp = await context.service + .addBreakpointWithScriptUri(isolateId, script.uri!, line); final event = await stream.firstWhere((e) => e.kind == EventKind.kPauseBreakpoint); @@ -417,7 +416,7 @@ Future _onBreakPoint( } finally { // Remove breakpoint so it doesn't impact other tests or retries. if (bp != null) { - await service.removeBreakpoint(isolateId, bp.id!); + await context.service.removeBreakpoint(isolateId, bp.id!); } } } From 11aa23f4bfc2f542bb24825532b934e1c5209132 Mon Sep 17 00:00:00 2001 From: Anna Gringauze Date: Wed, 15 Feb 2023 16:41:26 -0800 Subject: [PATCH 09/15] Pull out project definitions into separate file --- dwds/test/build_daemon_breakpoint_test.dart | 4 +- dwds/test/build_daemon_callstack_test.dart | 493 +++++++++--------- .../build_daemon_circular_evaluate_test.dart | 1 + dwds/test/build_daemon_evaluate_test.dart | 1 + dwds/test/chrome_proxy_service_test.dart | 3 +- dwds/test/dart_uri_file_uri_test.dart | 4 +- dwds/test/debug_extension_test.dart | 58 ++- dwds/test/debug_service_test.dart | 3 +- dwds/test/devtools_test.dart | 3 +- dwds/test/evaluate_circular_common.dart | 10 +- dwds/test/evaluate_common.dart | 17 +- dwds/test/events_test.dart | 3 +- dwds/test/fixtures/context.dart | 126 +---- dwds/test/fixtures/project.dart | 100 ++++ .../test/frontend_server_breakpoint_test.dart | 4 +- dwds/test/frontend_server_callstack_test.dart | 11 +- ...rontend_server_circular_evaluate_test.dart | 1 + .../frontend_server_evaluate_sound_test.dart | 1 + .../frontend_server_evaluate_weak_test.dart | 1 + dwds/test/handlers/asset_handler_test.dart | 5 +- dwds/test/inspector_test.dart | 5 +- dwds/test/instance_test.dart | 5 +- dwds/test/listviews_test.dart | 4 +- dwds/test/puppeteer/extension_test.dart | 4 +- dwds/test/puppeteer/lifeline_test.dart | 3 +- .../proxy_server_asset_reader_test.dart | 4 +- dwds/test/records_test.dart | 4 +- dwds/test/refresh_test.dart | 3 +- dwds/test/reload_test.dart | 4 +- dwds/test/restore_breakpoints_test.dart | 3 +- dwds/test/run_request_test.dart | 3 +- dwds/test/screenshot_test.dart | 3 +- dwds/test/variable_scope_test.dart | 4 +- 33 files changed, 477 insertions(+), 421 deletions(-) create mode 100644 dwds/test/fixtures/project.dart diff --git a/dwds/test/build_daemon_breakpoint_test.dart b/dwds/test/build_daemon_breakpoint_test.dart index cbb1fe3ff..2ce7b9ffb 100644 --- a/dwds/test/build_daemon_breakpoint_test.dart +++ b/dwds/test/build_daemon_breakpoint_test.dart @@ -11,12 +11,14 @@ import 'package:test_common/test_sdk_configuration.dart'; import 'package:vm_service/vm_service.dart'; import 'fixtures/context.dart'; +import 'fixtures/project.dart'; void main() { final provider = TestSdkConfigurationProvider(); tearDownAll(provider.dispose); - final context = TestContext.testPackageWithSoundNullSafety(provider); + final context = + TestContext(TestProject.testPackageWithSoundNullSafety(), provider); group('shared context', () { setUpAll(() async { diff --git a/dwds/test/build_daemon_callstack_test.dart b/dwds/test/build_daemon_callstack_test.dart index 7b4018888..2f1ce7185 100644 --- a/dwds/test/build_daemon_callstack_test.dart +++ b/dwds/test/build_daemon_callstack_test.dart @@ -12,278 +12,275 @@ import 'package:test_common/test_sdk_configuration.dart'; import 'package:vm_service/vm_service.dart'; import 'fixtures/context.dart'; +import 'fixtures/project.dart'; void main() { final provider = TestSdkConfigurationProvider(); tearDownAll(provider.dispose); - group( - 'shared context |', - () { - // Enable verbose logging for debugging. - final debug = false; + group('shared context |', () { + // Enable verbose logging for debugging. + final debug = false; + + for (var nullSafety in NullSafety.values) { + group('${nullSafety.name} null safety |', () { + final soundNullSafety = nullSafety == NullSafety.sound; + final context = TestContext( + TestProject.testPackage(nullSafety: nullSafety), provider); + + setUpAll(() async { + setCurrentLogWriter(debug: debug); + await context.setUp( + compilationMode: CompilationMode.buildDaemon, + enableExpressionEvaluation: true, + verboseCompiler: debug, + ); + }); + + tearDownAll(() async { + await context.tearDown(); + }); - for (var nullSafety in NullSafety.values) { - group('${nullSafety.name} null safety |', () { - final soundNullSafety = nullSafety == NullSafety.sound; - final context = TestContext.testPackage( - provider: provider, nullSafety: nullSafety); + group('callStack |', () { + late VmServiceInterface service; + VM vm; + late Isolate isolate; + ScriptList scripts; + late ScriptRef mainScript; + late ScriptRef testLibraryScript; + late Stream stream; - setUpAll(() async { + setUp(() async { setCurrentLogWriter(debug: debug); - await context.setUp( - compilationMode: CompilationMode.buildDaemon, - enableExpressionEvaluation: true, - verboseCompiler: debug, - ); - }); + service = context.service; + vm = await service.getVM(); + isolate = await service.getIsolate(vm.isolates!.first.id!); + scripts = await service.getScripts(isolate.id!); - tearDownAll(() async { - await context.tearDown(); - }); + await service.streamListen('Debug'); + stream = service.onEvent('Debug'); - group('callStack |', () { - late VmServiceInterface service; - VM vm; - late Isolate isolate; - ScriptList scripts; - late ScriptRef mainScript; - late ScriptRef testLibraryScript; - late Stream stream; - - setUp(() async { - setCurrentLogWriter(debug: debug); - service = context.service; - vm = await service.getVM(); - isolate = await service.getIsolate(vm.isolates!.first.id!); - scripts = await service.getScripts(isolate.id!); - - await service.streamListen('Debug'); - stream = service.onEvent('Debug'); - - final testPackage = - soundNullSafety ? '_test_package_sound' : '_test_package'; - - mainScript = scripts.scripts! - .firstWhere((each) => each.uri!.contains('main.dart')); - testLibraryScript = scripts.scripts!.firstWhere((each) => - each.uri!.contains('package:$testPackage/test_library.dart')); - }); + final testPackage = + soundNullSafety ? '_test_package_sound' : '_test_package'; - tearDown(() async { - await service.resume(isolate.id!); - }); + mainScript = scripts.scripts! + .firstWhere((each) => each.uri!.contains('main.dart')); + testLibraryScript = scripts.scripts!.firstWhere((each) => + each.uri!.contains('package:$testPackage/test_library.dart')); + }); - Future onBreakPoint(BreakpointTestData breakpoint, - Future Function() body) async { - Breakpoint? bp; - try { - final bpId = breakpoint.bpId; - final script = breakpoint.script; - final line = - await context.findBreakpointLine(bpId, isolate.id!, script); - bp = await context.service - .addBreakpointWithScriptUri(isolate.id!, script.uri!, line); - - expect(bp, isNotNull); - expect(bp.location, _matchBpLocation(script, line, 0)); - - await stream.firstWhere( - (Event event) => event.kind == EventKind.kPauseBreakpoint); - - await body(); - } finally { - // Remove breakpoint so it doesn't impact other tests or retries. - if (bp != null) { - await context.service.removeBreakpoint(isolate.id!, bp.id!); - } - } - } + tearDown(() async { + await service.resume(isolate.id!); + }); - Future testCallStack(List breakpoints, - {int frameIndex = 1}) async { - // Find lines the breakpoints are located on. - final lines = await Future.wait(breakpoints.map((frame) => context - .findBreakpointLine(frame.bpId, isolate.id!, frame.script))); - - // Get current stack. - final stack = await service.getStack(isolate.id!); - - // Verify the stack is correct. - expect(stack.frames!.length, greaterThanOrEqualTo(lines.length)); - final expected = [ - for (var i = 0; i < lines.length; i++) - _matchFrame( - breakpoints[i].script, breakpoints[i].function, lines[i]) - ]; - expect(stack.frames, containsAll(expected)); - - // Verify that expression evaluation is not failing. - final instance = await service.evaluateInFrame( - isolate.id!, frameIndex, 'true'); - expect(instance, isA()); + Future onBreakPoint(BreakpointTestData breakpoint, + Future Function() body) async { + Breakpoint? bp; + try { + final bpId = breakpoint.bpId; + final script = breakpoint.script; + final line = + await context.findBreakpointLine(bpId, isolate.id!, script); + bp = await context.service + .addBreakpointWithScriptUri(isolate.id!, script.uri!, line); + + expect(bp, isNotNull); + expect(bp.location, _matchBpLocation(script, line, 0)); + + await stream.firstWhere( + (Event event) => event.kind == EventKind.kPauseBreakpoint); + + await body(); + } finally { + // Remove breakpoint so it doesn't impact other tests or retries. + if (bp != null) { + await context.service.removeBreakpoint(isolate.id!, bp.id!); + } } + } + + Future testCallStack(List breakpoints, + {int frameIndex = 1}) async { + // Find lines the breakpoints are located on. + final lines = await Future.wait(breakpoints.map((frame) => context + .findBreakpointLine(frame.bpId, isolate.id!, frame.script))); + + // Get current stack. + final stack = await service.getStack(isolate.id!); + + // Verify the stack is correct. + expect(stack.frames!.length, greaterThanOrEqualTo(lines.length)); + final expected = [ + for (var i = 0; i < lines.length; i++) + _matchFrame( + breakpoints[i].script, breakpoints[i].function, lines[i]) + ]; + expect(stack.frames, containsAll(expected)); + + // Verify that expression evaluation is not failing. + final instance = + await service.evaluateInFrame(isolate.id!, frameIndex, 'true'); + expect(instance, isA()); + } + + test('breakpoint succeeds with correct callstack', () async { + // Expected breakpoints on the stack + final breakpoints = [ + BreakpointTestData( + 'printEnclosingObject', + 'printEnclosingObject', + mainScript, + ), + BreakpointTestData( + 'printEnclosingFunctionMultiLine', + 'printNestedObjectsMultiLine', + mainScript, + ), + BreakpointTestData( + 'callPrintEnclosingFunctionMultiLine', + '', + mainScript, + ), + ]; + await onBreakPoint( + breakpoints[0], () => testCallStack(breakpoints)); + }); - test('breakpoint succeeds with correct callstack', () async { - // Expected breakpoints on the stack - final breakpoints = [ - BreakpointTestData( - 'printEnclosingObject', - 'printEnclosingObject', - mainScript, - ), - BreakpointTestData( - 'printEnclosingFunctionMultiLine', - 'printNestedObjectsMultiLine', - mainScript, - ), - BreakpointTestData( - 'callPrintEnclosingFunctionMultiLine', - '', - mainScript, - ), - ]; - await onBreakPoint( - breakpoints[0], () => testCallStack(breakpoints)); - }); - - test('expression evaluation succeeds on parent frame', () async { - // Expected breakpoints on the stack - final breakpoints = [ - BreakpointTestData( - 'testLibraryClassConstructor', - 'new', - testLibraryScript, - ), - BreakpointTestData( - 'createLibraryObject', - 'printFieldFromLibraryClass', - mainScript, - ), - BreakpointTestData( - 'callPrintFieldFromLibraryClass', - '', - mainScript, - ), - ]; - await onBreakPoint(breakpoints[0], - () => testCallStack(breakpoints, frameIndex: 2)); - }); + test('expression evaluation succeeds on parent frame', () async { + // Expected breakpoints on the stack + final breakpoints = [ + BreakpointTestData( + 'testLibraryClassConstructor', + 'new', + testLibraryScript, + ), + BreakpointTestData( + 'createLibraryObject', + 'printFieldFromLibraryClass', + mainScript, + ), + BreakpointTestData( + 'callPrintFieldFromLibraryClass', + '', + mainScript, + ), + ]; + await onBreakPoint(breakpoints[0], + () => testCallStack(breakpoints, frameIndex: 2)); + }); - test('breakpoint inside a line gives correct callstack', () async { - // Expected breakpoints on the stack - final breakpoints = [ - BreakpointTestData( - 'newEnclosedClass', - 'new', - mainScript, - ), - BreakpointTestData( - 'printNestedObjectMultiLine', - 'printNestedObjectsMultiLine', - mainScript, - ), - BreakpointTestData( - 'callPrintEnclosingFunctionMultiLine', - '', - mainScript, - ), - ]; - await onBreakPoint( - breakpoints[0], () => testCallStack(breakpoints)); - }); + test('breakpoint inside a line gives correct callstack', () async { + // Expected breakpoints on the stack + final breakpoints = [ + BreakpointTestData( + 'newEnclosedClass', + 'new', + mainScript, + ), + BreakpointTestData( + 'printNestedObjectMultiLine', + 'printNestedObjectsMultiLine', + mainScript, + ), + BreakpointTestData( + 'callPrintEnclosingFunctionMultiLine', + '', + mainScript, + ), + ]; + await onBreakPoint( + breakpoints[0], () => testCallStack(breakpoints)); + }); - test('breakpoint gives correct callstack after step out', () async { - // Expected breakpoints on the stack - final breakpoints = [ - BreakpointTestData( - 'newEnclosedClass', - 'new', - mainScript, - ), - BreakpointTestData( - 'printEnclosingObjectMultiLine', - 'printNestedObjectsMultiLine', - mainScript, - ), - BreakpointTestData( - 'callPrintEnclosingFunctionMultiLine', - '', - mainScript, - ), - ]; - await onBreakPoint(breakpoints[0], () async { - await service.resume(isolate.id!, step: 'Out'); - await stream.firstWhere( - (Event event) => event.kind == EventKind.kPauseInterrupted); - return testCallStack([breakpoints[1], breakpoints[2]]); - }); + test('breakpoint gives correct callstack after step out', () async { + // Expected breakpoints on the stack + final breakpoints = [ + BreakpointTestData( + 'newEnclosedClass', + 'new', + mainScript, + ), + BreakpointTestData( + 'printEnclosingObjectMultiLine', + 'printNestedObjectsMultiLine', + mainScript, + ), + BreakpointTestData( + 'callPrintEnclosingFunctionMultiLine', + '', + mainScript, + ), + ]; + await onBreakPoint(breakpoints[0], () async { + await service.resume(isolate.id!, step: 'Out'); + await stream.firstWhere( + (Event event) => event.kind == EventKind.kPauseInterrupted); + return testCallStack([breakpoints[1], breakpoints[2]]); }); + }); - test('breakpoint gives correct callstack after step in', () async { - // Expected breakpoints on the stack - final breakpoints = [ - BreakpointTestData( - 'newEnclosedClass', - 'new', - mainScript, - ), - BreakpointTestData( - 'printNestedObjectMultiLine', - 'printNestedObjectsMultiLine', - mainScript, - ), - BreakpointTestData( - 'callPrintEnclosingFunctionMultiLine', - '', - mainScript, - ), - ]; - await onBreakPoint(breakpoints[1], () async { - await service.resume(isolate.id!, step: 'Into'); - await stream.firstWhere( - (Event event) => event.kind == EventKind.kPauseInterrupted); - return testCallStack(breakpoints); - }); + test('breakpoint gives correct callstack after step in', () async { + // Expected breakpoints on the stack + final breakpoints = [ + BreakpointTestData( + 'newEnclosedClass', + 'new', + mainScript, + ), + BreakpointTestData( + 'printNestedObjectMultiLine', + 'printNestedObjectsMultiLine', + mainScript, + ), + BreakpointTestData( + 'callPrintEnclosingFunctionMultiLine', + '', + mainScript, + ), + ]; + await onBreakPoint(breakpoints[1], () async { + await service.resume(isolate.id!, step: 'Into'); + await stream.firstWhere( + (Event event) => event.kind == EventKind.kPauseInterrupted); + return testCallStack(breakpoints); }); + }); - test( - 'breakpoint gives correct callstack after step into chain calls', - () async { - // Expected breakpoints on the stack - final breakpoints = [ - BreakpointTestData( - 'createObjectWithMethod', - 'createObject', - mainScript, - ), - BreakpointTestData( - // This is currently incorrect, should be printObjectMultiLine. - // See issue: https://github.com/dart-lang/sdk/issues/48874 - 'printMultiLine', - 'printObjectMultiLine', - mainScript, - ), - BreakpointTestData( - 'callPrintObjectMultiLine', - '', - mainScript, - ), - ]; - final bp = BreakpointTestData( - 'printMultiLine', 'printObjectMultiLine', mainScript); - await onBreakPoint(bp, () async { - await service.resume(isolate.id!, step: 'Into'); - await stream.firstWhere( - (Event event) => event.kind == EventKind.kPauseInterrupted); - return testCallStack(breakpoints); - }); + test('breakpoint gives correct callstack after step into chain calls', + () async { + // Expected breakpoints on the stack + final breakpoints = [ + BreakpointTestData( + 'createObjectWithMethod', + 'createObject', + mainScript, + ), + BreakpointTestData( + // This is currently incorrect, should be printObjectMultiLine. + // See issue: https://github.com/dart-lang/sdk/issues/48874 + 'printMultiLine', + 'printObjectMultiLine', + mainScript, + ), + BreakpointTestData( + 'callPrintObjectMultiLine', + '', + mainScript, + ), + ]; + final bp = BreakpointTestData( + 'printMultiLine', 'printObjectMultiLine', mainScript); + await onBreakPoint(bp, () async { + await service.resume(isolate.id!, step: 'Into'); + await stream.firstWhere( + (Event event) => event.kind == EventKind.kPauseInterrupted); + return testCallStack(breakpoints); }); }); }); - } - }, - ); + }); + } + }); } Matcher _matchFrame(ScriptRef script, String function, int line) => isA() diff --git a/dwds/test/build_daemon_circular_evaluate_test.dart b/dwds/test/build_daemon_circular_evaluate_test.dart index bc952c000..9111f14e7 100644 --- a/dwds/test/build_daemon_circular_evaluate_test.dart +++ b/dwds/test/build_daemon_circular_evaluate_test.dart @@ -10,6 +10,7 @@ import 'package:test_common/test_sdk_configuration.dart'; import 'evaluate_circular_common.dart'; import 'fixtures/context.dart'; +import 'fixtures/project.dart'; void main() async { // Enable verbose logging for debugging. diff --git a/dwds/test/build_daemon_evaluate_test.dart b/dwds/test/build_daemon_evaluate_test.dart index e50406849..daab203f7 100644 --- a/dwds/test/build_daemon_evaluate_test.dart +++ b/dwds/test/build_daemon_evaluate_test.dart @@ -10,6 +10,7 @@ import 'package:test_common/test_sdk_configuration.dart'; import 'evaluate_common.dart'; import 'fixtures/context.dart'; +import 'fixtures/project.dart'; void main() async { // Enable verbose logging for debugging. diff --git a/dwds/test/chrome_proxy_service_test.dart b/dwds/test/chrome_proxy_service_test.dart index 146daf229..714c5d6e5 100644 --- a/dwds/test/chrome_proxy_service_test.dart +++ b/dwds/test/chrome_proxy_service_test.dart @@ -20,6 +20,7 @@ import 'package:vm_service/vm_service.dart'; import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart'; import 'fixtures/context.dart'; +import 'fixtures/project.dart'; void main() { // Change to true to see verbose output from the tests. @@ -28,7 +29,7 @@ void main() { final provider = TestSdkConfigurationProvider(verbose: debug); tearDownAll(provider.dispose); - final context = TestContext.testWithSoundNullSafety(provider); + final context = TestContext(TestProject.testWithSoundNullSafety(), provider); group('shared context', () { setUpAll(() async { diff --git a/dwds/test/dart_uri_file_uri_test.dart b/dwds/test/dart_uri_file_uri_test.dart index 70ec2a73c..2fded12ee 100644 --- a/dwds/test/dart_uri_file_uri_test.dart +++ b/dwds/test/dart_uri_file_uri_test.dart @@ -11,6 +11,7 @@ import 'package:test/test.dart'; import 'package:test_common/test_sdk_configuration.dart'; import 'fixtures/context.dart'; +import 'fixtures/project.dart'; import 'fixtures/utilities.dart'; /// The directory for the general _test package. @@ -28,7 +29,8 @@ final testPackageDir = void main() { final provider = TestSdkConfigurationProvider(); tearDownAll(provider.dispose); - final context = TestContext.testWithSoundNullSafety(provider); + + final context = TestContext(TestProject.testWithSoundNullSafety(), provider); for (final compilationMode in CompilationMode.values) { group('$compilationMode |', () { diff --git a/dwds/test/debug_extension_test.dart b/dwds/test/debug_extension_test.dart index 1bd4cf7ab..31fabb3df 100644 --- a/dwds/test/debug_extension_test.dart +++ b/dwds/test/debug_extension_test.dart @@ -19,6 +19,7 @@ import 'package:test_common/test_sdk_configuration.dart'; import 'package:webdriver/io.dart'; import 'fixtures/context.dart'; +import 'fixtures/project.dart'; import 'fixtures/utilities.dart'; // Instructions for running: @@ -35,26 +36,10 @@ void main() async { final provider = TestSdkConfigurationProvider(); tearDownAll(provider.dispose); - final context = TestContext.testWithSoundNullSafety(provider); - - Future waitForDartDevToolsWithRetry({ - int retryCount = 6, - Duration retryWait = const Duration(seconds: 1), - }) async { - if (retryCount == 0) return; - final windows = await context.webDriver.windows.toList(); - await context.webDriver.driver.switchTo.window(windows.last); - final title = await context.webDriver.title; - if (title == 'Dart DevTools') return; - - await Future.delayed(retryWait); - return waitForDartDevToolsWithRetry( - retryCount: retryCount--, - retryWait: retryWait, - ); - } - for (var useSse in [true, false]) { + final context = + TestContext(TestProject.testWithSoundNullSafety(), provider); + group(useSse ? 'SSE' : 'WebSockets', () { group('Without encoding', () { setUp(() async { @@ -64,7 +49,7 @@ void main() async { 'expression': 'fakeClick()', }); // Wait for DevTools to actually open. - await waitForDartDevToolsWithRetry(); + await waitForDartDevToolsWithRetry(context); }); tearDown(() async { @@ -92,7 +77,7 @@ void main() async { await context.extensionConnection.sendCommand('Runtime.evaluate', { 'expression': 'fakeClick()', }); - await waitForDartDevToolsWithRetry(); + await waitForDartDevToolsWithRetry(context); expect(await context.webDriver.title, 'Dart DevTools'); }); @@ -158,7 +143,7 @@ void main() async { 'expression': 'fakeClick()', }); // Wait for DevTools to actually open. - await waitForDartDevToolsWithRetry(); + await waitForDartDevToolsWithRetry(context); }); tearDown(() async { @@ -184,7 +169,7 @@ void main() async { await context.extensionConnection.sendCommand('Runtime.evaluate', { 'expression': 'fakeClick()', }); - await waitForDartDevToolsWithRetry(); + await waitForDartDevToolsWithRetry(context); expect(await context.webDriver.title, 'Dart DevTools'); }); @@ -208,7 +193,9 @@ void main() async { } group('With encoding', () { - final context = TestContext.testWithSoundNullSafety(provider); + final context = + TestContext(TestProject.testWithSoundNullSafety(), provider); + setUpAll(() async { await context.setUp( enableDebugExtension: true, @@ -225,7 +212,9 @@ void main() async { }); group('With "any" hostname', () { - final context = TestContext.testWithSoundNullSafety(provider); + final context = + TestContext(TestProject.testWithSoundNullSafety(), provider); + final uriPattern = RegExp(r'dartExtensionUri = "([^"]+)";'); setUpAll(() async { @@ -255,3 +244,22 @@ void main() async { }); }); } + +Future waitForDartDevToolsWithRetry( + TestContext context, { + int retryCount = 6, + Duration retryWait = const Duration(seconds: 1), +}) async { + if (retryCount == 0) return; + final windows = await context.webDriver.windows.toList(); + await context.webDriver.driver.switchTo.window(windows.last); + final title = await context.webDriver.title; + if (title == 'Dart DevTools') return; + + await Future.delayed(retryWait); + return waitForDartDevToolsWithRetry( + context, + retryCount: retryCount--, + retryWait: retryWait, + ); +} diff --git a/dwds/test/debug_service_test.dart b/dwds/test/debug_service_test.dart index 768b3a7d2..ac5014be9 100644 --- a/dwds/test/debug_service_test.dart +++ b/dwds/test/debug_service_test.dart @@ -12,12 +12,13 @@ import 'package:test/test.dart'; import 'package:test_common/test_sdk_configuration.dart'; import 'fixtures/context.dart'; +import 'fixtures/project.dart'; void main() { final provider = TestSdkConfigurationProvider(); tearDownAll(provider.dispose); - final context = TestContext.testWithSoundNullSafety(provider); + final context = TestContext(TestProject.testWithSoundNullSafety(), provider); setUpAll(() async { // Disable DDS as we're testing DWDS behavior. diff --git a/dwds/test/devtools_test.dart b/dwds/test/devtools_test.dart index 8912ed3ce..e92c44258 100644 --- a/dwds/test/devtools_test.dart +++ b/dwds/test/devtools_test.dart @@ -13,6 +13,7 @@ import 'package:vm_service/vm_service.dart'; import 'package:webdriver/io.dart'; import 'fixtures/context.dart'; +import 'fixtures/project.dart'; Future _waitForPageReady(TestContext context) async { var attempt = 100; @@ -28,7 +29,7 @@ void main() { final provider = TestSdkConfigurationProvider(); tearDownAll(provider.dispose); - final context = TestContext.testWithSoundNullSafety(provider); + final context = TestContext(TestProject.testWithSoundNullSafety(), provider); group('Injected client', () { setUp(() async { diff --git a/dwds/test/evaluate_circular_common.dart b/dwds/test/evaluate_circular_common.dart index 03d727ab9..f6638a6d5 100644 --- a/dwds/test/evaluate_circular_common.dart +++ b/dwds/test/evaluate_circular_common.dart @@ -12,6 +12,7 @@ import 'package:test_common/test_sdk_configuration.dart'; import 'package:vm_service/vm_service.dart'; import 'fixtures/context.dart'; +import 'fixtures/project.dart'; void testAll({ required TestSdkConfigurationProvider provider, @@ -26,11 +27,10 @@ void testAll({ throw StateError( 'build daemon scenario does not support non-empty base in index file'); } - final context = TestContext.testCircular( - provider: provider, - nullSafety: nullSafety, - baseMode: indexBaseMode, - ); + + final context = TestContext( + TestProject.testCircular(nullSafety: nullSafety, baseMode: indexBaseMode), + provider); Future onBreakPoint(String isolate, ScriptRef script, String breakPointId, Future Function() body) async { diff --git a/dwds/test/evaluate_common.dart b/dwds/test/evaluate_common.dart index 25322abb5..26415cd7a 100644 --- a/dwds/test/evaluate_common.dart +++ b/dwds/test/evaluate_common.dart @@ -12,6 +12,7 @@ import 'package:test_common/test_sdk_configuration.dart'; import 'package:vm_service/vm_service.dart'; import 'fixtures/context.dart'; +import 'fixtures/project.dart'; void testAll({ required TestSdkConfigurationProvider provider, @@ -26,27 +27,29 @@ void testAll({ throw StateError( 'build daemon scenario does not support non-empty base in index file'); } - final context = TestContext.testPackage( - provider: provider, nullSafety: nullSafety, baseMode: indexBaseMode); + + final context = TestContext( + TestProject.testPackage(nullSafety: nullSafety, baseMode: indexBaseMode), + provider); Future onBreakPoint(String isolate, ScriptRef script, String breakPointId, Future Function() body) async { - final service = context.service; Breakpoint? bp; try { final line = await context.findBreakpointLine(breakPointId, isolate, script); - bp = await service.addBreakpointWithScriptUri(isolate, script.uri!, line); + bp = await context.service + .addBreakpointWithScriptUri(isolate, script.uri!, line); await body(); } finally { // Remove breakpoint so it doesn't impact other tests or retries. if (bp != null) { - await service.removeBreakpoint(isolate, bp.id!); + await context.service.removeBreakpoint(isolate, bp.id!); } } } - group('with evaluation |', () { + group('Shared context with evaluation |', () { setUpAll(() async { setCurrentLogWriter(debug: debug); await context.setUp( @@ -638,7 +641,7 @@ void testAll({ }); }, timeout: const Timeout.factor(2)); - group('with no evaluation |', () { + group('shared context with no evaluation |', () { setUpAll(() async { setCurrentLogWriter(debug: debug); await context.setUp( diff --git a/dwds/test/events_test.dart b/dwds/test/events_test.dart index 386b7e982..c7acd00c9 100644 --- a/dwds/test/events_test.dart +++ b/dwds/test/events_test.dart @@ -15,12 +15,13 @@ import 'package:vm_service/vm_service.dart'; import 'package:webdriver/async_core.dart'; import 'fixtures/context.dart'; +import 'fixtures/project.dart'; void main() { final provider = TestSdkConfigurationProvider(); tearDownAll(provider.dispose); - final context = TestContext.testWithSoundNullSafety(provider); + final context = TestContext(TestProject.testWithSoundNullSafety(), provider); group('serve requests', () { late HttpServer server; diff --git a/dwds/test/fixtures/context.dart b/dwds/test/fixtures/context.dart index 84ffe619a..350076e03 100644 --- a/dwds/test/fixtures/context.dart +++ b/dwds/test/fixtures/context.dart @@ -38,6 +38,7 @@ import 'package:vm_service/vm_service.dart'; import 'package:webdriver/async_io.dart'; import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart'; +import 'project.dart'; import 'server.dart'; import 'utilities.dart'; @@ -51,41 +52,37 @@ final Matcher throwsSentinelException = throwsA(isSentinelException); enum CompilationMode { buildDaemon, frontendServer } -enum IndexBaseMode { noBase, base } - -enum NullSafety { weak, sound } - class TestContext { - final String packageName; - final String webAssetsPath; - final String dartEntryFileName; - final String htmlEntryFileName; + final TestProject project; final NullSafety nullSafety; - final TestSdkConfigurationProvider sdkConfigurationProvider; - // late TestSdkLayout sdkLayout; /// Top level directory in which we run the test server, e.g. /// "/workstation/webdev/fixtures/_testSound". - String get workingDirectory => absolutePath(pathFromFixtures: packageName); + String get workingDirectory => + absolutePath(pathFromFixtures: project.packageDirectory); /// The directory to build and serve, e.g. "example". - String get directoryToServe => p.split(webAssetsPath).first; + String get directoryToServe => p.split(project.webAssetsPath).first; /// The path to the HTML file to serve, relative to the [directoryToServe], /// e.g. "hello_world/index.html". String get filePathToServe { - final pathParts = p.split(webAssetsPath).where( + final pathParts = p.split(project.webAssetsPath).where( (pathPart) => pathPart != directoryToServe, ); - return webCompatiblePath([...pathParts, htmlEntryFileName]); + return webCompatiblePath([...pathParts, project.htmlEntryFileName]); } /// The path to the Dart entry file, e.g, /// "/workstation/webdev/fixtures/_testSound/example/hello_world/main.dart": String get _dartEntryFilePath => absolutePath( pathFromFixtures: p.joinAll( - [packageName, webAssetsPath, dartEntryFileName], + [ + project.packageDirectory, + project.webAssetsPath, + project.dartEntryFileName + ], ), ); @@ -138,100 +135,8 @@ class TestContext { final _logger = logging.Logger('Context'); - static String _index(IndexBaseMode baseMode) => - baseMode == IndexBaseMode.base ? 'base_index.html' : 'index.html'; - - TestContext.testPackage({ - required TestSdkConfigurationProvider provider, - required NullSafety nullSafety, - IndexBaseMode baseMode = IndexBaseMode.noBase, - }) : this._( - packageName: nullSafety == NullSafety.sound - ? '_testPackageSound' - : '_testPackage', - webAssetsPath: 'web', - dartEntryFileName: 'main.dart', - htmlEntryFileName: _index(baseMode), - nullSafety: nullSafety, - sdkConfigurationProvider: provider, - ); - - TestContext.testPackageWithSoundNullSafety( - TestSdkConfigurationProvider provider) - : this.testPackage(provider: provider, nullSafety: NullSafety.sound); - - TestContext.testCircular({ - required TestSdkConfigurationProvider provider, - required NullSafety nullSafety, - IndexBaseMode baseMode = IndexBaseMode.noBase, - }) : this._( - packageName: nullSafety == NullSafety.sound - ? '_testCircular2Sound' - : '_testCircular2', - webAssetsPath: 'web', - dartEntryFileName: 'main.dart', - htmlEntryFileName: _index(baseMode), - nullSafety: nullSafety, - sdkConfigurationProvider: provider, - ); - - TestContext.testWithSoundNullSafety(TestSdkConfigurationProvider provider) - : this._( - packageName: '_testSound', - webAssetsPath: 'example/hello_world', - dartEntryFileName: 'main.dart', - htmlEntryFileName: 'index.html', - nullSafety: NullSafety.sound, - sdkConfigurationProvider: provider, - ); - - TestContext.testScopesWithSoundNullSafety( - TestSdkConfigurationProvider provider) - : this._( - packageName: '_testSound', - webAssetsPath: webCompatiblePath(['example', 'scopes']), - dartEntryFileName: 'main.dart', - htmlEntryFileName: 'scopes.html', - nullSafety: NullSafety.sound, - sdkConfigurationProvider: provider, - ); - - TestContext.testAppendBodyWithSoundNullSafety( - TestSdkConfigurationProvider provider) - : this._( - packageName: '_testSound', - webAssetsPath: webCompatiblePath(['example', 'append_body']), - dartEntryFileName: 'main.dart', - htmlEntryFileName: 'index.html', - nullSafety: NullSafety.sound, - sdkConfigurationProvider: provider, - ); - - TestContext.testExperimentWithSoundNullSafety( - TestSdkConfigurationProvider provider) - : this._( - packageName: '_experimentSound', - webAssetsPath: 'web', - dartEntryFileName: 'main.dart', - htmlEntryFileName: 'index.html', - nullSafety: NullSafety.sound, - sdkConfigurationProvider: provider, - ); - - TestContext._({ - required this.packageName, - required this.webAssetsPath, - required this.dartEntryFileName, - required this.htmlEntryFileName, - required this.nullSafety, - required this.sdkConfigurationProvider, - }) { - // Verify that the test fixtures package matches the null-safety mode: - final isSoundPackage = packageName.toLowerCase().contains('sound'); - assert(nullSafety == NullSafety.sound ? isSoundPackage : !isSoundPackage); - // Verify that the web assets path has no starting slash: - assert(!webAssetsPath.startsWith('/')); - + TestContext(this.project, this.sdkConfigurationProvider) + : nullSafety = project.nullSafety { DartUri.currentDirectory = workingDirectory; _logger.info('Serving: $directoryToServe/$filePathToServe'); @@ -373,7 +278,8 @@ class TestContext { { _logger.warning('Index: $filePathToServe'); - final entry = p.toUri(p.join(webAssetsPath, dartEntryFileName)); + final entry = p.toUri( + p.join(project.webAssetsPath, project.dartEntryFileName)); final fileSystem = LocalFileSystem(); final packageUriMapper = await PackageUriMapper.create( fileSystem, diff --git a/dwds/test/fixtures/project.dart b/dwds/test/fixtures/project.dart new file mode 100644 index 000000000..608348f09 --- /dev/null +++ b/dwds/test/fixtures/project.dart @@ -0,0 +1,100 @@ +// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +import 'utilities.dart'; + +enum NullSafety { weak, sound } + +enum IndexBaseMode { noBase, base } + +/// Project definitions from projects defined in webdev/fixtures. +class TestProject { + final String packageDirectory; + final String webAssetsPath; + final String dartEntryFileName; + final String htmlEntryFileName; + final NullSafety nullSafety; + + static String _index(IndexBaseMode baseMode) => + baseMode == IndexBaseMode.base ? 'base_index.html' : 'index.html'; + + TestProject.testPackage({ + NullSafety nullSafety = NullSafety.sound, + IndexBaseMode baseMode = IndexBaseMode.noBase, + }) : this._( + packageDirectory: nullSafety == NullSafety.sound + ? '_testPackageSound' + : '_testPackage', + webAssetsPath: 'web', + dartEntryFileName: 'main.dart', + htmlEntryFileName: _index(baseMode), + nullSafety: nullSafety, + ); + + TestProject.testPackageWithSoundNullSafety() : this.testPackage(); + + TestProject.testCircular({ + NullSafety nullSafety = NullSafety.sound, + IndexBaseMode baseMode = IndexBaseMode.noBase, + }) : this._( + packageDirectory: nullSafety == NullSafety.sound + ? '_testCircular2Sound' + : '_testCircular2', + webAssetsPath: 'web', + dartEntryFileName: 'main.dart', + htmlEntryFileName: _index(baseMode), + nullSafety: nullSafety, + ); + + TestProject.testWithSoundNullSafety() + : this._( + packageDirectory: '_testSound', + webAssetsPath: 'example/hello_world', + dartEntryFileName: 'main.dart', + htmlEntryFileName: 'index.html', + nullSafety: NullSafety.sound, + ); + + TestProject.testScopesWithSoundNullSafety() + : this._( + packageDirectory: '_testSound', + webAssetsPath: webCompatiblePath(['example', 'scopes']), + dartEntryFileName: 'main.dart', + htmlEntryFileName: 'scopes.html', + nullSafety: NullSafety.sound, + ); + + TestProject.testAppendBodyWithSoundNullSafety() + : this._( + packageDirectory: '_testSound', + webAssetsPath: webCompatiblePath(['example', 'append_body']), + dartEntryFileName: 'main.dart', + htmlEntryFileName: 'index.html', + nullSafety: NullSafety.sound, + ); + + TestProject.testExperimentWithSoundNullSafety() + : this._( + packageDirectory: '_experimentSound', + webAssetsPath: 'web', + dartEntryFileName: 'main.dart', + htmlEntryFileName: 'index.html', + nullSafety: NullSafety.sound, + ); + + TestProject._({ + required this.packageDirectory, + required this.webAssetsPath, + required this.dartEntryFileName, + required this.htmlEntryFileName, + required this.nullSafety, + }) { + // Verify that the test fixtures package matches the null-safety mode: + final isSoundPackage = packageDirectory.toLowerCase().contains('sound'); + assert(nullSafety == NullSafety.sound ? isSoundPackage : !isSoundPackage); + + // Verify that the web assets path has no starting slash: + assert(!webAssetsPath.startsWith('/')); + } +} diff --git a/dwds/test/frontend_server_breakpoint_test.dart b/dwds/test/frontend_server_breakpoint_test.dart index 3216f8ff9..5519a87ea 100644 --- a/dwds/test/frontend_server_breakpoint_test.dart +++ b/dwds/test/frontend_server_breakpoint_test.dart @@ -12,6 +12,7 @@ import 'package:test_common/test_sdk_configuration.dart'; import 'package:vm_service/vm_service.dart'; import 'fixtures/context.dart'; +import 'fixtures/project.dart'; void main() { // Enable verbose logging for debugging. @@ -20,7 +21,8 @@ void main() { final provider = TestSdkConfigurationProvider(verbose: debug); tearDownAll(provider.dispose); - final context = TestContext.testPackageWithSoundNullSafety(provider); + final context = + TestContext(TestProject.testPackageWithSoundNullSafety(), provider); // Change to 'true' to print expression compiler messages to console. // diff --git a/dwds/test/frontend_server_callstack_test.dart b/dwds/test/frontend_server_callstack_test.dart index 30332e057..758be5768 100644 --- a/dwds/test/frontend_server_callstack_test.dart +++ b/dwds/test/frontend_server_callstack_test.dart @@ -12,6 +12,7 @@ import 'package:test_common/test_sdk_configuration.dart'; import 'package:vm_service/vm_service.dart'; import 'fixtures/context.dart'; +import 'fixtures/project.dart'; void main() { // Enable verbose logging for debugging. @@ -23,9 +24,8 @@ void main() { group('shared context |', () { for (var nullSafety in NullSafety.values) { group('${nullSafety.name} null safety |', () { - final soundNullSafety = nullSafety == NullSafety.sound; - final context = - TestContext.testPackage(provider: provider, nullSafety: nullSafety); + final context = TestContext( + TestProject.testPackage(nullSafety: nullSafety), provider); setUpAll(() async { setCurrentLogWriter(debug: debug); @@ -60,8 +60,9 @@ void main() { await service.streamListen('Debug'); stream = service.onEvent('Debug'); - final testPackage = - soundNullSafety ? '_test_package_sound' : '_test_package'; + final testPackage = nullSafety == NullSafety.sound + ? '_test_package_sound' + : '_test_package'; mainScript = scripts.scripts! .firstWhere((each) => each.uri!.contains('main.dart')); diff --git a/dwds/test/frontend_server_circular_evaluate_test.dart b/dwds/test/frontend_server_circular_evaluate_test.dart index db453a5c7..7efabf0dd 100644 --- a/dwds/test/frontend_server_circular_evaluate_test.dart +++ b/dwds/test/frontend_server_circular_evaluate_test.dart @@ -12,6 +12,7 @@ import 'package:test_common/test_sdk_configuration.dart'; import 'evaluate_circular_common.dart'; import 'fixtures/context.dart'; +import 'fixtures/project.dart'; void main() async { // Enable verbose logging for debugging. diff --git a/dwds/test/frontend_server_evaluate_sound_test.dart b/dwds/test/frontend_server_evaluate_sound_test.dart index 8ac2462cf..f4fa02130 100644 --- a/dwds/test/frontend_server_evaluate_sound_test.dart +++ b/dwds/test/frontend_server_evaluate_sound_test.dart @@ -12,6 +12,7 @@ import 'package:test_common/test_sdk_configuration.dart'; import 'evaluate_common.dart'; import 'fixtures/context.dart'; +import 'fixtures/project.dart'; void main() async { // Enable verbose logging for debugging. diff --git a/dwds/test/frontend_server_evaluate_weak_test.dart b/dwds/test/frontend_server_evaluate_weak_test.dart index 284672cf2..c6bcc83d3 100644 --- a/dwds/test/frontend_server_evaluate_weak_test.dart +++ b/dwds/test/frontend_server_evaluate_weak_test.dart @@ -12,6 +12,7 @@ import 'package:test_common/test_sdk_configuration.dart'; import 'evaluate_common.dart'; import 'fixtures/context.dart'; +import 'fixtures/project.dart'; void main() async { // Enable verbose logging for debugging. diff --git a/dwds/test/handlers/asset_handler_test.dart b/dwds/test/handlers/asset_handler_test.dart index 3556d054f..6fd875787 100644 --- a/dwds/test/handlers/asset_handler_test.dart +++ b/dwds/test/handlers/asset_handler_test.dart @@ -10,11 +10,13 @@ import 'package:test_common/logging.dart'; import 'package:test_common/test_sdk_configuration.dart'; import '../fixtures/context.dart'; +import '../fixtures/project.dart'; void main() { group('Asset handler', () { final provider = TestSdkConfigurationProvider(); - final context = TestContext.testWithSoundNullSafety(provider); + final context = + TestContext(TestProject.testWithSoundNullSafety(), provider); setUpAll(() async { setCurrentLogWriter(); @@ -26,6 +28,7 @@ void main() { tearDownAll(() async { await context.tearDown(); + provider.dispose(); }); setUp(setCurrentLogWriter); diff --git a/dwds/test/inspector_test.dart b/dwds/test/inspector_test.dart index 2fb8db312..756231db3 100644 --- a/dwds/test/inspector_test.dart +++ b/dwds/test/inspector_test.dart @@ -16,12 +16,15 @@ import 'package:vm_service/vm_service.dart'; import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart'; import 'fixtures/context.dart'; +import 'fixtures/project.dart'; void main() { final provider = TestSdkConfigurationProvider(); tearDownAll(provider.dispose); - final context = TestContext.testScopesWithSoundNullSafety(provider); + final context = + TestContext(TestProject.testScopesWithSoundNullSafety(), provider); + late AppInspector inspector; late Debugger debugger; diff --git a/dwds/test/instance_test.dart b/dwds/test/instance_test.dart index 896afa803..0ddd4a55f 100644 --- a/dwds/test/instance_test.dart +++ b/dwds/test/instance_test.dart @@ -14,12 +14,15 @@ import 'package:vm_service/vm_service.dart'; import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart'; import 'fixtures/context.dart'; +import 'fixtures/project.dart'; void main() { final provider = TestSdkConfigurationProvider(); tearDownAll(provider.dispose); - final context = TestContext.testScopesWithSoundNullSafety(provider); + final context = + TestContext(TestProject.testScopesWithSoundNullSafety(), provider); + late AppInspector inspector; late Debugger debugger; diff --git a/dwds/test/listviews_test.dart b/dwds/test/listviews_test.dart index 92a42c896..0da9c93bd 100644 --- a/dwds/test/listviews_test.dart +++ b/dwds/test/listviews_test.dart @@ -8,12 +8,14 @@ import 'package:test/test.dart'; import 'package:test_common/test_sdk_configuration.dart'; import 'fixtures/context.dart'; +import 'fixtures/project.dart'; void main() { final provider = TestSdkConfigurationProvider(); tearDownAll(provider.dispose); - final context = TestContext.testWithSoundNullSafety(provider); + final context = TestContext(TestProject.testWithSoundNullSafety(), provider); + setUpAll(() async { await context.setUp(); }); diff --git a/dwds/test/puppeteer/extension_test.dart b/dwds/test/puppeteer/extension_test.dart index 7a5b7fb66..b004a2886 100644 --- a/dwds/test/puppeteer/extension_test.dart +++ b/dwds/test/puppeteer/extension_test.dart @@ -23,6 +23,7 @@ import 'package:test_common/test_sdk_configuration.dart'; import '../../debug_extension_mv3/web/data_serializers.dart'; import '../../debug_extension_mv3/web/data_types.dart'; import '../fixtures/context.dart'; +import '../fixtures/project.dart'; import '../fixtures/utilities.dart'; import 'test_utils.dart'; @@ -31,7 +32,8 @@ enum Panel { debugger, inspector } void main() async { group('MV3 Debug Extension', () { final provider = TestSdkConfigurationProvider(); - final context = TestContext.testWithSoundNullSafety(provider); + final context = + TestContext(TestProject.testWithSoundNullSafety(), provider); late String extensionPath; setUpAll(() async { diff --git a/dwds/test/puppeteer/lifeline_test.dart b/dwds/test/puppeteer/lifeline_test.dart index 5bb5061dd..7aeedc4cf 100644 --- a/dwds/test/puppeteer/lifeline_test.dart +++ b/dwds/test/puppeteer/lifeline_test.dart @@ -11,11 +11,12 @@ import 'package:test/test.dart'; import 'package:test_common/test_sdk_configuration.dart'; import '../fixtures/context.dart'; +import '../fixtures/project.dart'; import 'test_utils.dart'; void main() async { final provider = TestSdkConfigurationProvider(); - final context = TestContext.testWithSoundNullSafety(provider); + final context = TestContext(TestProject.testWithSoundNullSafety(), provider); late Worker worker; late Browser browser; late String extensionPath; diff --git a/dwds/test/readers/proxy_server_asset_reader_test.dart b/dwds/test/readers/proxy_server_asset_reader_test.dart index 235e71ac2..28799e988 100644 --- a/dwds/test/readers/proxy_server_asset_reader_test.dart +++ b/dwds/test/readers/proxy_server_asset_reader_test.dart @@ -9,13 +9,15 @@ import 'package:test/test.dart'; import 'package:test_common/test_sdk_configuration.dart'; import '../fixtures/context.dart'; +import '../fixtures/project.dart'; void main() { group('ProxyServerAssetReader', () { final provider = TestSdkConfigurationProvider(); tearDownAll(provider.dispose); - final context = TestContext.testWithSoundNullSafety(provider); + final context = + TestContext(TestProject.testWithSoundNullSafety(), provider); late ProxyServerAssetReader assetReader; setUpAll(() async { diff --git a/dwds/test/records_test.dart b/dwds/test/records_test.dart index 4396b383f..9d7d6f070 100644 --- a/dwds/test/records_test.dart +++ b/dwds/test/records_test.dart @@ -11,6 +11,7 @@ import 'package:test_common/test_sdk_configuration.dart'; import 'package:vm_service/vm_service.dart'; import 'fixtures/context.dart'; +import 'fixtures/project.dart'; void main() async { // Enable verbose logging for debugging. @@ -33,7 +34,8 @@ Future _runTests({ required CompilationMode compilationMode, required bool debug, }) async { - final context = TestContext.testExperimentWithSoundNullSafety(provider); + final context = + TestContext(TestProject.testExperimentWithSoundNullSafety(), provider); late VmServiceInterface service; late Stream stream; late String isolateId; diff --git a/dwds/test/refresh_test.dart b/dwds/test/refresh_test.dart index 2db21c90b..d04d2303b 100644 --- a/dwds/test/refresh_test.dart +++ b/dwds/test/refresh_test.dart @@ -15,12 +15,13 @@ import 'package:test_common/test_sdk_configuration.dart'; import 'package:vm_service/vm_service.dart'; import 'fixtures/context.dart'; +import 'fixtures/project.dart'; void main() { final provider = TestSdkConfigurationProvider(); tearDownAll(provider.dispose); - final context = TestContext.testWithSoundNullSafety(provider); + final context = TestContext(TestProject.testWithSoundNullSafety(), provider); group('fresh context', () { late VmServiceInterface service; diff --git a/dwds/test/reload_test.dart b/dwds/test/reload_test.dart index 0d6d7e39f..e51bc7190 100644 --- a/dwds/test/reload_test.dart +++ b/dwds/test/reload_test.dart @@ -11,6 +11,7 @@ import 'package:test_common/test_sdk_configuration.dart'; import 'package:vm_service/vm_service.dart'; import 'fixtures/context.dart'; +import 'fixtures/project.dart'; const originalString = 'Hello World!'; const newString = 'Bonjour le monde!'; @@ -22,7 +23,8 @@ void main() { final provider = TestSdkConfigurationProvider(verbose: debug); tearDownAll(provider.dispose); - final context = TestContext.testAppendBodyWithSoundNullSafety(provider); + final context = + TestContext(TestProject.testAppendBodyWithSoundNullSafety(), provider); Future makeEditAndWaitForRebuild() async { context.makeEditToDartEntryFile( diff --git a/dwds/test/restore_breakpoints_test.dart b/dwds/test/restore_breakpoints_test.dart index 15fe61567..8d40a868d 100644 --- a/dwds/test/restore_breakpoints_test.dart +++ b/dwds/test/restore_breakpoints_test.dart @@ -12,12 +12,13 @@ import 'package:test_common/test_sdk_configuration.dart'; import 'package:vm_service/vm_service.dart'; import 'fixtures/context.dart'; +import 'fixtures/project.dart'; void main() { final provider = TestSdkConfigurationProvider(); tearDownAll(provider.dispose); - final context = TestContext.testWithSoundNullSafety(provider); + final context = TestContext(TestProject.testWithSoundNullSafety(), provider); setUpAll(() async { setCurrentLogWriter(); diff --git a/dwds/test/run_request_test.dart b/dwds/test/run_request_test.dart index 57d8042c1..45c459fac 100644 --- a/dwds/test/run_request_test.dart +++ b/dwds/test/run_request_test.dart @@ -10,12 +10,13 @@ import 'package:test_common/test_sdk_configuration.dart'; import 'package:vm_service/vm_service.dart'; import 'fixtures/context.dart'; +import 'fixtures/project.dart'; void main() { final provider = TestSdkConfigurationProvider(); tearDownAll(provider.dispose); - final context = TestContext.testWithSoundNullSafety(provider); + final context = TestContext(TestProject.testWithSoundNullSafety(), provider); group('while debugger is attached', () { late VmServiceInterface service; diff --git a/dwds/test/screenshot_test.dart b/dwds/test/screenshot_test.dart index 0ef06aca4..36bc65237 100644 --- a/dwds/test/screenshot_test.dart +++ b/dwds/test/screenshot_test.dart @@ -8,12 +8,13 @@ import 'package:test/test.dart'; import 'package:test_common/test_sdk_configuration.dart'; import 'fixtures/context.dart'; +import 'fixtures/project.dart'; void main() { final provider = TestSdkConfigurationProvider(); tearDownAll(provider.dispose); - final context = TestContext.testWithSoundNullSafety(provider); + final context = TestContext(TestProject.testWithSoundNullSafety(), provider); setUpAll(() async { await context.setUp(); diff --git a/dwds/test/variable_scope_test.dart b/dwds/test/variable_scope_test.dart index 621e7d56b..447858cf6 100644 --- a/dwds/test/variable_scope_test.dart +++ b/dwds/test/variable_scope_test.dart @@ -11,12 +11,14 @@ import 'package:test_common/test_sdk_configuration.dart'; import 'package:vm_service/vm_service.dart'; import 'fixtures/context.dart'; +import 'fixtures/project.dart'; void main() { final provider = TestSdkConfigurationProvider(); tearDownAll(provider.dispose); - final context = TestContext.testScopesWithSoundNullSafety(provider); + final context = + TestContext(TestProject.testScopesWithSoundNullSafety(), provider); setUpAll(() async { await context.setUp(); From caeb6f9e83f9560b0484a9a9b0b2c065f46ce43a Mon Sep 17 00:00:00 2001 From: Anna Gringauze Date: Thu, 16 Feb 2023 15:03:47 -0800 Subject: [PATCH 10/15] Add package name to the project and use it in tests --- dwds/test/build_daemon_callstack_test.dart | 5 +- dwds/test/chrome_proxy_service_test.dart | 13 +- dwds/test/dart_uri_file_uri_test.dart | 35 ++-- dwds/test/debug_extension_test.dart | 9 +- dwds/test/debug_service_test.dart | 2 +- dwds/test/devtools_test.dart | 2 +- dwds/test/evaluate_circular_common.dart | 15 +- dwds/test/evaluate_common.dart | 14 +- dwds/test/events_test.dart | 2 +- dwds/test/fixtures/context.dart | 2 + dwds/test/fixtures/project.dart | 182 +++++++++++++----- dwds/test/frontend_server_callstack_test.dart | 7 +- dwds/test/handlers/asset_handler_test.dart | 3 +- dwds/test/inspector_test.dart | 2 +- dwds/test/instance_test.dart | 2 +- dwds/test/listviews_test.dart | 2 +- dwds/test/package_uri_mapper_test.dart | 17 +- dwds/test/puppeteer/extension_test.dart | 3 +- dwds/test/puppeteer/lifeline_test.dart | 2 +- .../frontend_server_asset_reader_test.dart | 6 +- .../proxy_server_asset_reader_test.dart | 3 +- dwds/test/records_test.dart | 2 +- dwds/test/refresh_test.dart | 2 +- dwds/test/reload_test.dart | 2 +- dwds/test/restore_breakpoints_test.dart | 2 +- dwds/test/run_request_test.dart | 2 +- dwds/test/screenshot_test.dart | 2 +- dwds/test/variable_scope_test.dart | 2 +- fixtures/_experimentSound/pubspec.yaml | 2 +- 29 files changed, 210 insertions(+), 134 deletions(-) diff --git a/dwds/test/build_daemon_callstack_test.dart b/dwds/test/build_daemon_callstack_test.dart index 2f1ce7185..e6342c5ef 100644 --- a/dwds/test/build_daemon_callstack_test.dart +++ b/dwds/test/build_daemon_callstack_test.dart @@ -24,7 +24,6 @@ void main() { for (var nullSafety in NullSafety.values) { group('${nullSafety.name} null safety |', () { - final soundNullSafety = nullSafety == NullSafety.sound; final context = TestContext( TestProject.testPackage(nullSafety: nullSafety), provider); @@ -60,9 +59,7 @@ void main() { await service.streamListen('Debug'); stream = service.onEvent('Debug'); - final testPackage = - soundNullSafety ? '_test_package_sound' : '_test_package'; - + final testPackage = context.project.packageName; mainScript = scripts.scripts! .firstWhere((each) => each.uri!.contains('main.dart')); testLibraryScript = scripts.scripts!.firstWhere((each) => diff --git a/dwds/test/chrome_proxy_service_test.dart b/dwds/test/chrome_proxy_service_test.dart index 714c5d6e5..134d5c078 100644 --- a/dwds/test/chrome_proxy_service_test.dart +++ b/dwds/test/chrome_proxy_service_test.dart @@ -29,7 +29,7 @@ void main() { final provider = TestSdkConfigurationProvider(verbose: debug); tearDownAll(provider.dispose); - final context = TestContext(TestProject.testWithSoundNullSafety(), provider); + final context = TestContext(TestProject.testWithSoundNullSafety, provider); group('shared context', () { setUpAll(() async { @@ -126,8 +126,7 @@ void main() { }); test('addBreakpointWithScriptUri absolute file URI', () async { - final current = context.workingDirectory; - final test = path.join(path.dirname(current), '_testSound'); + final test = context.project.absolutePackageDirectory; final scriptPath = Uri.parse(mainScript.uri!).path.substring(1); final fullPath = path.join(test, scriptPath); final fileUri = Uri.file(fullPath); @@ -163,15 +162,15 @@ void main() { }); }); - group('callcontext.serviceExtension', () { + group('callServiceExtension', () { setUp(() { setCurrentLogWriter(debug: debug); }); test('success', () async { - final serviceMethod = 'ext.test.callcontext.serviceExtension'; + final serviceMethod = 'ext.test.callServiceExtension'; await context.tabConnection.runtime - .evaluate('registerExtension("$context.serviceMethod");'); + .evaluate('registerExtension("$serviceMethod");'); // The non-string keys/values get auto json-encoded to match the vm // behavior. @@ -196,7 +195,7 @@ void main() { }); test('failure', () async { - final serviceMethod = 'ext.test.callcontext.serviceExtensionWithError'; + final serviceMethod = 'ext.test.callServiceExtensionWithError'; await context.tabConnection.runtime .evaluate('registerExtensionWithError("$serviceMethod");'); diff --git a/dwds/test/dart_uri_file_uri_test.dart b/dwds/test/dart_uri_file_uri_test.dart index 2fded12ee..f4ceb2df6 100644 --- a/dwds/test/dart_uri_file_uri_test.dart +++ b/dwds/test/dart_uri_file_uri_test.dart @@ -12,15 +12,6 @@ import 'package:test_common/test_sdk_configuration.dart'; import 'fixtures/context.dart'; import 'fixtures/project.dart'; -import 'fixtures/utilities.dart'; - -/// The directory for the general _test package. -final testDir = absolutePath(pathFromFixtures: p.join('_testSound')); - -/// The directory for the _testPackage package (contained within dwds), which -/// imports _test. -final testPackageDir = - absolutePath(pathFromFixtures: p.join('_testPackageSound')); // This tests converting file Uris into our internal paths. // @@ -30,7 +21,17 @@ void main() { final provider = TestSdkConfigurationProvider(); tearDownAll(provider.dispose); - final context = TestContext(TestProject.testWithSoundNullSafety(), provider); + final testProject = TestProject.testWithSoundNullSafety; + final testPackageProject = TestProject.testPackageWithSoundNullSafety(); + + /// The directory for the general _test package. + final testDir = testProject.absolutePackageDirectory; + + /// The directory for the _testPackage package (contained within dwds), + /// which imports _test. + final testPackageDir = testPackageProject.absolutePackageDirectory; + + final context = TestContext(testPackageProject, provider); for (final compilationMode in CompilationMode.values) { group('$compilationMode |', () { @@ -41,17 +42,17 @@ void main() { ? 'web/main.dart' : 'main.dart'; - final serverPath = - compilationMode == CompilationMode.frontendServer && - useDebuggerModuleNames - ? 'packages/_testPackageSound/lib/test_library.dart' - : 'packages/_test_package_sound/test_library.dart'; + final serverPath = compilationMode == + CompilationMode.frontendServer && + useDebuggerModuleNames + ? 'packages/${testPackageProject.packageDirectory}/lib/test_library.dart' + : 'packages/${testPackageProject.packageName}/test_library.dart'; final anotherServerPath = compilationMode == CompilationMode.frontendServer && useDebuggerModuleNames - ? 'packages/_testSound/lib/library.dart' - : 'packages/_test_sound/library.dart'; + ? 'packages/${testProject.packageDirectory}/lib/library.dart' + : 'packages/${testProject.packageName}/library.dart'; setUpAll(() async { await context.setUp( diff --git a/dwds/test/debug_extension_test.dart b/dwds/test/debug_extension_test.dart index 31fabb3df..5936dc6d7 100644 --- a/dwds/test/debug_extension_test.dart +++ b/dwds/test/debug_extension_test.dart @@ -37,8 +37,7 @@ void main() async { tearDownAll(provider.dispose); for (var useSse in [true, false]) { - final context = - TestContext(TestProject.testWithSoundNullSafety(), provider); + final context = TestContext(TestProject.testWithSoundNullSafety, provider); group(useSse ? 'SSE' : 'WebSockets', () { group('Without encoding', () { @@ -193,8 +192,7 @@ void main() async { } group('With encoding', () { - final context = - TestContext(TestProject.testWithSoundNullSafety(), provider); + final context = TestContext(TestProject.testWithSoundNullSafety, provider); setUpAll(() async { await context.setUp( @@ -212,8 +210,7 @@ void main() async { }); group('With "any" hostname', () { - final context = - TestContext(TestProject.testWithSoundNullSafety(), provider); + final context = TestContext(TestProject.testWithSoundNullSafety, provider); final uriPattern = RegExp(r'dartExtensionUri = "([^"]+)";'); diff --git a/dwds/test/debug_service_test.dart b/dwds/test/debug_service_test.dart index ac5014be9..5ecc447b8 100644 --- a/dwds/test/debug_service_test.dart +++ b/dwds/test/debug_service_test.dart @@ -18,7 +18,7 @@ void main() { final provider = TestSdkConfigurationProvider(); tearDownAll(provider.dispose); - final context = TestContext(TestProject.testWithSoundNullSafety(), provider); + final context = TestContext(TestProject.testWithSoundNullSafety, provider); setUpAll(() async { // Disable DDS as we're testing DWDS behavior. diff --git a/dwds/test/devtools_test.dart b/dwds/test/devtools_test.dart index e92c44258..d869158e1 100644 --- a/dwds/test/devtools_test.dart +++ b/dwds/test/devtools_test.dart @@ -29,7 +29,7 @@ void main() { final provider = TestSdkConfigurationProvider(); tearDownAll(provider.dispose); - final context = TestContext(TestProject.testWithSoundNullSafety(), provider); + final context = TestContext(TestProject.testWithSoundNullSafety, provider); group('Injected client', () { setUp(() async { diff --git a/dwds/test/evaluate_circular_common.dart b/dwds/test/evaluate_circular_common.dart index f6638a6d5..0561758b0 100644 --- a/dwds/test/evaluate_circular_common.dart +++ b/dwds/test/evaluate_circular_common.dart @@ -28,9 +28,11 @@ void testAll({ 'build daemon scenario does not support non-empty base in index file'); } - final context = TestContext( - TestProject.testCircular(nullSafety: nullSafety, baseMode: indexBaseMode), - provider); + final testCircular1 = TestProject.testCircular1(nullSafety: nullSafety); + final testCircular2 = TestProject.testCircular2( + nullSafety: nullSafety, baseMode: indexBaseMode); + + final context = TestContext(testCircular2, provider); Future onBreakPoint(String isolate, ScriptRef script, String breakPointId, Future Function() body) async { @@ -87,11 +89,8 @@ void testAll({ await service.streamListen('Debug'); stream = service.onEvent('Debug'); - final soundNullSafety = nullSafety == NullSafety.sound; - final test1 = - soundNullSafety ? '_test_circular1_sound' : '_test_circular1'; - final test2 = - soundNullSafety ? '_test_circular2_sound' : '_test_circular2'; + final test1 = testCircular1.packageName; + final test2 = testCircular2.packageName; test1LibraryScript = scripts.scripts!.firstWhere( (each) => each.uri!.contains('package:$test1/library1.dart')); diff --git a/dwds/test/evaluate_common.dart b/dwds/test/evaluate_common.dart index 26415cd7a..332625441 100644 --- a/dwds/test/evaluate_common.dart +++ b/dwds/test/evaluate_common.dart @@ -28,9 +28,11 @@ void testAll({ 'build daemon scenario does not support non-empty base in index file'); } - final context = TestContext( - TestProject.testPackage(nullSafety: nullSafety, baseMode: indexBaseMode), - provider); + final testProject = TestProject.test(nullSafety: nullSafety); + final testPackageProject = + TestProject.testPackage(nullSafety: nullSafety, baseMode: indexBaseMode); + + final context = TestContext(testPackageProject, provider); Future onBreakPoint(String isolate, ScriptRef script, String breakPointId, Future Function() body) async { @@ -89,10 +91,8 @@ void testAll({ await service.streamListen('Debug'); stream = service.onEvent('Debug'); - final soundNullSafety = nullSafety == NullSafety.sound; - final testPackage = - soundNullSafety ? '_test_package_sound' : '_test_package'; - final test = soundNullSafety ? '_test_sound' : '_test'; + final testPackage = testPackageProject.packageName; + final test = testProject.packageName; mainScript = scripts.scripts! .firstWhere((each) => each.uri!.contains('main.dart')); testLibraryScript = scripts.scripts!.firstWhere((each) => diff --git a/dwds/test/events_test.dart b/dwds/test/events_test.dart index c7acd00c9..272ba4ead 100644 --- a/dwds/test/events_test.dart +++ b/dwds/test/events_test.dart @@ -21,7 +21,7 @@ void main() { final provider = TestSdkConfigurationProvider(); tearDownAll(provider.dispose); - final context = TestContext(TestProject.testWithSoundNullSafety(), provider); + final context = TestContext(TestProject.testWithSoundNullSafety, provider); group('serve requests', () { late HttpServer server; diff --git a/dwds/test/fixtures/context.dart b/dwds/test/fixtures/context.dart index 350076e03..79f5e943b 100644 --- a/dwds/test/fixtures/context.dart +++ b/dwds/test/fixtures/context.dart @@ -139,6 +139,8 @@ class TestContext { : nullSafety = project.nullSafety { DartUri.currentDirectory = workingDirectory; + project.validate(); + _logger.info('Serving: $directoryToServe/$filePathToServe'); _logger.info('Project: $workingDirectory'); _logger.info('Packages: $_packageConfigFile'); diff --git a/dwds/test/fixtures/project.dart b/dwds/test/fixtures/project.dart index 608348f09..7a3a9f9a2 100644 --- a/dwds/test/fixtures/project.dart +++ b/dwds/test/fixtures/project.dart @@ -10,86 +10,172 @@ enum IndexBaseMode { noBase, base } /// Project definitions from projects defined in webdev/fixtures. class TestProject { + final String packageName; final String packageDirectory; final String webAssetsPath; final String dartEntryFileName; final String htmlEntryFileName; final NullSafety nullSafety; - static String _index(IndexBaseMode baseMode) => - baseMode == IndexBaseMode.base ? 'base_index.html' : 'index.html'; + String get absolutePackageDirectory => + absolutePath(pathFromFixtures: packageDirectory); - TestProject.testPackage({ - NullSafety nullSafety = NullSafety.sound, - IndexBaseMode baseMode = IndexBaseMode.noBase, - }) : this._( - packageDirectory: nullSafety == NullSafety.sound - ? '_testPackageSound' - : '_testPackage', - webAssetsPath: 'web', - dartEntryFileName: 'main.dart', - htmlEntryFileName: _index(baseMode), - nullSafety: nullSafety, - ); - - TestProject.testPackageWithSoundNullSafety() : this.testPackage(); - - TestProject.testCircular({ - NullSafety nullSafety = NullSafety.sound, - IndexBaseMode baseMode = IndexBaseMode.noBase, - }) : this._( - packageDirectory: nullSafety == NullSafety.sound - ? '_testCircular2Sound' - : '_testCircular2', - webAssetsPath: 'web', - dartEntryFileName: 'main.dart', - htmlEntryFileName: _index(baseMode), - nullSafety: nullSafety, - ); + // _test_package - TestProject.testWithSoundNullSafety() + const TestProject.testPackageWithSoundNullSafety( + {IndexBaseMode baseMode = IndexBaseMode.noBase}) : this._( - packageDirectory: '_testSound', - webAssetsPath: 'example/hello_world', + packageName: '_test_package_sound', + packageDirectory: '_testPackageSound', + webAssetsPath: 'web', dartEntryFileName: 'main.dart', - htmlEntryFileName: 'index.html', + htmlEntryFileName: + baseMode == IndexBaseMode.base ? 'base_index.html' : 'index.html', nullSafety: NullSafety.sound, ); - TestProject.testScopesWithSoundNullSafety() + const TestProject.testPackageWithWeakNullSafety( + {IndexBaseMode baseMode = IndexBaseMode.noBase}) : this._( - packageDirectory: '_testSound', - webAssetsPath: webCompatiblePath(['example', 'scopes']), + packageName: '_test_package', + packageDirectory: '_testPackage', + webAssetsPath: 'web', dartEntryFileName: 'main.dart', - htmlEntryFileName: 'scopes.html', - nullSafety: NullSafety.sound, + htmlEntryFileName: + baseMode == IndexBaseMode.base ? 'base_index.html' : 'index.html', + nullSafety: NullSafety.weak, ); - TestProject.testAppendBodyWithSoundNullSafety() + factory TestProject.testPackage({ + NullSafety nullSafety = NullSafety.sound, + IndexBaseMode baseMode = IndexBaseMode.noBase, + }) => + nullSafety == NullSafety.sound + ? TestProject.testPackageWithSoundNullSafety(baseMode: baseMode) + : TestProject.testPackageWithWeakNullSafety(baseMode: baseMode); + + /// _test_circular1 + + static const testCircular1WithSoundNullSafety = TestProject._( + packageName: '_test_circular1_sound', + packageDirectory: '_testCircular1Sound', + webAssetsPath: 'web', + dartEntryFileName: 'main.dart', + htmlEntryFileName: 'index.html', + nullSafety: NullSafety.sound, + ); + + static const testCircular1WithWeakNullSafety = TestProject._( + packageName: '_test_circular1', + packageDirectory: '_testCircular1', + webAssetsPath: 'web', + dartEntryFileName: 'main.dart', + htmlEntryFileName: 'index.html', + nullSafety: NullSafety.weak, + ); + + factory TestProject.testCircular1( + {NullSafety nullSafety = NullSafety.sound}) => + nullSafety == NullSafety.sound + ? TestProject.testCircular1WithSoundNullSafety + : TestProject.testCircular1WithWeakNullSafety; + + /// _test_circular2 + + const TestProject.testCircular2WithSoundNullSafety( + {IndexBaseMode baseMode = IndexBaseMode.noBase}) : this._( - packageDirectory: '_testSound', - webAssetsPath: webCompatiblePath(['example', 'append_body']), + packageName: '_test_circular2_sound', + packageDirectory: '_testCircular2Sound', + webAssetsPath: 'web', dartEntryFileName: 'main.dart', - htmlEntryFileName: 'index.html', + htmlEntryFileName: + baseMode == IndexBaseMode.base ? 'base_index.html' : 'index.html', nullSafety: NullSafety.sound, ); - TestProject.testExperimentWithSoundNullSafety() + const TestProject.testCircular2WithWeakNullSafety( + {IndexBaseMode baseMode = IndexBaseMode.noBase}) : this._( - packageDirectory: '_experimentSound', + packageName: '_test_circular2', + packageDirectory: '_testCircular2', webAssetsPath: 'web', dartEntryFileName: 'main.dart', - htmlEntryFileName: 'index.html', - nullSafety: NullSafety.sound, + htmlEntryFileName: + baseMode == IndexBaseMode.base ? 'base_index.html' : 'index.html', + nullSafety: NullSafety.weak, ); - TestProject._({ + factory TestProject.testCircular2({ + NullSafety nullSafety = NullSafety.sound, + IndexBaseMode baseMode = IndexBaseMode.noBase, + }) => + nullSafety == NullSafety.sound + ? TestProject.testCircular2WithSoundNullSafety(baseMode: baseMode) + : TestProject.testCircular2WithWeakNullSafety(baseMode: baseMode); + + /// _test + + static const testWithSoundNullSafety = TestProject._( + packageName: '_test_sound', + packageDirectory: '_testSound', + webAssetsPath: 'example/hello_world', + dartEntryFileName: 'main.dart', + htmlEntryFileName: 'index.html', + nullSafety: NullSafety.sound, + ); + + static const testWithWeakNullSafety = TestProject._( + packageName: '_test', + packageDirectory: '_test', + webAssetsPath: 'example/hello_world', + dartEntryFileName: 'main.dart', + htmlEntryFileName: 'index.html', + nullSafety: NullSafety.weak, + ); + + factory TestProject.test({NullSafety nullSafety = NullSafety.sound}) => + nullSafety == NullSafety.sound + ? TestProject.testWithSoundNullSafety + : TestProject.testWithWeakNullSafety; + + static final testScopesWithSoundNullSafety = TestProject._( + packageName: '_test_sound', + packageDirectory: '_testSound', + webAssetsPath: webCompatiblePath(['example', 'scopes']), + dartEntryFileName: 'main.dart', + htmlEntryFileName: 'scopes.html', + nullSafety: NullSafety.sound, + ); + + static final testAppendBodyWithSoundNullSafety = TestProject._( + packageName: '_test_sound', + packageDirectory: '_testSound', + webAssetsPath: webCompatiblePath(['example', 'append_body']), + dartEntryFileName: 'main.dart', + htmlEntryFileName: 'index.html', + nullSafety: NullSafety.sound, + ); + + static const testExperimentWithSoundNullSafety = TestProject._( + packageName: '_experiment_sound', + packageDirectory: '_experimentSound', + webAssetsPath: 'web', + dartEntryFileName: 'main.dart', + htmlEntryFileName: 'index.html', + nullSafety: NullSafety.sound, + ); + + const TestProject._({ + required this.packageName, required this.packageDirectory, required this.webAssetsPath, required this.dartEntryFileName, required this.htmlEntryFileName, required this.nullSafety, - }) { + }); + + void validate() { // Verify that the test fixtures package matches the null-safety mode: final isSoundPackage = packageDirectory.toLowerCase().contains('sound'); assert(nullSafety == NullSafety.sound ? isSoundPackage : !isSoundPackage); diff --git a/dwds/test/frontend_server_callstack_test.dart b/dwds/test/frontend_server_callstack_test.dart index 758be5768..c1cad4097 100644 --- a/dwds/test/frontend_server_callstack_test.dart +++ b/dwds/test/frontend_server_callstack_test.dart @@ -60,14 +60,11 @@ void main() { await service.streamListen('Debug'); stream = service.onEvent('Debug'); - final testPackage = nullSafety == NullSafety.sound - ? '_test_package_sound' - : '_test_package'; - + final packageName = context.project.packageName; mainScript = scripts.scripts! .firstWhere((each) => each.uri!.contains('main.dart')); testLibraryScript = scripts.scripts!.firstWhere((each) => - each.uri!.contains('package:$testPackage/test_library.dart')); + each.uri!.contains('package:$packageName/test_library.dart')); }); tearDown(() async { diff --git a/dwds/test/handlers/asset_handler_test.dart b/dwds/test/handlers/asset_handler_test.dart index 6fd875787..301136bca 100644 --- a/dwds/test/handlers/asset_handler_test.dart +++ b/dwds/test/handlers/asset_handler_test.dart @@ -15,8 +15,7 @@ import '../fixtures/project.dart'; void main() { group('Asset handler', () { final provider = TestSdkConfigurationProvider(); - final context = - TestContext(TestProject.testWithSoundNullSafety(), provider); + final context = TestContext(TestProject.testWithSoundNullSafety, provider); setUpAll(() async { setCurrentLogWriter(); diff --git a/dwds/test/inspector_test.dart b/dwds/test/inspector_test.dart index 756231db3..f40adeb0a 100644 --- a/dwds/test/inspector_test.dart +++ b/dwds/test/inspector_test.dart @@ -23,7 +23,7 @@ void main() { tearDownAll(provider.dispose); final context = - TestContext(TestProject.testScopesWithSoundNullSafety(), provider); + TestContext(TestProject.testScopesWithSoundNullSafety, provider); late AppInspector inspector; late Debugger debugger; diff --git a/dwds/test/instance_test.dart b/dwds/test/instance_test.dart index 0ddd4a55f..81fe99920 100644 --- a/dwds/test/instance_test.dart +++ b/dwds/test/instance_test.dart @@ -21,7 +21,7 @@ void main() { tearDownAll(provider.dispose); final context = - TestContext(TestProject.testScopesWithSoundNullSafety(), provider); + TestContext(TestProject.testScopesWithSoundNullSafety, provider); late AppInspector inspector; late Debugger debugger; diff --git a/dwds/test/listviews_test.dart b/dwds/test/listviews_test.dart index 0da9c93bd..2f039022e 100644 --- a/dwds/test/listviews_test.dart +++ b/dwds/test/listviews_test.dart @@ -14,7 +14,7 @@ void main() { final provider = TestSdkConfigurationProvider(); tearDownAll(provider.dispose); - final context = TestContext(TestProject.testWithSoundNullSafety(), provider); + final context = TestContext(TestProject.testWithSoundNullSafety, provider); setUpAll(() async { await context.setUp(); diff --git a/dwds/test/package_uri_mapper_test.dart b/dwds/test/package_uri_mapper_test.dart index 9bf1f18bc..a95fad031 100644 --- a/dwds/test/package_uri_mapper_test.dart +++ b/dwds/test/package_uri_mapper_test.dart @@ -12,7 +12,7 @@ import 'package:file/local.dart'; import 'package:path/path.dart' as p; import 'package:test/test.dart'; -import 'fixtures/utilities.dart'; +import 'fixtures/project.dart'; void main() { for (final useDebuggerModuleNames in [true, false]) { @@ -21,19 +21,18 @@ void main() { ' $useDebuggerModuleNames |', () { final fileSystem = LocalFileSystem(); - final packageUri = - Uri(scheme: 'package', path: '_test_package_sound/test_library.dart'); + final project = TestProject.testPackageWithSoundNullSafety(); + final packageUri = Uri( + scheme: 'package', path: '${project.packageName}/test_library.dart'); final serverPath = useDebuggerModuleNames - ? 'packages/_testPackageSound/lib/test_library.dart' - : '/packages/_test_package_sound/test_library.dart'; + ? 'packages/${project.packageDirectory}/lib/test_library.dart' + : '/packages/${project.packageName}/test_library.dart'; final resolvedPath = - '/webdev/fixtures/_testPackageSound/lib/test_library.dart'; - - final testPackageSoundPath = - absolutePath(pathFromFixtures: '_testPackageSound'); + '/webdev/fixtures/${project.packageDirectory}/lib/test_library.dart'; + final testPackageSoundPath = project.absolutePackageDirectory; final packageConfigFile = Uri.file(p.join( testPackageSoundPath, '.dart_tool', diff --git a/dwds/test/puppeteer/extension_test.dart b/dwds/test/puppeteer/extension_test.dart index 5eef71fe1..c97ea5f8e 100644 --- a/dwds/test/puppeteer/extension_test.dart +++ b/dwds/test/puppeteer/extension_test.dart @@ -32,8 +32,7 @@ enum Panel { debugger, inspector } void main() async { group('MV3 Debug Extension', () { final provider = TestSdkConfigurationProvider(); - final context = - TestContext(TestProject.testWithSoundNullSafety(), provider); + final context = TestContext(TestProject.testWithSoundNullSafety, provider); late String extensionPath; setUpAll(() async { diff --git a/dwds/test/puppeteer/lifeline_test.dart b/dwds/test/puppeteer/lifeline_test.dart index 7aeedc4cf..86c7156be 100644 --- a/dwds/test/puppeteer/lifeline_test.dart +++ b/dwds/test/puppeteer/lifeline_test.dart @@ -16,7 +16,7 @@ import 'test_utils.dart'; void main() async { final provider = TestSdkConfigurationProvider(); - final context = TestContext(TestProject.testWithSoundNullSafety(), provider); + final context = TestContext(TestProject.testWithSoundNullSafety, provider); late Worker worker; late Browser browser; late String extensionPath; diff --git a/dwds/test/readers/frontend_server_asset_reader_test.dart b/dwds/test/readers/frontend_server_asset_reader_test.dart index 4b1ae75b0..53506a6c3 100644 --- a/dwds/test/readers/frontend_server_asset_reader_test.dart +++ b/dwds/test/readers/frontend_server_asset_reader_test.dart @@ -11,10 +11,9 @@ import 'package:path/path.dart' as p; import 'package:test/test.dart'; import 'package:test_common/test_sdk_layout.dart'; +import '../fixtures/project.dart'; import '../fixtures/utilities.dart'; -final packagesDir = absolutePath(pathFromFixtures: '_test'); - final fixturesDir = absolutePath(pathFromDwds: p.join('test', 'fixtures')); void main() { @@ -23,6 +22,9 @@ void main() { late File jsonOriginal; late File mapOriginal; + final testProject = TestProject.testWithSoundNullSafety; + final packagesDir = testProject.absolutePackageDirectory; + Future createTempFixtures() async { tempFixtures = await Directory.systemTemp.createTemp('dwds_test_fixtures'); await tempFixtures.create(); diff --git a/dwds/test/readers/proxy_server_asset_reader_test.dart b/dwds/test/readers/proxy_server_asset_reader_test.dart index 28799e988..ef8bd0996 100644 --- a/dwds/test/readers/proxy_server_asset_reader_test.dart +++ b/dwds/test/readers/proxy_server_asset_reader_test.dart @@ -16,8 +16,7 @@ void main() { final provider = TestSdkConfigurationProvider(); tearDownAll(provider.dispose); - final context = - TestContext(TestProject.testWithSoundNullSafety(), provider); + final context = TestContext(TestProject.testWithSoundNullSafety, provider); late ProxyServerAssetReader assetReader; setUpAll(() async { diff --git a/dwds/test/records_test.dart b/dwds/test/records_test.dart index 9d7d6f070..f55352b9e 100644 --- a/dwds/test/records_test.dart +++ b/dwds/test/records_test.dart @@ -35,7 +35,7 @@ Future _runTests({ required bool debug, }) async { final context = - TestContext(TestProject.testExperimentWithSoundNullSafety(), provider); + TestContext(TestProject.testExperimentWithSoundNullSafety, provider); late VmServiceInterface service; late Stream stream; late String isolateId; diff --git a/dwds/test/refresh_test.dart b/dwds/test/refresh_test.dart index d04d2303b..2bfedb312 100644 --- a/dwds/test/refresh_test.dart +++ b/dwds/test/refresh_test.dart @@ -21,7 +21,7 @@ void main() { final provider = TestSdkConfigurationProvider(); tearDownAll(provider.dispose); - final context = TestContext(TestProject.testWithSoundNullSafety(), provider); + final context = TestContext(TestProject.testWithSoundNullSafety, provider); group('fresh context', () { late VmServiceInterface service; diff --git a/dwds/test/reload_test.dart b/dwds/test/reload_test.dart index e51bc7190..212621b69 100644 --- a/dwds/test/reload_test.dart +++ b/dwds/test/reload_test.dart @@ -24,7 +24,7 @@ void main() { tearDownAll(provider.dispose); final context = - TestContext(TestProject.testAppendBodyWithSoundNullSafety(), provider); + TestContext(TestProject.testAppendBodyWithSoundNullSafety, provider); Future makeEditAndWaitForRebuild() async { context.makeEditToDartEntryFile( diff --git a/dwds/test/restore_breakpoints_test.dart b/dwds/test/restore_breakpoints_test.dart index 8d40a868d..0be78bca6 100644 --- a/dwds/test/restore_breakpoints_test.dart +++ b/dwds/test/restore_breakpoints_test.dart @@ -18,7 +18,7 @@ void main() { final provider = TestSdkConfigurationProvider(); tearDownAll(provider.dispose); - final context = TestContext(TestProject.testWithSoundNullSafety(), provider); + final context = TestContext(TestProject.testWithSoundNullSafety, provider); setUpAll(() async { setCurrentLogWriter(); diff --git a/dwds/test/run_request_test.dart b/dwds/test/run_request_test.dart index 45c459fac..0d393ae32 100644 --- a/dwds/test/run_request_test.dart +++ b/dwds/test/run_request_test.dart @@ -16,7 +16,7 @@ void main() { final provider = TestSdkConfigurationProvider(); tearDownAll(provider.dispose); - final context = TestContext(TestProject.testWithSoundNullSafety(), provider); + final context = TestContext(TestProject.testWithSoundNullSafety, provider); group('while debugger is attached', () { late VmServiceInterface service; diff --git a/dwds/test/screenshot_test.dart b/dwds/test/screenshot_test.dart index 36bc65237..db9e4c4e5 100644 --- a/dwds/test/screenshot_test.dart +++ b/dwds/test/screenshot_test.dart @@ -14,7 +14,7 @@ void main() { final provider = TestSdkConfigurationProvider(); tearDownAll(provider.dispose); - final context = TestContext(TestProject.testWithSoundNullSafety(), provider); + final context = TestContext(TestProject.testWithSoundNullSafety, provider); setUpAll(() async { await context.setUp(); diff --git a/dwds/test/variable_scope_test.dart b/dwds/test/variable_scope_test.dart index 447858cf6..188a9fc42 100644 --- a/dwds/test/variable_scope_test.dart +++ b/dwds/test/variable_scope_test.dart @@ -18,7 +18,7 @@ void main() { tearDownAll(provider.dispose); final context = - TestContext(TestProject.testScopesWithSoundNullSafety(), provider); + TestContext(TestProject.testScopesWithSoundNullSafety, provider); setUpAll(() async { await context.setUp(); diff --git a/fixtures/_experimentSound/pubspec.yaml b/fixtures/_experimentSound/pubspec.yaml index 66555faa8..c86678ce3 100644 --- a/fixtures/_experimentSound/pubspec.yaml +++ b/fixtures/_experimentSound/pubspec.yaml @@ -1,4 +1,4 @@ -name: _experiment +name: _experiment_sound version: 1.0.0 description: >- A fake package used for testing experimental language features. From 8e1a7bfbe7feb62e7f5687aa1b3a5e2dcbc0483a Mon Sep 17 00:00:00 2001 From: Anna Gringauze Date: Fri, 17 Feb 2023 09:55:16 -0800 Subject: [PATCH 11/15] Fix sdk configiuration tests --- dwds/test/fixtures/server.dart | 2 +- dwds/test/sdk_configuration_test.dart | 22 +++-- test_common/lib/test_sdk_configuration.dart | 19 ++++- test_common/lib/test_sdk_layout.dart | 20 +++-- .../test/sdk_asset_generator_test.dart | 3 +- .../test/test_sdk_configuration_test.dart | 85 +++++++++++++++++++ 6 files changed, 133 insertions(+), 18 deletions(-) create mode 100644 test_common/test/test_sdk_configuration_test.dart diff --git a/dwds/test/fixtures/server.dart b/dwds/test/fixtures/server.dart index 8eaa4def7..57b511ded 100644 --- a/dwds/test/fixtures/server.dart +++ b/dwds/test/fixtures/server.dart @@ -122,7 +122,7 @@ class TestServer { final server = await DevToolsServer().serveDevTools( hostname: hostname, enableStdinCommands: false, - customDevToolsPath: sdkLayout.devToolsPath, + customDevToolsPath: sdkLayout.devToolsDirectory, ); if (server == null) { throw StateError('DevTools server could not be started.'); diff --git a/dwds/test/sdk_configuration_test.dart b/dwds/test/sdk_configuration_test.dart index 8717b2601..31218ca17 100644 --- a/dwds/test/sdk_configuration_test.dart +++ b/dwds/test/sdk_configuration_test.dart @@ -10,6 +10,7 @@ import 'package:dwds/src/utilities/sdk_configuration.dart'; import 'package:file/memory.dart'; import 'package:path/path.dart' as p; import 'package:test/test.dart'; +import 'package:test_common/test_sdk_configuration.dart'; var _throwsDoesNotExistException = throwsA( isA() @@ -21,7 +22,7 @@ void main() { final defaultConfiguration = await DefaultSdkConfigurationProvider().configuration; defaultConfiguration.validateSdkDir(); - defaultConfiguration.validate(); + defaultConfiguration.validateSoundSummaries(); }); test('Cannot validate an empty configuration layout', () async { @@ -52,13 +53,10 @@ void main() { final sdkLayout = FakeSdkLayout(sdkDirectory); final sdkConfiguration = FakeSdkLayout.createConfiguration(sdkLayout); - final weakSdkSummaryPath = sdkLayout.weakSummaryPath; final soundSdkSummaryPath = sdkLayout.soundSummaryPath; final summariesDir = p.dirname(soundSdkSummaryPath); Directory(summariesDir).createSync(recursive: true); - File(defaultSdkConfiguration.weakSdkSummaryPath!) - .copySync(weakSdkSummaryPath); File(defaultSdkConfiguration.soundSdkSummaryPath!) .copySync(soundSdkSummaryPath); @@ -70,12 +68,11 @@ void main() { .copySync(compilerWorkerPath); expect(sdkConfiguration.sdkDirectory, equals(sdkDirectory)); - expect(sdkConfiguration.weakSdkSummaryPath, equals(weakSdkSummaryPath)); expect(sdkConfiguration.soundSdkSummaryPath, equals(soundSdkSummaryPath)); expect(sdkConfiguration.compilerWorkerPath, equals(compilerWorkerPath)); sdkConfiguration.validateSdkDir(); - sdkConfiguration.validate(); + sdkConfiguration.validateSoundSummaries(); }); test('Cannot validate non-existing configuration layout', () async { @@ -89,7 +86,7 @@ void main() { }); }); - group('SDK configuration', () { + group('SDK configuration with memory file system', () { late MemoryFileSystem fs; final root = '/root'; @@ -119,6 +116,17 @@ void main() { sdkConfiguration.validate(fileSystem: fs); }); }); + + group('Test configuration', () { + final provider = TestSdkConfigurationProvider(); + tearDownAll(provider.dispose); + + test('Can validate configuration layout with generated assets', () async { + final sdkConfiguration = await provider.configuration; + sdkConfiguration.validateSdkDir(); + sdkConfiguration.validate(); + }); + }); } class FakeSdkLayout { diff --git a/test_common/lib/test_sdk_configuration.dart b/test_common/lib/test_sdk_configuration.dart index e90c19b96..02618529f 100644 --- a/test_common/lib/test_sdk_configuration.dart +++ b/test_common/lib/test_sdk_configuration.dart @@ -5,6 +5,7 @@ import 'dart:io'; import 'package:dwds/sdk_configuration.dart'; +import 'package:logging/logging.dart'; import 'package:test_common/sdk_asset_generator.dart'; import 'package:test_common/test_sdk_layout.dart'; @@ -20,6 +21,8 @@ import 'package:test_common/test_sdk_layout.dart'; /// TODO(annagrin): update to only generating missing sound artifacts /// for frontend server after we have no uses of weak null safety. class TestSdkConfigurationProvider extends SdkConfigurationProvider { + final _logger = Logger('TestSdkConfigurationProvider'); + final bool _verbose; late final Directory _sdkDirectory; SdkConfiguration? _configuration; @@ -44,7 +47,13 @@ class TestSdkConfigurationProvider extends SdkConfigurationProvider { try { await copyDirectory( TestSdkLayout.defaultSdkDirectory, _sdkDirectory.path); + } catch (e, s) { + _logger.severe('Failed to create SDK directory copy', e, s); + dispose(); + rethrow; + } + try { final assetGenerator = SdkAssetGenerator( sdkLayout: sdkLayout, verboseCompiler: _verbose, @@ -52,17 +61,21 @@ class TestSdkConfigurationProvider extends SdkConfigurationProvider { await assetGenerator.generateSdkAssets(); return TestSdkLayout.createConfiguration(sdkLayout); - } catch (_) { + } catch (e, s) { + _logger.severe('Failed generate missing assets', e, s); dispose(); rethrow; } } - void dispose() { + void dispose({bool retry = true}) { try { if (_sdkDirectory.existsSync()) { _sdkDirectory.deleteSync(recursive: true); } - } catch (_) {} + } catch (e, s) { + _logger.warning('Failed delete SDK directory copy', e, s); + dispose(retry: false); + } } } diff --git a/test_common/lib/test_sdk_layout.dart b/test_common/lib/test_sdk_layout.dart index 8a46f1056..04da509fb 100644 --- a/test_common/lib/test_sdk_layout.dart +++ b/test_common/lib/test_sdk_layout.dart @@ -85,7 +85,11 @@ class TestSdkLayout { 'web', 'dart_stack_trace_mapper.js', ), - dartPath: p.join(sdkLayout.sdkDirectory, 'bin', 'dart'), + dartPath: p.join( + sdkLayout.sdkDirectory, + 'bin', + 'dart', + ), frontendServerSnapshotPath: p.join( sdkLayout.sdkDirectory, 'bin', @@ -99,8 +103,12 @@ class TestSdkLayout { 'snapshots', 'kernel_worker.dart.snapshot', ), - devToolsPath: - p.join(sdkLayout.sdkDirectory, 'bin', 'resources', 'devtools'), + devToolsDirectory: p.join( + sdkLayout.sdkDirectory, + 'bin', + 'resources', + 'devtools', + ), ); final String sdkDirectory; @@ -132,7 +140,7 @@ class TestSdkLayout { final String frontendServerSnapshotPath; final String dartdevcSnapshotPath; final String kernelWorkerSnapshotPath; - final String devToolsPath; + final String devToolsDirectory; const TestSdkLayout({ required this.sdkDirectory, @@ -150,7 +158,7 @@ class TestSdkLayout { required this.frontendServerSnapshotPath, required this.dartdevcSnapshotPath, required this.kernelWorkerSnapshotPath, - required this.devToolsPath, + required this.devToolsDirectory, }); /// Creates configuration from sdk layout. @@ -168,7 +176,7 @@ Future copyDirectory(String from, String to) async { if (!Directory(from).existsSync()) return; await Directory(to).create(recursive: true); - await for (final file in Directory(from).list()) { + await for (final file in Directory(from).list(followLinks: false)) { final copyTo = p.join(to, p.relative(file.path, from: from)); if (file is Directory) { await copyDirectory(file.path, copyTo); diff --git a/test_common/test/sdk_asset_generator_test.dart b/test_common/test/sdk_asset_generator_test.dart index d4b23a7c8..5c54ceadd 100644 --- a/test_common/test/sdk_asset_generator_test.dart +++ b/test_common/test/sdk_asset_generator_test.dart @@ -111,7 +111,8 @@ void main() { }); } -Matcher _exists = predicate((String path) => File(path).existsSync()); +Matcher _exists = + predicate((String path) => File(path).existsSync(), 'File exists'); void _deleteIfExists(String path) { final file = File(path); diff --git a/test_common/test/test_sdk_configuration_test.dart b/test_common/test/test_sdk_configuration_test.dart new file mode 100644 index 000000000..8a701fc45 --- /dev/null +++ b/test_common/test/test_sdk_configuration_test.dart @@ -0,0 +1,85 @@ +// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +@TestOn('vm') +@Timeout(Duration(minutes: 2)) + +import 'dart:io'; + +import 'package:test/test.dart'; +import 'package:test_common/logging.dart'; +import 'package:test_common/test_sdk_configuration.dart'; + +void main() { + final debug = false; + + group('Test SDK configuration provider |', () { + setUpAll(() { + setCurrentLogWriter(debug: debug); + }); + + test('Creates and deletes SDK directory copy', () async { + final provider = TestSdkConfigurationProvider(verbose: debug); + final sdkDirectory = provider.sdkLayout.sdkDirectory; + final weakSdkSummary = provider.sdkLayout.weakSummaryPath; + try { + expect(sdkDirectory, _directoryExists, + reason: 'SDK directory should be created'); + expect(weakSdkSummary, isNot(_fileExists), + reason: 'Weak SDK summary should not be generated yet.'); + + await provider.configuration; + expect(weakSdkSummary, _fileExists, + reason: 'Weak SDK summary should be generated'); + } finally { + provider.dispose(); + expect(sdkDirectory, isNot(_directoryExists), + reason: 'SDK directory copy should be deleted on dispose'); + } + }); + }); + + group('Test SDK configuration |', () { + setCurrentLogWriter(debug: debug); + final provider = TestSdkConfigurationProvider(verbose: debug); + tearDownAll(provider.dispose); + + test('Can validate configuration with generated assets', () async { + final sdkConfiguration = await provider.configuration; + sdkConfiguration.validateSdkDir(); + sdkConfiguration.validate(); + }); + + test('SDK layout exists', () async { + await provider.configuration; + final sdkLayout = provider.sdkLayout; + + expect(sdkLayout.sdkDirectory, _directoryExists); + expect(sdkLayout.soundJsPath, _fileExists); + expect(sdkLayout.soundJsMapPath, _fileExists); + expect(sdkLayout.soundSummaryPath, _fileExists); + expect(sdkLayout.soundFullDillPath, _fileExists); + + expect(sdkLayout.weakJsPath, _fileExists); + expect(sdkLayout.weakJsMapPath, _fileExists); + expect(sdkLayout.weakSummaryPath, _fileExists); + expect(sdkLayout.weakFullDillPath, _fileExists); + + expect(sdkLayout.requireJsPath, _fileExists); + expect(sdkLayout.stackTraceMapperPath, _fileExists); + + expect(sdkLayout.dartPath, _fileExists); + expect(sdkLayout.frontendServerSnapshotPath, _fileExists); + expect(sdkLayout.dartdevcSnapshotPath, _fileExists); + expect(sdkLayout.kernelWorkerSnapshotPath, _fileExists); + expect(sdkLayout.devToolsDirectory, _directoryExists); + }); + }); +} + +Matcher _fileExists = + predicate((String path) => File(path).existsSync(), 'File exists'); + +Matcher _directoryExists = predicate( + (String path) => Directory(path).existsSync(), 'Directory exists'); From a3a68cf1b6aefc7ad526ac7b43e79318524b2219 Mon Sep 17 00:00:00 2001 From: Anna Gringauze Date: Fri, 17 Feb 2023 18:54:48 -0800 Subject: [PATCH 12/15] Update instance_inspection tests --- .../instances/instance_inspection_test.dart | 30 +++++++------------ .../instances/record_inspection_test.dart | 2 +- 2 files changed, 11 insertions(+), 21 deletions(-) diff --git a/dwds/test/instances/instance_inspection_test.dart b/dwds/test/instances/instance_inspection_test.dart index 082e8245d..176726047 100644 --- a/dwds/test/instances/instance_inspection_test.dart +++ b/dwds/test/instances/instance_inspection_test.dart @@ -5,36 +5,25 @@ @TestOn('vm') @Timeout(Duration(minutes: 2)) -import 'package:dwds/src/connections/debug_connection.dart'; -import 'package:dwds/src/services/chrome_proxy_service.dart'; import 'package:test/test.dart'; import 'package:test_common/logging.dart'; +import 'package:test_common/test_sdk_configuration.dart'; import 'package:vm_service/vm_service.dart'; import '../fixtures/context.dart'; +import '../fixtures/project.dart'; import 'instance_inspection_common.dart'; -class TestSetup { - TestContext context; - - TestSetup.sound() - : context = TestContext.withSoundNullSafety( - packageName: '_testPackageSound', - webAssetsPath: 'web', - dartEntryFileName: 'main.dart', - htmlEntryFileName: 'index.html', - ); - - ChromeProxyService get service => - fetchChromeProxyService(context.debugConnection); -} - void main() async { // Enable verbose logging for debugging. final debug = false; + final provider = TestSdkConfigurationProvider(verbose: debug); + tearDownAll(provider.dispose); + for (var compilationMode in CompilationMode.values) { await _runTests( + provider: provider, compilationMode: compilationMode, debug: debug, ); @@ -42,11 +31,12 @@ void main() async { } Future _runTests({ + required TestSdkConfigurationProvider provider, required CompilationMode compilationMode, required bool debug, }) async { - final setup = TestSetup.sound(); - final context = setup.context; + final context = + TestContext(TestProject.testPackageWithSoundNullSafety(), provider); late VmServiceInterface service; late Stream stream; late String isolateId; @@ -77,7 +67,7 @@ Future _runTests({ verboseCompiler: debug, experiments: ['records'], ); - service = setup.service; + service = context.debugConnection.vmService; final vm = await service.getVM(); isolateId = vm.isolates!.first.id!; diff --git a/dwds/test/instances/record_inspection_test.dart b/dwds/test/instances/record_inspection_test.dart index f7392078e..bd21741dd 100644 --- a/dwds/test/instances/record_inspection_test.dart +++ b/dwds/test/instances/record_inspection_test.dart @@ -67,7 +67,7 @@ Future _runTests({ verboseCompiler: debug, experiments: ['records'], ); - service = context.service; + service = context.debugConnection.vmService; final vm = await service.getVM(); isolateId = vm.isolates!.first.id!; From 3214af16c51fc69c6bcecca3c59f03104d10577c Mon Sep 17 00:00:00 2001 From: Anna Gringauze Date: Wed, 22 Feb 2023 15:26:20 -0800 Subject: [PATCH 13/15] Less changes in chrome_proxy_service.dart --- dwds/test/chrome_proxy_service_test.dart | 614 ++++++++++++----------- 1 file changed, 327 insertions(+), 287 deletions(-) diff --git a/dwds/test/chrome_proxy_service_test.dart b/dwds/test/chrome_proxy_service_test.dart index 324eb7a9a..cc657e27c 100644 --- a/dwds/test/chrome_proxy_service_test.dart +++ b/dwds/test/chrome_proxy_service_test.dart @@ -9,6 +9,7 @@ import 'dart:convert'; import 'dart:io'; import 'package:dwds/src/loaders/strategy.dart'; +import 'package:dwds/src/services/chrome_proxy_service.dart'; import 'package:dwds/src/utilities/dart_uri.dart'; import 'package:dwds/src/utilities/shared.dart'; import 'package:http/http.dart' as http; @@ -45,6 +46,7 @@ void main() { }); group('breakpoints', () { + late VmServiceInterface service; VM vm; late Isolate isolate; @@ -53,9 +55,10 @@ void main() { setUp(() async { setCurrentLogWriter(debug: debug); - vm = await context.service.getVM(); - isolate = await context.service.getIsolate(vm.isolates!.first.id!); - scripts = await context.service.getScripts(isolate.id!); + service = context.service; + vm = await service.getVM(); + isolate = await service.getIsolate(vm.isolates!.first.id!); + scripts = await service.getScripts(isolate.id!); mainScript = scripts.scripts! .firstWhere((each) => each.uri!.contains('main.dart')); }); @@ -63,20 +66,20 @@ void main() { test('addBreakpoint', () async { final line = await context.findBreakpointLine( 'printHelloWorld', isolate.id!, mainScript); - final firstBp = await context.service - .addBreakpoint(isolate.id!, mainScript.id!, line); + final firstBp = + await service.addBreakpoint(isolate.id!, mainScript.id!, line); expect(firstBp, isNotNull); expect(firstBp.id, isNotNull); - final secondBp = await context.service - .addBreakpoint(isolate.id!, mainScript.id!, line); + final secondBp = + await service.addBreakpoint(isolate.id!, mainScript.id!, line); expect(secondBp, isNotNull); expect(secondBp.id, isNotNull); expect(firstBp.id, equals(secondBp.id)); // Remove breakpoint so it doesn't impact other tests. - await context.service.removeBreakpoint(isolate.id!, firstBp.id!); + await service.removeBreakpoint(isolate.id!, firstBp.id!); }); test('addBreakpoint succeeds when sending the same breakpoint twice', @@ -84,44 +87,40 @@ void main() { final line = await context.findBreakpointLine( 'printHelloWorld', isolate.id!, mainScript); final firstBp = - context.service.addBreakpoint(isolate.id!, mainScript.id!, line); + service.addBreakpoint(isolate.id!, mainScript.id!, line); final secondBp = - context.service.addBreakpoint(isolate.id!, mainScript.id!, line); + service.addBreakpoint(isolate.id!, mainScript.id!, line); // Remove breakpoint so it doesn't impact other tests. - await context.service - .removeBreakpoint(isolate.id!, (await firstBp).id!); + await service.removeBreakpoint(isolate.id!, (await firstBp).id!); expect((await firstBp).id, equals((await secondBp).id)); }); test('addBreakpoint in nonsense location throws', () async { - expect( - context.service.addBreakpoint(isolate.id!, mainScript.id!, 200000), + expect(service.addBreakpoint(isolate.id!, mainScript.id!, 200000), throwsA(predicate((dynamic e) => e is RPCError && e.code == 102))); }); test('addBreakpoint on a part file', () async { final partScript = scripts.scripts! .firstWhere((script) => script.uri!.contains('part.dart')); - final bp = await context.service - .addBreakpoint(isolate.id!, partScript.id!, 10); + final bp = await service.addBreakpoint(isolate.id!, partScript.id!, 10); // Remove breakpoint so it doesn't impact other tests. - await context.service.removeBreakpoint(isolate.id!, bp.id!); + await service.removeBreakpoint(isolate.id!, bp.id!); expect(bp.id, isNotNull); }); test('addBreakpointAtEntry', () async { - await expectLater( - context.service.addBreakpointAtEntry('', ''), throwsRPCError); + await expectLater(service.addBreakpointAtEntry('', ''), throwsRPCError); }); test('addBreakpointWithScriptUri', () async { final line = await context.findBreakpointLine( 'printHelloWorld', isolate.id!, mainScript); - final bp = await context.service - .addBreakpointWithScriptUri(isolate.id!, mainScript.uri!, line); + final bp = await service.addBreakpointWithScriptUri( + isolate.id!, mainScript.uri!, line); // Remove breakpoint so it doesn't impact other tests. - await context.service.removeBreakpoint(isolate.id!, bp.id!); + await service.removeBreakpoint(isolate.id!, bp.id!); expect(bp.id, isNotNull); }); @@ -132,39 +131,42 @@ void main() { final fileUri = Uri.file(fullPath); final line = await context.findBreakpointLine( 'printHelloWorld', isolate.id!, mainScript); - final bp = await context.service - .addBreakpointWithScriptUri(isolate.id!, '$fileUri', line); + final bp = await service.addBreakpointWithScriptUri( + isolate.id!, '$fileUri', line); // Remove breakpoint so it doesn't impact other tests. - await context.service.removeBreakpoint(isolate.id!, bp.id!); + await service.removeBreakpoint(isolate.id!, bp.id!); expect(bp.id, isNotNull); }); test('removeBreakpoint null arguments', () async { await expectLater( - context.service.removeBreakpoint('', ''), throwsSentinelException); + service.removeBreakpoint('', ''), throwsSentinelException); await expectLater( - context.service.removeBreakpoint(isolate.id!, ''), throwsRPCError); + service.removeBreakpoint(isolate.id!, ''), throwsRPCError); }); test("removeBreakpoint that doesn't exist fails", () async { - await expectLater(context.service.removeBreakpoint(isolate.id!, '1234'), - throwsRPCError); + await expectLater( + service.removeBreakpoint(isolate.id!, '1234'), throwsRPCError); }); test('add and remove breakpoint', () async { final line = await context.findBreakpointLine( 'printHelloWorld', isolate.id!, mainScript); - final bp = await context.service - .addBreakpoint(isolate.id!, mainScript.id!, line); + final bp = + await service.addBreakpoint(isolate.id!, mainScript.id!, line); expect(isolate.breakpoints, [bp]); - await context.service.removeBreakpoint(isolate.id!, bp.id!); + await service.removeBreakpoint(isolate.id!, bp.id!); expect(isolate.breakpoints, isEmpty); }); }); group('callServiceExtension', () { + late ChromeProxyService service; + setUp(() { setCurrentLogWriter(debug: debug); + service = context.service; }); test('success', () async { @@ -184,8 +186,8 @@ void main() { false: true, }; - final result = await context.service - .callServiceExtension(serviceMethod, args: args); + final result = + await service.callServiceExtension(serviceMethod, args: args); expect( result.json, args.map((k, v) => MapEntry(k is String ? k : jsonEncode(k), @@ -201,7 +203,7 @@ void main() { final errorDetails = {'intentional': 'error'}; expect( - context.service.callServiceExtension(serviceMethod, args: { + service.callServiceExtension(serviceMethod, args: { 'code': '-32001', 'details': jsonEncode(errorDetails), }), @@ -215,38 +217,41 @@ void main() { }); group('VMTimeline', () { + late VmServiceInterface service; + setUp(() { setCurrentLogWriter(debug: debug); + service = context.service; }); test('clearVMTimeline', () async { - await expectLater(context.service.clearVMTimeline(), throwsRPCError); + await expectLater(service.clearVMTimeline(), throwsRPCError); }); test('getVMTimelineMicros', () async { - await expectLater( - context.service.getVMTimelineMicros(), throwsRPCError); + await expectLater(service.getVMTimelineMicros(), throwsRPCError); }); test('getVMTimeline', () async { - await expectLater(context.service.getVMTimeline(), throwsRPCError); + await expectLater(service.getVMTimeline(), throwsRPCError); }); test('getVMTimelineFlags', () async { - await expectLater(context.service.getVMTimelineFlags(), throwsRPCError); + await expectLater(service.getVMTimelineFlags(), throwsRPCError); }); test('setVMTimelineFlags', () async { await expectLater( - context.service.setVMTimelineFlags([]), throwsRPCError); + service.setVMTimelineFlags([]), throwsRPCError); }); }); test('getMemoryUsage', () async { - final vm = await context.service.getVM(); - final isolate = await context.service.getIsolate(vm.isolates!.first.id!); + final service = context.service; + final vm = await service.getVM(); + final isolate = await service.getIsolate(vm.isolates!.first.id!); - final memoryUsage = await context.service.getMemoryUsage(isolate.id!); + final memoryUsage = await service.getMemoryUsage(isolate.id!); expect(memoryUsage.heapUsage, isNotNull); expect(memoryUsage.heapUsage, greaterThan(0)); @@ -255,13 +260,15 @@ void main() { }); group('evaluate', () { + late VmServiceInterface service; late Isolate isolate; LibraryRef? bootstrap; setUpAll(() async { setCurrentLogWriter(debug: debug); - final vm = await context.service.getVM(); - isolate = await context.service.getIsolate(vm.isolates!.first.id!); + service = context.service; + final vm = await service.getVM(); + isolate = await service.getIsolate(vm.isolates!.first.id!); bootstrap = isolate.rootLib; }); @@ -272,7 +279,7 @@ void main() { test('can return strings', () async { expect( - await context.service.evaluate( + await service.evaluate( isolate.id!, bootstrap!.id!, "helloString('world')"), const TypeMatcher().having( (instance) => instance.valueAsString, 'value', 'world')); @@ -280,15 +287,15 @@ void main() { test('can return bools', () async { expect( - await context.service - .evaluate(isolate.id!, bootstrap!.id!, 'helloBool(true)'), + await service.evaluate( + isolate.id!, bootstrap!.id!, 'helloBool(true)'), const TypeMatcher().having( (instance) => instance.valueAsString, 'valueAsString', 'true')); expect( - await context.service - .evaluate(isolate.id!, bootstrap!.id!, 'helloBool(false)'), + await service.evaluate( + isolate.id!, bootstrap!.id!, 'helloBool(false)'), const TypeMatcher().having( (instance) => instance.valueAsString, 'valueAsString', @@ -297,13 +304,13 @@ void main() { test('can return nums', () async { expect( - await context.service - .evaluate(isolate.id!, bootstrap!.id!, 'helloNum(42.0)'), + await service.evaluate( + isolate.id!, bootstrap!.id!, 'helloNum(42.0)'), const TypeMatcher().having( (instance) => instance.valueAsString, 'valueAsString', '42')); expect( - await context.service - .evaluate(isolate.id!, bootstrap!.id!, 'helloNum(42.2)'), + await service.evaluate( + isolate.id!, bootstrap!.id!, 'helloNum(42.2)'), const TypeMatcher().having( (instance) => instance.valueAsString, 'valueAsString', @@ -311,8 +318,8 @@ void main() { }); test('can return objects with ids', () async { - final object = await context.service - .evaluate(isolate.id!, bootstrap!.id!, 'createObject("cool")'); + final object = await service.evaluate( + isolate.id!, bootstrap!.id!, 'createObject("cool")'); expect( object, const TypeMatcher() @@ -327,14 +334,14 @@ void main() { }); Future createRemoteObject(String message) async { - return await context.service.evaluate( + return await service.evaluate( isolate.id!, bootstrap!.id!, 'createObject("$message")') as InstanceRef; } test('single scope object', () async { final instance = await createRemoteObject('A'); - final result = await context.service.evaluate( + final result = await service.evaluate( isolate.id!, bootstrap!.id!, 'messageFor(arg1)', scope: {'arg1': instance.id!}); expect( @@ -348,7 +355,7 @@ void main() { test('multiple scope objects', () async { final instance1 = await createRemoteObject('A'); final instance2 = await createRemoteObject('B'); - final result = await context.service.evaluate( + final result = await service.evaluate( isolate.id!, bootstrap!.id!, 'messagesCombined(arg1, arg2)', scope: {'arg1': instance1.id!, 'arg2': instance2.id!}); expect( @@ -363,36 +370,41 @@ void main() { }); test('evaluateInFrame', () async { + final service = context.service; await expectLater( - context.service.evaluateInFrame('', 0, ''), throwsSentinelException); + service.evaluateInFrame('', 0, ''), throwsSentinelException); }); test('getAllocationProfile', () async { - await expectLater( - context.service.getAllocationProfile(''), throwsRPCError); + final service = context.service; + await expectLater(service.getAllocationProfile(''), throwsRPCError); }); test('getClassList', () async { - await expectLater(context.service.getClassList(''), throwsRPCError); + final service = context.service; + await expectLater(service.getClassList(''), throwsRPCError); }); test('getFlagList', () async { - expect(await context.service.getFlagList(), isA()); + final service = context.service; + expect(await service.getFlagList(), isA()); }); test('getInstances', () async { - await expectLater( - context.service.getInstances('', '', 0), throwsRPCError); + final service = context.service; + await expectLater(service.getInstances('', '', 0), throwsRPCError); }); group('getIsolate', () { + late VmServiceInterface service; setUp(() { setCurrentLogWriter(debug: debug); + service = context.service; }); test('works for existing isolates', () async { - final vm = await context.service.getVM(); - final result = await context.service.getIsolate(vm.isolates!.first.id!); + final vm = await service.getVM(); + final result = await service.getIsolate(vm.isolates!.first.id!); expect(result, const TypeMatcher()); final isolate = result; expect(isolate.name, contains('main')); @@ -410,11 +422,12 @@ void main() { }); test('throws for invalid ids', () async { - expect(context.service.getIsolate('bad'), throwsSentinelException); + expect(service.getIsolate('bad'), throwsSentinelException); }); }); group('getObject', () { + late ChromeProxyService service; late Isolate isolate; LibraryRef? bootstrap; @@ -422,11 +435,12 @@ void main() { setUpAll(() async { setCurrentLogWriter(debug: debug); - final vm = await context.service.getVM(); - isolate = await context.service.getIsolate(vm.isolates!.first.id!); + service = context.service; + final vm = await service.getVM(); + isolate = await service.getIsolate(vm.isolates!.first.id!); bootstrap = isolate.rootLib; - rootLibrary = await context.service - .getObject(isolate.id!, bootstrap!.id!) as Library; + rootLibrary = + await service.getObject(isolate.id!, bootstrap!.id!) as Library; }); setUp(() { @@ -443,8 +457,8 @@ void main() { }); test('Library only contains included scripts', () async { - final library = await context.service - .getObject(isolate.id!, rootLibrary!.id!) as Library; + final library = + await service.getObject(isolate.id!, rootLibrary!.id!) as Library; expect(library.scripts, hasLength(2)); expect( library.scripts, @@ -458,8 +472,8 @@ void main() { test('Can get the same library in parallel', () async { final futures = [ - context.service.getObject(isolate.id!, rootLibrary!.id!), - context.service.getObject(isolate.id!, rootLibrary!.id!), + service.getObject(isolate.id!, rootLibrary!.id!), + service.getObject(isolate.id!, rootLibrary!.id!), ]; final results = await Future.wait(futures); final library1 = results[0] as Library; @@ -468,8 +482,8 @@ void main() { }); test('Classes', () async { - final testClass = await context.service - .getObject(isolate.id!, rootLibrary!.classes!.first.id!) as Class; + final testClass = await service.getObject( + isolate.id!, rootLibrary!.classes!.first.id!) as Class; expect( testClass.functions, unorderedEquals([ @@ -509,21 +523,21 @@ void main() { }); test('Runtime classes', () async { - final testClass = await context.service - .getObject(isolate.id!, 'classes|dart:_runtime|_Type') as Class; + final testClass = await service.getObject( + isolate.id!, 'classes|dart:_runtime|_Type') as Class; expect(testClass.name, '_Type'); }); test('String', () async { - final worldRef = await context.service.evaluate( + final worldRef = await service.evaluate( isolate.id!, bootstrap!.id!, "helloString('world')") as InstanceRef; - final world = await context.service.getObject(isolate.id!, worldRef.id!) - as Instance; + final world = + await service.getObject(isolate.id!, worldRef.id!) as Instance; expect(world.valueAsString, 'world'); }); test('Large strings not truncated', () async { - final largeString = await context.service.evaluate( + final largeString = await service.evaluate( isolate.id!, bootstrap!.id!, "helloString('${'abcde' * 250}')") as InstanceRef; expect(largeString.valueAsStringIsTruncated, isNot(isTrue)); @@ -540,7 +554,7 @@ void main() { list[4] = 100; return list; })()'''; - return context.service.inspector.jsEvaluate(expr); + return service.inspector.jsEvaluate(expr); } /// Helper to create a LinkedHashMap with 1001 entries, doing a direct JS eval. @@ -556,13 +570,13 @@ void main() { const linkedMap = sdk.dart.dsend(sdk.collection.LinkedHashMap, "from", [map]); return linkedMap; })()'''; - return context.service.inspector.jsEvaluate(expr); + return service.inspector.jsEvaluate(expr); } test('Lists', () async { final list = await createList(); - final inst = await context.service - .getObject(isolate.id!, list.objectId!) as Instance; + final inst = + await service.getObject(isolate.id!, list.objectId!) as Instance; expect(inst.length, 1001); expect(inst.offset, null); expect(inst.count, null); @@ -575,8 +589,8 @@ void main() { test('Maps', () async { final map = await createMap(); - final inst = await context.service.getObject(isolate.id!, map.objectId!) - as Instance; + final inst = + await service.getObject(isolate.id!, map.objectId!) as Instance; expect(inst.length, 1001); expect(inst.offset, null); expect(inst.count, null); @@ -590,31 +604,29 @@ void main() { }); test('bool', () async { - final ref = await context.service.evaluate( + final ref = await service.evaluate( isolate.id!, bootstrap!.id!, 'helloBool(true)') as InstanceRef; - final obj = - await context.service.getObject(isolate.id!, ref.id!) as Instance; + final obj = await service.getObject(isolate.id!, ref.id!) as Instance; expect(obj.kind, InstanceKind.kBool); expect(obj.classRef!.name, 'Bool'); expect(obj.valueAsString, 'true'); }); test('num', () async { - final ref = await context.service.evaluate( + final ref = await service.evaluate( isolate.id!, bootstrap!.id!, 'helloNum(42)') as InstanceRef; - final obj = - await context.service.getObject(isolate.id!, ref.id!) as Instance; + final obj = await service.getObject(isolate.id!, ref.id!) as Instance; expect(obj.kind, InstanceKind.kDouble); expect(obj.classRef!.name, 'Double'); expect(obj.valueAsString, '42'); }); test('Scripts', () async { - final scripts = await context.service.getScripts(isolate.id!); + final scripts = await service.getScripts(isolate.id!); assert(scripts.scripts!.isNotEmpty); for (var scriptRef in scripts.scripts!) { - final script = await context.service - .getObject(isolate.id!, scriptRef.id!) as Script; + final script = + await service.getObject(isolate.id!, scriptRef.id!) as Script; final serverPath = DartUri(script.uri!, 'hello_world/').serverPath; final result = await http .get(Uri.parse('http://localhost:${context.port}/$serverPath')); @@ -627,7 +639,7 @@ void main() { group('getObject called with offset/count parameters', () { test('Lists with null offset and count are not truncated', () async { final list = await createList(); - final inst = await context.service.getObject( + final inst = await service.getObject( isolate.id!, list.objectId!, count: null, @@ -645,7 +657,7 @@ void main() { test('Lists with null count are not truncated', () async { final list = await createList(); - final inst = await context.service.getObject( + final inst = await service.getObject( isolate.id!, list.objectId!, count: null, @@ -665,7 +677,7 @@ void main() { 'Lists with null count and offset greater than 0 are ' 'truncated from offset to end of list', () async { final list = await createList(); - final inst = await context.service.getObject( + final inst = await service.getObject( isolate.id!, list.objectId!, count: null, @@ -681,7 +693,7 @@ void main() { test('Lists with offset/count are truncated', () async { final list = await createList(); - final inst = await context.service.getObject( + final inst = await service.getObject( isolate.id!, list.objectId!, count: 7, @@ -700,7 +712,7 @@ void main() { test('Lists are truncated to the end if offset/count runs off the end', () async { final list = await createList(); - final inst = await context.service.getObject( + final inst = await service.getObject( isolate.id!, list.objectId!, count: 5, @@ -717,7 +729,7 @@ void main() { test('Lists are truncated to empty if offset runs off the end', () async { final list = await createList(); - final inst = await context.service.getObject( + final inst = await service.getObject( isolate.id!, list.objectId!, count: 5, @@ -733,7 +745,7 @@ void main() { test('Lists are truncated to empty with 0 count and null offset', () async { final list = await createList(); - final inst = await context.service.getObject( + final inst = await service.getObject( isolate.id!, list.objectId!, count: 0, @@ -748,7 +760,7 @@ void main() { test('Maps with null offset/count are not truncated', () async { final map = await createMap(); - final inst = await context.service.getObject( + final inst = await service.getObject( isolate.id!, map.objectId!, count: null, @@ -770,7 +782,7 @@ void main() { 'Maps with null count and offset greater than 0 are ' 'truncated from offset to end of map', () async { final list = await createMap(); - final inst = await context.service.getObject( + final inst = await service.getObject( isolate.id!, list.objectId!, count: null, @@ -787,7 +799,7 @@ void main() { test('Maps with null count are not truncated', () async { final map = await createMap(); - final inst = await context.service.getObject( + final inst = await service.getObject( isolate.id!, map.objectId!, count: null, @@ -807,7 +819,7 @@ void main() { test('Maps with offset/count are truncated', () async { final map = await createMap(); - final inst = await context.service.getObject( + final inst = await service.getObject( isolate.id!, map.objectId!, count: 7, @@ -828,7 +840,7 @@ void main() { test('Maps are truncated to the end if offset/count runs off the end', () async { final map = await createMap(); - final inst = await context.service.getObject( + final inst = await service.getObject( isolate.id!, map.objectId!, count: 5, @@ -846,7 +858,7 @@ void main() { test('Maps are truncated to empty if offset runs off the end', () async { final list = await createMap(); - final inst = await context.service.getObject( + final inst = await service.getObject( isolate.id!, list.objectId!, count: 5, @@ -860,10 +872,10 @@ void main() { }); test('Strings with offset/count are truncated', () async { - final worldRef = await context.service - .evaluate(isolate.id!, bootstrap!.id!, "helloString('world')") + final worldRef = await service.evaluate( + isolate.id!, bootstrap!.id!, "helloString('world')") as InstanceRef; - final world = await context.service.getObject( + final world = await service.getObject( isolate.id!, worldRef.id!, count: 2, @@ -878,7 +890,7 @@ void main() { test('Maps are truncated to empty if offset runs off the end', () async { final list = await createMap(); - final inst = await context.service.getObject( + final inst = await service.getObject( isolate.id!, list.objectId!, count: 5, @@ -894,7 +906,7 @@ void main() { test('Maps are truncated to empty with 0 count and null offset', () async { final list = await createMap(); - final inst = await context.service.getObject( + final inst = await service.getObject( isolate.id!, list.objectId!, count: 0, @@ -910,10 +922,10 @@ void main() { test( 'Strings are truncated to the end if offset/count runs off the end', () async { - final worldRef = await context.service - .evaluate(isolate.id!, bootstrap!.id!, "helloString('world')") + final worldRef = await service.evaluate( + isolate.id!, bootstrap!.id!, "helloString('world')") as InstanceRef; - final world = await context.service.getObject( + final world = await service.getObject( isolate.id!, worldRef.id!, count: 5, @@ -928,7 +940,7 @@ void main() { test( 'offset/count parameters greater than zero are ignored for Classes', () async { - final testClass = await context.service.getObject( + final testClass = await service.getObject( isolate.id!, rootLibrary!.classes!.first.id!, offset: 100, @@ -976,7 +988,7 @@ void main() { test('offset/count parameters equal to zero are ignored for Classes', () async { - final testClass = await context.service.getObject( + final testClass = await service.getObject( isolate.id!, rootLibrary!.classes!.first.id!, offset: 0, @@ -1023,9 +1035,9 @@ void main() { }); test('offset/count parameters are ignored for bools', () async { - final ref = await context.service.evaluate( + final ref = await service.evaluate( isolate.id!, bootstrap!.id!, 'helloBool(true)') as InstanceRef; - final obj = await context.service.getObject( + final obj = await service.getObject( isolate.id!, ref.id!, offset: 100, @@ -1037,9 +1049,9 @@ void main() { }); test('offset/count parameters are ignored for nums', () async { - final ref = await context.service.evaluate( + final ref = await service.evaluate( isolate.id!, bootstrap!.id!, 'helloNum(42)') as InstanceRef; - final obj = await context.service.getObject( + final obj = await service.getObject( isolate.id!, ref.id!, offset: 100, @@ -1051,9 +1063,9 @@ void main() { }); test('offset/count parameters are ignored for null', () async { - final ref = await context.service.evaluate( + final ref = await service.evaluate( isolate.id!, bootstrap!.id!, 'helloNum(null)') as InstanceRef; - final obj = await context.service.getObject( + final obj = await service.getObject( isolate.id!, ref.id!, offset: 100, @@ -1067,9 +1079,10 @@ void main() { }); test('getScripts', () async { - final vm = await context.service.getVM(); + final service = context.service; + final vm = await service.getVM(); final isolateId = vm.isolates!.first.id!; - final scripts = await context.service.getScripts(isolateId); + final scripts = await service.getScripts(isolateId); expect(scripts, isNotNull); expect(scripts.scripts, isNotEmpty); @@ -1089,46 +1102,47 @@ void main() { }); group('getSourceReport', () { + late VmServiceInterface service; + setUp(() { setCurrentLogWriter(debug: debug); + service = context.service; }); test('Coverage report', () async { - final vm = await context.service.getVM(); + final vm = await service.getVM(); final isolateId = vm.isolates!.first.id!; await expectLater( - context.service.getSourceReport(isolateId, ['Coverage']), - throwsRPCError); + service.getSourceReport(isolateId, ['Coverage']), throwsRPCError); }); test('Coverage report', () async { - final vm = await context.service.getVM(); + final vm = await service.getVM(); final isolateId = vm.isolates!.first.id!; await expectLater( - context.service.getSourceReport(isolateId, ['Coverage'], + service.getSourceReport(isolateId, ['Coverage'], libraryFilters: ['foo']), throwsRPCError); }); test('report type not understood', () async { - final vm = await context.service.getVM(); + final vm = await service.getVM(); final isolateId = vm.isolates!.first.id!; await expectLater( - context.service.getSourceReport(isolateId, ['FooBar']), - throwsRPCError); + service.getSourceReport(isolateId, ['FooBar']), throwsRPCError); }); test('PossibleBreakpoints report', () async { - final vm = await context.service.getVM(); + final vm = await service.getVM(); final isolateId = vm.isolates!.first.id!; - final scripts = await context.service.getScripts(isolateId); + final scripts = await service.getScripts(isolateId); final mainScript = scripts.scripts! .firstWhere((script) => script.uri!.contains('main.dart')); - final sourceReport = await context.service.getSourceReport( + final sourceReport = await service.getSourceReport( isolateId, ['PossibleBreakpoints'], scriptId: mainScript.id, @@ -1143,6 +1157,7 @@ void main() { }); group('Pausing', () { + late VmServiceInterface service; String? isolateId; late Stream stream; ScriptList scripts; @@ -1150,11 +1165,12 @@ void main() { setUp(() async { setCurrentLogWriter(debug: debug); - final vm = await context.service.getVM(); + service = context.service; + final vm = await service.getVM(); isolateId = vm.isolates!.first.id; - scripts = await context.service.getScripts(isolateId!); - await context.service.streamListen('Debug'); - stream = context.service.onEvent('Debug'); + scripts = await service.getScripts(isolateId!); + await service.streamListen('Debug'); + stream = service.onEvent('Debug'); mainScript = scripts.scripts! .firstWhere((script) => script.uri!.contains('main.dart')); }); @@ -1162,23 +1178,24 @@ void main() { test('at breakpoints sets pauseBreakPoints', () async { final line = await context.findBreakpointLine( 'callPrintCount', isolateId!, mainScript); - final bp = await context.service - .addBreakpoint(isolateId!, mainScript.id!, line); + final bp = + await service.addBreakpoint(isolateId!, mainScript.id!, line); final event = await stream .firstWhere((event) => event.kind == EventKind.kPauseBreakpoint); final pauseBreakpoints = event.pauseBreakpoints!; expect(pauseBreakpoints, hasLength(1)); expect(pauseBreakpoints.first.id, bp.id); - await context.service.removeBreakpoint(isolateId!, bp.id!); + await service.removeBreakpoint(isolateId!, bp.id!); }); tearDown(() async { // Resume execution to not impact other tests. - await context.service.resume(isolateId!); + await service.resume(isolateId!); }); }); group('Step', () { + late VmServiceInterface service; String? isolateId; late Stream stream; ScriptList scripts; @@ -1186,34 +1203,35 @@ void main() { setUp(() async { setCurrentLogWriter(debug: debug); - final vm = await context.service.getVM(); + service = context.service; + final vm = await service.getVM(); isolateId = vm.isolates!.first.id; - scripts = await context.service.getScripts(isolateId!); - await context.service.streamListen('Debug'); - stream = context.service.onEvent('Debug'); + scripts = await service.getScripts(isolateId!); + await service.streamListen('Debug'); + stream = service.onEvent('Debug'); mainScript = scripts.scripts! .firstWhere((script) => script.uri!.contains('main.dart')); final line = await context.findBreakpointLine( 'callPrintCount', isolateId!, mainScript); - final bp = await context.service - .addBreakpoint(isolateId!, mainScript.id!, line); + final bp = + await service.addBreakpoint(isolateId!, mainScript.id!, line); // Wait for breakpoint to trigger. await stream .firstWhere((event) => event.kind == EventKind.kPauseBreakpoint); - await context.service.removeBreakpoint(isolateId!, bp.id!); + await service.removeBreakpoint(isolateId!, bp.id!); }); tearDown(() async { // Resume execution to not impact other tests. - await context.service.resume(isolateId!); + await service.resume(isolateId!); }); test('Into goes to the next Dart location', () async { - await context.service.resume(isolateId!, step: 'Into'); + await service.resume(isolateId!, step: 'Into'); // Wait for the step to actually occur. await stream .firstWhere((event) => event.kind == EventKind.kPauseInterrupted); - final stack = await context.service.getStack(isolateId!); + final stack = await service.getStack(isolateId!); expect(stack, isNotNull); final first = stack.frames!.first; expect(first.kind, 'Regular'); @@ -1222,11 +1240,11 @@ void main() { }); test('Over goes to the next Dart location', () async { - await context.service.resume(isolateId!, step: 'Over'); + await service.resume(isolateId!, step: 'Over'); // Wait for the step to actually occur. await stream .firstWhere((event) => event.kind == EventKind.kPauseInterrupted); - final stack = await context.service.getStack(isolateId!); + final stack = await service.getStack(isolateId!); expect(stack, isNotNull); final first = stack.frames!.first; expect(first.kind, 'Regular'); @@ -1235,11 +1253,11 @@ void main() { }); test('Out goes to the next Dart location', () async { - await context.service.resume(isolateId!, step: 'Out'); + await service.resume(isolateId!, step: 'Out'); // Wait for the step to actually occur. await stream .firstWhere((event) => event.kind == EventKind.kPauseInterrupted); - final stack = await context.service.getStack(isolateId!); + final stack = await service.getStack(isolateId!); expect(stack, isNotNull); final first = stack.frames!.first; expect(first.kind, 'Regular'); @@ -1249,6 +1267,7 @@ void main() { }); group('getStack', () { + late VmServiceInterface service; String? isolateId; late Stream stream; ScriptList scripts; @@ -1256,17 +1275,18 @@ void main() { setUp(() async { setCurrentLogWriter(debug: debug); - final vm = await context.service.getVM(); + service = context.service; + final vm = await service.getVM(); isolateId = vm.isolates!.first.id; - scripts = await context.service.getScripts(isolateId!); - await context.service.streamListen('Debug'); - stream = context.service.onEvent('Debug'); + scripts = await service.getScripts(isolateId!); + await service.streamListen('Debug'); + stream = service.onEvent('Debug'); mainScript = scripts.scripts! .firstWhere((each) => each.uri!.contains('main.dart')); }); test('throws if not paused', () async { - await expectLater(context.service.getStack(isolateId!), throwsRPCError); + await expectLater(service.getStack(isolateId!), throwsRPCError); }, skip: Platform .isWindows); // Issue: https://github.com/dart-lang/webdev/issues/1749 @@ -1277,18 +1297,17 @@ void main() { breakpointId, isolateId!, mainScript); Breakpoint? bp; try { - bp = await context.service - .addBreakpoint(isolateId!, mainScript.id!, line); + bp = await service.addBreakpoint(isolateId!, mainScript.id!, line); // Wait for breakpoint to trigger. await stream .firstWhere((event) => event.kind == EventKind.kPauseBreakpoint); - return await context.service.getStack(isolateId!, limit: limit); + return await service.getStack(isolateId!, limit: limit); } finally { // Remove breakpoint and resume so it doesn't impact other tests. if (bp != null) { - await context.service.removeBreakpoint(isolateId!, bp.id!); + await service.removeBreakpoint(isolateId!, bp.id!); } - await context.service.resume(isolateId!); + await service.resume(isolateId!); } } @@ -1364,8 +1383,8 @@ void main() { test('break on exceptions with setIsolatePauseMode', () async { final oldPauseMode = - (await context.service.getIsolate(isolateId!)).exceptionPauseMode; - await context.service.setIsolatePauseMode(isolateId!, + (await service.getIsolate(isolateId!)).exceptionPauseMode; + await service.setIsolatePauseMode(isolateId!, exceptionPauseMode: ExceptionPauseMode.kAll); // Wait for pausing to actually propagate. final event = await stream @@ -1375,27 +1394,28 @@ void main() { // TODO(https://github.com/dart-lang/webdev/issues/1821) Uncomment. // expect(event.exception!.valueAsString, contains('main.dart')); - final stack = await context.service.getStack(isolateId!); + final stack = await service.getStack(isolateId!); expect(stack, isNotNull); - await context.service - .setIsolatePauseMode(isolateId!, exceptionPauseMode: oldPauseMode); - await context.service.resume(isolateId!); + await service.setIsolatePauseMode(isolateId!, + exceptionPauseMode: oldPauseMode); + await service.resume(isolateId!); }); test('returns non-null stack when paused', () async { - await context.service.pause(isolateId!); + await service.pause(isolateId!); // Wait for pausing to actually propagate. await stream .firstWhere((event) => event.kind == EventKind.kPauseInterrupted); - expect(await context.service.getStack(isolateId!), isNotNull); + expect(await service.getStack(isolateId!), isNotNull); // Resume the isolate to not impact other tests. - await context.service.resume(isolateId!); + await service.resume(isolateId!); }); }); test('getVM', () async { - final vm = await context.service.getVM(); + final service = context.service; + final vm = await service.getVM(); expect(vm.name, isNotNull); expect(vm.version, Platform.version); expect(vm.isolates, hasLength(1)); @@ -1406,12 +1426,14 @@ void main() { }); test('getVersion', () async { - final version = await context.service.getVersion(); + final service = context.service; + final version = await service.getVersion(); expect(version, isNotNull); expect(version.major, greaterThan(0)); }); group('invoke', () { + late ChromeProxyService service; VM vm; late Isolate isolate; LibraryRef? bootstrap; @@ -1419,11 +1441,12 @@ void main() { setUp(() async { setCurrentLogWriter(debug: debug); - vm = await context.service.getVM(); - isolate = await context.service.getIsolate(vm.isolates!.first.id!); + service = context.service; + vm = await service.getVM(); + isolate = await service.getIsolate(vm.isolates!.first.id!); bootstrap = isolate.rootLib; - testInstance = await context.service - .evaluate(isolate.id!, bootstrap!.id!, 'myInstance') as InstanceRef; + testInstance = await service.evaluate( + isolate.id!, bootstrap!.id!, 'myInstance') as InstanceRef; }); test('rootLib', () async { @@ -1434,8 +1457,8 @@ void main() { }); test('toString()', () async { - final remote = await context.service - .invoke(isolate.id!, testInstance.id!, 'toString', []); + final remote = + await service.invoke(isolate.id!, testInstance.id!, 'toString', []); expect( remote, const TypeMatcher().having( @@ -1445,8 +1468,8 @@ void main() { }); test('hello()', () async { - final remote = await context.service - .invoke(isolate.id!, testInstance.id!, 'hello', []); + final remote = + await service.invoke(isolate.id!, testInstance.id!, 'hello', []); expect( remote, const TypeMatcher().having( @@ -1454,7 +1477,7 @@ void main() { }); test('helloString', () async { - final remote = await context.service.invoke(isolate.id!, bootstrap!.id!, + final remote = await service.invoke(isolate.id!, bootstrap!.id!, 'helloString', ['#StringInstanceRef#abc']); expect( remote, @@ -1467,7 +1490,7 @@ void main() { }); test('null argument', () async { - final remote = await context.service.invoke( + final remote = await service.invoke( isolate.id!, bootstrap!.id!, 'helloString', ['objects/null']); expect( remote, @@ -1480,7 +1503,7 @@ void main() { }); test('helloBool', () async { - final remote = await context.service.invoke( + final remote = await service.invoke( isolate.id!, bootstrap!.id!, 'helloBool', ['objects/bool-true']); expect( remote, @@ -1493,7 +1516,7 @@ void main() { }); test('helloNum', () async { - final remote = await context.service.invoke( + final remote = await service.invoke( isolate.id!, bootstrap!.id!, 'helloNum', ['objects/int-123']); expect( remote, @@ -1506,7 +1529,7 @@ void main() { }); test('two object arguments', () async { - final remote = await context.service.invoke(isolate.id!, bootstrap!.id!, + final remote = await service.invoke(isolate.id!, bootstrap!.id!, 'messagesCombined', [testInstance.id, testInstance.id]); expect( remote, @@ -1522,17 +1545,20 @@ void main() { }); test('kill', () async { - await expectLater(context.service.kill(''), throwsRPCError); + final service = context.service; + await expectLater(service.kill(''), throwsRPCError); }); test('onEvent', () async { - expect(() => context.service.onEvent(''), throwsRPCError); + final service = context.service; + expect(() => service.onEvent(''), throwsRPCError); }); test('pause / resume', () async { - await context.service.streamListen('Debug'); - final stream = context.service.onEvent('Debug'); - final vm = await context.service.getVM(); + final service = context.service; + await service.streamListen('Debug'); + final stream = service.onEvent('Debug'); + final vm = await service.getVM(); final isolateId = vm.isolates!.first.id!; final pauseCompleter = Completer(); final pauseSub = context.tabConnection.debugger.onPaused.listen((_) { @@ -1542,17 +1568,15 @@ void main() { final resumeSub = context.tabConnection.debugger.onResumed.listen((_) { resumeCompleter.complete(); }); - expect( - await context.service.pause(isolateId), const TypeMatcher()); + expect(await service.pause(isolateId), const TypeMatcher()); await stream .firstWhere((event) => event.kind == EventKind.kPauseInterrupted); - expect((await context.service.getIsolate(isolateId)).pauseEvent!.kind, + expect((await service.getIsolate(isolateId)).pauseEvent!.kind, EventKind.kPauseInterrupted); await pauseCompleter.future; - expect(await context.service.resume(isolateId), - const TypeMatcher()); + expect(await service.resume(isolateId), const TypeMatcher()); await stream.firstWhere((event) => event.kind == EventKind.kResume); - expect((await context.service.getIsolate(isolateId)).pauseEvent!.kind, + expect((await service.getIsolate(isolateId)).pauseEvent!.kind, EventKind.kResume); await resumeCompleter.future; await pauseSub.cancel(); @@ -1560,24 +1584,26 @@ void main() { }); test('getInboundReferences', () async { + final service = context.service; await expectLater( - context.service.getInboundReferences('', '', 0), throwsRPCError); + service.getInboundReferences('', '', 0), throwsRPCError); }); test('getRetainingPath', () async { - await expectLater( - context.service.getRetainingPath('', '', 0), throwsRPCError); + final service = context.service; + await expectLater(service.getRetainingPath('', '', 0), throwsRPCError); }); test('lookupResolvedPackageUris converts package and org-dartlang-app uris', () async { - final vm = await context.service.getVM(); + final service = context.service; + final vm = await service.getVM(); final isolateId = vm.isolates!.first.id!; - final scriptList = await context.service.getScripts(isolateId); + final scriptList = await service.getScripts(isolateId); final uris = scriptList.scripts!.map((e) => e.uri!).toList(); final resolvedUris = - await context.service.lookupResolvedPackageUris(isolateId, uris); + await service.lookupResolvedPackageUris(isolateId, uris); expect( resolvedUris.uris, @@ -1590,11 +1616,11 @@ void main() { test('lookupResolvedPackageUris does not translate non-existent paths', () async { - final vm = await context.service.getVM(); + final service = context.service; + final vm = await service.getVM(); final isolateId = vm.isolates!.first.id!; - final resolvedUris = - await context.service.lookupResolvedPackageUris(isolateId, [ + final resolvedUris = await service.lookupResolvedPackageUris(isolateId, [ 'package:does/not/exist.dart', 'dart:does_not_exist', 'file:///does_not_exist.dart', @@ -1603,11 +1629,11 @@ void main() { }); test('lookupResolvedPackageUris translates dart uris', () async { - final vm = await context.service.getVM(); + final service = context.service; + final vm = await service.getVM(); final isolateId = vm.isolates!.first.id!; - final resolvedUris = - await context.service.lookupResolvedPackageUris(isolateId, [ + final resolvedUris = await service.lookupResolvedPackageUris(isolateId, [ 'dart:html', 'dart:async', ]); @@ -1620,16 +1646,17 @@ void main() { test('lookupPackageUris finds package and org-dartlang-app paths', () async { - final vm = await context.service.getVM(); + final service = context.service; + final vm = await service.getVM(); final isolateId = vm.isolates!.first.id!; - final scriptList = await context.service.getScripts(isolateId); + final scriptList = await service.getScripts(isolateId); final uris = scriptList.scripts!.map((e) => e.uri!).toList(); final resolvedUris = - await context.service.lookupResolvedPackageUris(isolateId, uris); + await service.lookupResolvedPackageUris(isolateId, uris); - final packageUris = await context.service - .lookupPackageUris(isolateId, List.from(resolvedUris.uris!)); + final packageUris = await service.lookupPackageUris( + isolateId, List.from(resolvedUris.uris!)); expect( packageUris.uris, containsAll([ @@ -1640,15 +1667,16 @@ void main() { }); test('lookupPackageUris ignores local parameter', () async { - final vm = await context.service.getVM(); + final service = context.service; + final vm = await service.getVM(); final isolateId = vm.isolates!.first.id!; - final scriptList = await context.service.getScripts(isolateId); + final scriptList = await service.getScripts(isolateId); final uris = scriptList.scripts!.map((e) => e.uri!).toList(); - final resolvedUrisWithLocal = await context.service - .lookupResolvedPackageUris(isolateId, uris, local: true); + final resolvedUrisWithLocal = + await service.lookupResolvedPackageUris(isolateId, uris, local: true); - final packageUrisWithLocal = await context.service.lookupPackageUris( + final packageUrisWithLocal = await service.lookupPackageUris( isolateId, List.from(resolvedUrisWithLocal.uris!)); expect( packageUrisWithLocal.uris, @@ -1658,10 +1686,10 @@ void main() { 'package:path/src/path_set.dart', ])); - final resolvedUrisWithoutLocal = await context.service - .lookupResolvedPackageUris(isolateId, uris, local: true); + final resolvedUrisWithoutLocal = + await service.lookupResolvedPackageUris(isolateId, uris, local: true); - final packageUrisWithoutLocal = await context.service.lookupPackageUris( + final packageUrisWithoutLocal = await service.lookupPackageUris( isolateId, List.from(resolvedUrisWithoutLocal.uris!)); expect( packageUrisWithoutLocal.uris, @@ -1673,10 +1701,11 @@ void main() { }); test('lookupPackageUris does not translate non-existent paths', () async { - final vm = await context.service.getVM(); + final service = context.service; + final vm = await service.getVM(); final isolateId = vm.isolates!.first.id!; - final resolvedUris = await context.service.lookupPackageUris(isolateId, [ + final resolvedUris = await service.lookupPackageUris(isolateId, [ 'org-dartlang-sdk:///sdk/does/not/exist.dart', 'does_not_exist.dart', 'file:///does_not_exist.dart', @@ -1685,10 +1714,11 @@ void main() { }); test('lookupPackageUris translates dart uris', () async { - final vm = await context.service.getVM(); + final service = context.service; + final vm = await service.getVM(); final isolateId = vm.isolates!.first.id!; - final resolvedUris = await context.service.lookupPackageUris(isolateId, [ + final resolvedUris = await service.lookupPackageUris(isolateId, [ 'org-dartlang-sdk:///sdk/lib/html/dart2js/html_dart2js.dart', 'org-dartlang-sdk:///sdk/lib/async/async.dart', ]); @@ -1699,80 +1729,89 @@ void main() { ]); }, skip: 'https://github.com/dart-lang/webdev/issues/1584'); - test('registercontext.service', () async { + test('registerservice', () async { + final service = context.service; await expectLater( - context.service.registerService('ext.foo.bar', ''), throwsRPCError); + service.registerService('ext.foo.bar', ''), throwsRPCError); }); test('reloadSources', () async { - await expectLater(context.service.reloadSources(''), throwsRPCError); + final service = context.service; + await expectLater(service.reloadSources(''), throwsRPCError); }); test('setIsolatePauseMode', () async { - final vm = await context.service.getVM(); + final service = context.service; + final vm = await service.getVM(); final isolateId = vm.isolates!.first.id!; - expect(await context.service.setIsolatePauseMode(isolateId), _isSuccess); + expect(await service.setIsolatePauseMode(isolateId), _isSuccess); expect( - await context.service.setIsolatePauseMode(isolateId, + await service.setIsolatePauseMode(isolateId, exceptionPauseMode: ExceptionPauseMode.kAll), _isSuccess); expect( - await context.service.setIsolatePauseMode(isolateId, + await service.setIsolatePauseMode(isolateId, exceptionPauseMode: ExceptionPauseMode.kUnhandled), _isSuccess); // Make sure this is the last one - or future tests might hang. expect( - await context.service.setIsolatePauseMode(isolateId, + await service.setIsolatePauseMode(isolateId, exceptionPauseMode: ExceptionPauseMode.kNone), _isSuccess); await expectLater( - context.service - .setIsolatePauseMode(isolateId, exceptionPauseMode: 'invalid'), + service.setIsolatePauseMode(isolateId, exceptionPauseMode: 'invalid'), throwsRPCError); }); test('setFlag', () async { - await expectLater(context.service.setFlag('', ''), throwsRPCError); + final service = context.service; + await expectLater(service.setFlag('', ''), throwsRPCError); }); test('setLibraryDebuggable', () async { + final service = context.service; await expectLater( - context.service.setLibraryDebuggable('', '', false), throwsRPCError); + service.setLibraryDebuggable('', '', false), throwsRPCError); }); test('setName', () async { - final vm = await context.service.getVM(); + final service = context.service; + final vm = await service.getVM(); final isolateId = vm.isolates!.first.id!; - expect( - context.service.setName(isolateId, 'test'), completion(_isSuccess)); - final isolate = await context.service.getIsolate(isolateId); + expect(service.setName(isolateId, 'test'), completion(_isSuccess)); + final isolate = await service.getIsolate(isolateId); expect(isolate.name, 'test'); }); test('setVMName', () async { - expect(context.service.setVMName('foo'), completion(_isSuccess)); - final vm = await context.service.getVM(); + final service = context.service; + expect(service.setVMName('foo'), completion(_isSuccess)); + final vm = await service.getVM(); expect(vm.name, 'foo'); }); test('streamCancel', () async { - await expectLater(context.service.streamCancel(''), throwsRPCError); + final service = context.service; + await expectLater(service.streamCancel(''), throwsRPCError); }); group('streamListen/onEvent', () { + late ChromeProxyService service; + group('Debug', () { late Stream eventStream; setUp(() async { setCurrentLogWriter(debug: debug); - expect(await context.service.streamListen('Debug'), + service = context.service; + expect(await service.streamListen('Debug'), const TypeMatcher()); - eventStream = context.service.onEvent('Debug'); + eventStream = service.onEvent('Debug'); }); test('basic Pause/Resume', () async { - expect(context.service.streamListen('Debug'), completion(_isSuccess)); - final stream = context.service.onEvent('Debug'); + expect(service.streamListen('Debug'), completion(_isSuccess)); + final stream = service.onEvent('Debug'); safeUnawaited(context.tabConnection.debugger.pause()); await expectLater( stream, @@ -1802,13 +1841,15 @@ void main() { }); group('Extension', () { + late VmServiceInterface service; late Stream eventStream; setUp(() async { setCurrentLogWriter(debug: debug); - expect(await context.service.streamListen('Extension'), + service = context.service; + expect(await service.streamListen('Extension'), const TypeMatcher()); - eventStream = context.service.onEvent('Extension'); + eventStream = service.onEvent('Extension'); }); test('Custom debug event', () async { @@ -1863,19 +1904,18 @@ void main() { }); test('GC', () async { - expect(context.service.streamListen('GC'), completion(_isSuccess)); + expect(service.streamListen('GC'), completion(_isSuccess)); }); group('Isolate', () { late Stream isolateEventStream; setUp(() async { - expect(await context.service.streamListen(EventStreams.kIsolate), - _isSuccess); - isolateEventStream = context.service.onEvent(EventStreams.kIsolate); + expect(await service.streamListen(EventStreams.kIsolate), _isSuccess); + isolateEventStream = service.onEvent(EventStreams.kIsolate); }); - test('context.serviceExtensionAdded', () async { + test('serviceExtensionAdded', () async { final extensionMethod = 'ext.foo.bar'; expect( isolateEventStream, @@ -1887,7 +1927,7 @@ void main() { }); test('lifecycle events', () async { - final vm = await context.service.getVM(); + final vm = await service.getVM(); final initialIsolateId = vm.isolates!.first.id; final eventsDone = expectLater( isolateEventStream, @@ -1902,10 +1942,10 @@ void main() { event.kind == EventKind.kIsolateRunnable && event.isolate!.id != initialIsolateId), ]))); - context.service.destroyIsolate(); - await context.service.createIsolate(context.appConnection); + service.destroyIsolate(); + await service.createIsolate(context.appConnection); await eventsDone; - expect((await context.service.getVM()).isolates!.first.id, + expect((await service.getVM()).isolates!.first.id, isNot(initialIsolateId)); }); @@ -1931,14 +1971,13 @@ void main() { }); test('Timeline', () async { - expect( - context.service.streamListen('Timeline'), completion(_isSuccess)); + expect(service.streamListen('Timeline'), completion(_isSuccess)); }); test('Stdout', () async { - expect(context.service.streamListen('Stdout'), completion(_isSuccess)); + expect(service.streamListen('Stdout'), completion(_isSuccess)); expect( - context.service.onEvent('Stdout'), + service.onEvent('Stdout'), emitsThrough(predicate((Event event) => event.kind == EventKind.kWriteEvent && String.fromCharCodes(base64.decode(event.bytes!)) @@ -1947,8 +1986,8 @@ void main() { }); test('Stderr', () async { - expect(context.service.streamListen('Stderr'), completion(_isSuccess)); - final stderrStream = context.service.onEvent('Stderr'); + expect(service.streamListen('Stderr'), completion(_isSuccess)); + final stderrStream = service.onEvent('Stderr'); expect( stderrStream, emitsThrough(predicate((Event event) => @@ -1959,8 +1998,8 @@ void main() { }); test('exception stack trace mapper', () async { - expect(context.service.streamListen('Stderr'), completion(_isSuccess)); - final stderrStream = context.service.onEvent('Stderr'); + expect(service.streamListen('Stderr'), completion(_isSuccess)); + final stderrStream = service.onEvent('Stderr'); expect( stderrStream, emitsThrough(predicate((Event event) => @@ -1972,21 +2011,22 @@ void main() { }); test('VM', () async { - final status = await context.service.streamListen('VM'); + final status = await service.streamListen('VM'); expect(status, _isSuccess); - final stream = context.service.onEvent('VM'); + final stream = service.onEvent('VM'); expect( stream, emitsThrough(predicate((Event e) => e.kind == EventKind.kVMUpdate && e.vm!.name == 'test'))); - await context.service.setVMName('test'); + await service.setVMName('test'); }); }); test('Logging', () async { - expect(context.service.streamListen(EventStreams.kLogging), - completion(_isSuccess)); - final stream = context.service.onEvent(EventStreams.kLogging); + final service = context.service; + expect( + service.streamListen(EventStreams.kLogging), completion(_isSuccess)); + final stream = service.onEvent(EventStreams.kLogging); final message = 'myMessage'; safeUnawaited( From c08f1c6111c1c25a119c504d219e5a261db5ff23 Mon Sep 17 00:00:00 2001 From: Anna Gringauze Date: Wed, 22 Feb 2023 16:16:33 -0800 Subject: [PATCH 14/15] Add sdk configuration provider that copies the sdk directory --- dwds/test/build_daemon_breakpoint_test.dart | 12 +- dwds/test/build_daemon_callstack_test.dart | 12 +- .../build_daemon_circular_evaluate_test.dart | 5 - dwds/test/build_daemon_evaluate_test.dart | 5 - dwds/test/chrome_proxy_service_test.dart | 125 ++++---------- dwds/test/dart_uri_file_uri_test.dart | 27 ++- dwds/test/debug_extension_test.dart | 10 +- dwds/test/debug_service_test.dart | 8 +- dwds/test/debugger_test.dart | 3 + dwds/test/devtools_test.dart | 8 +- dwds/test/evaluate_circular_common.dart | 27 ++- dwds/test/evaluate_common.dart | 26 ++- dwds/test/events_test.dart | 23 +-- dwds/test/fixtures/context.dart | 23 ++- dwds/test/fixtures/server.dart | 6 +- dwds/test/fixtures/test_sdk_layout.dart | 159 ++++++++++++++++++ dwds/test/fixtures/utilities.dart | 20 ++- .../test/frontend_server_breakpoint_test.dart | 14 +- dwds/test/frontend_server_callstack_test.dart | 15 +- ...rontend_server_circular_evaluate_test.dart | 13 +- .../frontend_server_evaluate_sound_test.dart | 5 - .../frontend_server_evaluate_weak_test.dart | 5 - dwds/test/handlers/asset_handler_test.dart | 5 +- dwds/test/inspector_test.dart | 12 +- .../instances/instance_inspection_test.dart | 12 +- dwds/test/instances/instance_test.dart | 12 +- .../instances/record_inspection_test.dart | 16 +- dwds/test/listviews_test.dart | 10 +- dwds/test/package_uri_mapper_test.dart | 2 +- dwds/test/puppeteer/extension_test.dart | 8 +- dwds/test/puppeteer/lifeline_test.dart | 8 +- .../frontend_server_asset_reader_test.dart | 10 +- .../proxy_server_asset_reader_test.dart | 12 +- dwds/test/refresh_test.dart | 11 +- dwds/test/reload_test.dart | 40 ++--- dwds/test/restore_breakpoints_test.dart | 20 +-- dwds/test/run_request_test.dart | 13 +- dwds/test/screenshot_test.dart | 8 +- dwds/test/sdk_configuration_test.dart | 36 ++-- dwds/test/variable_scope_test.dart | 14 +- fixtures/_experimentSound/pubspec.yaml | 2 +- .../lib/src/asset_server.dart | 17 +- frontend_server_common/lib/src/devfs.dart | 2 +- .../lib/src/frontend_server_client.dart | 2 +- .../lib/src/resident_runner.dart | 3 +- frontend_server_common/lib/src/utilities.dart | 14 ++ test_common/lib/test_sdk_configuration.dart | 40 ++++- .../test/test_sdk_configuration_test.dart | 4 +- webdev/test/daemon/app_domain_test.dart | 38 ++--- webdev/test/daemon/daemon_domain_test.dart | 18 +- webdev/test/daemon/launch_app_test.dart | 9 +- webdev/test/daemon/utils.dart | 15 ++ webdev/test/e2e_test.dart | 43 +++-- webdev/test/integration_test.dart | 33 ++-- webdev/test/readme_test.dart | 12 +- webdev/test/test_utils.dart | 50 +----- 56 files changed, 531 insertions(+), 571 deletions(-) create mode 100644 dwds/test/fixtures/test_sdk_layout.dart diff --git a/dwds/test/build_daemon_breakpoint_test.dart b/dwds/test/build_daemon_breakpoint_test.dart index 2ce7b9ffb..2af540472 100644 --- a/dwds/test/build_daemon_breakpoint_test.dart +++ b/dwds/test/build_daemon_breakpoint_test.dart @@ -6,20 +6,18 @@ @Timeout(Duration(minutes: 2)) import 'dart:async'; +import 'package:dwds/src/services/chrome_proxy_service.dart'; import 'package:test/test.dart'; -import 'package:test_common/test_sdk_configuration.dart'; import 'package:vm_service/vm_service.dart'; import 'fixtures/context.dart'; import 'fixtures/project.dart'; -void main() { - final provider = TestSdkConfigurationProvider(); - tearDownAll(provider.dispose); +final context = TestContext(TestProject.testPackageWithSoundNullSafety()); - final context = - TestContext(TestProject.testPackageWithSoundNullSafety(), provider); +ChromeProxyService get service => context.service; +void main() { group('shared context', () { setUpAll(() async { await context.setUp(); @@ -37,10 +35,8 @@ void main() { late ScriptRef mainScript; late String mainScriptUri; late Stream stream; - late VmServiceInterface service; setUp(() async { - service = context.service; vm = await service.getVM(); isolate = await service.getIsolate(vm.isolates!.first.id!); isolateId = isolate.id!; diff --git a/dwds/test/build_daemon_callstack_test.dart b/dwds/test/build_daemon_callstack_test.dart index f425e9c82..e98f02ee5 100644 --- a/dwds/test/build_daemon_callstack_test.dart +++ b/dwds/test/build_daemon_callstack_test.dart @@ -4,19 +4,17 @@ @TestOn('vm') @Timeout(Duration(minutes: 2)) +import 'dart:async'; +import 'package:dwds/src/services/chrome_proxy_service.dart'; import 'package:test/test.dart'; import 'package:test_common/logging.dart'; -import 'package:test_common/test_sdk_configuration.dart'; import 'package:vm_service/vm_service.dart'; import 'fixtures/context.dart'; import 'fixtures/project.dart'; void main() { - final provider = TestSdkConfigurationProvider(); - tearDownAll(provider.dispose); - group( 'shared context |', () { @@ -26,7 +24,7 @@ void main() { for (var nullSafety in NullSafety.values) { group('${nullSafety.name} null safety |', () { final project = TestProject.testPackage(nullSafety: nullSafety); - final context = TestContext(project, provider); + final context = TestContext(project); setUpAll(() async { setCurrentLogWriter(debug: debug); @@ -42,7 +40,7 @@ void main() { }); group('callStack |', () { - late VmServiceInterface service; + late ChromeProxyService service; VM vm; late Isolate isolate; ScriptList scripts; @@ -60,7 +58,7 @@ void main() { await service.streamListen('Debug'); stream = service.onEvent('Debug'); - final testPackage = context.project.packageName; + final testPackage = project.packageName; mainScript = scripts.scripts! .firstWhere((each) => each.uri!.contains('main.dart')); testLibraryScript = scripts.scripts!.firstWhere((each) => diff --git a/dwds/test/build_daemon_circular_evaluate_test.dart b/dwds/test/build_daemon_circular_evaluate_test.dart index 9111f14e7..db3192365 100644 --- a/dwds/test/build_daemon_circular_evaluate_test.dart +++ b/dwds/test/build_daemon_circular_evaluate_test.dart @@ -6,7 +6,6 @@ @Timeout(Duration(minutes: 2)) import 'package:test/test.dart'; -import 'package:test_common/test_sdk_configuration.dart'; import 'evaluate_circular_common.dart'; import 'fixtures/context.dart'; @@ -16,13 +15,9 @@ void main() async { // Enable verbose logging for debugging. final debug = false; - final provider = TestSdkConfigurationProvider(verbose: debug); - tearDownAll(provider.dispose); - for (var nullSafety in NullSafety.values) { group('${nullSafety.name} null safety |', () { testAll( - provider: provider, compilationMode: CompilationMode.buildDaemon, nullSafety: nullSafety, debug: debug, diff --git a/dwds/test/build_daemon_evaluate_test.dart b/dwds/test/build_daemon_evaluate_test.dart index daab203f7..6c0bde0b7 100644 --- a/dwds/test/build_daemon_evaluate_test.dart +++ b/dwds/test/build_daemon_evaluate_test.dart @@ -6,7 +6,6 @@ @Timeout(Duration(minutes: 2)) import 'package:test/test.dart'; -import 'package:test_common/test_sdk_configuration.dart'; import 'evaluate_common.dart'; import 'fixtures/context.dart'; @@ -16,13 +15,9 @@ void main() async { // Enable verbose logging for debugging. final debug = false; - final provider = TestSdkConfigurationProvider(verbose: debug); - tearDownAll(provider.dispose); - for (var nullSafety in NullSafety.values) { group('${nullSafety.name} null safety |', () { testAll( - provider: provider, compilationMode: CompilationMode.buildDaemon, nullSafety: nullSafety, debug: debug, diff --git a/dwds/test/chrome_proxy_service_test.dart b/dwds/test/chrome_proxy_service_test.dart index cc657e27c..4a860fe9c 100644 --- a/dwds/test/chrome_proxy_service_test.dart +++ b/dwds/test/chrome_proxy_service_test.dart @@ -8,6 +8,7 @@ import 'dart:async'; import 'dart:convert'; import 'dart:io'; +import 'package:dwds/src/connections/debug_connection.dart'; import 'package:dwds/src/loaders/strategy.dart'; import 'package:dwds/src/services/chrome_proxy_service.dart'; import 'package:dwds/src/utilities/dart_uri.dart'; @@ -16,22 +17,20 @@ import 'package:http/http.dart' as http; import 'package:path/path.dart' as path; import 'package:test/test.dart'; import 'package:test_common/logging.dart'; -import 'package:test_common/test_sdk_configuration.dart'; import 'package:vm_service/vm_service.dart'; import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart'; import 'fixtures/context.dart'; import 'fixtures/project.dart'; +final context = TestContext(TestProject.testWithSoundNullSafety); + +ChromeProxyService get service => context.service; +WipConnection get tabConnection => context.tabConnection; + void main() { // Change to true to see verbose output from the tests. final debug = false; - - final provider = TestSdkConfigurationProvider(verbose: debug); - tearDownAll(provider.dispose); - - final context = TestContext(TestProject.testWithSoundNullSafety, provider); - group('shared context', () { setUpAll(() async { setCurrentLogWriter(debug: debug); @@ -46,7 +45,6 @@ void main() { }); group('breakpoints', () { - late VmServiceInterface service; VM vm; late Isolate isolate; @@ -55,15 +53,17 @@ void main() { setUp(() async { setCurrentLogWriter(debug: debug); - service = context.service; - vm = await service.getVM(); - isolate = await service.getIsolate(vm.isolates!.first.id!); - scripts = await service.getScripts(isolate.id!); + vm = await fetchChromeProxyService(context.debugConnection).getVM(); + isolate = await fetchChromeProxyService(context.debugConnection) + .getIsolate(vm.isolates!.first.id!); + scripts = await fetchChromeProxyService(context.debugConnection) + .getScripts(isolate.id!); mainScript = scripts.scripts! .firstWhere((each) => each.uri!.contains('main.dart')); }); test('addBreakpoint', () async { + // TODO: Much more testing. final line = await context.findBreakpointLine( 'printHelloWorld', isolate.id!, mainScript); final firstBp = @@ -125,7 +125,8 @@ void main() { }); test('addBreakpointWithScriptUri absolute file URI', () async { - final test = context.project.absolutePackageDirectory; + final current = context.workingDirectory; + final test = path.join(path.dirname(current), '_testSound'); final scriptPath = Uri.parse(mainScript.uri!).path.substring(1); final fullPath = path.join(test, scriptPath); final fileUri = Uri.file(fullPath); @@ -162,16 +163,13 @@ void main() { }); group('callServiceExtension', () { - late ChromeProxyService service; - setUp(() { setCurrentLogWriter(debug: debug); - service = context.service; }); test('success', () async { final serviceMethod = 'ext.test.callServiceExtension'; - await context.tabConnection.runtime + await tabConnection.runtime .evaluate('registerExtension("$serviceMethod");'); // The non-string keys/values get auto json-encoded to match the vm @@ -198,7 +196,7 @@ void main() { test('failure', () async { final serviceMethod = 'ext.test.callServiceExtensionWithError'; - await context.tabConnection.runtime + await tabConnection.runtime .evaluate('registerExtensionWithError("$serviceMethod");'); final errorDetails = {'intentional': 'error'}; @@ -217,11 +215,8 @@ void main() { }); group('VMTimeline', () { - late VmServiceInterface service; - setUp(() { setCurrentLogWriter(debug: debug); - service = context.service; }); test('clearVMTimeline', () async { @@ -247,7 +242,6 @@ void main() { }); test('getMemoryUsage', () async { - final service = context.service; final vm = await service.getVM(); final isolate = await service.getIsolate(vm.isolates!.first.id!); @@ -260,13 +254,11 @@ void main() { }); group('evaluate', () { - late VmServiceInterface service; late Isolate isolate; LibraryRef? bootstrap; setUpAll(() async { setCurrentLogWriter(debug: debug); - service = context.service; final vm = await service.getVM(); isolate = await service.getIsolate(vm.isolates!.first.id!); bootstrap = isolate.rootLib; @@ -370,36 +362,29 @@ void main() { }); test('evaluateInFrame', () async { - final service = context.service; await expectLater( service.evaluateInFrame('', 0, ''), throwsSentinelException); }); test('getAllocationProfile', () async { - final service = context.service; await expectLater(service.getAllocationProfile(''), throwsRPCError); }); test('getClassList', () async { - final service = context.service; await expectLater(service.getClassList(''), throwsRPCError); }); test('getFlagList', () async { - final service = context.service; expect(await service.getFlagList(), isA()); }); test('getInstances', () async { - final service = context.service; await expectLater(service.getInstances('', '', 0), throwsRPCError); }); group('getIsolate', () { - late VmServiceInterface service; setUp(() { setCurrentLogWriter(debug: debug); - service = context.service; }); test('works for existing isolates', () async { @@ -427,7 +412,6 @@ void main() { }); group('getObject', () { - late ChromeProxyService service; late Isolate isolate; LibraryRef? bootstrap; @@ -435,7 +419,6 @@ void main() { setUpAll(() async { setCurrentLogWriter(debug: debug); - service = context.service; final vm = await service.getVM(); isolate = await service.getIsolate(vm.isolates!.first.id!); bootstrap = isolate.rootLib; @@ -1079,7 +1062,6 @@ void main() { }); test('getScripts', () async { - final service = context.service; final vm = await service.getVM(); final isolateId = vm.isolates!.first.id!; final scripts = await service.getScripts(isolateId); @@ -1102,11 +1084,8 @@ void main() { }); group('getSourceReport', () { - late VmServiceInterface service; - setUp(() { setCurrentLogWriter(debug: debug); - service = context.service; }); test('Coverage report', () async { @@ -1157,7 +1136,6 @@ void main() { }); group('Pausing', () { - late VmServiceInterface service; String? isolateId; late Stream stream; ScriptList scripts; @@ -1165,7 +1143,6 @@ void main() { setUp(() async { setCurrentLogWriter(debug: debug); - service = context.service; final vm = await service.getVM(); isolateId = vm.isolates!.first.id; scripts = await service.getScripts(isolateId!); @@ -1195,7 +1172,6 @@ void main() { }); group('Step', () { - late VmServiceInterface service; String? isolateId; late Stream stream; ScriptList scripts; @@ -1203,7 +1179,6 @@ void main() { setUp(() async { setCurrentLogWriter(debug: debug); - service = context.service; final vm = await service.getVM(); isolateId = vm.isolates!.first.id; scripts = await service.getScripts(isolateId!); @@ -1267,7 +1242,6 @@ void main() { }); group('getStack', () { - late VmServiceInterface service; String? isolateId; late Stream stream; ScriptList scripts; @@ -1275,7 +1249,6 @@ void main() { setUp(() async { setCurrentLogWriter(debug: debug); - service = context.service; final vm = await service.getVM(); isolateId = vm.isolates!.first.id; scripts = await service.getScripts(isolateId!); @@ -1414,7 +1387,6 @@ void main() { }); test('getVM', () async { - final service = context.service; final vm = await service.getVM(); expect(vm.name, isNotNull); expect(vm.version, Platform.version); @@ -1426,14 +1398,12 @@ void main() { }); test('getVersion', () async { - final service = context.service; final version = await service.getVersion(); expect(version, isNotNull); expect(version.major, greaterThan(0)); }); group('invoke', () { - late ChromeProxyService service; VM vm; late Isolate isolate; LibraryRef? bootstrap; @@ -1441,7 +1411,6 @@ void main() { setUp(() async { setCurrentLogWriter(debug: debug); - service = context.service; vm = await service.getVM(); isolate = await service.getIsolate(vm.isolates!.first.id!); bootstrap = isolate.rootLib; @@ -1545,27 +1514,24 @@ void main() { }); test('kill', () async { - final service = context.service; await expectLater(service.kill(''), throwsRPCError); }); test('onEvent', () async { - final service = context.service; expect(() => service.onEvent(''), throwsRPCError); }); test('pause / resume', () async { - final service = context.service; await service.streamListen('Debug'); final stream = service.onEvent('Debug'); final vm = await service.getVM(); final isolateId = vm.isolates!.first.id!; final pauseCompleter = Completer(); - final pauseSub = context.tabConnection.debugger.onPaused.listen((_) { + final pauseSub = tabConnection.debugger.onPaused.listen((_) { pauseCompleter.complete(); }); final resumeCompleter = Completer(); - final resumeSub = context.tabConnection.debugger.onResumed.listen((_) { + final resumeSub = tabConnection.debugger.onResumed.listen((_) { resumeCompleter.complete(); }); expect(await service.pause(isolateId), const TypeMatcher()); @@ -1584,19 +1550,16 @@ void main() { }); test('getInboundReferences', () async { - final service = context.service; await expectLater( service.getInboundReferences('', '', 0), throwsRPCError); }); test('getRetainingPath', () async { - final service = context.service; await expectLater(service.getRetainingPath('', '', 0), throwsRPCError); }); test('lookupResolvedPackageUris converts package and org-dartlang-app uris', () async { - final service = context.service; final vm = await service.getVM(); final isolateId = vm.isolates!.first.id!; final scriptList = await service.getScripts(isolateId); @@ -1616,7 +1579,6 @@ void main() { test('lookupResolvedPackageUris does not translate non-existent paths', () async { - final service = context.service; final vm = await service.getVM(); final isolateId = vm.isolates!.first.id!; @@ -1629,7 +1591,6 @@ void main() { }); test('lookupResolvedPackageUris translates dart uris', () async { - final service = context.service; final vm = await service.getVM(); final isolateId = vm.isolates!.first.id!; @@ -1646,7 +1607,6 @@ void main() { test('lookupPackageUris finds package and org-dartlang-app paths', () async { - final service = context.service; final vm = await service.getVM(); final isolateId = vm.isolates!.first.id!; final scriptList = await service.getScripts(isolateId); @@ -1667,7 +1627,6 @@ void main() { }); test('lookupPackageUris ignores local parameter', () async { - final service = context.service; final vm = await service.getVM(); final isolateId = vm.isolates!.first.id!; final scriptList = await service.getScripts(isolateId); @@ -1701,7 +1660,6 @@ void main() { }); test('lookupPackageUris does not translate non-existent paths', () async { - final service = context.service; final vm = await service.getVM(); final isolateId = vm.isolates!.first.id!; @@ -1714,7 +1672,6 @@ void main() { }); test('lookupPackageUris translates dart uris', () async { - final service = context.service; final vm = await service.getVM(); final isolateId = vm.isolates!.first.id!; @@ -1729,19 +1686,16 @@ void main() { ]); }, skip: 'https://github.com/dart-lang/webdev/issues/1584'); - test('registerservice', () async { - final service = context.service; + test('registerService', () async { await expectLater( service.registerService('ext.foo.bar', ''), throwsRPCError); }); test('reloadSources', () async { - final service = context.service; await expectLater(service.reloadSources(''), throwsRPCError); }); test('setIsolatePauseMode', () async { - final service = context.service; final vm = await service.getVM(); final isolateId = vm.isolates!.first.id!; expect(await service.setIsolatePauseMode(isolateId), _isSuccess); @@ -1764,18 +1718,15 @@ void main() { }); test('setFlag', () async { - final service = context.service; await expectLater(service.setFlag('', ''), throwsRPCError); }); test('setLibraryDebuggable', () async { - final service = context.service; await expectLater( service.setLibraryDebuggable('', '', false), throwsRPCError); }); test('setName', () async { - final service = context.service; final vm = await service.getVM(); final isolateId = vm.isolates!.first.id!; expect(service.setName(isolateId, 'test'), completion(_isSuccess)); @@ -1784,26 +1735,21 @@ void main() { }); test('setVMName', () async { - final service = context.service; expect(service.setVMName('foo'), completion(_isSuccess)); final vm = await service.getVM(); expect(vm.name, 'foo'); }); test('streamCancel', () async { - final service = context.service; await expectLater(service.streamCancel(''), throwsRPCError); }); group('streamListen/onEvent', () { - late ChromeProxyService service; - group('Debug', () { late Stream eventStream; setUp(() async { setCurrentLogWriter(debug: debug); - service = context.service; expect(await service.streamListen('Debug'), const TypeMatcher()); eventStream = service.onEvent('Debug'); @@ -1812,12 +1758,12 @@ void main() { test('basic Pause/Resume', () async { expect(service.streamListen('Debug'), completion(_isSuccess)); final stream = service.onEvent('Debug'); - safeUnawaited(context.tabConnection.debugger.pause()); + safeUnawaited(tabConnection.debugger.pause()); await expectLater( stream, emitsThrough(const TypeMatcher() .having((e) => e.kind, 'kind', EventKind.kPauseInterrupted))); - safeUnawaited(context.tabConnection.debugger.resume()); + safeUnawaited(tabConnection.debugger.resume()); expect( eventStream, emitsThrough(const TypeMatcher() @@ -1836,17 +1782,15 @@ void main() { .having((instance) => instance.id, 'id', isNotNull) .having((instance) => instance.kind, 'inspectee.kind', InstanceKind.kPlainInstance)))); - await context.tabConnection.runtime.evaluate('inspectInstance()'); + await tabConnection.runtime.evaluate('inspectInstance()'); }); }); group('Extension', () { - late VmServiceInterface service; late Stream eventStream; setUp(() async { setCurrentLogWriter(debug: debug); - service = context.service; expect(await service.streamListen('Extension'), const TypeMatcher()); eventStream = service.onEvent('Extension'); @@ -1860,8 +1804,7 @@ void main() { event.kind == EventKind.kExtension && event.extensionKind == eventKind && event.extensionData!.data['example'] == 'data'))); - await context.tabConnection.runtime - .evaluate("postEvent('$eventKind');"); + await tabConnection.runtime.evaluate("postEvent('$eventKind');"); }); test('Batched debug events from injected client', () async { @@ -1894,11 +1837,11 @@ void main() { ])); for (var data in batch1) { - await context.tabConnection.runtime.evaluate(emitDebugEvent(data)); + await tabConnection.runtime.evaluate(emitDebugEvent(data)); } await Future.delayed(delay); for (var data in batch2) { - await context.tabConnection.runtime.evaluate(emitDebugEvent(data)); + await tabConnection.runtime.evaluate(emitDebugEvent(data)); } }); }); @@ -1915,14 +1858,14 @@ void main() { isolateEventStream = service.onEvent(EventStreams.kIsolate); }); - test('serviceExtensionAdded', () async { + test('ServiceExtensionAdded', () async { final extensionMethod = 'ext.foo.bar'; expect( isolateEventStream, emitsThrough(predicate((Event event) => event.kind == EventKind.kServiceExtensionAdded && event.extensionRPC == extensionMethod))); - await context.tabConnection.runtime + await tabConnection.runtime .evaluate("registerExtension('$extensionMethod');"); }); @@ -1964,8 +1907,7 @@ void main() { expect( isolateEventStream, emitsInOrder(extensions.map(eventMatcher))); for (var extension in extensions) { - await context.tabConnection.runtime - .evaluate(emitRegisterEvent(extension)); + await tabConnection.runtime.evaluate(emitRegisterEvent(extension)); } }); }); @@ -1982,7 +1924,7 @@ void main() { event.kind == EventKind.kWriteEvent && String.fromCharCodes(base64.decode(event.bytes!)) .contains('hello')))); - await context.tabConnection.runtime.evaluate('console.log("hello");'); + await tabConnection.runtime.evaluate('console.log("hello");'); }); test('Stderr', () async { @@ -1994,7 +1936,7 @@ void main() { event.kind == EventKind.kWriteEvent && String.fromCharCodes(base64.decode(event.bytes!)) .contains('Error')))); - await context.tabConnection.runtime.evaluate('console.error("Error");'); + await tabConnection.runtime.evaluate('console.error("Error");'); }); test('exception stack trace mapper', () async { @@ -2006,8 +1948,7 @@ void main() { event.kind == EventKind.kWriteEvent && String.fromCharCodes(base64.decode(event.bytes!)) .contains('main.dart')))); - await context.tabConnection.runtime - .evaluate('throwUncaughtException();'); + await tabConnection.runtime.evaluate('throwUncaughtException();'); }); test('VM', () async { @@ -2023,14 +1964,12 @@ void main() { }); test('Logging', () async { - final service = context.service; expect( service.streamListen(EventStreams.kLogging), completion(_isSuccess)); final stream = service.onEvent(EventStreams.kLogging); final message = 'myMessage'; - safeUnawaited( - context.tabConnection.runtime.evaluate("sendLog('$message');")); + safeUnawaited(tabConnection.runtime.evaluate("sendLog('$message');")); final event = await stream.first; expect(event.kind, EventKind.kLogging); diff --git a/dwds/test/dart_uri_file_uri_test.dart b/dwds/test/dart_uri_file_uri_test.dart index f4ceb2df6..293501f41 100644 --- a/dwds/test/dart_uri_file_uri_test.dart +++ b/dwds/test/dart_uri_file_uri_test.dart @@ -8,31 +8,26 @@ import 'package:dwds/src/utilities/dart_uri.dart'; import 'package:path/path.dart' as p; import 'package:test/test.dart'; -import 'package:test_common/test_sdk_configuration.dart'; import 'fixtures/context.dart'; import 'fixtures/project.dart'; +final testProject = TestProject.testWithSoundNullSafety; +final testPackageProject = TestProject.testPackageWithSoundNullSafety(); +final context = TestContext(testPackageProject); + +/// The directory for the general _test package. +final testDir = testProject.absolutePackageDirectory; + +/// The directory for the _testPackage package (contained within dwds), which +/// imports _test. +final testPackageDir = testPackageProject.absolutePackageDirectory; + // This tests converting file Uris into our internal paths. // // These tests are separated out because we need a running isolate in order to // look up packages. void main() { - final provider = TestSdkConfigurationProvider(); - tearDownAll(provider.dispose); - - final testProject = TestProject.testWithSoundNullSafety; - final testPackageProject = TestProject.testPackageWithSoundNullSafety(); - - /// The directory for the general _test package. - final testDir = testProject.absolutePackageDirectory; - - /// The directory for the _testPackage package (contained within dwds), - /// which imports _test. - final testPackageDir = testPackageProject.absolutePackageDirectory; - - final context = TestContext(testPackageProject, provider); - for (final compilationMode in CompilationMode.values) { group('$compilationMode |', () { for (final useDebuggerModuleNames in [false, true]) { diff --git a/dwds/test/debug_extension_test.dart b/dwds/test/debug_extension_test.dart index 5950eeb35..4df26f09f 100644 --- a/dwds/test/debug_extension_test.dart +++ b/dwds/test/debug_extension_test.dart @@ -14,7 +14,6 @@ import 'package:dwds/src/connections/debug_connection.dart'; import 'package:dwds/src/handlers/injector.dart'; import 'package:http/http.dart' as http; import 'package:test/test.dart'; -import 'package:test_common/test_sdk_configuration.dart'; // ignore: deprecated_member_use import 'package:webdriver/io.dart'; @@ -32,12 +31,9 @@ import 'fixtures/utilities.dart'; // Remove the key before pushing code to GitHub. // See go/extension-identification. -void main() async { - final provider = TestSdkConfigurationProvider(); - tearDownAll(provider.dispose); - - final context = TestContext(TestProject.testWithSoundNullSafety, provider); +final context = TestContext(TestProject.testWithSoundNullSafety); +void main() async { Future waitForDartDevToolsWithRetry({ int retryCount = 6, Duration retryWait = const Duration(seconds: 1), @@ -209,6 +205,7 @@ void main() async { } group('With encoding', () { + final context = TestContext(TestProject.testWithSoundNullSafety); setUp(() async { await context.setUp( enableDebugExtension: true, @@ -229,6 +226,7 @@ void main() async { }); group('With "any" hostname', () { + final context = TestContext(TestProject.testWithSoundNullSafety); final uriPattern = RegExp(r'dartExtensionUri = "([^"]+)";'); setUp(() async { diff --git a/dwds/test/debug_service_test.dart b/dwds/test/debug_service_test.dart index 5ecc447b8..9db319331 100644 --- a/dwds/test/debug_service_test.dart +++ b/dwds/test/debug_service_test.dart @@ -9,17 +9,13 @@ import 'dart:convert'; import 'dart:io'; import 'package:test/test.dart'; -import 'package:test_common/test_sdk_configuration.dart'; import 'fixtures/context.dart'; import 'fixtures/project.dart'; -void main() { - final provider = TestSdkConfigurationProvider(); - tearDownAll(provider.dispose); - - final context = TestContext(TestProject.testWithSoundNullSafety, provider); +final context = TestContext(TestProject.testWithSoundNullSafety); +void main() { setUpAll(() async { // Disable DDS as we're testing DWDS behavior. await context.setUp(spawnDds: false); diff --git a/dwds/test/debugger_test.dart b/dwds/test/debugger_test.dart index c6514e4aa..ce55a2fa2 100644 --- a/dwds/test/debugger_test.dart +++ b/dwds/test/debugger_test.dart @@ -18,9 +18,12 @@ import 'package:vm_service/vm_service.dart' hide LogRecord; import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart' show CallFrame, DebuggerPausedEvent, StackTrace, WipCallFrame, WipScript; +import 'fixtures/context.dart'; import 'fixtures/debugger_data.dart'; import 'fixtures/fakes.dart'; +import 'fixtures/project.dart'; +final context = TestContext(TestProject.testWithSoundNullSafety); late AppInspector inspector; late Debugger debugger; late FakeWebkitDebugger webkitDebugger; diff --git a/dwds/test/devtools_test.dart b/dwds/test/devtools_test.dart index d869158e1..58024df59 100644 --- a/dwds/test/devtools_test.dart +++ b/dwds/test/devtools_test.dart @@ -7,7 +7,6 @@ import 'dart:io'; import 'package:test/test.dart'; -import 'package:test_common/test_sdk_configuration.dart'; import 'package:vm_service/vm_service.dart'; // ignore: deprecated_member_use import 'package:webdriver/io.dart'; @@ -15,6 +14,8 @@ import 'package:webdriver/io.dart'; import 'fixtures/context.dart'; import 'fixtures/project.dart'; +final context = TestContext(TestProject.testWithSoundNullSafety); + Future _waitForPageReady(TestContext context) async { var attempt = 100; while (attempt-- > 0) { @@ -26,11 +27,6 @@ Future _waitForPageReady(TestContext context) async { } void main() { - final provider = TestSdkConfigurationProvider(); - tearDownAll(provider.dispose); - - final context = TestContext(TestProject.testWithSoundNullSafety, provider); - group('Injected client', () { setUp(() async { await context.setUp( diff --git a/dwds/test/evaluate_circular_common.dart b/dwds/test/evaluate_circular_common.dart index 0561758b0..43ec19915 100644 --- a/dwds/test/evaluate_circular_common.dart +++ b/dwds/test/evaluate_circular_common.dart @@ -8,14 +8,12 @@ import 'dart:async'; import 'package:test/test.dart'; import 'package:test_common/logging.dart'; -import 'package:test_common/test_sdk_configuration.dart'; import 'package:vm_service/vm_service.dart'; import 'fixtures/context.dart'; import 'fixtures/project.dart'; void testAll({ - required TestSdkConfigurationProvider provider, CompilationMode compilationMode = CompilationMode.buildDaemon, IndexBaseMode indexBaseMode = IndexBaseMode.noBase, NullSafety nullSafety = NullSafety.sound, @@ -28,11 +26,10 @@ void testAll({ 'build daemon scenario does not support non-empty base in index file'); } - final testCircular1 = TestProject.testCircular1(nullSafety: nullSafety); - final testCircular2 = TestProject.testCircular2( + final project1 = TestProject.testCircular1(nullSafety: nullSafety); + final project2 = TestProject.testCircular2( nullSafety: nullSafety, baseMode: indexBaseMode); - - final context = TestContext(testCircular2, provider); + final context = TestContext(project2); Future onBreakPoint(String isolate, ScriptRef script, String breakPointId, Future Function() body) async { @@ -69,7 +66,6 @@ void testAll({ setUp(() => setCurrentLogWriter(debug: debug)); group('evaluateInFrame', () { - late VmServiceInterface service; VM vm; late Isolate isolate; late String isolateId; @@ -80,17 +76,16 @@ void testAll({ setUp(() async { setCurrentLogWriter(debug: debug); - service = context.service; - vm = await service.getVM(); - isolate = await service.getIsolate(vm.isolates!.first.id!); + vm = await context.service.getVM(); + isolate = await context.service.getIsolate(vm.isolates!.first.id!); isolateId = isolate.id!; - scripts = await service.getScripts(isolateId); + scripts = await context.service.getScripts(isolateId); - await service.streamListen('Debug'); - stream = service.onEvent('Debug'); + await context.service.streamListen('Debug'); + stream = context.service.onEvent('Debug'); - final test1 = testCircular1.packageName; - final test2 = testCircular2.packageName; + final test1 = project1.packageName; + final test2 = project2.packageName; test1LibraryScript = scripts.scripts!.firstWhere( (each) => each.uri!.contains('package:$test1/library1.dart')); @@ -99,7 +94,7 @@ void testAll({ }); tearDown(() async { - await service.resume(isolateId); + await context.service.resume(isolateId); }); test('evaluate expression in _test_circular1/library', () async { diff --git a/dwds/test/evaluate_common.dart b/dwds/test/evaluate_common.dart index 49613c976..f889a6e7b 100644 --- a/dwds/test/evaluate_common.dart +++ b/dwds/test/evaluate_common.dart @@ -8,14 +8,12 @@ import 'dart:async'; import 'package:test/test.dart'; import 'package:test_common/logging.dart'; -import 'package:test_common/test_sdk_configuration.dart'; import 'package:vm_service/vm_service.dart'; import 'fixtures/context.dart'; import 'fixtures/project.dart'; void testAll({ - required TestSdkConfigurationProvider provider, CompilationMode compilationMode = CompilationMode.buildDaemon, IndexBaseMode indexBaseMode = IndexBaseMode.noBase, NullSafety nullSafety = NullSafety.sound, @@ -27,12 +25,10 @@ void testAll({ throw StateError( 'build daemon scenario does not support non-empty base in index file'); } - final testProject = TestProject.test(nullSafety: nullSafety); final testPackageProject = TestProject.testPackage(nullSafety: nullSafety, baseMode: indexBaseMode); - - final context = TestContext(testPackageProject, provider); + final context = TestContext(testPackageProject); Future onBreakPoint(String isolate, ScriptRef script, String breakPointId, Future Function() body) async { @@ -51,7 +47,7 @@ void testAll({ } } - group('Shared context with evaluation |', () { + group('shared context with evaluation |', () { setUpAll(() async { setCurrentLogWriter(debug: debug); await context.setUp( @@ -531,12 +527,11 @@ void testAll({ setUp(() async { setCurrentLogWriter(debug: debug); - final service = context.service; - vm = await service.getVM(); - isolate = await service.getIsolate(vm.isolates!.first.id!); + vm = await context.service.getVM(); + isolate = await context.service.getIsolate(vm.isolates!.first.id!); isolateId = isolate.id!; - await service.streamListen('Debug'); + await context.service.streamListen('Debug'); }); tearDown(() async {}); @@ -664,14 +659,13 @@ void testAll({ late Stream stream; setUp(() async { - final service = context.service; - vm = await service.getVM(); - isolate = await service.getIsolate(vm.isolates!.first.id!); + vm = await context.service.getVM(); + isolate = await context.service.getIsolate(vm.isolates!.first.id!); isolateId = isolate.id!; - scripts = await service.getScripts(isolateId); + scripts = await context.service.getScripts(isolateId); - await service.streamListen('Debug'); - stream = service.onEvent('Debug'); + await context.service.streamListen('Debug'); + stream = context.service.onEvent('Debug'); mainScript = scripts.scripts! .firstWhere((each) => each.uri!.contains('main.dart')); diff --git a/dwds/test/events_test.dart b/dwds/test/events_test.dart index 272ba4ead..31faad5a2 100644 --- a/dwds/test/events_test.dart +++ b/dwds/test/events_test.dart @@ -7,22 +7,21 @@ import 'dart:async'; import 'dart:io'; import 'package:dwds/src/events.dart'; +import 'package:dwds/src/services/chrome_proxy_service.dart'; import 'package:dwds/src/utilities/server.dart'; import 'package:test/test.dart'; import 'package:test_common/logging.dart'; -import 'package:test_common/test_sdk_configuration.dart'; import 'package:vm_service/vm_service.dart'; import 'package:webdriver/async_core.dart'; import 'fixtures/context.dart'; import 'fixtures/project.dart'; -void main() { - final provider = TestSdkConfigurationProvider(); - tearDownAll(provider.dispose); +final context = TestContext(TestProject.testWithSoundNullSafety); - final context = TestContext(TestProject.testWithSoundNullSafety, provider); +ChromeProxyService get service => context.service; +void main() { group('serve requests', () { late HttpServer server; @@ -169,13 +168,11 @@ void main() { }); group('evaluate', () { - late VmServiceInterface service; late String isolateId; late String bootstrapId; setUpAll(() async { setCurrentLogWriter(); - service = context.service; final vm = await service.getVM(); final isolate = await service.getIsolate(vm.isolates!.first.id!); isolateId = isolate.id!; @@ -215,14 +212,12 @@ void main() { }); group('evaluateInFrame', () { - late VmServiceInterface service; late String isolateId; late Stream stream; late ScriptRef mainScript; setUpAll(() async { setCurrentLogWriter(); - service = context.service; final vm = await service.getVM(); isolateId = vm.isolates!.first.id!; @@ -307,13 +302,11 @@ void main() { }); group('getSourceReport', () { - late VmServiceInterface service; late String isolateId; late ScriptRef mainScript; setUp(() async { setCurrentLogWriter(); - service = context.service; final vm = await service.getVM(); isolateId = vm.isolates!.first.id!; final scriptList = await service.getScripts(isolateId); @@ -334,12 +327,10 @@ void main() { }); group('getSripts', () { - late VmServiceInterface service; late String isolateId; setUp(() async { setCurrentLogWriter(); - service = context.service; final vm = await service.getVM(); isolateId = vm.isolates!.first.id!; }); @@ -354,12 +345,10 @@ void main() { }); group('getIsolate', () { - late VmServiceInterface service; late String isolateId; setUp(() async { setCurrentLogWriter(); - service = context.service; final vm = await service.getVM(); isolateId = vm.isolates!.first.id!; }); @@ -383,7 +372,7 @@ void main() { matchesEvent(DwdsEventKind.getVM, { 'elapsedMilliseconds': isNotNull, }), - () => context.service.getVM()); + () => service.getVM()); }); }); @@ -404,12 +393,10 @@ void main() { }); group('resume', () { - late VmServiceInterface service; late String isolateId; setUp(() async { setCurrentLogWriter(); - service = context.service; final vm = await service.getVM(); isolateId = vm.isolates!.first.id!; await service.streamListen('Debug'); diff --git a/dwds/test/fixtures/context.dart b/dwds/test/fixtures/context.dart index 518209c2b..de2168f49 100644 --- a/dwds/test/fixtures/context.dart +++ b/dwds/test/fixtures/context.dart @@ -35,7 +35,8 @@ import 'package:test/test.dart'; import 'package:test_common/logging.dart'; import 'package:test_common/test_sdk_configuration.dart'; import 'package:vm_service/vm_service.dart'; -import 'package:webdriver/async_io.dart'; +// ignore: deprecated_member_use +import 'package:webdriver/io.dart'; import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart'; import 'project.dart'; @@ -55,7 +56,6 @@ enum CompilationMode { buildDaemon, frontendServer } class TestContext { final TestProject project; final NullSafety nullSafety; - final TestSdkConfigurationProvider sdkConfigurationProvider; /// Top level directory in which we run the test server, e.g. /// "/workstation/webdev/fixtures/_testSound". @@ -144,8 +144,7 @@ class TestContext { /// External VM service. VmServiceInterface get vmService => debugConnection.vmService; - TestContext(this.project, this.sdkConfigurationProvider) - : nullSafety = project.nullSafety { + TestContext(this.project) : nullSafety = project.nullSafety { DartUri.currentDirectory = workingDirectory; project.validate(); @@ -176,13 +175,14 @@ class TestContext { bool isInternalBuild = false, List experiments = const [], }) async { + // Generate missing SDK assets if needed. + final sdkConfigurationProvider = + TestSdkConfigurationProvider(verboseCompiler: verboseCompiler); final sdkLayout = sdkConfigurationProvider.sdkLayout; + final configuration = await sdkConfigurationProvider.configuration; + configuration.validate(); try { - // Make sure configuration was created correctly. - final configuration = await sdkConfigurationProvider.configuration; - configuration.validate(); - DartUri.currentDirectory = workingDirectory; configureLogWriter(); @@ -222,7 +222,7 @@ class TestContext { 'Could not start ChromeDriver. Is it installed?\nError: $e'); } - await Process.run(sdkLayout.dartPath, ['pub', 'upgrade'], + await Process.run(dartPath, ['pub', 'upgrade'], workingDirectory: workingDirectory); ExpressionCompiler? expressionCompiler; @@ -244,8 +244,8 @@ class TestContext { '--enable-experiment=$experiment', '--verbose', ]; - _daemonClient = await connectClient( - sdkLayout.dartPath, workingDirectory, options, (log) { + _daemonClient = + await connectClient(workingDirectory, options, (log) { final record = log.toLogRecord(); final name = record.loggerName == '' ? '' : '${record.loggerName}: '; @@ -390,7 +390,6 @@ class TestContext { ddcService, isFlutterApp, isInternalBuild, - sdkLayout, ); _appUrl = basePath.isEmpty diff --git a/dwds/test/fixtures/server.dart b/dwds/test/fixtures/server.dart index 57b511ded..9c17b9567 100644 --- a/dwds/test/fixtures/server.dart +++ b/dwds/test/fixtures/server.dart @@ -16,9 +16,10 @@ import 'package:dwds/src/services/expression_compiler_service.dart'; import 'package:dwds/src/utilities/server.dart'; import 'package:logging/logging.dart'; import 'package:shelf/shelf.dart'; -import 'package:test_common/test_sdk_layout.dart'; import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart'; +import 'utilities.dart'; + Logger _logger = Logger('TestServer'); Handler _interceptFavicon(Handler handler) { @@ -81,7 +82,6 @@ class TestServer { ExpressionCompilerService? ddcService, bool isFlutterApp, bool isInternalBuild, - TestSdkLayout sdkLayout, ) async { var pipeline = const Pipeline(); @@ -122,7 +122,7 @@ class TestServer { final server = await DevToolsServer().serveDevTools( hostname: hostname, enableStdinCommands: false, - customDevToolsPath: sdkLayout.devToolsDirectory, + customDevToolsPath: devToolsPath, ); if (server == null) { throw StateError('DevTools server could not be started.'); diff --git a/dwds/test/fixtures/test_sdk_layout.dart b/dwds/test/fixtures/test_sdk_layout.dart new file mode 100644 index 000000000..488fdd009 --- /dev/null +++ b/dwds/test/fixtures/test_sdk_layout.dart @@ -0,0 +1,159 @@ +// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +// TODO:(annagrin) Move to a test_common package. +import 'package:dwds/src/utilities/sdk_configuration.dart'; +import 'package:path/path.dart' as p; + +/// Test Dart SDK layout. +/// +/// Contains definition of the default SDK layout required for tests. +/// We keep all the path constants in one place for ease of update. +class TestSdkLayout { + static final defaultSdkDirectory = SdkLayout.defaultSdkDirectory; + static TestSdkLayout defaultSdkLayout = + TestSdkLayout.createDefault(defaultSdkDirectory); + static SdkConfiguration defaultSdkConfiguration = + createConfiguration(defaultSdkLayout); + + factory TestSdkLayout.createDefault(String sdkDirectory) => + TestSdkLayout.createDefaultFromSdkLayout( + SdkLayout.createDefault(sdkDirectory)); + + factory TestSdkLayout.createDefaultFromSdkLayout(SdkLayout sdkLayout) => + TestSdkLayout( + sdkDirectory: sdkLayout.sdkDirectory, + soundSummaryPath: sdkLayout.soundSummaryPath, + soundFullDillPath: p.join( + sdkLayout.sdkDirectory, + 'lib', + '_internal', + 'ddc_platform.dill', + ), + soundJsPath: p.join( + sdkLayout.sdkDirectory, + 'lib', + 'dev_compiler', + 'kernel', + 'amd', + 'dart_sdk.js', + ), + soundJsMapPath: p.join( + sdkLayout.sdkDirectory, + 'lib', + 'dev_compiler', + 'kernel', + 'amd', + 'dart_sdk.js.map', + ), + weakSummaryPath: sdkLayout.weakSummaryPath, + weakFullDillPath: p.join( + sdkLayout.sdkDirectory, + 'lib', + '_internal', + 'ddc_platform_unsound.dill', + ), + weakJsPath: p.join( + sdkLayout.sdkDirectory, + 'lib', + 'dev_compiler', + 'kernel', + 'amd', + 'dart_sdk_unsound.js', + ), + weakJsMapPath: p.join( + sdkLayout.sdkDirectory, + 'lib', + 'dev_compiler', + 'kernel', + 'amd', + 'dart_sdk_unsound.js.map', + ), + requireJsPath: p.join( + sdkLayout.sdkDirectory, + 'lib', + 'dev_compiler', + 'amd', + 'require.js', + ), + stackTraceMapperPath: p.join( + sdkLayout.sdkDirectory, + 'lib', + 'dev_compiler', + 'web', + 'dart_stack_trace_mapper.js', + ), + dartPath: p.join(sdkLayout.sdkDirectory, 'bin', 'dart'), + frontendServerSnapshotPath: p.join( + sdkLayout.sdkDirectory, + 'bin', + 'snapshots', + 'frontend_server.dart.snapshot', + ), + dartdevcSnapshotPath: sdkLayout.dartdevcSnapshotPath, + kernelWorkerSnapshotPath: p.join( + sdkLayout.sdkDirectory, + 'bin', + 'snapshots', + 'kernel_worker.dart.snapshot', + ), + ); + + final String sdkDirectory; + + String get soundJsFileName => p.basename(soundJsPath); + String get soundJsMapFileName => p.basename(soundJsMapPath); + String get soundSummaryFileName => p.basename(soundSummaryPath); + String get soundFullDillFileName => p.basename(soundFullDillPath); + + final String soundJsPath; + final String soundJsMapPath; + final String soundSummaryPath; + final String soundFullDillPath; + + String get weakJsFileName => p.basename(weakJsPath); + String get weakJsMapFileName => p.basename(weakJsMapPath); + String get weakSummaryFileName => p.basename(weakSummaryPath); + String get weakFullDillFileName => p.basename(weakFullDillPath); + + final String weakJsPath; + final String weakJsMapPath; + final String weakSummaryPath; + final String weakFullDillPath; + + final String requireJsPath; + final String stackTraceMapperPath; + + final String dartPath; + final String frontendServerSnapshotPath; + final String dartdevcSnapshotPath; + final String kernelWorkerSnapshotPath; + + const TestSdkLayout({ + required this.sdkDirectory, + required this.soundJsPath, + required this.soundJsMapPath, + required this.soundSummaryPath, + required this.soundFullDillPath, + required this.weakJsPath, + required this.weakJsMapPath, + required this.weakSummaryPath, + required this.weakFullDillPath, + required this.requireJsPath, + required this.stackTraceMapperPath, + required this.dartPath, + required this.frontendServerSnapshotPath, + required this.dartdevcSnapshotPath, + required this.kernelWorkerSnapshotPath, + }); + + /// Creates configuration from sdk layout. + static SdkConfiguration createConfiguration(TestSdkLayout sdkLayout) => + SdkConfiguration( + sdkDirectory: sdkLayout.sdkDirectory, + weakSdkSummaryPath: sdkLayout.weakSummaryPath, + soundSdkSummaryPath: sdkLayout.soundSummaryPath, + compilerWorkerPath: sdkLayout.dartdevcSnapshotPath, + ); +} diff --git a/dwds/test/fixtures/utilities.dart b/dwds/test/fixtures/utilities.dart index 4c5db3f5b..1f153da02 100644 --- a/dwds/test/fixtures/utilities.dart +++ b/dwds/test/fixtures/utilities.dart @@ -68,15 +68,25 @@ String absolutePath({ } /// Connects to the `build_runner` daemon. -Future connectClient( - String dartPath, - String workingDirectory, - List options, - Function(ServerLog) logHandler) => +Future connectClient(String workingDirectory, + List options, Function(ServerLog) logHandler) => BuildDaemonClient.connect(workingDirectory, [dartPath, 'run', 'build_runner', 'daemon', ...options], logHandler: logHandler); +/// The path to the root directory of the SDK. +final String _sdkDir = (() { + // The Dart executable is in "/path/to/sdk/bin/dart", so two levels up is + // "/path/to/sdk". + final aboveExecutable = p.dirname(p.dirname(Platform.resolvedExecutable)); + assert(FileSystemEntity.isFileSync(p.join(aboveExecutable, 'version'))); + return aboveExecutable; +})(); + +final String dartSdkPath = _sdkDir; +final String dartPath = p.join(_sdkDir, 'bin', 'dart'); +final String devToolsPath = p.join(_sdkDir, 'bin', 'resources', 'devtools'); + /// Returns the port of the daemon asset server. int daemonPort(String workingDirectory) { final portFile = File(_assetServerPortFilePath(workingDirectory)); diff --git a/dwds/test/frontend_server_breakpoint_test.dart b/dwds/test/frontend_server_breakpoint_test.dart index 5519a87ea..4adc5fe3b 100644 --- a/dwds/test/frontend_server_breakpoint_test.dart +++ b/dwds/test/frontend_server_breakpoint_test.dart @@ -6,24 +6,22 @@ @Timeout(Duration(minutes: 2)) import 'dart:async'; +import 'package:dwds/src/services/chrome_proxy_service.dart'; import 'package:test/test.dart'; import 'package:test_common/logging.dart'; -import 'package:test_common/test_sdk_configuration.dart'; import 'package:vm_service/vm_service.dart'; import 'fixtures/context.dart'; import 'fixtures/project.dart'; +final context = TestContext(TestProject.testPackageWithSoundNullSafety()); + +ChromeProxyService get service => context.service; + void main() { // Enable verbose logging for debugging. final debug = false; - final provider = TestSdkConfigurationProvider(verbose: debug); - tearDownAll(provider.dispose); - - final context = - TestContext(TestProject.testPackageWithSoundNullSafety(), provider); - // Change to 'true' to print expression compiler messages to console. // // Note: expression compiler runs in an isolate, so its output is not @@ -44,7 +42,6 @@ void main() { }); group('breakpoint', () { - late VmServiceInterface service; VM vm; late Isolate isolate; late String isolateId; @@ -54,7 +51,6 @@ void main() { late Stream stream; setUp(() async { - service = context.service; setCurrentLogWriter(debug: debug); vm = await service.getVM(); isolate = await service.getIsolate(vm.isolates!.first.id!); diff --git a/dwds/test/frontend_server_callstack_test.dart b/dwds/test/frontend_server_callstack_test.dart index c02e4a2ec..3159449d5 100644 --- a/dwds/test/frontend_server_callstack_test.dart +++ b/dwds/test/frontend_server_callstack_test.dart @@ -6,26 +6,23 @@ @Timeout(Duration(minutes: 2)) import 'dart:async'; +import 'package:dwds/src/services/chrome_proxy_service.dart'; import 'package:test/test.dart'; import 'package:test_common/logging.dart'; -import 'package:test_common/test_sdk_configuration.dart'; import 'package:vm_service/vm_service.dart'; import 'fixtures/context.dart'; import 'fixtures/project.dart'; void main() { - // Enable verbose logging for debugging. - final debug = false; - - final provider = TestSdkConfigurationProvider(verbose: debug); - tearDownAll(provider.dispose); - group('shared context |', () { + // Enable verbose logging for debugging. + final debug = false; + for (var nullSafety in NullSafety.values) { group('${nullSafety.name} null safety |', () { final project = TestProject.testPackage(nullSafety: nullSafety); - final context = TestContext(project, provider); + final context = TestContext(project); setUpAll(() async { setCurrentLogWriter(debug: debug); @@ -40,7 +37,7 @@ void main() { }); group('callStack |', () { - late VmServiceInterface service; + late ChromeProxyService service; VM vm; late Isolate isolate; late String isolateId; diff --git a/dwds/test/frontend_server_circular_evaluate_test.dart b/dwds/test/frontend_server_circular_evaluate_test.dart index 7efabf0dd..437583be9 100644 --- a/dwds/test/frontend_server_circular_evaluate_test.dart +++ b/dwds/test/frontend_server_circular_evaluate_test.dart @@ -7,8 +7,8 @@ import 'dart:io'; +import 'package:pub_semver/pub_semver.dart'; import 'package:test/test.dart'; -import 'package:test_common/test_sdk_configuration.dart'; import 'evaluate_circular_common.dart'; import 'fixtures/context.dart'; @@ -18,8 +18,10 @@ void main() async { // Enable verbose logging for debugging. final debug = false; - final provider = TestSdkConfigurationProvider(verbose: debug); - tearDownAll(provider.dispose); + // TODO(annagrin): Remove when 2.19.0-150.0.dev is in stable. + final debuggerModuleNamesSupported = + Version.parse(Platform.version.split(' ').first) >= + Version.parse('2.19.0-150.0.dev'); group('Context with circular dependencies |', () { for (var nullSafety in NullSafety.values) { @@ -27,7 +29,6 @@ void main() async { for (var indexBaseMode in IndexBaseMode.values) { group('with ${indexBaseMode.name} |', () { testAll( - provider: provider, compilationMode: CompilationMode.frontendServer, indexBaseMode: indexBaseMode, nullSafety: nullSafety, @@ -37,7 +38,9 @@ void main() async { }, skip: // https://github.com/dart-lang/sdk/issues/49277 - indexBaseMode == IndexBaseMode.base && Platform.isWindows); + indexBaseMode == IndexBaseMode.base && Platform.isWindows || + // Needs debugger module names change in the SDK to work. + !debuggerModuleNamesSupported); } }); } diff --git a/dwds/test/frontend_server_evaluate_sound_test.dart b/dwds/test/frontend_server_evaluate_sound_test.dart index f4fa02130..4642748fa 100644 --- a/dwds/test/frontend_server_evaluate_sound_test.dart +++ b/dwds/test/frontend_server_evaluate_sound_test.dart @@ -8,7 +8,6 @@ import 'dart:io'; import 'package:test/test.dart'; -import 'package:test_common/test_sdk_configuration.dart'; import 'evaluate_common.dart'; import 'fixtures/context.dart'; @@ -18,9 +17,6 @@ void main() async { // Enable verbose logging for debugging. final debug = false; - final provider = TestSdkConfigurationProvider(verbose: debug); - tearDownAll(provider.dispose); - for (var useDebuggerModuleNames in [false, true]) { group('Debugger module names: $useDebuggerModuleNames |', () { final nullSafety = NullSafety.sound; @@ -28,7 +24,6 @@ void main() async { for (var indexBaseMode in IndexBaseMode.values) { group('with ${indexBaseMode.name} |', () { testAll( - provider: provider, compilationMode: CompilationMode.frontendServer, indexBaseMode: indexBaseMode, nullSafety: nullSafety, diff --git a/dwds/test/frontend_server_evaluate_weak_test.dart b/dwds/test/frontend_server_evaluate_weak_test.dart index c6bcc83d3..1b88cfb7a 100644 --- a/dwds/test/frontend_server_evaluate_weak_test.dart +++ b/dwds/test/frontend_server_evaluate_weak_test.dart @@ -8,7 +8,6 @@ import 'dart:io'; import 'package:test/test.dart'; -import 'package:test_common/test_sdk_configuration.dart'; import 'evaluate_common.dart'; import 'fixtures/context.dart'; @@ -18,9 +17,6 @@ void main() async { // Enable verbose logging for debugging. final debug = false; - final provider = TestSdkConfigurationProvider(verbose: debug); - tearDownAll(provider.dispose); - for (var useDebuggerModuleNames in [false, true]) { group('Debugger module names: $useDebuggerModuleNames |', () { final nullSafety = NullSafety.weak; @@ -28,7 +24,6 @@ void main() async { for (var indexBaseMode in IndexBaseMode.values) { group('with ${indexBaseMode.name} |', () { testAll( - provider: provider, compilationMode: CompilationMode.frontendServer, indexBaseMode: indexBaseMode, nullSafety: nullSafety, diff --git a/dwds/test/handlers/asset_handler_test.dart b/dwds/test/handlers/asset_handler_test.dart index 301136bca..ab2a34cea 100644 --- a/dwds/test/handlers/asset_handler_test.dart +++ b/dwds/test/handlers/asset_handler_test.dart @@ -7,15 +7,13 @@ import 'package:shelf/shelf.dart'; import 'package:test/test.dart'; import 'package:test_common/logging.dart'; -import 'package:test_common/test_sdk_configuration.dart'; import '../fixtures/context.dart'; import '../fixtures/project.dart'; void main() { group('Asset handler', () { - final provider = TestSdkConfigurationProvider(); - final context = TestContext(TestProject.testWithSoundNullSafety, provider); + final context = TestContext(TestProject.testWithSoundNullSafety); setUpAll(() async { setCurrentLogWriter(); @@ -27,7 +25,6 @@ void main() { tearDownAll(() async { await context.tearDown(); - provider.dispose(); }); setUp(setCurrentLogWriter); diff --git a/dwds/test/inspector_test.dart b/dwds/test/inspector_test.dart index f40adeb0a..894dc1684 100644 --- a/dwds/test/inspector_test.dart +++ b/dwds/test/inspector_test.dart @@ -6,31 +6,27 @@ @Timeout(Duration(minutes: 2)) import 'package:dwds/dwds.dart'; +import 'package:dwds/src/connections/debug_connection.dart'; import 'package:dwds/src/debugging/debugger.dart'; import 'package:dwds/src/debugging/inspector.dart'; import 'package:dwds/src/loaders/strategy.dart'; import 'package:dwds/src/utilities/conversions.dart'; import 'package:test/test.dart'; -import 'package:test_common/test_sdk_configuration.dart'; import 'package:vm_service/vm_service.dart'; import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart'; import 'fixtures/context.dart'; import 'fixtures/project.dart'; -void main() { - final provider = TestSdkConfigurationProvider(); - tearDownAll(provider.dispose); - - final context = - TestContext(TestProject.testScopesWithSoundNullSafety, provider); +final context = TestContext(TestProject.testScopesWithSoundNullSafety); +void main() { late AppInspector inspector; late Debugger debugger; setUpAll(() async { await context.setUp(); - final service = context.service; + final service = fetchChromeProxyService(context.debugConnection); inspector = service.inspector; debugger = await service.debuggerFuture; }); diff --git a/dwds/test/instances/instance_inspection_test.dart b/dwds/test/instances/instance_inspection_test.dart index 782a44ca6..7cf729015 100644 --- a/dwds/test/instances/instance_inspection_test.dart +++ b/dwds/test/instances/instance_inspection_test.dart @@ -7,7 +7,6 @@ import 'package:test/test.dart'; import 'package:test_common/logging.dart'; -import 'package:test_common/test_sdk_configuration.dart'; import 'package:vm_service/vm_service.dart'; import '../fixtures/context.dart'; @@ -18,12 +17,8 @@ void main() async { // Enable verbose logging for debugging. final debug = false; - final provider = TestSdkConfigurationProvider(verbose: debug); - tearDownAll(provider.dispose); - for (var compilationMode in CompilationMode.values) { await _runTests( - provider: provider, compilationMode: compilationMode, debug: debug, ); @@ -31,12 +26,10 @@ void main() async { } Future _runTests({ - required TestSdkConfigurationProvider provider, required CompilationMode compilationMode, required bool debug, }) async { - final context = - TestContext(TestProject.testPackageWithSoundNullSafety(), provider); + final context = TestContext(TestProject.testPackageWithSoundNullSafety()); late VmServiceInterface service; late Stream stream; late String isolateId; @@ -67,8 +60,7 @@ Future _runTests({ verboseCompiler: debug, experiments: ['records'], ); - service = context.debugConnection.vmService; - + service = context.service; final vm = await service.getVM(); isolateId = vm.isolates!.first.id!; final scripts = await service.getScripts(isolateId); diff --git a/dwds/test/instances/instance_test.dart b/dwds/test/instances/instance_test.dart index 2aa94061a..d4072aa9a 100644 --- a/dwds/test/instances/instance_test.dart +++ b/dwds/test/instances/instance_test.dart @@ -5,30 +5,28 @@ @Timeout(Duration(minutes: 2)) import 'dart:async'; +import 'package:dwds/src/connections/debug_connection.dart'; import 'package:dwds/src/debugging/debugger.dart'; import 'package:dwds/src/debugging/inspector.dart'; import 'package:dwds/src/loaders/strategy.dart'; import 'package:test/test.dart'; -import 'package:test_common/test_sdk_configuration.dart'; import 'package:vm_service/vm_service.dart'; import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart'; import '../fixtures/context.dart'; import '../fixtures/project.dart'; -void main() { - final provider = TestSdkConfigurationProvider(); - tearDownAll(provider.dispose); +final context = TestContext(TestProject.testScopesWithSoundNullSafety); - final context = - TestContext(TestProject.testScopesWithSoundNullSafety, provider); +WipConnection get tabConnection => context.tabConnection; +void main() { late AppInspector inspector; late Debugger debugger; setUpAll(() async { await context.setUp(); - final chromeProxyService = context.service; + final chromeProxyService = fetchChromeProxyService(context.debugConnection); inspector = chromeProxyService.inspector; debugger = await chromeProxyService.debuggerFuture; }); diff --git a/dwds/test/instances/record_inspection_test.dart b/dwds/test/instances/record_inspection_test.dart index 7cf0c8216..86fa0b18f 100644 --- a/dwds/test/instances/record_inspection_test.dart +++ b/dwds/test/instances/record_inspection_test.dart @@ -7,7 +7,6 @@ import 'package:test/test.dart'; import 'package:test_common/logging.dart'; -import 'package:test_common/test_sdk_configuration.dart'; import 'package:vm_service/vm_service.dart'; import '../fixtures/context.dart'; @@ -18,12 +17,8 @@ void main() async { // Enable verbose logging for debugging. final debug = false; - final provider = TestSdkConfigurationProvider(verbose: debug); - tearDownAll(provider.dispose); - for (var compilationMode in CompilationMode.values) { await _runTests( - provider: provider, compilationMode: compilationMode, debug: debug, ); @@ -31,12 +26,10 @@ void main() async { } Future _runTests({ - required TestSdkConfigurationProvider provider, required CompilationMode compilationMode, required bool debug, }) async { - final context = - TestContext(TestProject.testExperimentWithSoundNullSafety, provider); + final context = TestContext(TestProject.testExperimentWithSoundNullSafety); final testInspector = TestInspector(context); late VmServiceInterface service; @@ -67,8 +60,7 @@ Future _runTests({ verboseCompiler: debug, experiments: ['records'], ); - service = context.debugConnection.vmService; - + service = context.service; final vm = await service.getVM(); isolateId = vm.isolates!.first.id!; final scripts = await service.getScripts(isolateId); @@ -80,9 +72,7 @@ Future _runTests({ .firstWhere((each) => each.uri!.contains('main.dart')); }); - tearDownAll(() async { - await context.tearDown(); - }); + tearDownAll(context.tearDown); setUp(() => setCurrentLogWriter(debug: debug)); tearDown(() => service.resume(isolateId)); diff --git a/dwds/test/listviews_test.dart b/dwds/test/listviews_test.dart index 2f039022e..1ec528bda 100644 --- a/dwds/test/listviews_test.dart +++ b/dwds/test/listviews_test.dart @@ -5,17 +5,13 @@ @Timeout(Duration(minutes: 2)) import 'package:test/test.dart'; -import 'package:test_common/test_sdk_configuration.dart'; import 'fixtures/context.dart'; import 'fixtures/project.dart'; -void main() { - final provider = TestSdkConfigurationProvider(); - tearDownAll(provider.dispose); - - final context = TestContext(TestProject.testWithSoundNullSafety, provider); +final context = TestContext(TestProject.testWithSoundNullSafety); +void main() { setUpAll(() async { await context.setUp(); }); @@ -47,5 +43,7 @@ void main() { expect(result.json, expected); }, + // TODO(https://github.com/dart-lang/webdev/issues/1741): Re-enable when resolved. + skip: true, ); } diff --git a/dwds/test/package_uri_mapper_test.dart b/dwds/test/package_uri_mapper_test.dart index 8270d4ca7..f4185b0a7 100644 --- a/dwds/test/package_uri_mapper_test.dart +++ b/dwds/test/package_uri_mapper_test.dart @@ -16,7 +16,6 @@ import 'fixtures/project.dart'; void main() { final project = TestProject.testPackageWithSoundNullSafety(); - for (final useDebuggerModuleNames in [true, false]) { group( 'Package uri mapper with debugger module names: ' @@ -34,6 +33,7 @@ void main() { '/webdev/fixtures/${project.packageDirectory}/lib/test_library.dart'; final testPackageSoundPath = project.absolutePackageDirectory; + final packageConfigFile = Uri.file(p.join( testPackageSoundPath, '.dart_tool', diff --git a/dwds/test/puppeteer/extension_test.dart b/dwds/test/puppeteer/extension_test.dart index c660e564e..feb097ccf 100644 --- a/dwds/test/puppeteer/extension_test.dart +++ b/dwds/test/puppeteer/extension_test.dart @@ -18,7 +18,6 @@ import 'package:dwds/data/debug_info.dart'; import 'package:path/path.dart' as p; import 'package:puppeteer/puppeteer.dart'; import 'package:test/test.dart'; -import 'package:test_common/test_sdk_configuration.dart'; import '../../debug_extension_mv3/web/data_serializers.dart'; import '../../debug_extension_mv3/web/data_types.dart'; @@ -36,13 +35,11 @@ import 'test_utils.dart'; // To run the MV2 tests only: // dart test test/puppeteer/extension_test.dart --r=expanded --no-retry --n="MV2 Debug Extension" +final context = TestContext(TestProject.testWithSoundNullSafety); + enum Panel { debugger, inspector } void main() async { - final provider = TestSdkConfigurationProvider(); - final context = TestContext(TestProject.testWithSoundNullSafety, provider); - tearDownAll(provider.dispose); - for (var isMV3 in [true, false]) { group('${isMV3 ? 'MV3' : 'MV2'} Debug Extension', () { late String extensionPath; @@ -87,7 +84,6 @@ void main() async { tearDownAll(() async { await browser.close(); - await context.tearDown(); }); test('the debug info for a Dart app is saved in session storage', diff --git a/dwds/test/puppeteer/lifeline_test.dart b/dwds/test/puppeteer/lifeline_test.dart index c50e4bc4e..dc4f95d37 100644 --- a/dwds/test/puppeteer/lifeline_test.dart +++ b/dwds/test/puppeteer/lifeline_test.dart @@ -8,23 +8,20 @@ import 'dart:async'; import 'package:puppeteer/puppeteer.dart'; import 'package:test/test.dart'; -import 'package:test_common/test_sdk_configuration.dart'; import '../fixtures/context.dart'; import '../fixtures/project.dart'; import 'test_utils.dart'; +final context = TestContext(TestProject.testWithSoundNullSafety); + void main() async { - final provider = TestSdkConfigurationProvider(); - final context = TestContext(TestProject.testWithSoundNullSafety, provider); late Worker worker; late Browser browser; late String extensionPath; int connectionCount = 0; - tearDownAll(provider.dispose); - group('MV3 Debug Extension Lifeline Connection', () { setUpAll(() async { extensionPath = await buildDebugExtension(isMV3: true); @@ -38,7 +35,6 @@ void main() async { tearDownAll(() async { await browser.close(); - await context.tearDown(); }); test('connects to a lifeline port', () async { diff --git a/dwds/test/readers/frontend_server_asset_reader_test.dart b/dwds/test/readers/frontend_server_asset_reader_test.dart index 53506a6c3..619038873 100644 --- a/dwds/test/readers/frontend_server_asset_reader_test.dart +++ b/dwds/test/readers/frontend_server_asset_reader_test.dart @@ -9,11 +9,11 @@ import 'dart:io'; import 'package:dwds/src/readers/frontend_server_asset_reader.dart'; import 'package:path/path.dart' as p; import 'package:test/test.dart'; -import 'package:test_common/test_sdk_layout.dart'; -import '../fixtures/project.dart'; import '../fixtures/utilities.dart'; +final packagesDir = absolutePath(pathFromFixtures: '_test'); + final fixturesDir = absolutePath(pathFromDwds: p.join('test', 'fixtures')); void main() { @@ -22,9 +22,6 @@ void main() { late File jsonOriginal; late File mapOriginal; - final testProject = TestProject.testWithSoundNullSafety; - final packagesDir = testProject.absolutePackageDirectory; - Future createTempFixtures() async { tempFixtures = await Directory.systemTemp.createTemp('dwds_test_fixtures'); await tempFixtures.create(); @@ -35,8 +32,7 @@ void main() { } setUpAll(() async { - final sdkLayout = TestSdkLayout.defaultSdkLayout; - await Process.run(sdkLayout.dartPath, ['pub', 'upgrade'], + await Process.run(dartPath, ['pub', 'upgrade'], workingDirectory: packagesDir); }); diff --git a/dwds/test/readers/proxy_server_asset_reader_test.dart b/dwds/test/readers/proxy_server_asset_reader_test.dart index 9f0e0887e..b2363bb11 100644 --- a/dwds/test/readers/proxy_server_asset_reader_test.dart +++ b/dwds/test/readers/proxy_server_asset_reader_test.dart @@ -6,28 +6,18 @@ import 'package:dwds/src/readers/proxy_server_asset_reader.dart'; import 'package:test/test.dart'; -import 'package:test_common/test_sdk_configuration.dart'; import '../fixtures/context.dart'; import '../fixtures/project.dart'; void main() { group('ProxyServerAssetReader', () { - final provider = TestSdkConfigurationProvider(); - tearDownAll(provider.dispose); - - final context = TestContext(TestProject.testWithSoundNullSafety, provider); - + final context = TestContext(TestProject.testWithSoundNullSafety); late ProxyServerAssetReader assetReader; setUpAll(() async { await context.setUp(); assetReader = context.testServer.assetReader as ProxyServerAssetReader; }); - - tearDownAll(() async { - await context.tearDown(); - }); - test('returns null if the dart path does not exist', () async { final result = await assetReader.dartSourceContents('some/path/foo.dart'); expect(result, isNull); diff --git a/dwds/test/refresh_test.dart b/dwds/test/refresh_test.dart index 2bfedb312..e7d1eaf6a 100644 --- a/dwds/test/refresh_test.dart +++ b/dwds/test/refresh_test.dart @@ -10,25 +10,22 @@ library refresh_test; import 'dart:async'; +import 'package:dwds/src/services/chrome_proxy_service.dart'; import 'package:test/test.dart'; -import 'package:test_common/test_sdk_configuration.dart'; import 'package:vm_service/vm_service.dart'; import 'fixtures/context.dart'; import 'fixtures/project.dart'; -void main() { - final provider = TestSdkConfigurationProvider(); - tearDownAll(provider.dispose); +final context = TestContext(TestProject.testWithSoundNullSafety); - final context = TestContext(TestProject.testWithSoundNullSafety, provider); +ChromeProxyService get service => context.service; +void main() { group('fresh context', () { - late VmServiceInterface service; late VM vm; setUpAll(() async { await context.setUp(); - service = context.service; vm = await service.getVM(); }); diff --git a/dwds/test/reload_test.dart b/dwds/test/reload_test.dart index 212621b69..5dd30e98a 100644 --- a/dwds/test/reload_test.dart +++ b/dwds/test/reload_test.dart @@ -7,40 +7,19 @@ import 'package:dwds/src/loaders/strategy.dart'; import 'package:test/test.dart'; import 'package:test_common/logging.dart'; -import 'package:test_common/test_sdk_configuration.dart'; import 'package:vm_service/vm_service.dart'; import 'fixtures/context.dart'; import 'fixtures/project.dart'; +final context = TestContext(TestProject.testAppendBodyWithSoundNullSafety); + const originalString = 'Hello World!'; const newString = 'Bonjour le monde!'; void main() { // set to true for debug logging. final debug = false; - - final provider = TestSdkConfigurationProvider(verbose: debug); - tearDownAll(provider.dispose); - - final context = - TestContext(TestProject.testAppendBodyWithSoundNullSafety, provider); - - Future makeEditAndWaitForRebuild() async { - context.makeEditToDartEntryFile( - toReplace: originalString, - replaceWith: newString, - ); - await context.waitForSuccessfulBuild(propagateToBrowser: true); - } - - void undoEdit() { - context.makeEditToDartEntryFile( - toReplace: newString, - replaceWith: originalString, - ); - } - group('Injected client with live reload', () { group('and with debugging', () { setUp(() async { @@ -459,5 +438,20 @@ void main() { }); } +Future makeEditAndWaitForRebuild() async { + context.makeEditToDartEntryFile( + toReplace: originalString, + replaceWith: newString, + ); + await context.waitForSuccessfulBuild(propagateToBrowser: true); +} + +void undoEdit() { + context.makeEditToDartEntryFile( + toReplace: newString, + replaceWith: originalString, + ); +} + TypeMatcher _hasKind(String kind) => isA().having((e) => e.kind, 'kind', kind); diff --git a/dwds/test/restore_breakpoints_test.dart b/dwds/test/restore_breakpoints_test.dart index 0be78bca6..1629c22d6 100644 --- a/dwds/test/restore_breakpoints_test.dart +++ b/dwds/test/restore_breakpoints_test.dart @@ -6,20 +6,20 @@ @Timeout(Duration(minutes: 2)) import 'dart:async'; +import 'package:dwds/src/connections/debug_connection.dart'; +import 'package:dwds/src/services/chrome_proxy_service.dart'; import 'package:test/test.dart'; import 'package:test_common/logging.dart'; -import 'package:test_common/test_sdk_configuration.dart'; import 'package:vm_service/vm_service.dart'; import 'fixtures/context.dart'; import 'fixtures/project.dart'; -void main() { - final provider = TestSdkConfigurationProvider(); - tearDownAll(provider.dispose); +final context = TestContext(TestProject.testWithSoundNullSafety); - final context = TestContext(TestProject.testWithSoundNullSafety, provider); +ChromeProxyService get service => context.service; +void main() { setUpAll(() async { setCurrentLogWriter(); await context.setUp(); @@ -30,7 +30,6 @@ void main() { }); group('breakpoints', () { - late VmServiceInterface service; VM vm; late Isolate isolate; ScriptList scripts; @@ -39,10 +38,11 @@ void main() { setUp(() async { setCurrentLogWriter(); - service = context.service; - vm = await service.getVM(); - isolate = await service.getIsolate(vm.isolates!.first.id!); - scripts = await service.getScripts(isolate.id!); + vm = await fetchChromeProxyService(context.debugConnection).getVM(); + isolate = await fetchChromeProxyService(context.debugConnection) + .getIsolate(vm.isolates!.first.id!); + scripts = await fetchChromeProxyService(context.debugConnection) + .getScripts(isolate.id!); mainScript = scripts.scripts! .firstWhere((each) => each.uri!.contains('main.dart')); isolateEventStream = service.onEvent('Isolate'); diff --git a/dwds/test/run_request_test.dart b/dwds/test/run_request_test.dart index 0d393ae32..8cb878396 100644 --- a/dwds/test/run_request_test.dart +++ b/dwds/test/run_request_test.dart @@ -5,24 +5,21 @@ @Timeout(Duration(minutes: 2)) import 'dart:async'; +import 'package:dwds/src/services/chrome_proxy_service.dart'; import 'package:test/test.dart'; -import 'package:test_common/test_sdk_configuration.dart'; import 'package:vm_service/vm_service.dart'; import 'fixtures/context.dart'; import 'fixtures/project.dart'; -void main() { - final provider = TestSdkConfigurationProvider(); - tearDownAll(provider.dispose); +final context = TestContext(TestProject.testWithSoundNullSafety); - final context = TestContext(TestProject.testWithSoundNullSafety, provider); +ChromeProxyService get service => context.service; +void main() { group('while debugger is attached', () { - late VmServiceInterface service; setUp(() async { await context.setUp(autoRun: false); - service = context.service; }); tearDown(() async { @@ -59,10 +56,8 @@ void main() { }); group('while debugger is not attached', () { - late VmServiceInterface service; setUp(() async { await context.setUp(autoRun: false, waitToDebug: true); - service = context.service; }); tearDown(() async { diff --git a/dwds/test/screenshot_test.dart b/dwds/test/screenshot_test.dart index db9e4c4e5..84a2c4814 100644 --- a/dwds/test/screenshot_test.dart +++ b/dwds/test/screenshot_test.dart @@ -5,17 +5,13 @@ @Timeout(Duration(minutes: 2)) import 'package:test/test.dart'; -import 'package:test_common/test_sdk_configuration.dart'; import 'fixtures/context.dart'; import 'fixtures/project.dart'; -void main() { - final provider = TestSdkConfigurationProvider(); - tearDownAll(provider.dispose); - - final context = TestContext(TestProject.testWithSoundNullSafety, provider); +final context = TestContext(TestProject.testWithSoundNullSafety); +void main() { setUpAll(() async { await context.setUp(); }); diff --git a/dwds/test/sdk_configuration_test.dart b/dwds/test/sdk_configuration_test.dart index b24e55651..89b2abe55 100644 --- a/dwds/test/sdk_configuration_test.dart +++ b/dwds/test/sdk_configuration_test.dart @@ -10,7 +10,6 @@ import 'package:dwds/src/utilities/sdk_configuration.dart'; import 'package:file/memory.dart'; import 'package:path/path.dart' as p; import 'package:test/test.dart'; -import 'package:test_common/test_sdk_configuration.dart'; var _throwsDoesNotExistException = throwsA( isA() @@ -22,7 +21,7 @@ void main() { final defaultConfiguration = await DefaultSdkConfigurationProvider().configuration; defaultConfiguration.validateSdkDir(); - defaultConfiguration.validateSoundSummaries(); + defaultConfiguration.validate(); }); test('Cannot validate an empty configuration layout', () async { @@ -49,13 +48,16 @@ void main() { await DefaultSdkConfigurationProvider().configuration; final sdkDirectory = outputDir.path; - final sdkLayout = FakeSdkLayout(sdkDirectory); - final sdkConfiguration = FakeSdkLayout.createConfiguration(sdkLayout); + final sdkLayout = TestSdkLayout(sdkDirectory); + final sdkConfiguration = TestSdkLayout.createConfiguration(sdkLayout); + final weakSdkSummaryPath = sdkLayout.weakSummaryPath; final soundSdkSummaryPath = sdkLayout.soundSummaryPath; final summariesDir = p.dirname(soundSdkSummaryPath); Directory(summariesDir).createSync(recursive: true); + File(defaultSdkConfiguration.weakSdkSummaryPath!) + .copySync(weakSdkSummaryPath); File(defaultSdkConfiguration.soundSdkSummaryPath!) .copySync(soundSdkSummaryPath); @@ -67,25 +69,26 @@ void main() { .copySync(compilerWorkerPath); expect(sdkConfiguration.sdkDirectory, equals(sdkDirectory)); + expect(sdkConfiguration.weakSdkSummaryPath, equals(weakSdkSummaryPath)); expect(sdkConfiguration.soundSdkSummaryPath, equals(soundSdkSummaryPath)); expect(sdkConfiguration.compilerWorkerPath, equals(compilerWorkerPath)); sdkConfiguration.validateSdkDir(); - sdkConfiguration.validateSoundSummaries(); + sdkConfiguration.validate(); }); test('Cannot validate non-existing configuration layout', () async { final sdkDirectory = outputDir.path; - final sdkLayout = FakeSdkLayout(sdkDirectory); - final sdkConfiguration = FakeSdkLayout.createConfiguration(sdkLayout); + final sdkLayout = TestSdkLayout(sdkDirectory); + final sdkConfiguration = TestSdkLayout.createConfiguration(sdkLayout); sdkConfiguration.validateSdkDir(); expect(sdkConfiguration.validate, _throwsDoesNotExistException); }); }); - group('SDK configuration with memory file system', () { + group('SDK configuration', () { late MemoryFileSystem fs; final root = '/root'; @@ -115,23 +118,12 @@ void main() { sdkConfiguration.validate(fileSystem: fs); }); }); - - group('Test configuration', () { - final provider = TestSdkConfigurationProvider(); - tearDownAll(provider.dispose); - - test('Can validate configuration layout with generated assets', () async { - final sdkConfiguration = await provider.configuration; - sdkConfiguration.validateSdkDir(); - sdkConfiguration.validate(); - }); - }); } -class FakeSdkLayout { +class TestSdkLayout { final String sdkDirectory; - static SdkConfiguration createConfiguration(FakeSdkLayout sdkLayout) => + static SdkConfiguration createConfiguration(TestSdkLayout sdkLayout) => SdkConfiguration( sdkDirectory: sdkLayout.sdkDirectory, soundSdkSummaryPath: sdkLayout.soundSummaryPath, @@ -139,7 +131,7 @@ class FakeSdkLayout { compilerWorkerPath: sdkLayout.compilerWorkerPath, ); - FakeSdkLayout(this.sdkDirectory); + TestSdkLayout(this.sdkDirectory); String get weakSummaryPath => p.join(sdkDirectory, 'summaries', 'unsound.dill'); diff --git a/dwds/test/variable_scope_test.dart b/dwds/test/variable_scope_test.dart index 188a9fc42..40c2c2cd0 100644 --- a/dwds/test/variable_scope_test.dart +++ b/dwds/test/variable_scope_test.dart @@ -4,22 +4,22 @@ @TestOn('vm') @Timeout(Duration(minutes: 2)) + import 'package:dwds/src/debugging/dart_scope.dart'; import 'package:dwds/src/services/chrome_proxy_service.dart'; import 'package:test/test.dart'; -import 'package:test_common/test_sdk_configuration.dart'; import 'package:vm_service/vm_service.dart'; +import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart'; import 'fixtures/context.dart'; import 'fixtures/project.dart'; -void main() { - final provider = TestSdkConfigurationProvider(); - tearDownAll(provider.dispose); +final context = TestContext(TestProject.testScopesWithSoundNullSafety); - final context = - TestContext(TestProject.testScopesWithSoundNullSafety, provider); +ChromeProxyService get service => context.service; +WipConnection get tabConnection => context.tabConnection; +void main() { setUpAll(() async { await context.setUp(); }); @@ -48,7 +48,6 @@ void main() { }); group('variable scope', () { - late ChromeProxyService service; VM vm; String? isolateId; late Stream stream; @@ -109,7 +108,6 @@ void main() { } setUp(() async { - service = context.service; vm = await service.getVM(); isolateId = vm.isolates!.first.id; scripts = await service.getScripts(isolateId!); diff --git a/fixtures/_experimentSound/pubspec.yaml b/fixtures/_experimentSound/pubspec.yaml index c86678ce3..66555faa8 100644 --- a/fixtures/_experimentSound/pubspec.yaml +++ b/fixtures/_experimentSound/pubspec.yaml @@ -1,4 +1,4 @@ -name: _experiment_sound +name: _experiment version: 1.0.0 description: >- A fake package used for testing experimental language features. diff --git a/frontend_server_common/lib/src/asset_server.dart b/frontend_server_common/lib/src/asset_server.dart index 2731d1d30..6e56e9478 100644 --- a/frontend_server_common/lib/src/asset_server.dart +++ b/frontend_server_common/lib/src/asset_server.dart @@ -14,7 +14,8 @@ import 'package:file/file.dart'; import 'package:logging/logging.dart'; import 'package:mime/mime.dart' as mime; import 'package:shelf/shelf.dart' as shelf; -import 'package:test_common/test_sdk_layout.dart'; + +import 'utilities.dart'; class TestAssetServer implements AssetReader { late final String basePath; @@ -33,7 +34,6 @@ class TestAssetServer implements AssetReader { late String _mergedMetadata; final PackageUriMapper _packageUriMapper; final InternetAddress internetAddress; - final TestSdkLayout _sdkLayout; TestAssetServer( this.index, @@ -41,7 +41,6 @@ class TestAssetServer implements AssetReader { this._packageUriMapper, this.internetAddress, this._fileSystem, - this._sdkLayout, ) { basePath = _parseBasePathFromIndexHtml(index); } @@ -60,7 +59,6 @@ class TestAssetServer implements AssetReader { /// Unhandled exceptions will throw a exception with the error and stack /// trace. static Future start( - String sdkDirectory, FileSystem fileSystem, String index, String hostname, @@ -68,11 +66,10 @@ class TestAssetServer implements AssetReader { UrlEncoder? urlTunneler, PackageUriMapper packageUriMapper, ) async { - final address = (await InternetAddress.lookup(hostname)).first; - final httpServer = await HttpServer.bind(address, port); - final sdkLayout = TestSdkLayout.createDefault(sdkDirectory); - final server = TestAssetServer( - index, httpServer, packageUriMapper, address, fileSystem, sdkLayout); + var address = (await InternetAddress.lookup(hostname)).first; + var httpServer = await HttpServer.bind(address, port); + var server = TestAssetServer( + index, httpServer, packageUriMapper, address, fileSystem); return server; } @@ -260,7 +257,7 @@ class TestAssetServer implements AssetReader { } // Otherwise it must be a Dart SDK source. - var dartSdkParent = _fileSystem.directory(_sdkLayout.sdkDirectory).parent; + var dartSdkParent = _fileSystem.directory(dartSdkPath).parent; var dartSdkFile = _fileSystem.file( _fileSystem.path.joinAll([dartSdkParent.path, ...segments])); return dartSdkFile; diff --git a/frontend_server_common/lib/src/devfs.dart b/frontend_server_common/lib/src/devfs.dart index 1c1c71db5..9bd7c9cbc 100644 --- a/frontend_server_common/lib/src/devfs.dart +++ b/frontend_server_common/lib/src/devfs.dart @@ -43,7 +43,7 @@ class WebDevFS { fileSystem.currentDirectory = projectDirectory.toFilePath(); - assetServer = await TestAssetServer.start(sdkLayout.sdkDirectory, + assetServer = await TestAssetServer.start( fileSystem, index, hostname, port, urlTunneler, packageUriMapper); return Uri.parse('http://$hostname:$port'); } diff --git a/frontend_server_common/lib/src/frontend_server_client.dart b/frontend_server_common/lib/src/frontend_server_client.dart index 3a5300d23..5aa733b32 100644 --- a/frontend_server_common/lib/src/frontend_server_client.dart +++ b/frontend_server_common/lib/src/frontend_server_client.dart @@ -396,7 +396,7 @@ class ResidentCompiler { _logger.info(args.join(' ')); final workingDirectory = projectDirectory.toFilePath(); - _server = await Process.start(sdkLayout.dartPath, args, + _server = await Process.start(Platform.resolvedExecutable, args, workingDirectory: workingDirectory); var server = _server!; diff --git a/frontend_server_common/lib/src/resident_runner.dart b/frontend_server_common/lib/src/resident_runner.dart index 826fc6a38..1c9af81d1 100644 --- a/frontend_server_common/lib/src/resident_runner.dart +++ b/frontend_server_common/lib/src/resident_runner.dart @@ -15,6 +15,7 @@ import 'package:test_common/test_sdk_layout.dart'; import 'devfs.dart'; import 'frontend_server_client.dart'; +import 'utilities.dart'; class ResidentWebRunner { final _logger = Logger('ResidentWebRunner'); @@ -38,7 +39,7 @@ class ResidentWebRunner { : sdkLayout.weakSummaryPath); generator = ResidentCompiler( - sdkLayout.sdkDirectory, + dartSdkPath, projectDirectory: projectDirectory, packageConfigFile: packageConfigFile, useDebuggerModuleNames: packageUriMapper.useDebuggerModuleNames, diff --git a/frontend_server_common/lib/src/utilities.dart b/frontend_server_common/lib/src/utilities.dart index eddc3b40a..1c68b52e6 100644 --- a/frontend_server_common/lib/src/utilities.dart +++ b/frontend_server_common/lib/src/utilities.dart @@ -2,7 +2,21 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. +import 'dart:io'; + import 'package:file/file.dart' as fs; import 'package:file/local.dart'; +import 'package:path/path.dart' as p; + +/// The path to the root directory of the SDK. +final String _sdkDir = (() { + // The Dart executable is in "/path/to/sdk/bin/dart", so two levels up is + // "/path/to/sdk". + var aboveExecutable = p.dirname(p.dirname(Platform.resolvedExecutable)); + assert(FileSystemEntity.isFileSync(p.join(aboveExecutable, 'version'))); + return aboveExecutable; +})(); + +final String dartSdkPath = _sdkDir; const fs.FileSystem localFileSystem = LocalFileSystem(); diff --git a/test_common/lib/test_sdk_configuration.dart b/test_common/lib/test_sdk_configuration.dart index 02618529f..dabb616e0 100644 --- a/test_common/lib/test_sdk_configuration.dart +++ b/test_common/lib/test_sdk_configuration.dart @@ -20,7 +20,7 @@ import 'package:test_common/test_sdk_layout.dart'; /// /// TODO(annagrin): update to only generating missing sound artifacts /// for frontend server after we have no uses of weak null safety. -class TestSdkConfigurationProvider extends SdkConfigurationProvider { +class TestSdkCopyConfigurationProvider extends SdkConfigurationProvider { final _logger = Logger('TestSdkConfigurationProvider'); final bool _verbose; @@ -29,7 +29,8 @@ class TestSdkConfigurationProvider extends SdkConfigurationProvider { late final TestSdkLayout sdkLayout; - TestSdkConfigurationProvider({bool verbose = false}) : _verbose = verbose { + TestSdkCopyConfigurationProvider({bool verbose = false}) + : _verbose = verbose { _sdkDirectory = Directory.systemTemp.createTempSync('sdk copy'); sdkLayout = TestSdkLayout.createDefault(_sdkDirectory.path); } @@ -79,3 +80,38 @@ class TestSdkConfigurationProvider extends SdkConfigurationProvider { } } } + +/// Implementation for SDK configuration for tests that can generate +/// missing assets. +/// +/// - Generate SDK js, source map, and full dill for weak and sound +/// modes (normally included in flutter SDK or produced by build). +/// - Need to generate SDK summary for weak null safety mode as it +/// is not provided by the SDK installation. +/// +/// TODO(annagrin): update to only generating missing sound artifacts +/// for frontend server after we have no uses of weak null safety. +class TestSdkConfigurationProvider extends SdkConfigurationProvider { + final bool _verboseCompiler; + SdkConfiguration? _configuration; + + final sdkLayout = TestSdkLayout.defaultSdkLayout; + + TestSdkConfigurationProvider({bool verboseCompiler = false}) + : _verboseCompiler = verboseCompiler; + + @override + Future get configuration async => + _configuration ??= await _create(); + + /// Generate missing assets in the default SDK layout. + Future _create() async { + final assetGenerator = SdkAssetGenerator( + sdkLayout: sdkLayout, + verboseCompiler: _verboseCompiler, + ); + + await assetGenerator.generateSdkAssets(); + return TestSdkLayout.defaultSdkConfiguration; + } +} diff --git a/test_common/test/test_sdk_configuration_test.dart b/test_common/test/test_sdk_configuration_test.dart index 8a701fc45..bbb88dd08 100644 --- a/test_common/test/test_sdk_configuration_test.dart +++ b/test_common/test/test_sdk_configuration_test.dart @@ -20,7 +20,7 @@ void main() { }); test('Creates and deletes SDK directory copy', () async { - final provider = TestSdkConfigurationProvider(verbose: debug); + final provider = TestSdkCopyConfigurationProvider(verbose: debug); final sdkDirectory = provider.sdkLayout.sdkDirectory; final weakSdkSummary = provider.sdkLayout.weakSummaryPath; try { @@ -42,7 +42,7 @@ void main() { group('Test SDK configuration |', () { setCurrentLogWriter(debug: debug); - final provider = TestSdkConfigurationProvider(verbose: debug); + final provider = TestSdkCopyConfigurationProvider(verbose: debug); tearDownAll(provider.dispose); test('Can validate configuration with generated assets', () async { diff --git a/webdev/test/daemon/app_domain_test.dart b/webdev/test/daemon/app_domain_test.dart index 546172400..ad6f6735e 100644 --- a/webdev/test/daemon/app_domain_test.dart +++ b/webdev/test/daemon/app_domain_test.dart @@ -14,43 +14,39 @@ import 'utils.dart'; void main() { late String exampleDirectory; - final testRunner = TestRunner(); setUpAll(() async { - await testRunner.setUpAll(); - exampleDirectory = await testRunner.prepareWorkspace(); + exampleDirectory = await prepareWorkspace(); }); - tearDownAll(testRunner.tearDownAll); - group('AppDomain', () { group('Events', () { test('.start', () async { - var webdev = await testRunner - .runWebDev(['daemon'], workingDirectory: exampleDirectory); + var webdev = + await runWebDev(['daemon'], workingDirectory: exampleDirectory); await expectLater( webdev.stdout, emitsThrough(startsWith('[{"event":"app.start"'))); await exitWebdev(webdev); }); test('.started', () async { - var webdev = await testRunner - .runWebDev(['daemon'], workingDirectory: exampleDirectory); + var webdev = + await runWebDev(['daemon'], workingDirectory: exampleDirectory); await expectLater( webdev.stdout, emitsThrough(startsWith('[{"event":"app.started"'))); await exitWebdev(webdev); }); test('.debugPort', () async { - var webdev = await testRunner - .runWebDev(['daemon'], workingDirectory: exampleDirectory); + var webdev = + await runWebDev(['daemon'], workingDirectory: exampleDirectory); await expectLater(webdev.stdout, emitsThrough(startsWith('[{"event":"app.debugPort"'))); await exitWebdev(webdev); }); test('.log', () async { - var webdev = await testRunner - .runWebDev(['daemon'], workingDirectory: exampleDirectory); + var webdev = + await runWebDev(['daemon'], workingDirectory: exampleDirectory); var appId = await waitForAppId(webdev); // The example app does an initial print. await expectLater( @@ -64,8 +60,8 @@ void main() { group('Methods', () { test('.callServiceExtension', () async { - var webdev = await testRunner - .runWebDev(['daemon'], workingDirectory: exampleDirectory); + var webdev = + await runWebDev(['daemon'], workingDirectory: exampleDirectory); var appId = await waitForAppId(webdev); if (Platform.isWindows) { // Windows takes a bit longer to run the application and register @@ -85,8 +81,8 @@ void main() { }); test('.reload', () async { - var webdev = await testRunner - .runWebDev(['daemon'], workingDirectory: exampleDirectory); + var webdev = + await runWebDev(['daemon'], workingDirectory: exampleDirectory); var appId = await waitForAppId(webdev); var extensionCall = '[{"method":"app.restart","id":0,' '"params" : { "appId" : "$appId", "fullRestart" : false}}]'; @@ -101,8 +97,8 @@ void main() { }); test('.restart', () async { - var webdev = await testRunner - .runWebDev(['daemon'], workingDirectory: exampleDirectory); + var webdev = + await runWebDev(['daemon'], workingDirectory: exampleDirectory); var appId = await waitForAppId(webdev); var extensionCall = '[{"method":"app.restart","id":0,' '"params" : { "appId" : "$appId", "fullRestart" : true}}]'; @@ -121,8 +117,8 @@ void main() { }); test('.stop', () async { - var webdev = await testRunner - .runWebDev(['daemon'], workingDirectory: exampleDirectory); + var webdev = + await runWebDev(['daemon'], workingDirectory: exampleDirectory); var appId = await waitForAppId(webdev); var stopCall = '[{"method":"app.stop","id":0,' '"params" : { "appId" : "$appId"}}]'; diff --git a/webdev/test/daemon/daemon_domain_test.dart b/webdev/test/daemon/daemon_domain_test.dart index 45cfdf07d..a7102a622 100644 --- a/webdev/test/daemon/daemon_domain_test.dart +++ b/webdev/test/daemon/daemon_domain_test.dart @@ -14,19 +14,15 @@ import 'utils.dart'; void main() { late String exampleDirectory; - final testRunner = TestRunner(); setUpAll(() async { - await testRunner.setUpAll(); - exampleDirectory = await testRunner.prepareWorkspace(); + exampleDirectory = await prepareWorkspace(); }); - tearDownAll(testRunner.tearDownAll); - group('Daemon', () { group('Events', () { test('.connected', () async { - var webdev = await testRunner - .runWebDev(['daemon'], workingDirectory: exampleDirectory); + var webdev = + await runWebDev(['daemon'], workingDirectory: exampleDirectory); await expectLater( webdev.stdout, emits(startsWith('[{"event":"daemon.connected"'))); await exitWebdev(webdev); @@ -35,8 +31,8 @@ void main() { group('Methods', () { test('.version', () async { - var webdev = await testRunner - .runWebDev(['daemon'], workingDirectory: exampleDirectory); + var webdev = + await runWebDev(['daemon'], workingDirectory: exampleDirectory); webdev.stdin.add(utf8.encode('[{"method":"daemon.version","id":0}]\n')); await expectLater( webdev.stdout, emitsThrough(equals('[{"id":0,"result":"0.4.2"}]'))); @@ -44,8 +40,8 @@ void main() { }); test('.shutdown', () async { - var webdev = await testRunner - .runWebDev(['daemon'], workingDirectory: exampleDirectory); + var webdev = + await runWebDev(['daemon'], workingDirectory: exampleDirectory); webdev.stdin .add(utf8.encode('[{"method":"daemon.shutdown","id":0}]\n')); await expectLater(webdev.stdout, emitsThrough(equals('[{"id":0}]'))); diff --git a/webdev/test/daemon/launch_app_test.dart b/webdev/test/daemon/launch_app_test.dart index d37e74ac0..9818e7ba9 100644 --- a/webdev/test/daemon/launch_app_test.dart +++ b/webdev/test/daemon/launch_app_test.dart @@ -11,17 +11,12 @@ import 'utils.dart'; void main() { late String exampleDirectory; - final testRunner = TestRunner(); setUpAll(() async { - await testRunner.setUpAll(); - exampleDirectory = await testRunner.prepareWorkspace(); + exampleDirectory = await prepareWorkspace(); }); - tearDownAll(testRunner.tearDownAll); - test('--launch-app launches the specified app', () async { - var webdev = await testRunner.runWebDev( - ['daemon', '--launch-app=web/scopes.html'], + var webdev = await runWebDev(['daemon', '--launch-app=web/scopes.html'], workingDirectory: exampleDirectory); var appId = await waitForAppId(webdev); diff --git a/webdev/test/daemon/utils.dart b/webdev/test/daemon/utils.dart index edc856ce7..f124a2fcd 100644 --- a/webdev/test/daemon/utils.dart +++ b/webdev/test/daemon/utils.dart @@ -5,9 +5,13 @@ import 'dart:async'; import 'dart:convert'; +import 'package:path/path.dart' as p; import 'package:test/test.dart'; import 'package:test_process/test_process.dart'; import 'package:vm_service/vm_service.dart'; +import 'package:webdev/src/util.dart'; + +import '../test_utils.dart'; const isRPCError = TypeMatcher(); @@ -33,6 +37,17 @@ Future waitForAppId(TestProcess webdev) async { return appId; } +Future prepareWorkspace() async { + var exampleDirectory = + p.absolute(p.join(p.current, '..', 'fixtures', '_webdevSoundSmoke')); + + var process = await TestProcess.start(dartPath, ['pub', 'upgrade'], + workingDirectory: exampleDirectory, environment: getPubEnvironment()); + + await process.shouldExit(0); + return exampleDirectory; +} + String? getDebugServiceUri(String line) { var regex = RegExp(r'Debug service listening on (?[^\s^\\]*)'); var match = regex.firstMatch(line); diff --git a/webdev/test/e2e_test.dart b/webdev/test/e2e_test.dart index 6c6d09248..8d706a434 100644 --- a/webdev/test/e2e_test.dart +++ b/webdev/test/e2e_test.dart @@ -36,12 +36,10 @@ void main() { // Change to true for debugging. final debug = false; - final testRunner = TestRunner(); late String exampleDirectory; late String soundExampleDirectory; setUpAll(() async { configureLogWriter(debug); - await testRunner.setUpAll(); exampleDirectory = p.absolute(p.join(p.current, '..', 'fixtures', '_webdevSmoke')); soundExampleDirectory = @@ -64,8 +62,6 @@ void main() { await d.file('pubspec.lock', isNotEmpty).validate(soundExampleDirectory); }); - tearDownAll(testRunner.tearDownAll); - test('smoke test is configured properly', () async { var smokeYaml = loadYaml( await File('$soundExampleDirectory/pubspec.yaml').readAsString()) @@ -85,8 +81,8 @@ void main() { var args = ['build', '-o', 'web:${d.sandbox}']; - var process = await testRunner.runWebDev(args, - workingDirectory: soundExampleDirectory); + var process = + await runWebDev(args, workingDirectory: soundExampleDirectory); // NOTE: We'd like this to be more useful // See https://github.com/dart-lang/build/issues/1283 @@ -113,8 +109,8 @@ void main() { '--delete-conflicting-outputs' ]; - var process = await testRunner.runWebDev(args, - workingDirectory: soundExampleDirectory); + var process = + await runWebDev(args, workingDirectory: soundExampleDirectory); await checkProcessStdout(process, ['Succeeded']); await process.shouldExit(0); @@ -128,8 +124,8 @@ void main() { args.add('--no-release'); } - var process = await testRunner.runWebDev(args, - workingDirectory: soundExampleDirectory); + var process = + await runWebDev(args, workingDirectory: soundExampleDirectory); var expectedItems = ['Succeeded']; @@ -156,8 +152,8 @@ void main() { '--null-safety=sound' ]; - var process = await testRunner.runWebDev(args, - workingDirectory: soundExampleDirectory); + var process = + await runWebDev(args, workingDirectory: soundExampleDirectory); var expectedItems = ['Succeeded']; @@ -176,8 +172,7 @@ void main() { '--null-safety=unsound' ]; - var process = - await testRunner.runWebDev(args, workingDirectory: exampleDirectory); + var process = await runWebDev(args, workingDirectory: exampleDirectory); var expectedItems = ['Succeeded']; @@ -196,8 +191,8 @@ void main() { args.add('--no-release'); } - var process = await testRunner.runWebDev(args, - workingDirectory: soundExampleDirectory); + var process = + await runWebDev(args, workingDirectory: soundExampleDirectory); var expectedItems = ['Succeeded']; @@ -219,8 +214,8 @@ void main() { args.add('--release'); } - var process = await testRunner.runWebDev(args, - workingDirectory: soundExampleDirectory); + var process = + await runWebDev(args, workingDirectory: soundExampleDirectory); var hostUrl = 'http://localhost:$openPort'; @@ -261,8 +256,8 @@ void main() { if (command == 'build') '--output=$dir:foo' else dir ]; - var process = await testRunner.runWebDev(args, - workingDirectory: soundExampleDirectory); + var process = + await runWebDev(args, workingDirectory: soundExampleDirectory); await expectLater( process.stdout, emitsThrough(contains( @@ -299,7 +294,7 @@ void main() { '--null-safety=$nullSafetyOption', '--verbose', ]; - var process = await testRunner.runWebDev(args, + var process = await runWebDev(args, workingDirectory: soundNullSafety ? soundExampleDirectory : exampleDirectory); VmService? vmService; @@ -365,7 +360,7 @@ void main() { '--enable-expression-evaluation', '--verbose', ]; - var process = await testRunner.runWebDev(args, + var process = await runWebDev(args, workingDirectory: soundNullSafety ? soundExampleDirectory : exampleDirectory); VmService? vmService; @@ -423,7 +418,7 @@ void main() { '--no-enable-expression-evaluation', '--verbose', ]; - var process = await testRunner.runWebDev(args, + var process = await runWebDev(args, workingDirectory: soundNullSafety ? soundExampleDirectory : exampleDirectory); VmService? vmService; @@ -478,7 +473,7 @@ void main() { '--no-enable-expression-evaluation', '--verbose', ]; - var process = await testRunner.runWebDev(args, + var process = await runWebDev(args, workingDirectory: soundNullSafety ? soundExampleDirectory : exampleDirectory); VmService? vmService; diff --git a/webdev/test/integration_test.dart b/webdev/test/integration_test.dart index 6739b8bdf..2e9154388 100644 --- a/webdev/test/integration_test.dart +++ b/webdev/test/integration_test.dart @@ -18,12 +18,8 @@ void main() { var pubCommand = sdkVersion.compareTo(firstSdkVersionWithoutPub) < 0 ? 'pub' : 'dart pub'; - final testRunner = TestRunner(); - setUpAll(testRunner.setUpAll); - tearDownAll(testRunner.tearDownAll); - test('non-existant commands create errors', () async { - var process = await testRunner.runWebDev(['monkey']); + var process = await runWebDev(['monkey']); await expectLater( process.stdout, emits('Could not find a command named "monkey".')); @@ -32,7 +28,7 @@ void main() { }); test('passing extra args to build fails with bad usage', () async { - var process = await testRunner.runWebDev(['build', 'extra', 'args']); + var process = await runWebDev(['build', 'extra', 'args']); await expectLater(process.stdout, emits('Arguments were provided that are not supported: "extra args".')); @@ -59,8 +55,7 @@ name: sample await d.file('.dart_tool/package_config.json', ''' ''').create(); - var process = - await testRunner.runWebDev(['serve'], workingDirectory: d.sandbox); + var process = await runWebDev(['serve'], workingDirectory: d.sandbox); var output = await process.stdout.rest.toList(); @@ -92,8 +87,7 @@ name: sample await d.file('.dart_tool/package_config.json', ''' ''').create(); - var process = await testRunner - .runWebDev([command], workingDirectory: d.sandbox); + var process = await runWebDev([command], workingDirectory: d.sandbox); await checkProcessStdout(process, [ 'webdev could not run for this project.', @@ -116,8 +110,7 @@ name: sample await d.file('.dart_tool/package_config.json', ''' ''').create(); - var process = await testRunner - .runWebDev(['serve'], workingDirectory: d.sandbox); + var process = await runWebDev(['serve'], workingDirectory: d.sandbox); await checkProcessStdout(process, [ 'webdev could not run for this project.', @@ -145,8 +138,7 @@ name: sample // Required for webdev to not complain about nothing to serve. await d.dir('web').create(); - var process = await testRunner.runWebDev( - ['serve', '--no-build-web-compilers'], + var process = await runWebDev(['serve', '--no-build-web-compilers'], workingDirectory: d.sandbox); // Fails since this is a fake package @@ -195,8 +187,8 @@ name: sample await d.file('.dart_tool/package_config.json', ''' ''').create(); - var process = await testRunner - .runWebDev(['serve'], workingDirectory: d.sandbox); + var process = + await runWebDev(['serve'], workingDirectory: d.sandbox); if (entry.key == 'build_daemon') { await checkProcessStdout(process, [ @@ -220,8 +212,7 @@ name: sample } test('no pubspec.yaml', () async { - var process = - await testRunner.runWebDev(['serve'], workingDirectory: d.sandbox); + var process = await runWebDev(['serve'], workingDirectory: d.sandbox); await checkProcessStdout(process, [ 'webdev could not run for this project.', @@ -235,8 +226,7 @@ name: sample name: sample ''').create(); - var process = - await testRunner.runWebDev(['serve'], workingDirectory: d.sandbox); + var process = await runWebDev(['serve'], workingDirectory: d.sandbox); await checkProcessStdout(process, [ 'webdev could not run for this project.', @@ -260,8 +250,7 @@ dependencies: args: ^1.0.0 ''').create(); - var process = - await testRunner.runWebDev(['serve'], workingDirectory: d.sandbox); + var process = await runWebDev(['serve'], workingDirectory: d.sandbox); await checkProcessStdout(process, [ 'webdev could not run for this project.', diff --git a/webdev/test/readme_test.dart b/webdev/test/readme_test.dart index 77def258a..0f57f0f96 100644 --- a/webdev/test/readme_test.dart +++ b/webdev/test/readme_test.dart @@ -15,18 +15,14 @@ import 'package:test/test.dart'; import 'test_utils.dart'; void main() { - final testRunner = TestRunner(); - setUpAll(testRunner.setUpAll); - tearDownAll(testRunner.tearDownAll); - - test('help build', () => _readmeCheck(testRunner, ['help', 'build'])); - test('help serve', () => _readmeCheck(testRunner, ['help', 'serve'])); + test('help build', () => _readmeCheck(['help', 'build'])); + test('help serve', () => _readmeCheck(['help', 'serve'])); } final _readmeContents = File('README.md').readAsStringSync(); -Future _readmeCheck(TestRunner testRunner, List args) async { - var process = await testRunner.runWebDev(args); +Future _readmeCheck(List args) async { + var process = await runWebDev(args); var output = (await process.stdoutStream().map((line) => line.trimRight()).join('\n')) .trim(); diff --git a/webdev/test/test_utils.dart b/webdev/test/test_utils.dart index 0b8615dde..67ee55813 100644 --- a/webdev/test/test_utils.dart +++ b/webdev/test/test_utils.dart @@ -8,53 +8,21 @@ import 'dart:io'; import 'package:path/path.dart' as p; import 'package:test/test.dart'; import 'package:test_common/test_sdk_configuration.dart'; -import 'package:test_common/test_sdk_layout.dart'; import 'package:test_process/test_process.dart'; +import 'package:webdev/src/util.dart'; final _webdevBin = p.absolute(p.join('bin', 'webdev.dart')); +final _sdkConfigurationProvider = TestSdkConfigurationProvider(); -class TestRunner { - late TestSdkConfigurationProvider sdkConfigurationProvider; - late TestSdkLayout sdkLayout; +Future runWebDev(List args, + {String? workingDirectory}) async { + // Generate missing test assets in the SDK. + await _sdkConfigurationProvider.configuration; - Future setUpAll({bool verbose = false}) async { - // Generate missing SDK assets if needed. - sdkConfigurationProvider = TestSdkConfigurationProvider(verbose: verbose); - sdkLayout = sdkConfigurationProvider.sdkLayout; + var fullArgs = [_webdevBin, ...args]; - try { - // Make sure configuration was created correctly. - final configuration = await sdkConfigurationProvider.configuration; - configuration.validate(); - } catch (_) { - tearDownAll(); - rethrow; - } - } - - void tearDownAll() { - sdkConfigurationProvider.dispose(); - } - - Future runWebDev(List args, - {String? workingDirectory}) async { - var fullArgs = [_webdevBin, ...args]; - - return TestProcess.start(sdkLayout.dartPath, fullArgs, - workingDirectory: workingDirectory); - } - - Future prepareWorkspace() async { - var exampleDirectory = - p.absolute(p.join(p.current, '..', 'fixtures', '_webdevSoundSmoke')); - - var process = await TestProcess.start( - sdkLayout.dartPath, ['pub', 'upgrade'], - workingDirectory: exampleDirectory, environment: getPubEnvironment()); - - await process.shouldExit(0); - return exampleDirectory; - } + return TestProcess.start(dartPath, fullArgs, + workingDirectory: workingDirectory); } Future checkProcessStdout(TestProcess process, List items) async { From aa0c2ff4342f5b5e30abfc7f6cde9a3ae07bb3ea Mon Sep 17 00:00:00 2001 From: Anna Gringauze Date: Wed, 22 Feb 2023 16:39:46 -0800 Subject: [PATCH 15/15] Remove duplicate file, fix windows test failures --- dwds/test/fixtures/test_sdk_layout.dart | 159 ------------------------ test_common/lib/test_sdk_layout.dart | 2 +- 2 files changed, 1 insertion(+), 160 deletions(-) delete mode 100644 dwds/test/fixtures/test_sdk_layout.dart diff --git a/dwds/test/fixtures/test_sdk_layout.dart b/dwds/test/fixtures/test_sdk_layout.dart deleted file mode 100644 index 488fdd009..000000000 --- a/dwds/test/fixtures/test_sdk_layout.dart +++ /dev/null @@ -1,159 +0,0 @@ -// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -// TODO:(annagrin) Move to a test_common package. -import 'package:dwds/src/utilities/sdk_configuration.dart'; -import 'package:path/path.dart' as p; - -/// Test Dart SDK layout. -/// -/// Contains definition of the default SDK layout required for tests. -/// We keep all the path constants in one place for ease of update. -class TestSdkLayout { - static final defaultSdkDirectory = SdkLayout.defaultSdkDirectory; - static TestSdkLayout defaultSdkLayout = - TestSdkLayout.createDefault(defaultSdkDirectory); - static SdkConfiguration defaultSdkConfiguration = - createConfiguration(defaultSdkLayout); - - factory TestSdkLayout.createDefault(String sdkDirectory) => - TestSdkLayout.createDefaultFromSdkLayout( - SdkLayout.createDefault(sdkDirectory)); - - factory TestSdkLayout.createDefaultFromSdkLayout(SdkLayout sdkLayout) => - TestSdkLayout( - sdkDirectory: sdkLayout.sdkDirectory, - soundSummaryPath: sdkLayout.soundSummaryPath, - soundFullDillPath: p.join( - sdkLayout.sdkDirectory, - 'lib', - '_internal', - 'ddc_platform.dill', - ), - soundJsPath: p.join( - sdkLayout.sdkDirectory, - 'lib', - 'dev_compiler', - 'kernel', - 'amd', - 'dart_sdk.js', - ), - soundJsMapPath: p.join( - sdkLayout.sdkDirectory, - 'lib', - 'dev_compiler', - 'kernel', - 'amd', - 'dart_sdk.js.map', - ), - weakSummaryPath: sdkLayout.weakSummaryPath, - weakFullDillPath: p.join( - sdkLayout.sdkDirectory, - 'lib', - '_internal', - 'ddc_platform_unsound.dill', - ), - weakJsPath: p.join( - sdkLayout.sdkDirectory, - 'lib', - 'dev_compiler', - 'kernel', - 'amd', - 'dart_sdk_unsound.js', - ), - weakJsMapPath: p.join( - sdkLayout.sdkDirectory, - 'lib', - 'dev_compiler', - 'kernel', - 'amd', - 'dart_sdk_unsound.js.map', - ), - requireJsPath: p.join( - sdkLayout.sdkDirectory, - 'lib', - 'dev_compiler', - 'amd', - 'require.js', - ), - stackTraceMapperPath: p.join( - sdkLayout.sdkDirectory, - 'lib', - 'dev_compiler', - 'web', - 'dart_stack_trace_mapper.js', - ), - dartPath: p.join(sdkLayout.sdkDirectory, 'bin', 'dart'), - frontendServerSnapshotPath: p.join( - sdkLayout.sdkDirectory, - 'bin', - 'snapshots', - 'frontend_server.dart.snapshot', - ), - dartdevcSnapshotPath: sdkLayout.dartdevcSnapshotPath, - kernelWorkerSnapshotPath: p.join( - sdkLayout.sdkDirectory, - 'bin', - 'snapshots', - 'kernel_worker.dart.snapshot', - ), - ); - - final String sdkDirectory; - - String get soundJsFileName => p.basename(soundJsPath); - String get soundJsMapFileName => p.basename(soundJsMapPath); - String get soundSummaryFileName => p.basename(soundSummaryPath); - String get soundFullDillFileName => p.basename(soundFullDillPath); - - final String soundJsPath; - final String soundJsMapPath; - final String soundSummaryPath; - final String soundFullDillPath; - - String get weakJsFileName => p.basename(weakJsPath); - String get weakJsMapFileName => p.basename(weakJsMapPath); - String get weakSummaryFileName => p.basename(weakSummaryPath); - String get weakFullDillFileName => p.basename(weakFullDillPath); - - final String weakJsPath; - final String weakJsMapPath; - final String weakSummaryPath; - final String weakFullDillPath; - - final String requireJsPath; - final String stackTraceMapperPath; - - final String dartPath; - final String frontendServerSnapshotPath; - final String dartdevcSnapshotPath; - final String kernelWorkerSnapshotPath; - - const TestSdkLayout({ - required this.sdkDirectory, - required this.soundJsPath, - required this.soundJsMapPath, - required this.soundSummaryPath, - required this.soundFullDillPath, - required this.weakJsPath, - required this.weakJsMapPath, - required this.weakSummaryPath, - required this.weakFullDillPath, - required this.requireJsPath, - required this.stackTraceMapperPath, - required this.dartPath, - required this.frontendServerSnapshotPath, - required this.dartdevcSnapshotPath, - required this.kernelWorkerSnapshotPath, - }); - - /// Creates configuration from sdk layout. - static SdkConfiguration createConfiguration(TestSdkLayout sdkLayout) => - SdkConfiguration( - sdkDirectory: sdkLayout.sdkDirectory, - weakSdkSummaryPath: sdkLayout.weakSummaryPath, - soundSdkSummaryPath: sdkLayout.soundSummaryPath, - compilerWorkerPath: sdkLayout.dartdevcSnapshotPath, - ); -} diff --git a/test_common/lib/test_sdk_layout.dart b/test_common/lib/test_sdk_layout.dart index 04da509fb..072bd3f1f 100644 --- a/test_common/lib/test_sdk_layout.dart +++ b/test_common/lib/test_sdk_layout.dart @@ -88,7 +88,7 @@ class TestSdkLayout { dartPath: p.join( sdkLayout.sdkDirectory, 'bin', - 'dart', + Platform.isWindows ? 'dart.exe' : 'dart', ), frontendServerSnapshotPath: p.join( sdkLayout.sdkDirectory,