import 'package:angel3_framework/angel3_framework.dart';
import 'package:angel3_seo/angel3_seo.dart';
import 'package:angel3_static/angel3_static.dart';
import 'package:angel3_test/angel3_test.dart';
import 'package:file/file.dart';
import 'package:file/memory.dart';
import 'package:html/dom.dart' as html;
import 'package:html/parser.dart' as html;
import 'package:http_parser/http_parser.dart';
import 'package:logging/logging.dart';
import 'package:test/test.dart';
void main() {
group('inlineAssets', () {
group('buffer', inlineAssetsTests((app, dir) {
app.get('/', (req, res) async {
var indexHtml = dir.childFile('index.html');
var contents = await indexHtml.readAsBytes();
res
..useBuffer()
..contentType = MediaType.parse('text/html; charset=utf-8')
..buffer!.add(contents);
});
app.responseFinalizers.add(inlineAssets(dir));
}));
group('virtual_directory', inlineAssetsTests((app, dir) {
var vDir = inlineAssetsFromVirtualDirectory(
VirtualDirectory(app, dir.fileSystem, source: dir));
app.fallback(vDir.handleRequest);
}));
});
}
/// Typedef for backwards-compatibility with Dart 1.
typedef InlineAssetTest = void Function(Angel app, Directory dir);
void Function() inlineAssetsTests(InlineAssetTest f) {
return () {
late TestClient client;
setUp(() async {
var app = Angel();
var fs = MemoryFileSystem();
var dir = fs.currentDirectory;
f(app, dir);
client = await connectTo(app);
for (var path in contents.keys) {
var file = fs.file(path);
await file.writeAsString(contents[path]!.trim());
}
app.logger = Logger('angel_seo')
..onRecord.listen((rec) {
print(rec);
if (rec.error != null) print(rec.error);
if (rec.stackTrace != null) print(rec.stackTrace);
});
});
tearDown(() => client.close());
group('sends html', () {
late html.Document doc;
setUp(() async {
var res =
await client.get(Uri.parse('/'), headers: {'accept': 'text/html'});
print(res.body);
doc = html.parse(res.body);
});
group('stylesheets', () {
test('replaces with