[web] Update index.html template to support new path strategy (#67081)
This commit is contained in:
@@ -55,7 +55,6 @@ void main() {
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -215,6 +214,85 @@ void main() {
|
||||
expect(response.statusCode, HttpStatus.notFound);
|
||||
}));
|
||||
|
||||
test('parses base path from index.html', () => testbed.run(() async {
|
||||
const String htmlContent = '<html><head><base href="/foo/bar/"></head><body id="test"></body></html>';
|
||||
final Directory webDir = globals.fs.currentDirectory
|
||||
.childDirectory('web')
|
||||
..createSync();
|
||||
webDir.childFile('index.html').writeAsStringSync(htmlContent);
|
||||
|
||||
final WebAssetServer webAssetServer = WebAssetServer(
|
||||
mockHttpServer,
|
||||
packages,
|
||||
InternetAddress.loopbackIPv4,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
);
|
||||
|
||||
expect(webAssetServer.basePath, 'foo/bar');
|
||||
}));
|
||||
|
||||
test('handles lack of base path in index.html', () => testbed.run(() async {
|
||||
const String htmlContent = '<html><head></head><body id="test"></body></html>';
|
||||
final Directory webDir = globals.fs.currentDirectory
|
||||
.childDirectory('web')
|
||||
..createSync();
|
||||
webDir.childFile('index.html').writeAsStringSync(htmlContent);
|
||||
|
||||
final WebAssetServer webAssetServer = WebAssetServer(
|
||||
mockHttpServer,
|
||||
packages,
|
||||
InternetAddress.loopbackIPv4,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
);
|
||||
|
||||
// Defaults to "/" when there's no base element.
|
||||
expect(webAssetServer.basePath, '');
|
||||
}));
|
||||
|
||||
test('throws if base path is relative', () => testbed.run(() async {
|
||||
const String htmlContent = '<html><head><base href="foo/bar/"></head><body id="test"></body></html>';
|
||||
final Directory webDir = globals.fs.currentDirectory
|
||||
.childDirectory('web')
|
||||
..createSync();
|
||||
webDir.childFile('index.html').writeAsStringSync(htmlContent);
|
||||
|
||||
expect(
|
||||
() => WebAssetServer(
|
||||
mockHttpServer,
|
||||
packages,
|
||||
InternetAddress.loopbackIPv4,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
),
|
||||
throwsToolExit(),
|
||||
);
|
||||
}));
|
||||
|
||||
test('throws if base path does not end with slash', () => testbed.run(() async {
|
||||
const String htmlContent = '<html><head><base href="/foo/bar"></head><body id="test"></body></html>';
|
||||
final Directory webDir = globals.fs.currentDirectory
|
||||
.childDirectory('web')
|
||||
..createSync();
|
||||
webDir.childFile('index.html').writeAsStringSync(htmlContent);
|
||||
|
||||
expect(
|
||||
() => WebAssetServer(
|
||||
mockHttpServer,
|
||||
packages,
|
||||
InternetAddress.loopbackIPv4,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
),
|
||||
throwsToolExit(),
|
||||
);
|
||||
}));
|
||||
|
||||
test('serves JavaScript files from in memory cache not from manifest', () => testbed.run(() async {
|
||||
webAssetServer.writeFile('foo.js', 'main() {}');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user