Add app source and tests
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
74
test/web_build_test.dart
Normal file
74
test/web_build_test.dart
Normal file
@@ -0,0 +1,74 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:archive/archive.dart';
|
||||
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';
|
||||
import 'package:peach/Peach/about/internal/file/WebArchive.dart';
|
||||
|
||||
void main() {
|
||||
test('buildWeb locates the React build/ output', () async {
|
||||
final dir = Directory.systemTemp.createTempSync('peachdeploy_web_test');
|
||||
addTearDown(() => dir.deleteSync(recursive: true));
|
||||
|
||||
Directory('${dir.path}/build').createSync(recursive: true);
|
||||
File('${dir.path}/build/index.html').writeAsStringSync('<html></html>');
|
||||
File('${dir.path}/build/main.js').writeAsStringSync('console.log(1)');
|
||||
|
||||
final svc = ServiceConfig(
|
||||
name: 'site',
|
||||
kind: ServiceKind.webApp,
|
||||
framework: WebFramework.react,
|
||||
localProjectPath: dir.path,
|
||||
buildCommand: Platform.isWindows ? 'echo building' : 'true',
|
||||
);
|
||||
|
||||
final build = BuildService();
|
||||
addTearDown(build.dispose);
|
||||
|
||||
final result = await build.buildWeb(svc);
|
||||
expect(result.ok, isTrue, reason: result.message);
|
||||
expect(result.dir, isNotNull);
|
||||
expect(result.dir!.path.replaceAll('\\', '/'), endsWith('build'));
|
||||
});
|
||||
|
||||
test('static framework needs no build and publishes the folder', () async {
|
||||
final dir = Directory.systemTemp.createTempSync('peachdeploy_static_test');
|
||||
addTearDown(() => dir.deleteSync(recursive: true));
|
||||
File('${dir.path}/index.html').writeAsStringSync('<html></html>');
|
||||
|
||||
final svc = ServiceConfig(
|
||||
name: 'static',
|
||||
kind: ServiceKind.webApp,
|
||||
framework: WebFramework.staticFiles,
|
||||
localProjectPath: dir.path,
|
||||
);
|
||||
final build = BuildService();
|
||||
addTearDown(build.dispose);
|
||||
|
||||
final result = await build.buildWeb(svc);
|
||||
expect(result.ok, isTrue, reason: result.message);
|
||||
expect(result.dir, isNotNull);
|
||||
});
|
||||
|
||||
test('WebArchive tar.gz round-trips files at the archive root', () {
|
||||
final dir = Directory.systemTemp.createTempSync('peachdeploy_arch_test');
|
||||
addTearDown(() => dir.deleteSync(recursive: true));
|
||||
File('${dir.path}/index.html').writeAsStringSync('hello');
|
||||
Directory('${dir.path}/assets').createSync();
|
||||
File('${dir.path}/assets/app.js').writeAsStringSync('x = 1;');
|
||||
|
||||
final (bytes, count) = WebArchive.tarGz(dir);
|
||||
expect(count, 2);
|
||||
|
||||
final tar = GZipDecoder().decodeBytes(bytes);
|
||||
final archive = TarDecoder().decodeBytes(tar);
|
||||
final names = archive.files.map((f) => f.name).toSet();
|
||||
// Paths must be POSIX (forward slashes) so `tar` on Linux rebuilds the
|
||||
// directory tree instead of creating literal `assets\app.js` files.
|
||||
expect(names.any((n) => n.contains('\\')), isFalse,
|
||||
reason: 'archive entries must use forward slashes');
|
||||
expect(names, contains('index.html'));
|
||||
expect(names, contains('assets/app.js'));
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user