[dartdev] Fix webdev integration test

Closes: https://github.com/dart-lang/sdk/issues/51106
Closes: https://github.com/dart-lang/sdk/issues/51037
Change-Id: If88b3e800764dbf0be4e294dc996fa2bc74be1f3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/280561
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Reviewed-by: Ben Konyi <bkonyi@google.com>
Commit-Queue: Anna Gringauze <annagrin@google.com>
diff --git a/pkg/dartdev/test/commands/create_integration_test.dart b/pkg/dartdev/test/commands/create_integration_test.dart
index 510e34d..09e29cd 100644
--- a/pkg/dartdev/test/commands/create_integration_test.dart
+++ b/pkg/dartdev/test/commands/create_integration_test.dart
@@ -133,20 +133,31 @@
           // if they've executed correctly. These templates won't exit on their
           // own, so we'll need to terminate the process once we've verified it
           // runs correctly.
+          var hasError = false;
           stdoutSub = process.stdout.transform(utf8.decoder).listen((e) {
             print('stdout: $e');
-            if ((isServerTemplate && e.contains('Server listening on port')) ||
+            if (e.contains('[SEVERE]') ||
+                (isServerTemplate && e.contains('Server listening on port')) ||
                 (isWebTemplate && e.contains('Succeeded after'))) {
+              if (e.contains('[SEVERE]')) {
+                hasError = true;
+              }
               stderrSub.cancel();
               stdoutSub.cancel();
               process.kill();
               completer.complete();
             }
           });
-          stderrSub = process.stderr
-              .transform(utf8.decoder)
-              .listen((e) => print('stderr: $e'));
+          stderrSub = process.stderr.transform(utf8.decoder).listen((e) {
+            print('stderr: $e');
+            hasError = true;
+            stderrSub.cancel();
+            stdoutSub.cancel();
+            process.kill();
+            completer.complete();
+          });
           await completer.future;
+          expect(hasError, isFalse, reason: 'Command $command failed.');
 
           // Since we had to terminate the process manually, we aren't certain
           // as to what the exit code will be on all platforms (should be -15
@@ -154,9 +165,25 @@
           // here.
           await process.exitCode;
         } else {
+          final output = <String>[];
+          final errors = <String>[];
+          process.stdout.transform(utf8.decoder).listen(output.add);
+          process.stderr.transform(utf8.decoder).listen(errors.add);
+
           // If the sample should exit on its own, it should always result in
           // an exit code of 0.
-          expect(await process.exitCode, 0);
+          final duration = const Duration(seconds: 30);
+          final exitCode =
+              await process.exitCode.timeout(duration, onTimeout: () {
+            print('Command $command timed out');
+            return -1;
+          });
+          if (exitCode != 0) {
+            print('Command $command exited with code $exitCode');
+            print('Output: \n${output.join('\n')}');
+            print('Errors: \n${errors.join('\n')}');
+          }
+          expect(exitCode, 0);
         }
         print('[${i + 1} / ${runCommands.length}] Done "$command".');
       }
diff --git a/pkg/pkg.status b/pkg/pkg.status
index f10c167..c53c32a 100644
--- a/pkg/pkg.status
+++ b/pkg/pkg.status
@@ -147,7 +147,6 @@
 vm_snapshot_analysis/test/*: SkipByDesign # Only meant to run on vm
 
 [ $system == windows ]
-dartdev/test/commands/create_integration_test: Skip # dartbug.com/51037 until fix lands for windows
 front_end/test/fasta/bootstrap_test: Skip # Issue 31902
 front_end/test/fasta/strong_test: Pass, Slow, Timeout
 front_end/test/incremental_dart2js_load_from_dill_test: Pass, Slow