flutter_gallery_v2_web_compile_test.dart 1.61 KB
Newer Older
1 2 3 4 5 6 7
// 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 'dart:io';

import 'package:flutter_devicelab/framework/framework.dart';
8
import 'package:flutter_devicelab/framework/task_result.dart';
9 10
import 'package:flutter_devicelab/framework/utils.dart';
import 'package:flutter_devicelab/tasks/perf_tests.dart' show WebCompileTest;
11 12
import 'package:flutter_devicelab/versions/gallery.dart' show galleryVersion;
import 'package:path/path.dart' as path;
13 14 15 16 17 18 19 20 21 22 23 24 25 26

Future<void> main() async {
  await task(const NewGalleryWebCompileTest().run);
}

/// Measures the time to compile the New Flutter Gallery to JavaScript
/// and the size of the compiled code.
class NewGalleryWebCompileTest {
  const NewGalleryWebCompileTest();

  String get metricKeyPrefix => 'new_gallery';

  /// Runs the test.
  Future<TaskResult> run() async {
27
    final Directory galleryParentDir =
28
        Directory.systemTemp.createTempSync('flutter_gallery_v2_web_compile.');
29 30 31 32
    final Directory galleryDir =
        Directory(path.join(galleryParentDir.path, 'gallery'));

    await getNewGallery(galleryVersion, galleryDir);
33 34

    final Map<String, Object> metrics = await inDirectory<Map<String, int>>(
35
      galleryDir,
36 37 38
      () async {
        await flutter('doctor');

39
        return WebCompileTest.runSingleBuildTest(
40
          directory: galleryDir.path,
41 42 43 44 45 46
          metric: metricKeyPrefix,
          measureBuildTime: true,
        );
      },
    );

47
    rmTree(galleryParentDir);
48 49 50 51

    return TaskResult.success(metrics, benchmarkScoreKeys: metrics.keys.toList());
  }
}