From 2ae6afbb6590018bb94aaf329013d22a22e16894 Mon Sep 17 00:00:00 2001 From: Eric Seidel Date: Wed, 20 Nov 2024 09:35:49 -0800 Subject: [PATCH] fix: unbreak web build for 2.x (#241) * fix: unbreak web build * chore: add cspell config --- .github/actions/flutter_package/action.yaml | 11 +++-- cspell.config.yaml | 7 +++ .../lib/src/shorebird_updater.dart | 3 +- .../lib/src/shorebird_updater_io.dart | 5 +- .../lib/src/shorebird_updater_web.dart | 6 +-- .../test/src/shorebird_updater_io_test.dart | 48 +++++++++---------- .../test/src/shorebird_updater_web_test.dart | 14 +----- 7 files changed, 46 insertions(+), 48 deletions(-) create mode 100644 cspell.config.yaml diff --git a/.github/actions/flutter_package/action.yaml b/.github/actions/flutter_package/action.yaml index 027c28f..2ba04a6 100644 --- a/.github/actions/flutter_package/action.yaml +++ b/.github/actions/flutter_package/action.yaml @@ -29,10 +29,10 @@ inputs: required: false default: "lib" description: Directories to report on when collecting coverage - platform: + example_platform: required: false - default: "vm" - description: Platform to use when running tests + default: "web" + description: Platform to use when building example runs: using: "composite" @@ -54,6 +54,11 @@ runs: shell: ${{ inputs.shell }} run: dart analyze --fatal-warnings ${{inputs.analyze_directories}} + - name: Build Example + working-directory: ${{ inputs.working_directory }}/example + shell: ${{ inputs.shell }} + run: flutter build ${{ inputs.example_platform }} + - name: Test working-directory: ${{ inputs.working_directory }} shell: ${{ inputs.shell }} diff --git a/cspell.config.yaml b/cspell.config.yaml new file mode 100644 index 0000000..6a65f8f --- /dev/null +++ b/cspell.config.yaml @@ -0,0 +1,7 @@ +$schema: https://raw.githubusercontent.com/streetsidesoftware/cspell/main/cspell.schema.json +version: '0.2' +ignorePaths: ['build', '**/*.g.dart'] +words: + - subosito + - carryforward + - endtemplate diff --git a/shorebird_code_push/lib/src/shorebird_updater.dart b/shorebird_code_push/lib/src/shorebird_updater.dart index 9329282..fa5dbf8 100644 --- a/shorebird_code_push/lib/src/shorebird_updater.dart +++ b/shorebird_code_push/lib/src/shorebird_updater.dart @@ -1,6 +1,5 @@ import 'package:shorebird_code_push/src/shorebird_updater_io.dart' if (dart.library.js_interop) './shorebird_updater_web.dart'; -import 'package:shorebird_code_push/src/updater.dart'; /// The reason a call to [ShorebirdUpdater.update] failed. enum UpdateFailureReason { @@ -95,7 +94,7 @@ enum UpdateStatus { /// {@endtemplate} abstract class ShorebirdUpdater { /// {@macro shorebird_updater} - factory ShorebirdUpdater() => ShorebirdUpdaterImpl(const Updater()); + factory ShorebirdUpdater() => ShorebirdUpdaterImpl(); /// Whether the updater is available on the current platform. /// The most common reasons for this returning false are: diff --git a/shorebird_code_push/lib/src/shorebird_updater_io.dart b/shorebird_code_push/lib/src/shorebird_updater_io.dart index b41df0a..53f8655 100644 --- a/shorebird_code_push/lib/src/shorebird_updater_io.dart +++ b/shorebird_code_push/lib/src/shorebird_updater_io.dart @@ -21,8 +21,9 @@ typedef IsolateRun = Future Function( /// {@endtemplate} class ShorebirdUpdaterImpl implements ShorebirdUpdater { /// {@macro shorebird_updater_io} - ShorebirdUpdaterImpl(this._updater, {IsolateRun? run}) - : _run = run ?? Isolate.run { + ShorebirdUpdaterImpl({Updater? updater, IsolateRun? run}) + : _updater = updater ?? const Updater(), + _run = run ?? Isolate.run { try { // If the Shorebird Engine is not available, this will throw an exception. // FIXME: Run this in an isolate or refactor the updater to avoid risking diff --git a/shorebird_code_push/lib/src/shorebird_updater_web.dart b/shorebird_code_push/lib/src/shorebird_updater_web.dart index 8deb040..509e3b2 100644 --- a/shorebird_code_push/lib/src/shorebird_updater_web.dart +++ b/shorebird_code_push/lib/src/shorebird_updater_web.dart @@ -1,18 +1,14 @@ import 'package:shorebird_code_push/src/shorebird_updater.dart'; -import 'package:shorebird_code_push/src/updater.dart'; /// {@template shorebird_updater_web} /// The Shorebird web updater. /// {@endtemplate} class ShorebirdUpdaterImpl implements ShorebirdUpdater { /// {@macro shorebird_updater_web} - ShorebirdUpdaterImpl(this._updater) { + ShorebirdUpdaterImpl() { logShorebirdEngineUnavailableMessage(); } - // ignore: unused_field - final Updater _updater; - @override bool get isAvailable => false; diff --git a/shorebird_code_push/test/src/shorebird_updater_io_test.dart b/shorebird_code_push/test/src/shorebird_updater_io_test.dart index 84f683a..e5ae595 100644 --- a/shorebird_code_push/test/src/shorebird_updater_io_test.dart +++ b/shorebird_code_push/test/src/shorebird_updater_io_test.dart @@ -37,7 +37,7 @@ void main() { group('when updater is available', () { setUp(() { when(updater.currentPatchNumber).thenReturn(1); - shorebirdUpdater = ShorebirdUpdaterImpl(updater, run: run); + shorebirdUpdater = ShorebirdUpdaterImpl(updater: updater, run: run); }); test('returns true', () { @@ -53,7 +53,7 @@ void main() { test( 'returns false', overridePrint((_) { - shorebirdUpdater = ShorebirdUpdaterImpl(updater, run: run); + shorebirdUpdater = ShorebirdUpdaterImpl(updater: updater, run: run); expect(shorebirdUpdater.isAvailable, isFalse); }), ); @@ -69,7 +69,7 @@ void main() { test( 'returns null', overridePrint((_) async { - shorebirdUpdater = ShorebirdUpdaterImpl(updater, run: run); + shorebirdUpdater = ShorebirdUpdaterImpl(updater: updater, run: run); await expectLater( shorebirdUpdater.readCurrentPatch(), completion(isNull), @@ -86,7 +86,7 @@ void main() { setUp(() { when(updater.currentPatchNumber).thenReturn(0); when(updater.nextPatchNumber).thenReturn(0); - shorebirdUpdater = ShorebirdUpdaterImpl(updater, run: run); + shorebirdUpdater = ShorebirdUpdaterImpl(updater: updater, run: run); }); test('returns null', () async { @@ -107,7 +107,7 @@ void main() { setUp(() { when(updater.currentPatchNumber).thenReturn(currentPatchNumber); when(updater.nextPatchNumber).thenReturn(nextPatchNumber); - shorebirdUpdater = ShorebirdUpdaterImpl(updater, run: run); + shorebirdUpdater = ShorebirdUpdaterImpl(updater: updater, run: run); }); test('returns correct patch numbers', () async { @@ -134,7 +134,7 @@ void main() { setUp(() { when(updater.currentPatchNumber).thenReturn(currentPatchNumber); when(updater.nextPatchNumber).thenReturn(nextPatchNumber); - shorebirdUpdater = ShorebirdUpdaterImpl(updater, run: run); + shorebirdUpdater = ShorebirdUpdaterImpl(updater: updater, run: run); }); test('returns correct patch numbers', () async { @@ -169,7 +169,7 @@ void main() { setUp(() { when(updater.currentPatchNumber).thenReturn(currentPatchNumber); when(updater.nextPatchNumber).thenReturn(nextPatchNumber); - shorebirdUpdater = ShorebirdUpdaterImpl(updater, run: run); + shorebirdUpdater = ShorebirdUpdaterImpl(updater: updater, run: run); }); test('returns correct patch numbers', () async { @@ -205,7 +205,7 @@ void main() { return value; }); when(updater.nextPatchNumber).thenThrow(Exception('oops')); - shorebirdUpdater = ShorebirdUpdaterImpl(updater, run: run); + shorebirdUpdater = ShorebirdUpdaterImpl(updater: updater, run: run); }); test('throws $ReadPatchException', () async { @@ -230,7 +230,7 @@ void main() { test( 'returns UpdateStatus.unavailable', overridePrint((_) async { - shorebirdUpdater = ShorebirdUpdaterImpl(updater, run: run); + shorebirdUpdater = ShorebirdUpdaterImpl(updater: updater, run: run); await expectLater( shorebirdUpdater.checkForUpdate(), completion(equals(UpdateStatus.unavailable)), @@ -243,7 +243,7 @@ void main() { setUp(() { when(updater.currentPatchNumber).thenReturn(0); when(updater.checkForDownloadableUpdate).thenReturn(true); - shorebirdUpdater = ShorebirdUpdaterImpl(updater, run: run); + shorebirdUpdater = ShorebirdUpdaterImpl(updater: updater, run: run); }); test('returns UpdateStatus.outdated', () async { @@ -259,7 +259,7 @@ void main() { when(updater.currentPatchNumber).thenReturn(0); when(updater.nextPatchNumber).thenReturn(1); when(updater.checkForDownloadableUpdate).thenReturn(false); - shorebirdUpdater = ShorebirdUpdaterImpl(updater, run: run); + shorebirdUpdater = ShorebirdUpdaterImpl(updater: updater, run: run); }); test('returns UpdateStatus.restartRequired', () async { @@ -275,7 +275,7 @@ void main() { when(updater.currentPatchNumber).thenReturn(1); when(updater.nextPatchNumber).thenReturn(1); when(updater.checkForDownloadableUpdate).thenReturn(false); - shorebirdUpdater = ShorebirdUpdaterImpl(updater, run: run); + shorebirdUpdater = ShorebirdUpdaterImpl(updater: updater, run: run); }); test('returns UpdateStatus.upToDate', () async { @@ -294,7 +294,7 @@ void main() { when( () => updater.checkForDownloadableUpdate(track: track), ).thenReturn(true); - shorebirdUpdater = ShorebirdUpdaterImpl(updater, run: run); + shorebirdUpdater = ShorebirdUpdaterImpl(updater: updater, run: run); }); test('forwards the provided track to the underlying updater call', @@ -318,7 +318,7 @@ void main() { test( 'does nothing', overridePrint((_) async { - shorebirdUpdater = ShorebirdUpdaterImpl(updater, run: run); + shorebirdUpdater = ShorebirdUpdaterImpl(updater: updater, run: run); await expectLater(shorebirdUpdater.update(), completes); verifyNever(updater.downloadUpdate); }), @@ -329,7 +329,7 @@ void main() { setUp(() { when(() => updater.currentPatchNumber()).thenReturn(0); when(() => updater.update()).thenReturn(nullptr); - shorebirdUpdater = ShorebirdUpdaterImpl(updater, run: run); + shorebirdUpdater = ShorebirdUpdaterImpl(updater: updater, run: run); }); test('throws $UpdateException', () async { @@ -365,7 +365,7 @@ void main() { ..free(result); }); when(() => updater.update()).thenReturn(result); - shorebirdUpdater = ShorebirdUpdaterImpl(updater, run: run); + shorebirdUpdater = ShorebirdUpdaterImpl(updater: updater, run: run); }); test('throws $UpdateException', () async { @@ -402,7 +402,7 @@ void main() { ..free(result); }); when(() => updater.update()).thenReturn(result); - shorebirdUpdater = ShorebirdUpdaterImpl(updater, run: run); + shorebirdUpdater = ShorebirdUpdaterImpl(updater: updater, run: run); }); test('throws $UpdateException', () async { @@ -439,7 +439,7 @@ void main() { ..free(result); }); when(() => updater.update()).thenReturn(result); - shorebirdUpdater = ShorebirdUpdaterImpl(updater, run: run); + shorebirdUpdater = ShorebirdUpdaterImpl(updater: updater, run: run); }); test('throws $UpdateException', () async { @@ -467,7 +467,7 @@ void main() { result.ref.status = SHOREBIRD_UPDATE_ERROR; addTearDown(() => calloc.free(result)); when(() => updater.update()).thenReturn(result); - shorebirdUpdater = ShorebirdUpdaterImpl(updater, run: run); + shorebirdUpdater = ShorebirdUpdaterImpl(updater: updater, run: run); }); test('throws $UpdateException', () async { @@ -497,7 +497,7 @@ void main() { when(updater.currentPatchNumber).thenReturn(0); when(updater.nextPatchNumber).thenReturn(1); when(() => updater.update()).thenThrow(Exception('oops')); - shorebirdUpdater = ShorebirdUpdaterImpl(updater, run: run); + shorebirdUpdater = ShorebirdUpdaterImpl(updater: updater, run: run); }); test('falls back to downloadUpdate', () async { @@ -511,7 +511,7 @@ void main() { setUp(() { when(updater.currentPatchNumber).thenReturn(0); when(updater.nextPatchNumber).thenReturn(0); - shorebirdUpdater = ShorebirdUpdaterImpl(updater, run: run); + shorebirdUpdater = ShorebirdUpdaterImpl(updater: updater, run: run); }); test('throws if legacy update fails', () async { @@ -546,7 +546,7 @@ Please upgrade the Shorebird Engine for improved error messages.''', result.ref.message = nullptr; addTearDown(() => calloc.free(result)); when(() => updater.update()).thenReturn(result); - shorebirdUpdater = ShorebirdUpdaterImpl(updater, run: run); + shorebirdUpdater = ShorebirdUpdaterImpl(updater: updater, run: run); }); test('throws $UpdateException', () async { @@ -578,7 +578,7 @@ Please upgrade the Shorebird Engine for improved error messages.''', result.ref.status = SHOREBIRD_UPDATE_INSTALLED; addTearDown(() => calloc.free(result)); when(() => updater.update()).thenReturn(result); - shorebirdUpdater = ShorebirdUpdaterImpl(updater, run: run); + shorebirdUpdater = ShorebirdUpdaterImpl(updater: updater, run: run); }); test('completes', () async { @@ -597,7 +597,7 @@ Please upgrade the Shorebird Engine for improved error messages.''', result.ref.status = SHOREBIRD_UPDATE_INSTALLED; addTearDown(() => calloc.free(result)); when(() => updater.update(track: track)).thenReturn(result); - shorebirdUpdater = ShorebirdUpdaterImpl(updater, run: run); + shorebirdUpdater = ShorebirdUpdaterImpl(updater: updater, run: run); }); test('forwards the provided track to the underlying updater call', diff --git a/shorebird_code_push/test/src/shorebird_updater_web_test.dart b/shorebird_code_push/test/src/shorebird_updater_web_test.dart index 6bdcbb5..bc7270a 100644 --- a/shorebird_code_push/test/src/shorebird_updater_web_test.dart +++ b/shorebird_code_push/test/src/shorebird_updater_web_test.dart @@ -1,26 +1,17 @@ -import 'package:mocktail/mocktail.dart'; import 'package:shorebird_code_push/src/shorebird_updater.dart'; import 'package:shorebird_code_push/src/shorebird_updater_web.dart'; -import 'package:shorebird_code_push/src/updater.dart'; import 'package:test/test.dart'; import '../override_print.dart'; -class _MockUpdater extends Mock implements Updater {} - void main() { group(ShorebirdUpdaterImpl, () { - late Updater updater; late ShorebirdUpdaterImpl shorebirdUpdater; - setUp(() { - updater = _MockUpdater(); - }); - test( 'logs unavailable error', overridePrint((logs) { - shorebirdUpdater = ShorebirdUpdaterImpl(updater); + shorebirdUpdater = ShorebirdUpdaterImpl(); expect( logs, contains( @@ -40,7 +31,7 @@ void main() { test( 'returns false', overridePrint((_) { - shorebirdUpdater = ShorebirdUpdaterImpl(updater); + shorebirdUpdater = ShorebirdUpdaterImpl(); expect(shorebirdUpdater.isAvailable, isFalse); }), ); @@ -79,7 +70,6 @@ void main() { 'does nothing', overridePrint((_) async { await expectLater(shorebirdUpdater.update(), completes); - verifyNever(updater.downloadUpdate); }), ); });