bootstrap_test.dart 4.15 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
2 3 4 5
// 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';
6
import 'package:package_config/package_config.dart';
7 8 9 10 11 12 13 14 15 16 17 18 19 20

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.
21
    expect(result, contains('requireEl.setAttribute("data-main", "main_module.bootstrap");'));
22 23
  });

24 25 26 27 28 29
test('generateBootstrapScript includes loading indicator', () {
    final String result = generateBootstrapScript(
      requireUrl: 'require.js',
      mapperUrl: 'mapper.js',
    );
    expect(result, contains('"flutter-loader"'));
30
    expect(result, contains('"indeterminate"'));
31 32
  });

33 34 35
  test('generateMainModule embeds urls correctly', () {
    final String result = generateMainModule(
      entrypoint: 'foo/bar/main.js',
36
      nullAssertions: false,
37
      nativeNullAssertions: false,
38 39
    );
    // bootstrap main module has correct defined module.
40
    expect(result, contains('define("main_module.bootstrap", ["foo/bar/main.js", "dart_sdk"], '
41 42
      'function(app, dart_sdk) {'));
  });
43

44 45 46 47
  test('generateMainModule can set bootstrap name', () {
    final String result = generateMainModule(
      entrypoint: 'foo/bar/main.js',
      nullAssertions: false,
48
      nativeNullAssertions: false,
49 50 51 52 53 54 55
      bootstrapModule: 'foo_module.bootstrap',
    );
    // bootstrap main module has correct defined module.
    expect(result, contains('define("foo_module.bootstrap", ["foo/bar/main.js", "dart_sdk"], '
      'function(app, dart_sdk) {'));
  });

56 57 58
  test('generateMainModule includes null safety switches', () {
    final String result = generateMainModule(
      entrypoint: 'foo/bar/main.js',
59
      nullAssertions: true,
60
      nativeNullAssertions: true,
61 62
    );

63 64 65 66 67 68 69 70 71 72 73 74 75
    expect(result, contains('''dart_sdk.dart.nonNullAsserts(true);'''));
    expect(result, contains('''dart_sdk.dart.nativeNonNullAsserts(true);'''));
  });

  test('generateMainModule can disable null safety switches', () {
    final String result = generateMainModule(
      entrypoint: 'foo/bar/main.js',
      nullAssertions: false,
      nativeNullAssertions: false,
    );

    expect(result, contains('''dart_sdk.dart.nonNullAsserts(false);'''));
    expect(result, contains('''dart_sdk.dart.nativeNonNullAsserts(false);'''));
76
  });
77 78 79 80 81 82

  test('generateTestBootstrapFileContents embeds urls correctly', () {
    final String result = generateTestBootstrapFileContents('foo.dart.js', 'require.js', 'mapper.js');

    expect(result, contains('el.setAttribute("data-main", \'foo.dart.js\');'));
  });
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104

  test('generateTestEntrypoint does not generate test config wrappers when testConfigPath is not passed', () {
    final String result = generateTestEntrypoint(
      relativeTestPath: 'relative_path.dart',
      absolutePath: 'absolute_path.dart',
      testConfigPath: null,
      languageVersion: LanguageVersion(2, 8),
    );

    expect(result, isNot(contains('test_config.testExecutable')));
  });

  test('generateTestEntrypoint generates test config wrappers when testConfigPath is passed', () {
    final String result = generateTestEntrypoint(
      relativeTestPath: 'relative_path.dart',
      absolutePath: 'absolute_path.dart',
      testConfigPath: 'test_config_path.dart',
      languageVersion: LanguageVersion(2, 8),
    );

    expect(result, contains('test_config.testExecutable'));
  });
105 106 107 108 109 110 111 112 113 114 115

  test('generateTestEntrypoint embeds urls correctly', () {
    final String result = generateTestEntrypoint(
      relativeTestPath: 'relative_path.dart',
      absolutePath: '/test/absolute_path.dart',
      testConfigPath: null,
      languageVersion: LanguageVersion(2, 8),
    );

    expect(result, contains("Uri.parse('file:///test/absolute_path.dart')"));
  });
116
}