From d032fd0880cd0a3e4e58bbcaad9b10972cb5740f Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Mon, 9 Apr 2018 16:34:08 -0700 Subject: [PATCH 1/4] Move (slow) integration tests to their own file --- webdev/test/e2e_test.dart | 74 ++++++++++++++++++++++++ webdev/test/integration_test.dart | 93 ++++--------------------------- webdev/test/test_utils.dart | 11 ++++ 3 files changed, 95 insertions(+), 83 deletions(-) create mode 100644 webdev/test/e2e_test.dart diff --git a/webdev/test/e2e_test.dart b/webdev/test/e2e_test.dart new file mode 100644 index 000000000..8f3d30b8e --- /dev/null +++ b/webdev/test/e2e_test.dart @@ -0,0 +1,74 @@ +// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file +// for details. 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:path/path.dart' as p; +import 'package:test/test.dart'; +import 'package:test_descriptor/test_descriptor.dart' as d; +import 'package:test_process/test_process.dart'; +import 'package:webdev/src/util.dart'; + +import 'test_utils.dart'; + +void main() { + group('should succeed with valid configuration', () { + for (var withDDC in [true, false]) { + test(withDDC ? 'DDC' : 'dart2js', () async { + var exampleDirectory = p.absolute(p.join(p.current, '..', 'example')); + var process = await TestProcess.start(pubPath, ['get'], + workingDirectory: exampleDirectory, + environment: _getPubEnvironment()); + + await process.shouldExit(0); + + await d.file('.packages', isNotEmpty).validate(exampleDirectory); + await d.file('pubspec.lock', isNotEmpty).validate(exampleDirectory); + + var args = ['build', '-o', 'web:${d.sandbox}']; + if (withDDC) { + args.add('--no-release'); + } + + process = await runWebDev(args, workingDirectory: exampleDirectory); + + var expectedItems = ['[INFO] Succeeded']; + if (!withDDC) { + expectedItems.add(anyOf( + contains('with 0 outputs'), contains('Running dart2js with'))); + } + + await checkProcessStdout(process, expectedItems); + await process.shouldExit(0); + + await d.file('main.dart.js', isNotEmpty).validate(); + + for (var ddcFile in ['main.dart.bootstrap.js', 'main.ddc.js']) { + if (withDDC) { + await d.file(ddcFile, isNotEmpty).validate(); + } else { + await d.nothing(ddcFile).validate(); + } + } + }, timeout: const Timeout(const Duration(minutes: 5))); + } + }); +} + +/// Returns an environment map that includes `PUB_ENVIRONMENT`. +/// +/// Maintains any existing values for this environment var. +/// Adds a new value that flags this is a bot/test and not human usage. +Map _getPubEnvironment() { + var pubEnvironmentKey = 'PUB_ENVIRONMENT'; + var pubEnvironment = Platform.environment[pubEnvironmentKey] ?? ''; + if (pubEnvironment.isNotEmpty) { + pubEnvironment = '$pubEnvironment;'; + } + pubEnvironment = '${pubEnvironment}bot.pkg.webdev.test'; + + var environment = {'PUB_ENVIRONMENT': pubEnvironment}; + + return environment; +} diff --git a/webdev/test/integration_test.dart b/webdev/test/integration_test.dart index 74abee1f8..7d80dc81d 100644 --- a/webdev/test/integration_test.dart +++ b/webdev/test/integration_test.dart @@ -3,13 +3,9 @@ // BSD-style license that can be found in the LICENSE file. import 'dart:async'; -import 'dart:io'; -import 'package:path/path.dart' as p; import 'package:test/test.dart'; import 'package:test_descriptor/test_descriptor.dart' as d; -import 'package:test_process/test_process.dart'; -import 'package:webdev/src/util.dart'; import 'test_utils.dart'; @@ -41,7 +37,7 @@ name: sample var process = await runWebDev(['build'], workingDirectory: d.sandbox); - await _checkProcessStdout(process, [ + await checkProcessStdout(process, [ r'''webdev could not run for this project. You must have a dependency on `build_runner` in `pubspec.yaml`.''' ]); @@ -62,7 +58,7 @@ name: sample var process = await runWebDev(['serve'], workingDirectory: d.sandbox); - await _checkProcessStdout(process, [ + await checkProcessStdout(process, [ r'''webdev could not run for this project. You must have a dependency on `build_web_compilers` in `pubspec.yaml`.''' ]); @@ -88,7 +84,7 @@ name: sample workingDirectory: d.sandbox); // Fails w/ an isolate exception instead - since this is a fake package - await _checkProcessStdout(process, [ + await checkProcessStdout(process, [ 'webdev failed with an unexpected exception.', // The isolate will fail - broken .packages file 'Unable to spawn isolate' @@ -112,7 +108,7 @@ name: sample var process = await runWebDev(['build'], workingDirectory: d.sandbox); // Fails w/ an isolate exception instead - since this is a fake package - await _checkProcessStdout(process, [ + await checkProcessStdout(process, [ 'webdev failed with an unexpected exception.', // The isolate will fail - broken .packages file 'Unable to spawn isolate' @@ -155,7 +151,7 @@ name: sample var process = await runWebDev(['serve'], workingDirectory: d.sandbox); - await _checkProcessStdout(process, [ + await checkProcessStdout(process, [ 'webdev could not run for this project.', // See https://github.com/dart-lang/linter/issues/965 // ignore: prefer_adjacent_string_concatenation @@ -171,7 +167,7 @@ name: sample test('no pubspec.yaml', () async { var process = await runWebDev(['build'], workingDirectory: d.sandbox); - await _checkProcessStdout(process, [ + await checkProcessStdout(process, [ 'webdev could not run for this project.', 'Could not find a file named "pubspec.yaml"' ]); @@ -185,7 +181,7 @@ name: sample var process = await runWebDev(['build'], workingDirectory: d.sandbox); - await _checkProcessStdout(process, [ + await checkProcessStdout(process, [ 'webdev could not run for this project.', 'No pubspec.lock file found, please run "pub get" first.' ]); @@ -201,7 +197,7 @@ name: sample var process = await runWebDev(['build'], workingDirectory: d.sandbox); - await _checkProcessStdout(process, [ + await checkProcessStdout(process, [ 'webdev could not run for this project.', 'No .packages file found, please run "pub get" first.' ]); @@ -219,7 +215,7 @@ name: sample var process = await runWebDev(['build'], workingDirectory: d.sandbox); - await _checkProcessStdout(process, [ + await checkProcessStdout(process, [ 'webdev failed with an unexpected exception.', // The isolate will fail - broken .packages file 'Unable to spawn isolate' @@ -243,7 +239,7 @@ dependencies: var process = await runWebDev(['build'], workingDirectory: d.sandbox); - await _checkProcessStdout(process, [ + await checkProcessStdout(process, [ 'webdev could not run for this project.', // See https://github.com/dart-lang/linter/issues/965 // ignore: prefer_adjacent_string_concatenation @@ -252,58 +248,6 @@ dependencies: ]); await process.shouldExit(78); }); - - group('should succeed with valid configuration', () { - for (var withDDC in [true, false]) { - test(withDDC ? 'DDC' : 'dart2js', () async { - var exampleDirectory = p.absolute(p.join(p.current, '..', 'example')); - var process = await TestProcess.start(pubPath, ['get'], - workingDirectory: exampleDirectory, - environment: _getPubEnvironment()); - - await process.shouldExit(0); - - await d.file('.packages', isNotEmpty).validate(exampleDirectory); - await d.file('pubspec.lock', isNotEmpty).validate(exampleDirectory); - - var args = ['build', '-o', 'web:${d.sandbox}']; - if (withDDC) { - args.add('--no-release'); - } - - process = await runWebDev(args, workingDirectory: exampleDirectory); - - var expectedItems = ['[INFO] Succeeded']; - if (!withDDC) { - expectedItems.add(anyOf( - contains('with 0 outputs'), contains('Running dart2js with'))); - } - - await _checkProcessStdout(process, expectedItems); - await process.shouldExit(0); - - await d.file('main.dart.js', isNotEmpty).validate(); - - for (var ddcFile in ['main.dart.bootstrap.js', 'main.ddc.js']) { - if (withDDC) { - await d.file(ddcFile, isNotEmpty).validate(); - } else { - await d.nothing(ddcFile).validate(); - } - } - }, timeout: const Timeout(const Duration(minutes: 5))); - } - }); -} - -Future _checkProcessStdout(TestProcess process, List items) async { - var output = await process.stdoutStream().join('\n'); - for (var item in items) { - if (item is! Matcher) { - item = contains(item); - } - expect(output, item); - } } const _supportedBuildRunnerVersion = '0.8.2'; @@ -343,20 +287,3 @@ packages: return buffer.toString(); } - -/// Returns an environment map that includes `PUB_ENVIRONMENT`. -/// -/// Maintains any existing values for this environment var. -/// Adds a new value that flags this is a bot/test and not human usage. -Map _getPubEnvironment() { - var pubEnvironmentKey = 'PUB_ENVIRONMENT'; - var pubEnvironment = Platform.environment[pubEnvironmentKey] ?? ''; - if (pubEnvironment.isNotEmpty) { - pubEnvironment = '$pubEnvironment;'; - } - pubEnvironment = '${pubEnvironment}bot.pkg.webdev.test'; - - var environment = {'PUB_ENVIRONMENT': pubEnvironment}; - - return environment; -} diff --git a/webdev/test/test_utils.dart b/webdev/test/test_utils.dart index eca36c09d..be1628f4f 100644 --- a/webdev/test/test_utils.dart +++ b/webdev/test/test_utils.dart @@ -5,6 +5,7 @@ import 'dart:async'; import 'package:path/path.dart' as p; +import 'package:test/test.dart'; import 'package:test_process/test_process.dart'; import 'package:webdev/src/util.dart'; @@ -16,3 +17,13 @@ Future runWebDev(List args, {String workingDirectory}) { return TestProcess.start(dartPath, fullArgs, workingDirectory: workingDirectory); } + +Future checkProcessStdout(TestProcess process, List items) async { + var output = await process.stdoutStream().join('\n'); + for (var item in items) { + if (item is! Matcher) { + item = contains(item); + } + expect(output, item); + } +} From 6d3064d63cbb8fe2d1b0522102294516284b8449 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Mon, 9 Apr 2018 16:35:43 -0700 Subject: [PATCH 2/4] Run tests in serial on travis Minimize chance of a timeout --- tool/travis.sh | 4 ++-- webdev/.mono_repo.yml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tool/travis.sh b/tool/travis.sh index a28953b9f..48da89830 100755 --- a/tool/travis.sh +++ b/tool/travis.sh @@ -31,8 +31,8 @@ while (( "$#" )); do ;; test) echo echo -e '\033[1mTASK: test\033[22m' - echo -e 'pub run test' - pub run test || EXIT_CODE=$? + echo -e 'pub run test -j 1' + pub run test -j 1 || EXIT_CODE=$? ;; *) echo -e "\033[31mNot expecting TASK '${TASK}'. Error!\033[0m" EXIT_CODE=1 diff --git a/webdev/.mono_repo.yml b/webdev/.mono_repo.yml index c44173cf8..6bf69b56b 100644 --- a/webdev/.mono_repo.yml +++ b/webdev/.mono_repo.yml @@ -7,4 +7,4 @@ stages: - dartfmt - dartanalyzer: --fatal-infos --fatal-warnings . - unit_test: - - test + - test: -j 1 From 0ce8ed77e1ed0f55d222e171382e00803cdab139 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Mon, 9 Apr 2018 16:36:35 -0700 Subject: [PATCH 3/4] Prepare to release v0.1.4 --- webdev/pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webdev/pubspec.yaml b/webdev/pubspec.yaml index 6a7220494..e9eac1d25 100644 --- a/webdev/pubspec.yaml +++ b/webdev/pubspec.yaml @@ -1,5 +1,5 @@ name: webdev -version: 0.1.4-dev +version: 0.1.4 author: Dart Team homepage: https://github.com/dart-lang/webdev description: >- From 4d2489d67da6dfc9b98ad099fabfa90f4a6310fa Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Mon, 9 Apr 2018 16:48:39 -0700 Subject: [PATCH 4/4] Extend timeout for e2e tests to 8 minutes --- webdev/test/e2e_test.dart | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/webdev/test/e2e_test.dart b/webdev/test/e2e_test.dart index 8f3d30b8e..3be61735e 100644 --- a/webdev/test/e2e_test.dart +++ b/webdev/test/e2e_test.dart @@ -2,6 +2,8 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. +@Timeout(const Duration(minutes: 8)) + import 'dart:io'; import 'package:path/path.dart' as p; @@ -51,7 +53,7 @@ void main() { await d.nothing(ddcFile).validate(); } } - }, timeout: const Timeout(const Duration(minutes: 5))); + }); } }); }