Unverified Commit bb5c3400 authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

[flutter_tools] cache the base URL as index.html (#53666)

parent d62c7ecc
......@@ -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 {}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment