Skip to content

Commit

Permalink
Split tests up into separate targets. (#133)
Browse files Browse the repository at this point in the history
- Use codegen to select between io and html test configs.
- Implement io test config.
- Mark test flaky.
  • Loading branch information
DrMarcII authored and staats-google committed Jan 11, 2017
1 parent 00bf9f1 commit e651776
Show file tree
Hide file tree
Showing 19 changed files with 151 additions and 200 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ addons:
- pkg-config

before_install:
- wget https://github.com/bazelbuild/bazel/releases/download/0.4.2/bazel_0.4.2-linux-x86_64.deb
- sudo dpkg -i bazel_0.4.2-linux-x86_64.deb
- wget https://github.com/bazelbuild/bazel/releases/download/0.4.3/bazel_0.4.3-linux-x86_64.deb
- sudo dpkg -i bazel_0.4.3-linux-x86_64.deb

script:
- bazel test --test_output=streamed --keep_going ...
10 changes: 9 additions & 1 deletion BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.

load("@io_bazel_rules_dart//dart/build_rules:core.bzl", "dart_library")
load("@io_bazel_rules_dart//dart/build_rules:vm.bzl", "dart_vm_test")
load("@io_bazel_rules_dart//dart/build_rules:vm.bzl", "dart_vm_binary", "dart_vm_test")

licenses(["notice"]) # Apache (Google-authored with external contributions)

Expand All @@ -22,6 +22,7 @@ exports_files(["LICENSE"])
dart_library(
name = "webdriver",
srcs = glob(["lib/**"]),
enable_ddc = False,
license_files = ["LICENSE"],
pub_pkg_name = "webdriver",
visibility = ["//visibility:public"],
Expand All @@ -34,5 +35,12 @@ dart_library(
],
)

dart_vm_binary(
name = "transform_tests",
srcs = ["bin/transform_tests.dart"],
script_file = "bin/transform_tests.dart",
visibility = ["//test:__subpackages__"],
)

# Test BUILD rules are defined test/BUILD instead of here to prevent cyclic
# dependency between this and rules_webtesting.
65 changes: 65 additions & 0 deletions bin/transform_tests.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Copyright 2017 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

library webdriver.transform_tests;

import 'dart:io';

void main(List<String> args) {
String inExtension;
String outExtension;
String outDirectory;
String srcsFile;

// Stupid simple arg parsing.
for (var arg in args.takeWhile((arg) => arg != '--')) {
if (arg.startsWith('--in-extension=')) {
inExtension = arg.split('=')[1];
} else if (arg.startsWith('--out-extension=')) {
outExtension = arg.split('=')[1];
} else if (arg.startsWith('--out=')) {
outDirectory = arg.split('=')[1];
} else if (arg.startsWith('--srcs-file=')) {
srcsFile = arg.split('=')[1];
}
}

print('Parsed --in-extension $inExtension');
print('Parsed --out-extension $outExtension');
print('Parsed --out $outDirectory');
print('Parsed --srcs-file $srcsFile');

String testUtilImport;
for (var arg in args.skipWhile((arg) => arg != '--')) {
if (arg.startsWith('--test_util_import=')) {
testUtilImport = arg.split('=')[1];
}
}

print('Parsed --test_util_import $testUtilImport');

var srcsList = new File(srcsFile).readAsLinesSync();
var year = new DateTime.now().year;
for (var srcFile in srcsList) {
if (!srcFile.endsWith(inExtension)) {
continue;
}
var outFile = '$outDirectory/$srcFile'
.replaceFirst(new RegExp('$inExtension\$'), outExtension);

var srcContents = new File(srcFile).readAsStringSync();
srcContents = srcContents.replaceFirst('test_util.dart', '$testUtilImport');
new File(outFile).writeAsString(srcContents);
}
}
59 changes: 36 additions & 23 deletions test/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,48 @@
# limitations under the License.

load("@io_bazel_rules_dart//dart/build_rules:vm.bzl", "dart_vm_test")
load("@io_bazel_rules_dart//dart/build_rules:code_gen.bzl", "dart_code_gen")
load("@io_bazel_rules_webtesting//web:dart.bzl", "dart_web_test_suite")

licenses(["notice"]) # Apache (Google-authored with external contributions)

dart_web_test_suite(
name = "io_test",
srcs = glob(
["**/*.dart"],
exclude = [
"**/html_*.dart",
"support/async_test.dart",
],
),
browsers = ["//browsers:chromium-native"],
data = glob(
["**"],
exclude = ["**/*.dart"],
),
local = True,
pub_pkg_name = "webdriver_test",
script_file = "io_test.dart",
deps = [
"//:webdriver",
"@org_dartlang_pub_matcher//:matcher",
"@org_dartlang_pub_path//:path",
"@org_dartlang_pub_test//:test",
],
# TODO(DrMarcII) Add support html webdriver tests when rules_dart support dart_web_test

dart_code_gen(
name = "generate_io_tests",
srcs = glob(["*_test.dart"]),
generator = "//:transform_tests",
generator_args = ["--test_util_import=io_test_util.dart"],
out_extensions = [".io.dart"],
)

[
dart_web_test_suite(
name = dart_file[:-5] + "_io",
srcs = [
dart_file[:-5] + ".io.dart",
"io_test_util.dart",
"test_util.dart",
],
browsers = ["//browsers:chromium-native"],
data = [
"frame.html",
"test_page.html",
],
flaky = True,
local = True,
pub_pkg_name = "webdriver_test",
script_file = dart_file[:-5] + ".io.dart",
deps = [
"//:webdriver",
"@org_dartlang_pub_matcher//:matcher",
"@org_dartlang_pub_path//:path",
"@org_dartlang_pub_test//:test",
],
)
for dart_file in glob(["*_test.dart"])
]

dart_vm_test(
name = "async_test",
srcs = ["support/async_test.dart"],
Expand Down
4 changes: 2 additions & 2 deletions test/src/alert.dart → test/alert_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ library webdriver.alert_test;
import 'package:test/test.dart';
import 'package:webdriver/core.dart';

import '../test_util.dart';
import 'test_util.dart';

void runTests() {
void main() {
group('Alert', () {
WebDriver driver;
WebElement button;
Expand Down
4 changes: 2 additions & 2 deletions test/src/command_event.dart → test/command_event_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ import 'package:test/test.dart';
import 'package:webdriver/core.dart';
import 'package:webdriver/support/async.dart';

import '../test_util.dart';
import 'test_util.dart';

void runTests() {
void main() {
group('CommandEvent', () {
WebDriver driver;

Expand Down
85 changes: 0 additions & 85 deletions test/html_test.dart

This file was deleted.

50 changes: 0 additions & 50 deletions test/io_test.dart

This file was deleted.

21 changes: 11 additions & 10 deletions test/io_config.dart → test/io_test_util.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015 Google Inc. All Rights Reserved.
// Copyright 2017 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -12,25 +12,26 @@
// See the License for the specific language governing permissions and
// limitations under the License.

library webdriver.io_test;
library io_test_util;

import 'dart:io' show FileSystemEntity, Platform;

import 'package:path/path.dart' as path;
import 'package:webdriver/io.dart' show Capabilities, createDriver;
import 'package:webdriver/core.dart' show WebDriver;
import 'package:webdriver/io.dart' as wdio;

import 'test_util.dart' as test_util;
export 'test_util.dart' show isWebElement, isRectangle, isPoint;

void config() {
test_util.runningOnTravis = Platform.environment['TRAVIS'] == 'true';
test_util.createTestDriver = ({Map<String, dynamic> additionalCapabilities}) {
Future<WebDriver> createTestDriver({Map<String, dynamic> additionalCapabilities}) {
var address = Platform.environment['WEB_TEST_WEBDRIVER_SERVER'];
if (!address.endsWith('/')) {
address += '/';
}
var uri = Uri.parse(address);
return createDriver(uri: uri, desired: additionalCapabilities);
};
return wdio.createDriver(uri: uri, desired: additionalCapabilities);
}

String get testPagePath {
var testSrcDir = Platform.environment['TEST_SRCDIR'];
String testPagePath;
if (testSrcDir != null) {
Expand All @@ -43,5 +44,5 @@ void config() {
throw new Exception('Could not find the test file at "$testPagePath".'
' Make sure you are running tests from the root of the project.');
}
test_util.testPagePath = path.toUri(testPagePath).toString();
return path.toUri(testPagePath).toString();
}
Loading

0 comments on commit e651776

Please sign in to comment.