Skip to content

Commit 284fa73

Browse files
committed
Merge master.
2 parents 4028f0d + 69426d3 commit 284fa73

File tree

151 files changed

+1492
-1736
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

151 files changed

+1492
-1736
lines changed

.github/workflows/dart.yml

Lines changed: 70 additions & 705 deletions
Large diffs are not rendered by default.

_tests/dart_test.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ presets:
55
browser:
66
platforms:
77
- chrome
8+
compilers:
9+
- dart2js
10+
- dart2wasm
811
paths:
912
- test/bootstrap
1013
- test/common

_tests/lib/compiler.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ Future<void> _testBuilder(
106106
inputIds,
107107
reader,
108108
writer,
109-
AnalyzerResolvers(),
109+
AnalyzerResolvers.custom(),
110110
logger: logger,
111111
),
112112
['non-nullable'],

_tests/lib/matchers.dart

Lines changed: 92 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
1-
import 'dart:html';
1+
import 'dart:js_interop';
22

33
import 'package:ngdart/angular.dart';
44
import 'package:test/test.dart';
5+
import 'package:web/web.dart';
56

67
/// Matches textual content of an element including children.
78
Matcher hasTextContent(String expected) => _HasTextContent(expected);
89

10+
/// Matches DOMTokenList.
11+
Matcher hasDomTokenList(List<String> expected) => _HasDomTokenList(expected);
12+
13+
/// Matches textual content of an element including children.
14+
Matcher hasInnerHtml(String expected) => _HasInnerHtml(expected);
15+
916
final throwsNoProviderError = throwsA(_isNoProviderError);
1017
final _isNoProviderError = const TypeMatcher<NoProviderError>();
1118

@@ -15,7 +22,8 @@ class _HasTextContent extends Matcher {
1522
const _HasTextContent(this.expectedText);
1623

1724
@override
18-
bool matches(Object? item, void _) => _elementText(item) == expectedText;
25+
bool matches(Object? item, void _) =>
26+
_elementText(item as JSAny?) == expectedText;
1927

2028
@override
2129
Description describe(Description description) =>
@@ -29,33 +37,100 @@ class _HasTextContent extends Matcher {
2937
void __,
3038
) {
3139
mismatchDescription.add('Text content of element: '
32-
'\'${_elementText(item)}\'');
40+
'\'${_elementText(item as JSAny?)}\'');
3341
return mismatchDescription;
3442
}
3543
}
3644

