2021-05-15 13:28:26 +00:00
|
|
|
import 'package:angel3_framework/angel3_framework.dart';
|
|
|
|
import 'package:angel3_static/angel3_static.dart';
|
|
|
|
import 'package:angel3_test/angel3_test.dart';
|
2017-09-24 05:02:10 +00:00
|
|
|
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 {
|
2021-07-04 05:59:50 +00:00
|
|
|
// For teting on Linux/MacOS
|
2019-05-02 23:29:09 +00:00
|
|
|
fileSystem = MemoryFileSystem();
|
2017-09-24 05:02:10 +00:00
|
|
|
|
2021-07-04 05:59:50 +00:00
|
|
|
// For testing on Windows
|
|
|
|
//fileSystem = MemoryFileSystem(style: FileSystemStyle.windows);
|
|
|
|
|
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');
|
|
|
|
});
|
|
|
|
}
|