flutter/packages/flutter_tools/test/general.shard/web/bootstrap_test.dart
Jonah Williams cb7770b3a5
[flutter_tools] add support for enable null safety asserts (#61114)
Enable null safety asserts for web debug mode. This induces runtime asserts at the boundaries between null safe and non-null safe libraries. Adds integration test that validates assertion error is thrown.

#61042
2020-07-15 09:54:39 -07:00

44 lines
1.5 KiB
Dart

// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter_tools/src/web/bootstrap.dart';
import '../../src/common.dart';
void main() {
test('generateBootstrapScript embeds urls correctly', () {
final String result = generateBootstrapScript(
requireUrl: 'require.js',
mapperUrl: 'mapper.js',
);
// require js source is interpolated correctly.
expect(result, contains('requireEl.src = "require.js";'));
// stack trace mapper source is interpolated correctly.
expect(result, contains('mapperEl.src = "mapper.js";'));
// data-main is set to correct bootstrap module.
expect(result, contains('requireEl.setAttribute("data-main", "main_module.bootstrap");'));
});
test('generateMainModule embeds urls correctly', () {
final String result = generateMainModule(
entrypoint: 'foo/bar/main.js',
nullSafety: false,
);
// bootstrap main module has correct defined module.
expect(result, contains('define("main_module.bootstrap", ["foo/bar/main.js", "dart_sdk"], '
'function(app, dart_sdk) {'));
});
test('generateMainModule includes null safety switches', () {
final String result = generateMainModule(
entrypoint: 'foo/bar/main.js',
nullSafety: true,
);
expect(result, contains(
''' if (true) {
dart_sdk.dart.nonNullAsserts(true);'''));
});
}