Skip to content

Test cleanup, prepare for v0.1.4 #33

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions tool/travis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion webdev/.mono_repo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ stages:
- dartfmt
- dartanalyzer: --fatal-infos --fatal-warnings .
- unit_test:
- test
- test: -j 1
2 changes: 1 addition & 1 deletion webdev/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: webdev
version: 0.1.4-dev
version: 0.1.4
author: Dart Team <misc@dartlang.org>
homepage: https://github.com/dart-lang/webdev
description: >-
Expand Down
76 changes: 76 additions & 0 deletions webdev/test/e2e_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// 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.

@Timeout(const Duration(minutes: 8))

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 = <Object>['[INFO] Succeeded'];
if (!withDDC) {
expectedItems.add(anyOf(
contains('with 0 outputs'), contains('Running dart2js with')));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could the "with 0 outputs" case indicate a problem?

Also the "Running dart2js with" case could be broken for subsequent builds if I implement a change in build_web_compilers... it would be breaking there though so I guess we could update this test if that happens.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could the "with 0 outputs" case indicate a problem?

Maybe, although I validate dart2js output below. It's mostly for my dev machine where the output may already exist.

it would be breaking there though so I guess we could update this test if that happens.

Yup

}

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();
}
}
});
}
});
}

/// 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<String, String> _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;
}
93 changes: 10 additions & 83 deletions webdev/test/integration_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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`.'''
]);
Expand All @@ -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`.'''
]);
Expand All @@ -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'
Expand All @@ -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'
Expand Down Expand Up @@ -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
Expand All @@ -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"'
]);
Expand All @@ -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.'
]);
Expand All @@ -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.'
]);
Expand All @@ -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'
Expand All @@ -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
Expand All @@ -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 = <Object>['[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';
Expand Down Expand Up @@ -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<String, String> _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;
}
11 changes: 11 additions & 0 deletions webdev/test/test_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -16,3 +17,13 @@ Future<TestProcess> runWebDev(List<String> 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);
}
}