Skip to content

Commit

Permalink
test: add test for cache.
Browse files Browse the repository at this point in the history
  • Loading branch information
wssgcg1213 committed Mar 8, 2022
1 parent fac57fc commit d588582
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion kraken/lib/src/launcher/bundle.dart
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ class NetworkAssetBundle extends AssetBundle {
_additionalHttpHeaders = additionalHttpHeaders,
httpClient = HttpClient();

int? contextId;
final int? contextId;
final Uri _baseUrl;
final HttpClient httpClient;
final Map<String, String>? _additionalHttpHeaders;
Expand Down
6 changes: 6 additions & 0 deletions kraken/test/kraken_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import 'src/css/values.dart' as css_values;

import 'src/gesture/scroll_physics.dart' as scroll_physics;

import 'src/launcher/bundle.dart' as bundle;

// The main entry for kraken unit test.
// Setup all common logic.
void main() {
Expand Down Expand Up @@ -64,6 +66,10 @@ void main() {
scroll_physics.main();
});

group('launcher', () {
bundle.main();
});

tearDownAll(() {
if (tempDirectory.existsSync()) {
tempDirectory.deleteSync(recursive: true);
Expand Down
23 changes: 23 additions & 0 deletions kraken/test/src/launcher/bundle.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import 'dart:convert';
import 'dart:typed_data';

import 'package:kraken/launcher.dart';
import 'package:test/test.dart';

import '../../local_http_server.dart';

void main() {
var server = LocalHttpServer.getInstance();

group('Bundle', () {
test('NetworkAssetsBundle basic', () async {
Uri uri = server.getUri('js_over_128k');
// Using contextId to active cache.
var bundle = NetworkAssetBundle(uri, contextId: 1);
ByteData data = await bundle.load(uri.toString());
var code = utf8.decode(data.buffer.asUint8List(data.offsetInBytes, data.lengthInBytes));

expect(code.length > 128 * 1024, true);
});
});
}

0 comments on commit d588582

Please sign in to comment.