diff --git a/packages/flutter_tools/lib/src/commands/build_web.dart b/packages/flutter_tools/lib/src/commands/build_web.dart index 091e676d098..6fdca627530 100644 --- a/packages/flutter_tools/lib/src/commands/build_web.dart +++ b/packages/flutter_tools/lib/src/commands/build_web.dart @@ -217,7 +217,10 @@ class BuildWebCommand extends BuildSubCommand { ); } if (!project.web.existsSync()) { - throwToolExit('Missing index.html.'); + throwToolExit( + 'This project is not configured for the web.\n' + 'To configure this project for the web, run flutter create . --platforms web', + ); } if (!_fileSystem.currentDirectory .childDirectory('web') diff --git a/packages/flutter_tools/test/commands.shard/hermetic/build_web_test.dart b/packages/flutter_tools/test/commands.shard/hermetic/build_web_test.dart index 01f7fa1583b..509a6e37f71 100644 --- a/packages/flutter_tools/test/commands.shard/hermetic/build_web_test.dart +++ b/packages/flutter_tools/test/commands.shard/hermetic/build_web_test.dart @@ -64,7 +64,11 @@ void main() { expect( () => runner.run(['build', 'web', '--no-pub']), - throwsToolExit(message: 'Missing index.html.'), + throwsToolExit( + message: + 'This project is not configured for the web.\n' + 'To configure this project for the web, run flutter create . --platforms web', + ), ); }, overrides: { @@ -588,6 +592,37 @@ void main() { ProcessManager: () => processManager, }, ); + + testUsingContext( + 'Refuses to build for web when folder is missing', + () async { + fileSystem.file(fileSystem.path.join('web')).deleteSync(recursive: true); + final CommandRunner runner = createTestCommandRunner( + BuildCommand( + androidSdk: FakeAndroidSdk(), + buildSystem: TestBuildSystem.all(BuildResult(success: true)), + fileSystem: fileSystem, + logger: logger, + osUtils: FakeOperatingSystemUtils(), + ), + ); + + expect( + () => runner.run(['build', 'web', '--no-pub']), + throwsToolExit( + message: + 'This project is not configured for the web.\n' + 'To configure this project for the web, run flutter create . --platforms web', + ), + ); + }, + overrides: { + Platform: () => fakePlatform, + FileSystem: () => fileSystem, + FeatureFlags: () => TestFeatureFlags(isWebEnabled: true), + ProcessManager: () => processManager, + }, + ); } void setupFileSystemForEndToEndTest(FileSystem fileSystem) {