Skip to content

Commit a824ded

Browse files
committed
test: pre_gen
1 parent 5707a45 commit a824ded

1 file changed

Lines changed: 71 additions & 0 deletions

File tree

bricks/test_optimizer/hooks/test/pre_gen_test.dart

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,26 @@ class _FakeContext extends Fake implements HookContext {
1616
Map<String, Object?> vars = {};
1717
}
1818

19+
final notOptimizedTestContent =
20+
'''
21+
@Tags(['${pre_gen.skipVeryGoodOptimizationTag}'])
22+
void main() {
23+
test('test', () {
24+
expect(1, 1);
25+
});
26+
}
27+
''';
28+
29+
final anotherNotOptimizedTestContent =
30+
'''
31+
@Tags(['${pre_gen.skipVeryGoodOptimizationTag}', 'another_tag'])
32+
void main() {
33+
test('another test', () {
34+
expect(1, 1);
35+
});
36+
}
37+
''';
38+
1939
void main() {
2040
late Directory tempDirectory;
2141

@@ -86,6 +106,57 @@ dependencies:
86106

87107
expect(context.vars['isFlutter'], true);
88108
});
109+
110+
test('with proper not optimized tests identification', () async {
111+
File(path.join(tempDirectory.path, 'pubspec.yaml')).createSync();
112+
113+
final testDir = Directory(path.join(tempDirectory.path, 'test'))
114+
..createSync();
115+
File(path.join(testDir.path, 'test1_test.dart')).createSync();
116+
File(path.join(testDir.path, 'test2_test.dart')).createSync();
117+
File(path.join(testDir.path, 'no_test_here.dart')).createSync();
118+
File(
119+
path.join(testDir.path, 'not_optimized_test.dart'),
120+
).writeAsStringSync(notOptimizedTestContent);
121+
File(
122+
path.join(testDir.path, 'another_not_optimized_test.dart'),
123+
).writeAsStringSync(anotherNotOptimizedTestContent);
124+
125+
context.vars['package-root'] = tempDirectory.absolute.path;
126+
127+
await pre_gen.run(context);
128+
129+
final tests = context.vars['tests'] as List<Map<String, String>>;
130+
final testsMap = <String, String>{};
131+
for (final test in tests) {
132+
final path = test['path']!;
133+
final identifier = test['identifier']!;
134+
testsMap[path] = identifier;
135+
}
136+
137+
final paths = testsMap.keys;
138+
expect(paths, contains('test1_test.dart'));
139+
expect(paths, contains('test2_test.dart'));
140+
expect(paths, isNot(contains('no_test_here.dart')));
141+
expect(paths, isNot(contains('not_optimized_test.dart')));
142+
expect(paths, isNot(contains('another_not_optimized_test.dart')));
143+
144+
expect(
145+
testsMap.values.toSet().length,
146+
equals(tests.length),
147+
reason: 'All tests files should have unique identifiers',
148+
);
149+
final notOptimizedTests =
150+
context.vars['notOptimizedTests'] as List<String>;
151+
expect(
152+
notOptimizedTests,
153+
contains('not_optimized_test.dart'),
154+
);
155+
expect(
156+
notOptimizedTests,
157+
contains('another_not_optimized_test.dart'),
158+
);
159+
});
89160
});
90161

91162
group('Fails', () {

0 commit comments

Comments
 (0)