platform/packages/static/test/push_state_test.dart
2024-10-12 18:45:27 -07:00

58 lines
1.4 KiB
Dart

import 'package:protevus_framework/protevus_framework.dart';
import 'package:protevus_static/protevus_static.dart';
import 'package:protevus_test/protevus_test.dart';
import 'package:file/memory.dart';
import 'package:logging/logging.dart';
import 'package:test/test.dart';
void main() {
Protevus app;
MemoryFileSystem fileSystem;
late TestClient client;
setUp(() async {
// For teting on Linux/MacOS
fileSystem = MemoryFileSystem();
// For testing on Windows
//fileSystem = MemoryFileSystem(style: FileSystemStyle.windows);
var webDir = fileSystem.directory('web');
await webDir.create(recursive: true);
var indexFile = webDir.childFile('index.html');
await indexFile.writeAsString('index');
app = Protevus();
var vDir = VirtualDirectory(
app,
fileSystem,
source: webDir,
);
app
..fallback(vDir.handleRequest)
..fallback(vDir.pushState('index.html'))
..fallback((req, res) => 'Fallback');
app.logger = Logger('push_state')
..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(Uri.parse('/nope'));
print(response);
expect(response.body, 'index');
});
}