Skip to content

Commit 94e7461

Browse files
committed
Add tests to ensure all tests complete for Run All Tests
This fails because of #1673.
1 parent 2d26bd2 commit 94e7461

7 files changed

Lines changed: 95 additions & 27 deletions

File tree

‎test/dart_only/debug/dart_test.test.ts‎

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import { fsPath } from "../../../src/utils";
77
import { log, logInfo } from "../../../src/utils/log";
88
import { makeRegexForTest } from "../../../src/utils/test";
99
import { TestOutlineVisitor } from "../../../src/utils/vscode/outline";
10-
import { SuiteTreeItem, TestResultsProvider, TestStatus } from "../../../src/views/test_view";
10+
import { TestStatus } from "../../../src/views/test_view";
1111
import { DartDebugClient } from "../../dart_debug_client";
12-
import { activate, defer, delay, ext, extApi, getExpectedResults, getLaunchConfiguration, getPackages, helloWorldTestBrokenFile, helloWorldTestDupeNameFile, helloWorldTestMainFile, helloWorldTestSkipFile, helloWorldTestTreeFile, openFile, positionOf, withTimeout } from "../../helpers";
12+
import { activate, defer, delay, ext, extApi, getExpectedResults, getLaunchConfiguration, getPackages, helloWorldTestBrokenFile, helloWorldTestDupeNameFile, helloWorldTestMainFile, helloWorldTestSkipFile, helloWorldTestTreeFile, makeTextTree, openFile, positionOf, withTimeout } from "../../helpers";
1313

1414
describe("dart test debugger", () => {
1515
// We have tests that require external packages.
@@ -291,21 +291,3 @@ describe("dart test debugger", () => {
291291
]);
292292
}
293293
});
294-
function makeTextTree(suite: vs.Uri, provider: TestResultsProvider, parent?: vs.TreeItem, buffer: string[] = [], indent = 0) {
295-
const items = provider.getChildren(parent)
296-
// Filter to only the suite we were given (though includes all children).
297-
.filter((item) => (fsPath(item.resourceUri!) === fsPath(suite)) || !!parent);
298-
const wsPath = fsPath(vs.workspace.getWorkspaceFolder(suite)!.uri);
299-
items.forEach((item) => {
300-
// Suites don't have a .label (since the rendering is based on the resourceUri) so just
301-
// fabricate one here that can be compared in the test. Note: For simplity we always use
302-
// forward slashes in these names, since the comparison is against hard-coded comments
303-
// in the file that can only be on way.
304-
const expectedLabel = item instanceof SuiteTreeItem
305-
? path.relative(wsPath, fsPath(item.resourceUri!)).replace("\\", "/")
306-
: item.label;
307-
buffer.push(`${" ".repeat(indent * 4)}${expectedLabel} (${TestStatus[item.status]})`);
308-
makeTextTree(suite, provider, item, buffer, indent + 1);
309-
});
310-
return buffer;
311-
}

‎test/flutter_only/debug/flutter_test.test.ts‎

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { fsPath, versionIsAtLeast } from "../../../src/utils";
66
import { logInfo } from "../../../src/utils/log";
77
import { DartDebugClient } from "../../dart_debug_client";
88
import { killFlutterTester } from "../../debug_helpers";
9-
import { activate, defer, delay, ext, extApi, flutterHelloWorldFolder, flutterTestBrokenFile, flutterTestMainFile, flutterTestOtherFile, getLaunchConfiguration, getPackages, openFile, positionOf, withTimeout } from "../../helpers";
9+
import { activate, defer, delay, ext, extApi, flutterHelloWorldFolder, flutterTestAnotherFile, flutterTestBrokenFile, flutterTestMainFile, flutterTestOtherFile, getExpectedResults, getLaunchConfiguration, getPackages, makeTextTree, openFile, positionOf, withTimeout } from "../../helpers";
1010

1111
describe("flutter test debugger", () => {
1212

@@ -151,9 +151,26 @@ describe("flutter test debugger", () => {
151151
dc.launch(config),
152152
]);
153153

154+
const testFiles = [
155+
flutterTestMainFile,
156+
flutterTestOtherFile,
157+
flutterTestAnotherFile,
158+
flutterTestBrokenFile,
159+
];
160+
154161
const topLevelNodes = extApi.testTreeProvider.getChildren();
155162
assert.ok(topLevelNodes);
156-
assert.equal(topLevelNodes.length, 4);
163+
assert.equal(topLevelNodes.length, testFiles.length);
164+
165+
for (const file of testFiles) {
166+
await openFile(file);
167+
const expectedResults = getExpectedResults();
168+
const actualResults = makeTextTree(file, extApi.testTreeProvider).join("\n");
169+
170+
assert.ok(expectedResults);
171+
assert.ok(actualResults);
172+
assert.equal(actualResults, expectedResults);
173+
}
157174
});
158175

