From b2fe66ec57ef234bcdc7df07660370a254c66f65 Mon Sep 17 00:00:00 2001 From: evanweible-wf Date: Thu, 7 Nov 2024 11:41:15 -0700 Subject: [PATCH 1/7] Only generate backwards-compatible output when necessary --- CHANGELOG.md | 6 ++++ lib/src/builder.dart | 35 +++++++++++++++++++++-- test/lib/dart_test_yaml_builder_test.dart | 26 +++++++++++++++++ 3 files changed, 64 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d5f8106..63c643d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## 3.1.0 + +- The `test/dart_test.browser_aggregate.yaml` file was previously always +generated for backwards-compatibility. With this release, it is only generated +if a reference to it is found in `dart_test.yaml`. + ## 3.0.3 - Compatible with Dart 3. diff --git a/lib/src/builder.dart b/lib/src/builder.dart index 99e05a3..99590af 100644 --- a/lib/src/builder.dart +++ b/lib/src/builder.dart @@ -333,9 +333,38 @@ class DartTestYamlBuilder extends Builder { AssetId(buildStep.inputId.package, 'dart_test.browser_aggregate.yaml'); await buildStep.writeAsString(outputId, contents.toString()); - final backwardsCompatOutputId = AssetId( - buildStep.inputId.package, 'test/dart_test.browser_aggregate.yaml'); - await buildStep.writeAsString(backwardsCompatOutputId, contents.toString()); + var shouldWriteBackwardsCompatOutput = false; + try { + final dartTestYamlId = + AssetId(buildStep.inputId.package, 'dart_test.yaml'); + final dartTestYaml = await buildStep.readAsString(dartTestYamlId); + if (dartTestYaml.contains('test/dart_test.browser_aggregate.yaml')) { + log.fine( + 'Found `test/dart_test.browser_aggregate.yaml` in `dart_test.yaml`, will generate it for backwards-compatibility.'); + shouldWriteBackwardsCompatOutput = true; + } else { + log.fine( + 'No `test/dart_test.browser_aggregate.yaml` found in `dart_test.yaml`, skipping backwards-compatible generation.'); + } + } on AssetNotFoundException catch (_) { + log.fine( + 'No `dart_test.yaml` found, skipping backwards-compatible generation of `test/dart_test.browser_aggregate.yaml`.'); + } catch (e) { + log.fine( + 'Error reading `dart_test.yaml`, skipping backwards-compatible generation of `test/dart_test.browser_aggregate.yaml`.', + e); + } + + if (shouldWriteBackwardsCompatOutput) { + final backwardsCompatOutputId = AssetId( + buildStep.inputId.package, + 'test/dart_test.browser_aggregate.yaml', + ); + await buildStep.writeAsString( + backwardsCompatOutputId, + contents.toString(), + ); + } } } diff --git a/test/lib/dart_test_yaml_builder_test.dart b/test/lib/dart_test_yaml_builder_test.dart index 6445d05..4578972 100644 --- a/test/lib/dart_test_yaml_builder_test.dart +++ b/test/lib/dart_test_yaml_builder_test.dart @@ -38,6 +38,32 @@ void main() { paths: - test/foo_template.browser_aggregate_test.dart - test/custom_test.dart +''' + }); + }); + + test('generates the backwards-compatible yaml output when needed', + () async { + final config = TestHtmlBuilderConfig(browserAggregation: true); + final builder = DartTestYamlBuilder(); + await testBuilder(builder, { + 'a|dart_test.yaml': 'include: "test/dart_test.browser_aggregate.yaml"', + 'a|test/test_html_builder_config.json': jsonEncode(config), + 'a|test/foo_template.browser_aggregate_test.dart': '', + 'a|test/foo_template.html': '', + // This template should be found, but ignored because there is no + // accompanying .browser_aggregate_test.dart + 'a|test/bar_template.html': '', + // This test should get included because it has a custom HTML + 'a|test/custom_test.dart': '', + 'a|test/custom_test.custom.html': '', + }, outputs: { + 'a|dart_test.browser_aggregate.yaml': '''presets: + browser-aggregate: + platforms: [chrome] + paths: + - test/foo_template.browser_aggregate_test.dart + - test/custom_test.dart ''', 'a|test/dart_test.browser_aggregate.yaml': '''presets: browser-aggregate: From feb2a23a8973c016b8a136591c670d002aa80465 Mon Sep 17 00:00:00 2001 From: evanweible-wf Date: Tue, 12 Nov 2024 09:32:12 -0700 Subject: [PATCH 2/7] Widen `test_core` range to fix issue on latest stable Dart --- pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index b7fd9a5..277a2b8 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -20,7 +20,7 @@ dependencies: json_annotation: ^4.1.0 path: ^1.8.0 test: ^1.17.12 - test_core: ">=0.4.2 <0.6.0" + test_core: ">=0.4.2 <0.7.0" yaml: ^3.1.0 dev_dependencies: From 425e77c87793c768714d043569c92cf3f4f6b8ef Mon Sep 17 00:00:00 2001 From: evanweible-wf Date: Tue, 12 Nov 2024 09:59:01 -0700 Subject: [PATCH 3/7] Simplify test running in CI --- .github/workflows/dart_ci.yaml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/dart_ci.yaml b/.github/workflows/dart_ci.yaml index f22689a..71d5e7b 100644 --- a/.github/workflows/dart_ci.yaml +++ b/.github/workflows/dart_ci.yaml @@ -34,8 +34,7 @@ jobs: - run: dart pub get - run: dart run dependency_validator - run: dart analyze - - run: dart test test/lib - - run: dart test test/bin + - run: dart test - uses: anchore/sbom-action@v0 if: ${{ matrix.sdk == 'stable' }} with: From 068b4f7958191eccb2e11cd6851a500337e6c151 Mon Sep 17 00:00:00 2001 From: evanweible-wf Date: Tue, 12 Nov 2024 09:59:18 -0700 Subject: [PATCH 4/7] Ensure a `pub upgrade` when testing example project --- tool/test_example.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tool/test_example.sh b/tool/test_example.sh index 5fd9ce8..6602cc0 100755 --- a/tool/test_example.sh +++ b/tool/test_example.sh @@ -3,7 +3,7 @@ set -e cd example/project -dart pub get +dart pub upgrade dart run build_runner build --delete-conflicting-outputs dart run build_runner test dart run test_html_builder:browser_aggregate_tests From 3e4e1be31d05461e52019bbca11d327733e21072 Mon Sep 17 00:00:00 2001 From: evanweible-wf Date: Wed, 13 Nov 2024 10:18:55 -0700 Subject: [PATCH 5/7] Workaround https://github.com/dart-lang/test/issues/2294 --- tool/test_example.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tool/test_example.sh b/tool/test_example.sh index 6602cc0..950130d 100755 --- a/tool/test_example.sh +++ b/tool/test_example.sh @@ -5,10 +5,10 @@ set -e cd example/project dart pub upgrade dart run build_runner build --delete-conflicting-outputs -dart run build_runner test +dart run build_runner test -- --concurrency=1 # concurrency=1 is a workaround for this issue: https://github.com/dart-lang/test/issues/2294 dart run test_html_builder:browser_aggregate_tests # These commands target a scenario where there is no build cache and someone # uses build filters to run a subset of tests. dart run build_runner clean -dart run build_runner test --delete-conflicting-outputs --build-filter="test/unit/css_test.**" -- test/unit/css_test.dart +dart run build_runner test --delete-conflicting-outputs --build-filter="test/unit/css_test.**" -- --concurrency=1 test/unit/css_test.dart # concurrency=1 is a workaround for this issue: https://github.com/dart-lang/test/issues/2294 From 3979b9df394f1b9e596fe128f72ea6786840f977 Mon Sep 17 00:00:00 2001 From: evanweible-wf Date: Tue, 19 Nov 2024 07:40:31 -0700 Subject: [PATCH 6/7] Support `--test-args` in `browser_aggregate_tests` executable --- bin/browser_aggregate_tests.dart | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/bin/browser_aggregate_tests.dart b/bin/browser_aggregate_tests.dart index 5091d92..f25f28c 100644 --- a/bin/browser_aggregate_tests.dart +++ b/bin/browser_aggregate_tests.dart @@ -23,7 +23,10 @@ final argParser = ArgParser() ..addOption('build-args', help: 'Args to pass to the build runner process.\n' 'Run "dart run build_runner build -h -v" to see all available ' - 'options.'); + 'options.') + ..addOption('test-args', + help: 'Args to pass to the dart test process.\n' + 'Run "dart test -h" to see all available options.'); enum Mode { // Print build and test args separated by `--` @@ -62,6 +65,7 @@ void main(List args) async { final bool? release = parsed['release']; final String? buildArgs = parsed['build-args']; + final String? testArgs = parsed['test-args']; buildAggregateTestYaml(mode, userBuildArgs: buildArgs); final testPaths = parseAggregateTestPaths(mode); @@ -70,7 +74,8 @@ void main(List args) async { } else if (mode == Mode.build) { await buildTests(testPaths, release: release, userBuildArgs: buildArgs); } else { - await runTests(testPaths, release: release, userBuildArgs: buildArgs); + await runTests(testPaths, + release: release, userBuildArgs: buildArgs, userTestArgs: testArgs); } } @@ -187,7 +192,7 @@ Future buildTests(List testPaths, /// /// Includes `--release` if [release] is true. Future runTests(List testPaths, - {bool? release, String? userBuildArgs}) async { + {bool? release, String? userBuildArgs, String? userTestArgs}) async { final executable = 'dart'; final args = [ 'run', @@ -196,6 +201,7 @@ Future runTests(List testPaths, ...buildRunnerBuildArgs(testPaths, release: release, userBuildArgs: userBuildArgs), '--', + ...?userTestArgs?.split(' '), testPreset, ]; stdout From 6934175425d253b7704ea069b93de0bc27aa3607 Mon Sep 17 00:00:00 2001 From: evanweible-wf Date: Tue, 19 Nov 2024 07:40:52 -0700 Subject: [PATCH 7/7] Workaround https://github.com/dart-lang/test/issues/2294 --- tool/test_example.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tool/test_example.sh b/tool/test_example.sh index 950130d..668572f 100755 --- a/tool/test_example.sh +++ b/tool/test_example.sh @@ -6,7 +6,7 @@ cd example/project dart pub upgrade dart run build_runner build --delete-conflicting-outputs dart run build_runner test -- --concurrency=1 # concurrency=1 is a workaround for this issue: https://github.com/dart-lang/test/issues/2294 -dart run test_html_builder:browser_aggregate_tests +dart run test_html_builder:browser_aggregate_tests --test-args="--concurrency=1" # concurrency=1 is a workaround for this issue: https://github.com/dart-lang/test/issues/2294 # These commands target a scenario where there is no build cache and someone # uses build filters to run a subset of tests.