From 67a62e751fb0632540638e767bd7482a2e3a5f03 Mon Sep 17 00:00:00 2001 From: Tobe O Date: Mon, 9 Jul 2018 13:20:14 -0400 Subject: [PATCH] Add tests + Travis --- .travis.yml | 4 + README.md | 3 + lib/angel_seo.dart | 2 +- pubspec.yaml | 10 ++- test/inline_assets_test.dart | 142 +++++++++++++++++++++++++++++++++++ 5 files changed, 159 insertions(+), 2 deletions(-) create mode 100644 .travis.yml create mode 100644 test/inline_assets_test.dart diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..a9e2c109 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,4 @@ +language: dart +dart: + - dev + - stable \ No newline at end of file diff --git a/README.md b/README.md index ba53635b..32297322 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,7 @@ # seo +[![Pub](https://img.shields.io/pub/v/angel_seo.svg)](https://pub.dartlang.org/packages/angel_seo) +[![build status](https://travis-ci.org/angel-dart/seo.svg?branch=master)](https://travis-ci.org/angel-dart/seo) + Helpers for building SEO-friendly Web pages in Angel. The goal of `package:angel_seo` is to speed up perceived client page loads, prevent the infamous diff --git a/lib/angel_seo.dart b/lib/angel_seo.dart index 8288ada9..8a291cdc 100644 --- a/lib/angel_seo.dart +++ b/lib/angel_seo.dart @@ -1 +1 @@ -export 'src/inline_assets.dart'; \ No newline at end of file +export 'src/inline_assets.dart'; diff --git a/pubspec.yaml b/pubspec.yaml index 781443aa..c919faae 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,9 +1,17 @@ name: angel_seo +description: Helpers for building SEO-friendly Web pages in Angel. +author: Tobe O +homepage: https://github.com/angel-dart/seo +version: 1.0.0 +environment: + sdk: ">=1.8.0 <3.0.0" dependencies: angel_framework: ^1.0.0-dev + angel_static: ^1.3.0 dart2_constant: ^1.0.0 file: ^2.0.0 html: ^0.13.0 path: ^1.0.0 dev_dependencies: - angel_static: ^1.3.0 \ No newline at end of file + angel_test: ^1.0.0 + test: ^0.12.0 \ No newline at end of file diff --git a/test/inline_assets_test.dart b/test/inline_assets_test.dart new file mode 100644 index 00000000..99aa2a21 --- /dev/null +++ b/test/inline_assets_test.dart @@ -0,0 +1,142 @@ +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:dart2_constant/convert.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:test/test.dart'; + +void main() { + group('inlineAssets', () { + group('buffer', inlineAssetsTests((app, dir) { + app.get('/', (ResponseContext res) async { + var indexHtml = dir.childFile('index.html'); + var contents = await indexHtml.readAsString(); + res + ..headers['content-type'] = 'text/html; charset=utf-8' + ..buffer.add(utf8.encode(contents)); + }); + + app.responseFinalizers.add(inlineAssets(dir)); + })); + + group('virtual_directory', inlineAssetsTests((app, dir) { + var vDir = inlineAssetsFromVirtualDirectory( + new VirtualDirectory(app, dir.fileSystem, source: dir)); + app.use(vDir.handleRequest); + })); + }); +} + +void Function() inlineAssetsTests(void Function(Angel, Directory) f) { + return () { + TestClient client; + + setUp(() async { + var app = new Angel(); + var fs = new 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()); + } + }); + + tearDown(() => client.close()); + + group('sends html', () { + html.Document doc; + + setUp(() async { + var res = await client.get('/', headers: {'accept': 'text/html'}); + doc = html.parse(res.body); + }); + + group('stylesheets', () { + test('replaces with