159176
it("stops at a breakpoint", async () => {

‎test/helpers.ts‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { tryDeleteFile } from "../src/utils/fs";
1515
import { log, logError, logTo, logWarn } from "../src/utils/log";
1616
import { waitFor } from "../src/utils/promises";
1717
import { PackageDep } from "../src/views/packages_view";
18+
import { SuiteTreeItem, TestResultsProvider, TestStatus } from "../src/views/test_view";
1819

1920
export const ext = vs.extensions.getExtension(dartCodeExtensionIdentifier)!;
2021
export let extApi: InternalExtensionApi;
@@ -81,6 +82,7 @@ export const flutterHelloWorldBrokenFile = vs.Uri.file(path.join(fsPath(flutterH
8182
// Flutter tests
8283
export const flutterTestMainFile = vs.Uri.file(path.join(fsPath(flutterHelloWorldFolder), "test/widget_test.dart"));
8384
export const flutterTestOtherFile = vs.Uri.file(path.join(fsPath(flutterHelloWorldFolder), "test/other_test.dart"));
85+
export const flutterTestAnotherFile = vs.Uri.file(path.join(fsPath(flutterHelloWorldFolder), "test/another_test.dart"));
8486
export const flutterTestBrokenFile = vs.Uri.file(path.join(fsPath(flutterHelloWorldFolder), "test/broken_test.dart"));
8587
// Flutter for Web
8688
export const flutterWebProjectContainerFolder = vs.Uri.file(path.join(ext.extensionPath, "test/test_projects/flutter_web"));
@@ -797,3 +799,22 @@ export function ensurePackageTreeNode<T extends PackageDep>(items: PackageDep[],
797799
export function renderedItemLabel(item: PackageDep): string {
798800
return item.label || path.basename(fsPath(item.resourceUri));
799801
}
802+
803+
export function makeTextTree(suite: vs.Uri, provider: TestResultsProvider, parent?: vs.TreeItem, buffer: string[] = [], indent = 0) {
804+
const items = provider.getChildren(parent)
805+
// Filter to only the suite we were given (though includes all children).
806+
.filter((item) => (fsPath(item.resourceUri!) === fsPath(suite)) || !!parent);
807+
const wsPath = fsPath(vs.workspace.getWorkspaceFolder(suite)!.uri);
808+
items.forEach((item) => {
809+
// Suites don't have a .label (since the rendering is based on the resourceUri) so just
810+
// fabricate one here that can be compared in the test. Note: For simplity we always use
811+
// forward slashes in these names, since the comparison is against hard-coded comments
812+
// in the file that can only be on way.
813+
const expectedLabel = item instanceof SuiteTreeItem
814+
? path.relative(wsPath, fsPath(item.resourceUri!)).replace("\\", "/")
815+
: item.label;
816+
buffer.push(`${" ".repeat(indent * 4)}${expectedLabel} (${TestStatus[item.status]})`);
817+
makeTextTree(suite, provider, item, buffer, indent + 1);
818+
});
819+
return buffer;
820+
}

‎test/test_projects/flutter_hello_world/test/another_test.dart‎

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,33 @@ import 'package:flutter_test/flutter_test.dart';
22

33
import '../lib/main.dart' as hello_world;
44

5+
// This comment is extracted by the test and compared to a text representation
6+
// built from the tree provider in the test. It must be maintained to match
7+
// the results from teh tests below.
8+
// == EXPECTED RESULTS ==
9+
// test/another_test.dart (Passed)
10+
// Another tests group (Passed)
11+
// Another test (Passed)
12+
// == /EXPECTED RESULTS ==
13+
514
void main() {
615
group('Another tests group', () {
7-
testWidgets('Another test', (WidgetTester tester) async {
8-
hello_world.main(); // BREAKPOINT1
9-
await tester.pump();
10-
expect(find.text('Hello, world!'), findsOneWidget);
11-
});
16+
testWidgets(
17+
'Another test',
18+
(WidgetTester tester) async {
19+
hello_world.main(); // BREAKPOINT1
20+
await tester.pump();
21+
22+
// This test runs slower than others to make sure that it doesn't get
23+
// terminated when the other tests finish during Run All Tests as was
24+
// the case when we enabled connecting the VM.
25+
// https://github.com/Dart-Code/Dart-Code/issues/1673
26+
27+
tester.binding.addTime(const Duration(seconds: 10));
28+
await tester.runAsync(() => Future.delayed(const Duration(seconds: 3)));
29+
expect(find.text('Hello, world!'), findsOneWidget);
30+
},
31+
timeout: Timeout(const Duration(seconds: 10)),
32+
);
1233
});
1334
}

‎test/test_projects/flutter_hello_world/test/broken_test.dart‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
import 'package:flutter_test/flutter_test.dart';
2+
23
import '../lib/main.dart' as hello_world;
34

5+
// This comment is extracted by the test and compared to a text representation
6+
// built from the tree provider in the test. It must be maintained to match
7+
// the results from teh tests below.
8+
// == EXPECTED RESULTS ==
9+
// test/broken_test.dart (Errored)
10+
// Hello world test (Errored)
11+
// == /EXPECTED RESULTS ==
12+
413
void main() {
514
testWidgets('Hello world test', (WidgetTester tester) async {
615
hello_world.main();

‎test/test_projects/flutter_hello_world/test/other_test.dart‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@ import 'package:flutter_test/flutter_test.dart';
22

33
import '../lib/main.dart' as hello_world;
44

5+
// This comment is extracted by the test and compared to a text representation
6+
// built from the tree provider in the test. It must be maintained to match
7+
// the results from teh tests below.
8+
// == EXPECTED RESULTS ==
9+
// test/other_test.dart (Passed)
10+
// Other tests group (Passed)
11+
// Other test (Passed)
12+
// == /EXPECTED RESULTS ==
13+
514
void main() {
615
group('Other tests group', () {
716
testWidgets('Other test', (WidgetTester tester) async {

‎test/test_projects/flutter_hello_world/test/widget_test.dart‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
import 'package:flutter_test/flutter_test.dart';
2+
23
import '../lib/main.dart' as hello_world;
34

5+
// This comment is extracted by the test and compared to a text representation
6+
// built from the tree provider in the test. It must be maintained to match
7+
// the results from teh tests below.
8+
// == EXPECTED RESULTS ==
9+
// test/widget_test.dart (Passed)
10+
// Hello world test (Passed)
11+
// == /EXPECTED RESULTS ==
12+
413
void main() {
514
testWidgets('Hello world test', (WidgetTester tester) async {
615
hello_world.main(); // BREAKPOINT1

0 commit comments

Comments
 (0)