forked from firka/flutter
[flutter_tools] cache the base URL as index.html (#53666)
This commit is contained in:
@@ -354,6 +354,10 @@ class WebServiceWorker extends Target {
|
||||
).toString();
|
||||
final String hash = md5.convert(await file.readAsBytes()).toString();
|
||||
urlToHash[url] = hash;
|
||||
// Add an additional entry for the base URL.
|
||||
if (globals.fs.path.basename(url) == 'index.html') {
|
||||
urlToHash['/'] = hash;
|
||||
}
|
||||
}
|
||||
|
||||
final File serviceWorkerFile = environment.outputDir
|
||||
|
||||
@@ -462,6 +462,21 @@ void main() {
|
||||
// Depends on resource file.
|
||||
expect(environment.buildDir.childFile('service_worker.d').readAsStringSync(), contains('a/a.txt'));
|
||||
}));
|
||||
|
||||
test('WebServiceWorker contains baseUrl cache', () => testbed.run(() async {
|
||||
environment.outputDir
|
||||
.childFile('index.html')
|
||||
.createSync(recursive: true);
|
||||
await const WebServiceWorker().build(environment);
|
||||
|
||||
expect(environment.outputDir.childFile('flutter_service_worker.js'), exists);
|
||||
// Contains file hash for both `/` and index.html.
|
||||
expect(environment.outputDir.childFile('flutter_service_worker.js').readAsStringSync(),
|
||||
contains('"/": "d41d8cd98f00b204e9800998ecf8427e"'));
|
||||
expect(environment.outputDir.childFile('flutter_service_worker.js').readAsStringSync(),
|
||||
contains('"index.html": "d41d8cd98f00b204e9800998ecf8427e"'));
|
||||
expect(environment.buildDir.childFile('service_worker.d'), exists);
|
||||
}));
|
||||
}
|
||||
|
||||
class MockProcessManager extends Mock implements ProcessManager {}
|
||||
|
||||
Reference in New Issue
Block a user