Skip to content

Commit

Permalink
Migrate html tests off of unittest.dart
Browse files Browse the repository at this point in the history
Changed tests either use expect/minitest or async_helper/async_minitest
as a replacement. There are still a few outstanding tests that need to
be migrated off of unittest.dart.

Change-Id: I9231d453f61507110b5a89360dfb9e5647a5b4c7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/135420
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Reviewed-by: Bob Nystrom <rnystrom@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
  • Loading branch information
srujzs authored and commit-bot@chromium.org committed Feb 15, 2020
1 parent 361f881 commit 6ae9ded
Show file tree
Hide file tree
Showing 38 changed files with 56 additions and 137 deletions.
2 changes: 1 addition & 1 deletion tests/lib_2/html/async_cancellingisolate.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
library async_cancellingisolate;

import 'dart:async';
import 'package:unittest/unittest.dart';
import 'package:expect/minitest.dart';

main(message, replyTo) {
var command = message.first;
Expand Down
2 changes: 1 addition & 1 deletion tests/lib_2/html/async_oneshot.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'dart:async';
import 'package:unittest/unittest.dart';
import 'package:expect/minitest.dart';

main(message, replyTo) {
var command = message.first;
Expand Down
2 changes: 1 addition & 1 deletion tests/lib_2/html/async_periodictimer.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
library async_periodictimer;

import 'dart:async';
import 'package:unittest/unittest.dart';
import 'package:expect/minitest.dart';

main(message, replyTo) {
var command = message.first;
Expand Down
5 changes: 1 addition & 4 deletions tests/lib_2/html/async_test.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
library async_test;

import 'package:unittest/unittest.dart';
import 'package:unittest/html_config.dart';
import 'package:async_helper/async_minitest.dart';

import 'dart:async';
import 'dart:isolate';
Expand All @@ -17,8 +16,6 @@ periodicTimerIsolate(message) =>
cancellingIsolate(message) => cancelling_test.main(message.first, message.last);

main() {
useHtmlConfiguration();

test('one shot timer in pure isolate', () {
var response = new ReceivePort();
var remote = Isolate.spawn(oneshot, [
Expand Down
4 changes: 1 addition & 3 deletions tests/lib_2/html/callback_list_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ library callback_list_test;
import 'dart:html';
import 'dart:async';

import 'package:unittest/unittest.dart';
import 'package:unittest/html_config.dart';
import 'package:expect/minitest.dart';

var callbackDone = false;
bool isCallbackDone() => callbackDone;
Expand All @@ -24,7 +23,6 @@ Future waitUntilCallbackDone(bool test()) async {
}

void main() async {
useHtmlConfiguration();
window.navigator.persistentStorage.requestQuota(1024 * 1024, _quotaHandler);

await waitUntilCallbackDone(isCallbackDone);
Expand Down
4 changes: 2 additions & 2 deletions tests/lib_2/html/canvas_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ library CanvasTest;

import 'dart:html';

import 'package:unittest/unittest.dart';
import 'package:async_helper/async_minitest.dart';

main() {
CanvasElement canvas;
Expand All @@ -19,7 +19,7 @@ main() {
ImageData image = context.createImageData(canvas.width, canvas.height);
List<int> data = image.data;

expect(data, hasLength(40000));
expect(data.length, 40000);
checkPixel(data, 0, [0, 0, 0, 0]);
checkPixel(data, width * height - 1, [0, 0, 0, 0]);

Expand Down
2 changes: 1 addition & 1 deletion tests/lib_2/html/css_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ library CssTest;

import 'dart:html';

import 'package:unittest/unittest.dart';
import 'package:expect/minitest.dart';

main() {
group('supportsPointConversions', () {
Expand Down
16 changes: 8 additions & 8 deletions tests/lib_2/html/cssstyledeclaration_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ library CssStyleDeclarationTest;
import 'dart:async';
import 'dart:html';

import 'package:unittest/unittest.dart';
import 'package:async_helper/async_minitest.dart';

import 'utils.dart';

Expand All @@ -23,23 +23,23 @@ main() {

test('default constructor is empty', () {
var style = new CssStyleDeclaration();
expect(style.cssText, isEmpty);
expect(style.getPropertyPriority('color'), isEmpty);
expect(style.item(0), isEmpty);
expect(style, hasLength(0));
expect(style.cssText.isEmpty, isTrue);
expect(style.getPropertyPriority('color').isEmpty, isTrue);
expect(style.item(0).isEmpty, isTrue);
expect(style.length, 0);
// These assertions throw a UnimplementedError in dartium:
// expect(style.parentRule, isNull);
// expect(style.getPropertyCssValue('color'), isNull);
// expect(style.getPropertyShorthand('color'), isNull);
});

test('length is wrapped', () {
expect(createTestStyle(), hasLength(2));
expect(createTestStyle().length, 2);
});

test('getPropertyPriority is wrapped', () {
var style = createTestStyle();
expect(style.getPropertyPriority("color"), isEmpty);
expect(style.getPropertyPriority("color").isEmpty, isTrue);
expect(style.getPropertyPriority("width"), equals("important"));
});

Expand Down Expand Up @@ -94,7 +94,7 @@ main() {
new Timer(const Duration(milliseconds: 10), expectAsync(() {
element.style.textDecoration = 'underline';
var style = element.getComputedStyle();
expect(style.textDecoration, contains('underline'));
expect(style.textDecoration.contains('underline'), isTrue);
}));
});

Expand Down
5 changes: 1 addition & 4 deletions tests/lib_2/html/event_customevent_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

library EventCustomEventTest;

import 'package:unittest/unittest.dart';
import 'package:unittest/html_config.dart';
import 'package:async_helper/async_minitest.dart';
import 'dart:html';
import 'dart:js' as js;

Expand All @@ -16,8 +15,6 @@ class DartPayloadData {
}

main() {
useHtmlConfiguration();

test('custom events', () {
var provider = new EventStreamProvider<CustomEvent>('foo');
var el = new DivElement();
Expand Down
3 changes: 0 additions & 3 deletions tests/lib_2/html/events_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ library tests.html.events_test;
import 'dart:async';
import 'dart:html';
import 'package:unittest/unittest.dart';
import 'package:unittest/html_config.dart';
import 'package:unittest/src/expected_function.dart' show ExpectedFunction;

T Function() expectAsync0<T>(T Function() callback,
Expand All @@ -19,8 +18,6 @@ T Function(A) expectAsync1<T, A>(T Function(A) callback,
new ExpectedFunction<T>(callback, count, max).max1;

main() {
useHtmlConfiguration();

test('TimeStamp', () {
var event = new Event('test');

Expand Down
5 changes: 1 addition & 4 deletions tests/lib_2/html/file_sample_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ library file_sample;
import 'dart:async';
import 'dart:html';

import 'package:unittest/unittest.dart';
import 'package:unittest/html_config.dart';
import 'package:async_helper/async_helper.dart';
import 'package:unittest/unittest.dart';

// Expected output from all functions, asynchronous, and event routines.
const String log_results = 'test-first\n' +
Expand Down Expand Up @@ -101,8 +100,6 @@ Future<List<Entry>> readEntries(DirectoryEntry directory) async {
}

main() {
useHtmlConfiguration();

group('test FileSystem', () {
test('FileSystem request #1', () async {
testLog.log('test-first');
Expand Down
5 changes: 1 addition & 4 deletions tests/lib_2/html/fileapi_directory_reader_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ library fileapi;
import 'dart:async';
import 'dart:html';

import 'package:unittest/unittest.dart';
import 'package:unittest/html_config.dart';
import 'package:async_helper/async_helper.dart';
import 'package:async_helper/async_minitest.dart';

class FileAndDir {
FileEntry file;
Expand All @@ -16,8 +15,6 @@ class FileAndDir {
FileSystem fs;

main() async {
useHtmlConfiguration();

getFileSystem() async {
var fileSystem = await window.requestFileSystem(100);
fs = fileSystem;
Expand Down
6 changes: 1 addition & 5 deletions tests/lib_2/html/fileapi_directory_test.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
library fileapi;


import 'dart:async';
import 'dart:html';

import 'package:unittest/unittest.dart';
import 'package:unittest/html_config.dart';
import 'package:async_helper/async_helper.dart';
import 'package:async_helper/async_minitest.dart';

class FileAndDir {
FileEntry file;
Expand All @@ -17,8 +15,6 @@ class FileAndDir {
FileSystem fs;

main() async {
useHtmlConfiguration();

getFileSystem() async {
var fileSystem = await window.requestFileSystem(100);
fs = fileSystem;
Expand Down
5 changes: 1 addition & 4 deletions tests/lib_2/html/fileapi_entry_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ library fileapi;
import 'dart:async';
import 'dart:html';

import 'package:unittest/unittest.dart';
import 'package:unittest/html_config.dart';
import 'package:async_helper/async_helper.dart';
import 'package:expect/minitest.dart';

class FileAndDir {
FileEntry file;
Expand All @@ -16,8 +15,6 @@ class FileAndDir {
FileSystem fs;

main() async {
useHtmlConfiguration();

getFileSystem() async {
return await window.requestFileSystem(100).then((FileSystem fileSystem) {
fs = fileSystem;
Expand Down
11 changes: 5 additions & 6 deletions tests/lib_2/html/fileapi_file_entry_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ library fileapi;
import 'dart:async';
import 'dart:html';

import 'package:unittest/unittest.dart';
import 'package:unittest/html_config.dart';
import 'package:async_helper/async_helper.dart';
import 'package:async_helper/async_minitest.dart';

class FileAndDir {
FileEntry file;
Expand All @@ -16,8 +15,6 @@ class FileAndDir {
FileSystem fs;

main() async {
useHtmlConfiguration();

getFileSystem() async {
var fileSystem = await window.requestFileSystem(100);
fs = fileSystem;
Expand Down Expand Up @@ -47,8 +44,10 @@ main() async {
var fileObj = await fileAndDir.file.file();
expect(fileObj.name, fileAndDir.file.name);
expect(fileObj.relativePath, '');
expect(new DateTime.now().difference(fileObj.lastModifiedDate).inMinutes,
lessThan(30));
expect(
new DateTime.now().difference(fileObj.lastModifiedDate).inMinutes <
30,
isTrue);
});
}
}
Expand Down
7 changes: 2 additions & 5 deletions tests/lib_2/html/fileapi_file_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ library fileapi;
import 'dart:async';
import 'dart:html';

import 'package:unittest/unittest.dart';
import 'package:unittest/html_config.dart';
import 'package:async_helper/async_helper.dart';
import 'package:async_helper/async_minitest.dart';

class FileAndDir {
FileEntry file;
Expand All @@ -16,8 +15,6 @@ class FileAndDir {
FileSystem fs;

main() async {
useHtmlConfiguration();

getFileSystem() async {
var fileSystem = await window.requestFileSystem(100);
fs = fileSystem;
Expand Down Expand Up @@ -45,7 +42,7 @@ main() async {
var changeTime = metadata.modificationTime;

// Increased Windows buildbots can sometimes be particularly slow.
expect(new DateTime.now().difference(changeTime).inMinutes, lessThan(4));
expect(new DateTime.now().difference(changeTime).inMinutes < 4, isTrue);
expect(metadata.size, equals(0));
});
}
Expand Down
10 changes: 4 additions & 6 deletions tests/lib_2/html/fileapi_supported_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ library fileapi;
import 'dart:async';
import 'dart:html';

import 'package:unittest/unittest.dart';
import 'package:unittest/html_config.dart';
import 'package:async_helper/async_helper.dart';
import 'package:async_helper/async_minitest.dart';
import 'package:expect/minitest.dart' as minitest;


Future<FileSystem> _fileSystem;
Expand All @@ -25,15 +25,13 @@ Future<FileSystem> get fileSystem async {
}

main() {
useHtmlConfiguration();

test('supported', () {
expect(FileSystem.supported, true);
});

test('requestFileSystem', () async {
var expectation = FileSystem.supported ? returnsNormally : throws;
expect(() async {
var expectation = FileSystem.supported ? minitest.returnsNormally : throws;
minitest.expect(() async {
var fs = await fileSystem;
expect(fs.root != null, true);
}, expectation);
Expand Down
10 changes: 4 additions & 6 deletions tests/lib_2/html/fileapi_supported_throws_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@ library fileapi;
import 'dart:async';
import 'dart:html';

import 'package:unittest/unittest.dart';
import 'package:unittest/html_config.dart';
import 'package:async_helper/async_helper.dart';
import 'package:async_helper/async_minitest.dart';
import 'package:expect/minitest.dart' as minitest;

main() {
useHtmlConfiguration();

test('requestFileSystem', () async {
var expectation = FileSystem.supported ? returnsNormally : throws;
expect(() async {
var expectation = FileSystem.supported ? minitest.returnsNormally : throws;
minitest.expect(() async {
await window.requestFileSystem(100);
}, expectation);
});
Expand Down
7 changes: 2 additions & 5 deletions tests/lib_2/html/filereader_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,11 @@

library filereader_test;

import 'package:unittest/unittest.dart';
import 'package:unittest/html_config.dart';
import 'package:async_helper/async_minitest.dart';
import 'dart:html';
import 'dart:typed_data';

main() {
useHtmlConfiguration();

test('readAsText', () {
var reader = new FileReader();
reader.onLoad.listen(expectAsync((event) {
Expand All @@ -26,7 +23,7 @@ main() {
reader.onLoad.listen(expectAsync((event) {
var result = reader.result;
expect(result is Uint8List, isTrue);
expect(result, orderedEquals([65, 66, 67]));
expect(result, equals([65, 66, 67]));
}));
reader.readAsArrayBuffer(new Blob(['ABC']));
});
Expand Down
Loading

0 comments on commit 6ae9ded

Please sign in to comment.