platform/packages/static/test/push_state_test.dart

54 lines
1.2 KiB
Dart
Raw Normal View History

2017-09-24 05:02:10 +00:00
import 'package:angel_framework/angel_framework.dart';
import 'package:angel_static/angel_static.dart';
import 'package:angel_test/angel_test.dart';
import 'package:file/memory.dart';
import 'package:logging/logging.dart';
import 'package:test/test.dart';
main() {
Angel app;
MemoryFileSystem fileSystem;
TestClient client;
setUp(() async {
2019-05-02 23:29:09 +00:00
fileSystem = MemoryFileSystem();
2017-09-24 05:02:10 +00:00
var webDir = fileSystem.directory('web');
await webDir.create(recursive: true);
var indexFile = webDir.childFile('index.html');
await indexFile.writeAsString('index');
2019-05-02 23:29:09 +00:00
app = Angel();
2017-09-24 05:02:10 +00:00
2019-05-02 23:29:09 +00:00
var vDir = VirtualDirectory(
2017-09-24 05:02:10 +00:00
app,
fileSystem,
source: webDir,
);
app
2018-08-28 14:58:28 +00:00
..fallback(vDir.handleRequest)
..fallback(vDir.pushState('index.html'))
..fallback((req, res) => 'Fallback');
2017-09-24 05:02:10 +00:00
2019-05-02 23:29:09 +00:00
app.logger = Logger('push_state')
2017-09-24 05:02:10 +00:00
..onRecord.listen(
(rec) {
print(rec);
if (rec.error != null) print(rec.error);
if (rec.stackTrace != null) print(rec.stackTrace);
},
);
client = await connectTo(app);
});
tearDown(() => client.close());
test('serves as fallback', () async {
var response = await client.get('/nope');
expect(response.body, 'index');
});
}