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

7 8
import 'package:path/path.dart' as path;

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

import 'package:flutter_devicelab/tasks/perf_tests.dart' show WebCompileTest;

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 {
29 30 31 32 33 34
    final Directory galleryParentDir =
        Directory.systemTemp.createTempSync('temp');
    final Directory galleryDir =
        Directory(path.join(galleryParentDir.path, 'gallery'));

    await getNewGallery(galleryVersion, galleryDir);
35 36

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

        return await WebCompileTest.runSingleBuildTest(
42
          directory: galleryDir.path,
43 44 45 46 47 48
          metric: metricKeyPrefix,
          measureBuildTime: true,
        );
      },
    );

49
    rmTree(galleryParentDir);
50 51 52 53

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