@@ -43,6 +43,7 @@ void main() {
4343 writePackageConfigFile (mainLibName: 'foo' , directory: fileSystem.currentDirectory);
4444 fileSystem.file (fileSystem.path.join ('web' , 'index.html' )).createSync (recursive: true );
4545 fileSystem.file (fileSystem.path.join ('lib' , 'main.dart' )).createSync (recursive: true );
46+ fileSystem.file (fileSystem.path.join ('lib' , 'a.dart' )).createSync (recursive: true );
4647 logger = BufferLogger .test ();
4748 processManager = FakeProcessManager .any ();
4849 });
@@ -155,6 +156,110 @@ void main() {
155156 },
156157 );
157158
159+ testUsingContext (
160+ 'Infers target entrypoint correctly from --target' ,
161+ () async {
162+ // Regression test for https://github.com/flutter/flutter/issues/136830.
163+ final BuildCommand buildCommand = BuildCommand (
164+ androidSdk: FakeAndroidSdk (),
165+ buildSystem: TestBuildSystem .all (BuildResult (success: true )),
166+ fileSystem: fileSystem,
167+ logger: logger,
168+ osUtils: FakeOperatingSystemUtils (),
169+ );
170+ final CommandRunner <void > runner = createTestCommandRunner (buildCommand);
171+ setupFileSystemForEndToEndTest (fileSystem);
172+ await runner.run (< String > [
173+ 'build' ,
174+ 'web' ,
175+ '--no-pub' ,
176+ '--no-web-resources-cdn' ,
177+ '--target=lib/a.dart' ,
178+ ]);
179+
180+ final Directory buildDir = fileSystem.directory (fileSystem.path.join ('build' , 'web' ));
181+ expect (buildDir.existsSync (), true );
182+ expect (testLogger.statusText, contains ('Compiling lib/a.dart for the Web...' ));
183+ expect (testLogger.statusText, contains ('✓ Built ${buildDir .path }' ));
184+ },
185+ overrides: < Type , Generator > {
186+ Platform : () => fakePlatform,
187+ FileSystem : () => fileSystem,
188+ FeatureFlags : () => TestFeatureFlags (isWebEnabled: true ),
189+ ProcessManager : () => processManager,
190+ BuildSystem :
191+ () => TestBuildSystem .all (BuildResult (success: true ), (
192+ Target target,
193+ Environment environment,
194+ ) {
195+ expect (environment.defines, < String , String > {
196+ 'TargetFile' : 'lib/a.dart' ,
197+ 'HasWebPlugins' : 'true' ,
198+ 'ServiceWorkerStrategy' : 'offline-first' ,
199+ 'BuildMode' : 'release' ,
200+ 'DartDefines' :
201+ 'RkxVVFRFUl9WRVJTSU9OPTAuMC4w,RkxVVFRFUl9DSEFOTkVMPW1hc3Rlcg==,RkxVVFRFUl9HSVRfVVJMPWh0dHBzOi8vZ2l0aHViLmNvbS9mbHV0dGVyL2ZsdXR0ZXIuZ2l0,RkxVVFRFUl9GUkFNRVdPUktfUkVWSVNJT049MTExMTE=,RkxVVFRFUl9FTkdJTkVfUkVWSVNJT049YWJjZGU=,RkxVVFRFUl9EQVJUX1ZFUlNJT049MTI=' ,
202+ 'DartObfuscation' : 'false' ,
203+ 'TrackWidgetCreation' : 'false' ,
204+ 'TreeShakeIcons' : 'true' ,
205+ 'UseLocalCanvasKit' : 'true' ,
206+ });
207+ }),
208+ },
209+ );
210+
211+ testUsingContext (
212+ 'Infers target entrypoint correctly from positional argument list' ,
213+ () async {
214+ // Regression test for https://github.com/flutter/flutter/issues/136830.
215+ final BuildCommand buildCommand = BuildCommand (
216+ androidSdk: FakeAndroidSdk (),
217+ buildSystem: TestBuildSystem .all (BuildResult (success: true )),
218+ fileSystem: fileSystem,
219+ logger: logger,
220+ osUtils: FakeOperatingSystemUtils (),
221+ );
222+ final CommandRunner <void > runner = createTestCommandRunner (buildCommand);
223+ setupFileSystemForEndToEndTest (fileSystem);
224+ await runner.run (< String > [
225+ 'build' ,
226+ 'web' ,
227+ '--no-pub' ,
228+ '--no-web-resources-cdn' ,
229+ 'lib/a.dart' ,
230+ ]);
231+
232+ final Directory buildDir = fileSystem.directory (fileSystem.path.join ('build' , 'web' ));
233+ expect (buildDir.existsSync (), true );
234+ expect (testLogger.statusText, contains ('Compiling lib/a.dart for the Web...' ));
235+ expect (testLogger.statusText, contains ('✓ Built ${buildDir .path }' ));
236+ },
237+ overrides: < Type , Generator > {
238+ Platform : () => fakePlatform,
239+ FileSystem : () => fileSystem,
240+ FeatureFlags : () => TestFeatureFlags (isWebEnabled: true ),
241+ ProcessManager : () => processManager,
242+ BuildSystem :
243+ () => TestBuildSystem .all (BuildResult (success: true ), (
244+ Target target,
245+ Environment environment,
246+ ) {
247+ expect (environment.defines, < String , String > {
248+ 'TargetFile' : 'lib/a.dart' ,
249+ 'HasWebPlugins' : 'true' ,
250+ 'ServiceWorkerStrategy' : 'offline-first' ,
251+ 'BuildMode' : 'release' ,
252+ 'DartDefines' :
253+ 'RkxVVFRFUl9WRVJTSU9OPTAuMC4w,RkxVVFRFUl9DSEFOTkVMPW1hc3Rlcg==,RkxVVFRFUl9HSVRfVVJMPWh0dHBzOi8vZ2l0aHViLmNvbS9mbHV0dGVyL2ZsdXR0ZXIuZ2l0,RkxVVFRFUl9GUkFNRVdPUktfUkVWSVNJT049MTExMTE=,RkxVVFRFUl9FTkdJTkVfUkVWSVNJT049YWJjZGU=,RkxVVFRFUl9EQVJUX1ZFUlNJT049MTI=' ,
254+ 'DartObfuscation' : 'false' ,
255+ 'TrackWidgetCreation' : 'false' ,
256+ 'TreeShakeIcons' : 'true' ,
257+ 'UseLocalCanvasKit' : 'true' ,
258+ });
259+ }),
260+ },
261+ );
262+
158263 testUsingContext (
159264 'Does not allow -O0 optimization level' ,
160265 () async {
0 commit comments