[web] Move JS content to its own .js files (#117691)
This commit is contained in:
@@ -785,19 +785,40 @@ void main() {
|
||||
}));
|
||||
|
||||
test('Generated service worker is empty with none-strategy', () {
|
||||
final String result = generateServiceWorker(<String, String>{'/foo': 'abcd'}, <String>[], serviceWorkerStrategy: ServiceWorkerStrategy.none);
|
||||
final String fileGeneratorsPath =
|
||||
environment.artifacts.getArtifactPath(Artifact.flutterToolsFileGenerators);
|
||||
final String result = generateServiceWorker(
|
||||
fileGeneratorsPath,
|
||||
<String, String>{'/foo': 'abcd'},
|
||||
<String>[],
|
||||
serviceWorkerStrategy: ServiceWorkerStrategy.none,
|
||||
);
|
||||
|
||||
expect(result, '');
|
||||
});
|
||||
|
||||
test('Generated service worker correctly inlines file hashes', () {
|
||||
final String result = generateServiceWorker(<String, String>{'/foo': 'abcd'}, <String>[], serviceWorkerStrategy: ServiceWorkerStrategy.offlineFirst);
|
||||
final String fileGeneratorsPath =
|
||||
environment.artifacts.getArtifactPath(Artifact.flutterToolsFileGenerators);
|
||||
final String result = generateServiceWorker(
|
||||
fileGeneratorsPath,
|
||||
<String, String>{'/foo': 'abcd'},
|
||||
<String>[],
|
||||
serviceWorkerStrategy: ServiceWorkerStrategy.offlineFirst,
|
||||
);
|
||||
|
||||
expect(result, contains('{\n "/foo": "abcd"\n};'));
|
||||
expect(result, contains('{"/foo": "abcd"};'));
|
||||
});
|
||||
|
||||
test('Generated service worker includes core files', () {
|
||||
final String result = generateServiceWorker(<String, String>{'/foo': 'abcd'}, <String>['foo', 'bar'], serviceWorkerStrategy: ServiceWorkerStrategy.offlineFirst);
|
||||
final String fileGeneratorsPath =
|
||||
environment.artifacts.getArtifactPath(Artifact.flutterToolsFileGenerators);
|
||||
final String result = generateServiceWorker(
|
||||
fileGeneratorsPath,
|
||||
<String, String>{'/foo': 'abcd'},
|
||||
<String>['foo', 'bar'],
|
||||
serviceWorkerStrategy: ServiceWorkerStrategy.offlineFirst,
|
||||
);
|
||||
|
||||
expect(result, contains('"foo",\n"bar"'));
|
||||
});
|
||||
@@ -854,7 +875,10 @@ void main() {
|
||||
}));
|
||||
|
||||
test('flutter.js sanity checks', () {
|
||||
final String flutterJsContents = flutter_js.generateFlutterJsFile();
|
||||
final String fileGeneratorsPath = environment.artifacts
|
||||
.getArtifactPath(Artifact.flutterToolsFileGenerators);
|
||||
final String flutterJsContents =
|
||||
flutter_js.generateFlutterJsFile(fileGeneratorsPath);
|
||||
expect(flutterJsContents, contains('"use strict";'));
|
||||
expect(flutterJsContents, contains('main.dart.js'));
|
||||
expect(flutterJsContents, contains('flutter_service_worker.js?v='));
|
||||
@@ -873,8 +897,14 @@ void main() {
|
||||
await WebBuiltInAssets(globals.fs, globals.cache, false).build(environment);
|
||||
|
||||
// No caching of source maps.
|
||||
expect(environment.outputDir.childFile('flutter.js').readAsStringSync(),
|
||||
equals(flutter_js.generateFlutterJsFile()));
|
||||
final String fileGeneratorsPath = environment.artifacts
|
||||
.getArtifactPath(Artifact.flutterToolsFileGenerators);
|
||||
final String flutterJsContents =
|
||||
flutter_js.generateFlutterJsFile(fileGeneratorsPath);
|
||||
expect(
|
||||
environment.outputDir.childFile('flutter.js').readAsStringSync(),
|
||||
equals(flutterJsContents),
|
||||
);
|
||||
}));
|
||||
|
||||
test('wasm build copies and generates specific files', () => testbed.run(() async {
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:file/file.dart';
|
||||
import 'package:flutter_tools/src/artifacts.dart';
|
||||
import 'package:flutter_tools/src/web/file_generators/flutter_js.dart';
|
||||
|
||||
import '../test_utils.dart';
|
||||
@@ -59,9 +60,13 @@ abstract class Project {
|
||||
}
|
||||
deferredComponents?.setUpIn(dir);
|
||||
|
||||
final String fileGeneratorsPath =
|
||||
Artifacts.test().getArtifactPath(Artifact.flutterToolsFileGenerators);
|
||||
final String flutterJsContents = generateFlutterJsFile(fileGeneratorsPath);
|
||||
|
||||
// Setup for different flutter web initializations
|
||||
writeFile(fileSystem.path.join(dir.path, 'web', 'index.html'), indexHtml);
|
||||
writeFile(fileSystem.path.join(dir.path, 'web', 'flutter.js'), generateFlutterJsFile());
|
||||
writeFile(fileSystem.path.join(dir.path, 'web', 'flutter.js'), flutterJsContents);
|
||||
writeFile(fileSystem.path.join(dir.path, 'web', 'flutter_service_worker.js'), '');
|
||||
writePackages(dir.path);
|
||||
await getPackages(dir.path);
|
||||
|
||||
Reference in New Issue
Block a user