@@ -17,6 +17,16 @@ class _FakeContext extends Fake implements HookContext {
1717}
1818
1919void main () {
20+ late Directory tempDirectory;
21+
22+ setUp (() {
23+ tempDirectory = Directory .systemTemp.createTempSync ('test_optimizer' );
24+ });
25+
26+ tearDown (() {
27+ tempDirectory.deleteSync (recursive: true );
28+ });
29+
2030 group ('Pre gen hook' , () {
2131 late HookContext context;
2232
@@ -26,17 +36,15 @@ void main() {
2636
2737 group ('Completes' , () {
2838 test ('with test files list' , () async {
29- final packageRoot =
30- Directory .systemTemp.createTempSync ('test_optimizer' );
31- File (path.join (packageRoot.path, 'pubspec.yaml' )).createSync ();
39+ File (path.join (tempDirectory.path, 'pubspec.yaml' )).createSync ();
3240
33- final testDir = Directory (path.join (packageRoot .path, 'test' ))
41+ final testDir = Directory (path.join (tempDirectory .path, 'test' ))
3442 ..createSync ();
3543 File (path.join (testDir.path, 'test1_test.dart' )).createSync ();
3644 File (path.join (testDir.path, 'test2_test.dart' )).createSync ();
3745 File (path.join (testDir.path, 'no_test_here.dart' )).createSync ();
3846
39- context.vars['package-root' ] = packageRoot .absolute.path;
47+ context.vars['package-root' ] = tempDirectory .absolute.path;
4048
4149 await pre_gen.run (context);
4250
@@ -63,25 +71,23 @@ void main() {
6371 });
6472
6573 test ('with proper isFlutter identification' , () async {
66- final packageRoot =
67- Directory .systemTemp.createTempSync ('test_optimizer' );
68-
69- File (path.join (packageRoot.path, 'pubspec.yaml' ))
74+ File (path.join (tempDirectory.path, 'pubspec.yaml' ))
7075 ..createSync ()
7176 ..writeAsStringSync ('''
7277dependencies:
7378 flutter:
7479 sdk: flutter''' );
7580
76- Directory (path.join (packageRoot .path, 'test' )).createSync ();
81+ Directory (path.join (tempDirectory .path, 'test' )).createSync ();
7782
78- context.vars['package-root' ] = packageRoot .absolute.path;
83+ context.vars['package-root' ] = tempDirectory .absolute.path;
7984
8085 await pre_gen.run (context);
8186
8287 expect (context.vars['isFlutter' ], true );
8388 });
8489 });
90+
8591 group ('Fails' , () {
8692 setUp (() {
8793 pre_gen.exitFn = (code) {
@@ -94,13 +100,11 @@ dependencies:
94100 });
95101
96102 test ('when target test dir does not exist' , () async {
97- final packageRoot =
98- Directory .systemTemp.createTempSync ('test_optimizer' );
99- File (path.join (packageRoot.path, 'pubspec.yaml' )).createSync ();
103+ File (path.join (tempDirectory.path, 'pubspec.yaml' )).createSync ();
100104
101- final testDir = Directory (path.join (packageRoot .path, 'test' ));
105+ final testDir = Directory (path.join (tempDirectory .path, 'test' ));
102106
103- context.vars['package-root' ] = packageRoot .absolute.path;
107+ context.vars['package-root' ] = tempDirectory .absolute.path;
104108
105109 await expectLater (
106110 () => pre_gen.run (context),
@@ -122,16 +126,13 @@ dependencies:
122126 });
123127
124128 test ('when target dir does not contain a pubspec.yaml' , () async {
125- final packageRoot =
126- Directory .systemTemp.createTempSync ('test_optimizer' );
127-
128- final testDir = Directory (path.join (packageRoot.path, 'test' ))
129+ final testDir = Directory (path.join (tempDirectory.path, 'test' ))
129130 ..createSync ();
130131 File (path.join (testDir.path, 'test1_test.dart' )).createSync ();
131132 File (path.join (testDir.path, 'test2_test.dart' )).createSync ();
132133 File (path.join (testDir.path, 'no_test_here.dart' )).createSync ();
133134
134- context.vars['package-root' ] = packageRoot .absolute.path;
135+ context.vars['package-root' ] = tempDirectory .absolute.path;
135136
136137 await expectLater (
137138 () => pre_gen.run (context),
0 commit comments