import 'package:angel_framework/angel_framework.dart'; import 'package:angel_seo/angel_seo.dart'; import 'package:angel_static/angel_static.dart'; import 'package:angel_test/angel_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 void InlineAssetTest(Angel app, Directory dir); void Function() inlineAssetsTests(InlineAssetTest f) { return () { 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', () { html.Document doc; setUp(() async { var res = await client.get('/', headers: {'accept': 'text/html'}); print(res.body); doc = html.parse(res.body); }); group('stylesheets', () { test('replaces with