platform/packages/static/test/push_state_test.dart

55 lines
1.3 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';
2021-03-05 07:51:48 +00:00
void main() {
2017-09-24 05:02:10 +00:00
Angel app;
MemoryFileSystem fileSystem;
2021-05-01 03:53:04 +00:00
late TestClient client;
2017-09-24 05:02:10 +00:00
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 {
2021-03-08 13:22:29 +00:00
var response = await client.get(Uri.parse('/nope'));
2021-03-05 07:51:48 +00:00
print(response);
2017-09-24 05:02:10 +00:00
expect(response.body, 'index');
});
}