37-
String? _elementText(Object? n) {
38-
if (n is Iterable) {
39-
return n.map(_elementText).join('');
40-
} else if (n is Node) {
41-
if (n is Comment) {
45+
String? _elementText(JSAny? node) {
46+
if (node.isA<NodeList>()) {
47+
return <String?>[
48+
for (var i = 0; i < (node as NodeList).length; i++)
49+
_elementText(node.item(i))
50+
].join('');
51+
}
52+
53+
if (node.isA<Node>()) {
54+
if (node.isA<Comment>()) {
4255
return '';
4356
}
4457

45-
if (n is ContentElement) {
46-
return _elementText(n.getDistributedNodes());
58+
if (node.isA<Element>() && (node as Element).shadowRoot != null) {
59+
return _elementText(node.shadowRoot!.childNodes);
60+
}
61+
62+
if ((node as Node).childNodes.length != 0) {
63+
return _elementText(node.childNodes);
4764
}
4865

49-
if (n is Element && n.shadowRoot != null) {
50-
return _elementText(n.shadowRoot!.nodes);
66+
return node.textContent;
67+
}
68+
69+
return null;
70+
}
71+
72+
class _HasDomTokenList extends Matcher {
73+
final List<String?> expectedTokens;
74+
75+
const _HasDomTokenList(this.expectedTokens);
76+
77+
@override
78+
bool matches(Object? item, void _) {
79+
final tokens = item as DOMTokenList;
80+
81+
if (tokens.length != expectedTokens.length) {
82+
return false;
5183
}
5284

53-
if (n.nodes.isNotEmpty) {
54-
return _elementText(n.nodes);
85+
for (var i = 0; i < expectedTokens.length; i++) {
86+
if (tokens.item(i) != expectedTokens[i]) {
87+
return false;
88+
}
5589
}
5690

57-
return n.text;
58-
} else {
59-
return '$n';
91+
return true;
92+
}
93+
94+
@override
95+
Description describe(Description description) {
96+
return description.add(expectedTokens.join(','));
97+
}
98+
99+
@override
100+
Description describeMismatch(
101+
item,
102+
Description mismatchDescription,
103+
void _,
104+
void __,
105+
) {
106+
mismatchDescription.add('DOMTokenList: \'$item}\'');
107+
return mismatchDescription;
108+
}
109+
}
110+
111+
class _HasInnerHtml extends Matcher {
112+
final String expectedHtml;
113+
114+
const _HasInnerHtml(this.expectedHtml);
115+
116+
@override
117+
bool matches(Object? item, void _) {
118+
return ((item as Element).innerHTML as JSString).toDart == expectedHtml;
119+
}
120+
121+
@override
122+
Description describe(Description description) =>
123+
description.add(expectedHtml);
124+
125+
@override
126+
Description describeMismatch(
127+
item,
128+
Description mismatchDescription,
129+
void _,
130+
void __,
131+
) {
132+
mismatchDescription.add('Inner HTML of element: '
133+
'\'${_elementText(item as Element)}\'');
134+
return mismatchDescription;
60135
}
61136
}

_tests/mono_pkg.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
sdk:
22
- pubspec
3-
- dev
43
- stable
4+
# - dev
55

66
stages:
77
- build:
8-
- command: dart run build_runner build --fail-on-severe
8+
- command: dart run build_runner build --delete-conflicting-outputs --fail-on-severe
99
- unit_test:
1010
- command: dart test -P vm
11-
- command: dart run build_runner test --fail-on-severe -- -P browser
11+
- command: dart run build_runner test --delete-conflicting-outputs --fail-on-severe -- -P browser

_tests/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ dependencies:
1313
build_test: ^2.2.2
1414
collection: ^1.19.1
1515
glob: ^2.1.2
16-
js: ^0.7.1
1716
logging: ^1.3.0
1817
ngcompiler: ^3.0.0-dev.3
1918
ngdart: ^8.0.0-dev.4
2019
ngtest: ^5.0.0-dev.2
2120
source_gen: ^1.5.0
2221
test: ^1.25.9
22+
web: ^1.1.1
2323

2424
dev_dependencies:
2525
analyzer: ^6.5.0

_tests/test/bootstrap/run_app_test.dart

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
@JS()
2-
library angular.test.bootstrap.run_app_test;
3-
41
import 'dart:async';
5-
import 'dart:html';
2+
import 'dart:js_interop';
63

7-
import 'package:js/js.dart';
84
import 'package:ngdart/angular.dart';
95
import 'package:test/test.dart';
6+
import 'package:web/web.dart';
107

118
import 'run_app_test.template.dart' as ng;
129

@@ -27,9 +24,9 @@ void main() {
2724

2825
/// Verify that the DOM of the page represents the component.
2926
void verifyDomAndStyles({String innerText = 'Hello World!'}) {
30-
expect(rootDomContainer.text, innerText);
27+
expect(rootDomContainer.textContent, innerText);
3128
final h1 = rootDomContainer.querySelector('h1');
32-
expect(h1!.getComputedStyle().height, '100px');
29+
expect(window.getComputedStyle(h1!).height, '100px');
3330
}
3431

3532
/// Verify the `Testability` interface is working for this application.
@@ -38,21 +35,21 @@ void main() {
3835
void verifyTestability() {
3936
expect(component.injector.get(Testability), isNotNull);
4037
var jsTestability = getAngularTestability(
41-
rootDomContainer.children.first,
38+
rootDomContainer.children.item(0)!,
4239
);
43-
expect(getAllAngularTestabilities(), isNot(hasLength(0)));
40+
expect(getAllAngularTestabilities().length, isNot(equals(0)));
4441
expect(jsTestability.isStable(), isTrue, reason: 'Expected stability');
45-
jsTestability.whenStable(allowInterop(expectAsync0(() {
42+
jsTestability.whenStable(expectAsync0(() {
4643
Future(expectAsync0(() {
4744
verifyDomAndStyles(innerText: 'Hello Universe!');
4845
}));
49-
})));
46+
}).toJS);
5047
runInApp(() => HelloWorldComponent.doAsyncTaskAndThenRename('Universe'));
5148
}
5249

5350
setUp(() {
54-
rootDomContainer = DivElement()..id = 'test-root-dom';
55-
rootDomContainer.append(Element.tag('hello-world'));
51+
rootDomContainer = HTMLDivElement()..id = 'test-root-dom';
52+
rootDomContainer.append(document.createElement('hello-world'));
5653
document.body!.append(rootDomContainer);
5754
HelloWorldComponent.name = 'World';
5855
});
@@ -166,10 +163,9 @@ class StubExceptionHandler implements ExceptionHandler {
166163
external JsTestability getAngularTestability(Element e);
167164

168165
@JS()
169-
external List<JsTestability> getAllAngularTestabilities();
166+
external JSArray<JsTestability> getAllAngularTestabilities();
170167

171-
@JS()
172-
abstract class JsTestability {
168+
extension type JsTestability._(JSObject _) implements JSObject {
173169
external bool isStable();
174-
external void whenStable(void Function() fn);
170+
external void whenStable(JSFunction fn);
175171
}

_tests/test/common/directives/for_test.dart

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
library angular2.test.common.directives.for_test;
2-
31
import 'dart:async';
42

53
import 'package:_tests/matchers.dart';
@@ -298,7 +296,7 @@ void main() {
298296
await testFixture.update((component) {
299297
component.child!.items = ['a', 'b', 'c'];
300298
});
301-
expect(testFixture.text, hasTextContent('0: a;1: b;2: c;'));
299+
expect(testFixture.text, equals('0: a;1: b;2: c;'));
302300
});
303301

304302
test('should use a default template if a custom one is null', () async {
@@ -308,7 +306,7 @@ void main() {
308306
await testFixture.update((NgForCustomTemplateNullTest component) {
309307
component.child!.items = ['a', 'b', 'c'];
310308
});
311-
expect(testFixture.text, hasTextContent('0: a;1: b;2: c;'));
309+
expect(testFixture.text, equals('0: a;1: b;2: c;'));
312310
});
313311

314312
test(
@@ -320,7 +318,7 @@ void main() {
320318
await testFixture.update((NgForCustomTemplatePrecedenceTest component) {
321319
component.child!.items = ['a', 'b', 'c'];
322320
});
323-
expect(testFixture.text, hasTextContent('0: a;1: b;2: c;'));
321+
expect(testFixture.text, equals('0: a;1: b;2: c;'));
324322
});
325323

326324
group('track by', () {
@@ -380,8 +378,8 @@ void main() {
380378
];
381379
});
382380
var endElements = testFixture.rootElement.querySelectorAll('p');
383-
expect(startElements[0], endElements[1]);
384-
expect(startElements[1], endElements[0]);
381+
expect(startElements.item(0), endElements.item(1));
382+
expect(startElements.item(1), endElements.item(0));
385383
});
386384

387385
test(

_tests/test/common/directives/if_test.dart

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import 'dart:js_interop';
2+
13
import 'package:ngdart/angular.dart';
24
import 'package:ngdart/src/runtime/check_binding.dart';
35
import 'package:ngtest/angular_test.dart';
@@ -15,7 +17,7 @@ void main() {
1517
var testFixture = await testBed.create();
1618
var element = testFixture.rootElement;
1719
expect(element.querySelectorAll('copy-me'), hasLength(1));
18-
expect(element.innerHtml, contains('hello2'));
20+
expect(element.innerHTML, contains('hello2'));
1921
});
2022

2123
test('should toggle node when condition changes', () async {
@@ -50,31 +52,31 @@ void main() {
5052
component.booleanCondition = false;
5153
});
5254
expect(element.querySelectorAll('copy-me'), hasLength(0));
53-
expect(element.innerHtml!.contains('hello'), false);
55+
expect((element.innerHTML as JSString).toDart.contains('hello'), isFalse);
5456

5557
await testFixture.update((NgIfNestedTestComponent component) {
5658
component.booleanCondition = true;
5759
});
5860
expect(element.querySelectorAll('copy-me'), hasLength(1));
59-
expect(element.innerHtml!.contains('hello'), true);
61+
expect((element.innerHTML as JSString).toDart.contains('hello'), isTrue);
6062

6163
await testFixture.update((NgIfNestedTestComponent component) {
6264
component.nestedBooleanCondition = false;
6365
});
6466
expect(element.querySelectorAll('copy-me'), hasLength(0));
65-
expect(element.innerHtml!.contains('hello'), false);
67+
expect((element.innerHTML as JSString).toDart.contains('hello'), isFalse);
6668

6769
await testFixture.update((NgIfNestedTestComponent component) {
6870
component.nestedBooleanCondition = true;
6971
});
7072
expect(element.querySelectorAll('copy-me'), hasLength(1));
71-
expect(element.innerHtml!.contains('hello'), true);
73+
expect((element.innerHTML as JSString).toDart.contains('hello'), isTrue);
7274

7375
await testFixture.update((NgIfNestedTestComponent component) {
7476
component.booleanCondition = false;
7577
});
7678
expect(element.querySelectorAll('copy-me'), hasLength(0));
77-
expect(element.innerHtml!.contains('hello'), false);
79+
expect((element.innerHTML as JSString).toDart.contains('hello'), isFalse);
7880
});
7981

8082
test('should update multiple bindings', () async {
@@ -84,20 +86,21 @@ void main() {
8486
var element = testFixture.rootElement;
8587
// Check startup.
8688
expect(element.querySelectorAll('copy-me'), hasLength(3));
87-
expect(element.text, 'helloNumberhelloStringhelloFunction');
89+
expect(
90+
element.textContent, equals('helloNumberhelloStringhelloFunction'));
8891

8992
await testFixture.update((NgIfMultiUpdateTestComponent component) {
9093
component.numberCondition = 0;
9194
});
9295
expect(element.querySelectorAll('copy-me'), hasLength(1));
93-
expect(element.text, 'helloString');
96+
expect(element.textContent, equals('helloString'));
9497

9598
await testFixture.update((NgIfMultiUpdateTestComponent component) {
9699
component.numberCondition = 1;
97100
component.stringCondition = 'bar';
98101
});
99102
expect(element.querySelectorAll('copy-me'), hasLength(1));
100-
expect(element.text, 'helloNumber');
103+
expect(element.textContent, equals('helloNumber'));
101104
await testFixture.update((NgIfMultiUpdateTestComponent component) {
102105
component.booleanCondition = false;
103106
});

0 commit comments

Comments
 (0)