import 'dart:io'; import 'package:flutter_test/flutter_test.dart'; import 'package:peach/Peach/about/internal/application/ServiceConfig.dart'; import 'package:peach/Peach/about/internal/file/BuildService.dart'; void main() { test('runs custom build command and picks the runnable jar', () async { // Fake Gradle project with several jars in build/libs. final dir = Directory.systemTemp.createTempSync('peachdeploy_build_test'); addTearDown(() => dir.deleteSync(recursive: true)); File('${dir.path}/build.gradle').writeAsStringSync('// fake'); final libs = Directory('${dir.path}/build/libs')..createSync(recursive: true); // Distractors that must be excluded, plus the real artifact. File('${libs.path}/app-sources.jar').writeAsStringSync('x'); File('${libs.path}/app-plain.jar').writeAsStringSync('x'); File('${libs.path}/app.jar').writeAsStringSync('runnable'); final svc = ServiceConfig( name: 'demo', localProjectPath: dir.path, // Trivial command so we don't need a real Gradle install. buildCommand: Platform.isWindows ? 'echo building' : 'true', ); final build = BuildService(); addTearDown(build.dispose); final result = await build.build(svc); expect(result.ok, isTrue, reason: result.message); expect(result.jar, isNotNull); expect(result.jar!.path.replaceAll('\\', '/'), endsWith('app.jar')); }); test('reports a helpful error when no project is detected', () async { final dir = Directory.systemTemp.createTempSync('peachdeploy_empty_test'); addTearDown(() => dir.deleteSync(recursive: true)); final svc = ServiceConfig(name: 'empty', localProjectPath: dir.path); final build = BuildService(); addTearDown(build.dispose); final result = await build.build(svc); expect(result.ok, isFalse); expect(result.message.toLowerCase(), contains('detect')); }); }