From db06a528eb43c11cb3df8cd1e74c5e4bc1a34362 Mon Sep 17 00:00:00 2001 From: Felix Angelov Date: Thu, 21 Sep 2023 23:28:01 -0500 Subject: [PATCH] chore(mason): upgrade to mason_logger ^0.2.9 (#1078) --- packages/mason/pubspec.yaml | 2 +- packages/mason/test/src/hooks_test.dart | 913 ++++++++++++------------ 2 files changed, 461 insertions(+), 454 deletions(-) diff --git a/packages/mason/pubspec.yaml b/packages/mason/pubspec.yaml index 6ff1e11b9..276ab61ac 100644 --- a/packages/mason/pubspec.yaml +++ b/packages/mason/pubspec.yaml @@ -18,7 +18,7 @@ dependencies: crypto: ^3.0.1 http: '>=0.13.3 <2.0.0' json_annotation: ^4.8.1 - mason_logger: ^0.2.7 + mason_logger: ^0.2.9 meta: ^1.7.0 mustache_template: ^2.0.0 path: ^1.8.0 diff --git a/packages/mason/test/src/hooks_test.dart b/packages/mason/test/src/hooks_test.dart index a23b0cbd4..cfcb33d10 100644 --- a/packages/mason/test/src/hooks_test.dart +++ b/packages/mason/test/src/hooks_test.dart @@ -11,474 +11,481 @@ class _MockLogger extends Mock implements Logger {} class _MockProgress extends Mock implements Progress {} void main() { - group('Hooks', () { - test('supports non-ascii characters', () async { - final brick = Brick.path( - path.join('test', 'fixtures', 'unicode_hook'), - ); - final generator = await MasonGenerator.fromBrick(brick); - - expect(generator.hooks.preGen(), completes); - }); - - test( - 'throws HookDependencyInstallFailure ' - 'when pubspec is malformed', () async { - final brick = Brick.path( - path.join('test', 'fixtures', 'malformed_pubspec'), - ); - final generator = await MasonGenerator.fromBrick(brick); - - try { - await generator.hooks.preGen(); - fail('should throw'); - } catch (error) { - expect(error, isA()); - } - }); - - test( - 'throws HookCompileException ' - 'when unable to resolve a type', () async { - final brick = Brick.path( - path.join('test', 'fixtures', 'compile_exception'), - ); - final generator = await MasonGenerator.fromBrick(brick); - - try { - await generator.hooks.preGen(); - fail('should throw'); - } catch (error) { - expect(error, isA()); - } - }); - - test( - 'throws HookCompileException ' - 'when unable to resolve a type (back-to-back)', () async { - final brick = Brick.path( - path.join('test', 'fixtures', 'compile_exception'), - ); - final generator = await MasonGenerator.fromBrick(brick); - - try { - await generator.hooks.preGen(); - fail('should throw'); - } catch (error) { - expect(error, isA()); - } - - try { - await generator.hooks.preGen(); - fail('should throw'); - } catch (error) { - expect(error, isA()); - } - }); - - test( - 'throws HookMissingRunException ' - 'when hook does not contain a valid run method', () async { - final brick = Brick.path( - path.join('test', 'fixtures', 'missing_run'), - ); - final generator = await MasonGenerator.fromBrick(brick); - - try { - await generator.hooks.preGen(); - fail('should throw'); - } catch (error) { - expect(error, isA()); - } - }); - - test('throws HookCompileException when hook cannot be run', () async { - final brick = Brick.path( - path.join('test', 'fixtures', 'run_exception'), - ); - final generator = await MasonGenerator.fromBrick(brick); - - try { - await generator.hooks.preGen(); - fail('should throw'); - } catch (error) { - expect(error, isA()); - } - }); - - test('throws HookExecutionException on IsolateSpawnException', () async { - final hookDirectoryPath = path.join('test', 'fixtures', 'basic', 'hooks'); - final files = [ - File( - canonicalize( - path.join( - hookDirectoryPath, - 'pre_gen.dart', + group( + 'Hooks', + () { + test('supports non-ascii characters', () async { + final brick = Brick.path( + path.join('test', 'fixtures', 'unicode_hook'), + ); + final generator = await MasonGenerator.fromBrick(brick); + + expect(generator.hooks.preGen(), completes); + }); + + test( + 'throws HookDependencyInstallFailure ' + 'when pubspec is malformed', () async { + final brick = Brick.path( + path.join('test', 'fixtures', 'malformed_pubspec'), + ); + final generator = await MasonGenerator.fromBrick(brick); + + try { + await generator.hooks.preGen(); + fail('should throw'); + } catch (error) { + expect(error, isA()); + } + }); + + test( + 'throws HookCompileException ' + 'when unable to resolve a type', () async { + final brick = Brick.path( + path.join('test', 'fixtures', 'compile_exception'), + ); + final generator = await MasonGenerator.fromBrick(brick); + + try { + await generator.hooks.preGen(); + fail('should throw'); + } catch (error) { + expect(error, isA()); + } + }); + + test( + 'throws HookCompileException ' + 'when unable to resolve a type (back-to-back)', () async { + final brick = Brick.path( + path.join('test', 'fixtures', 'compile_exception'), + ); + final generator = await MasonGenerator.fromBrick(brick); + + try { + await generator.hooks.preGen(); + fail('should throw'); + } catch (error) { + expect(error, isA()); + } + + try { + await generator.hooks.preGen(); + fail('should throw'); + } catch (error) { + expect(error, isA()); + } + }); + + test( + 'throws HookMissingRunException ' + 'when hook does not contain a valid run method', () async { + final brick = Brick.path( + path.join('test', 'fixtures', 'missing_run'), + ); + final generator = await MasonGenerator.fromBrick(brick); + + try { + await generator.hooks.preGen(); + fail('should throw'); + } catch (error) { + expect(error, isA()); + } + }); + + test('throws HookCompileException when hook cannot be run', () async { + final brick = Brick.path( + path.join('test', 'fixtures', 'run_exception'), + ); + final generator = await MasonGenerator.fromBrick(brick); + + try { + await generator.hooks.preGen(); + fail('should throw'); + } catch (error) { + expect(error, isA()); + } + }); + + test('throws HookExecutionException on IsolateSpawnException', () async { + final hookDirectoryPath = + path.join('test', 'fixtures', 'basic', 'hooks'); + final files = [ + File( + canonicalize( + path.join( + hookDirectoryPath, + 'pre_gen.dart', + ), ), ), - ), - File( - canonicalize( - path.join( - hookDirectoryPath, - 'build', - 'hooks', - 'pre_gen', - 'pre_gen_4eda2b9684fa8a724e89999f292f9f40e1a444cc.dart', + File( + canonicalize( + path.join( + hookDirectoryPath, + 'build', + 'hooks', + 'pre_gen', + 'pre_gen_4eda2b9684fa8a724e89999f292f9f40e1a444cc.dart', + ), ), ), - ), - File( - canonicalize( - path.join( - hookDirectoryPath, - 'build', - 'hooks', - 'pre_gen', - 'pre_gen_504cde6a6747442973ca41234b44dd7d38d3778f.dart', + File( + canonicalize( + path.join( + hookDirectoryPath, + 'build', + 'hooks', + 'pre_gen', + 'pre_gen_504cde6a6747442973ca41234b44dd7d38d3778f.dart', + ), ), ), - ), - File( - canonicalize( - path.join( - hookDirectoryPath, - 'build', - 'hooks', - 'pre_gen', - 'pre_gen_c648b1ccbe45ae1e0894b8a25df9c108bc2e919a.dart', + File( + canonicalize( + path.join( + hookDirectoryPath, + 'build', + 'hooks', + 'pre_gen', + 'pre_gen_c648b1ccbe45ae1e0894b8a25df9c108bc2e919a.dart', + ), ), ), - ), - File( - canonicalize( - path.join( - hookDirectoryPath, - 'build', - 'hooks', - 'pre_gen', - 'pre_gen_e19e73f11217ea54ff2948c6d2d931fac9a51aa5.dart', + File( + canonicalize( + path.join( + hookDirectoryPath, + 'build', + 'hooks', + 'pre_gen', + 'pre_gen_e19e73f11217ea54ff2948c6d2d931fac9a51aa5.dart', + ), ), ), - ), - File( - canonicalize( - path.join( - hookDirectoryPath, - '.dart_tool', - 'package_config.json', + File( + canonicalize( + path.join( + hookDirectoryPath, + '.dart_tool', + 'package_config.json', + ), ), ), - ), - File( - canonicalize( - path.join( - '.dart_tool', - 'package_config.json', + File( + canonicalize( + path.join( + '.dart_tool', + 'package_config.json', + ), ), ), - ), - ]; - - final tempFile = File('.tmp.dill'); - final hooksDartToolDirectory = Directory( - path.join('test', 'fixtures', 'basic', 'hooks', '.dart_tool'), - ); - final hooksBuildDirectory = Directory( - path.join('test', 'fixtures', 'basic', 'hooks', 'build', 'hooks'), - ); - - try { - await hooksDartToolDirectory.delete(recursive: true); - } catch (_) {} - try { - await hooksBuildDirectory.delete(recursive: true); - } catch (_) {} - - final brick = Brick.path(path.join('test', 'fixtures', 'basic')); - final generator = await MasonGenerator.fromBrick(brick); - await IOOverrides.runZoned( - () async { - // 1st time, fresh run should not retry - try { - await generator.hooks.preGen(); - fail('should throw'); - } catch (error) { - expect(error, isA()); + ]; + + final tempFile = File('.tmp.dill'); + final hooksDartToolDirectory = Directory( + path.join('test', 'fixtures', 'basic', 'hooks', '.dart_tool'), + ); + final hooksBuildDirectory = Directory( + path.join('test', 'fixtures', 'basic', 'hooks', 'build', 'hooks'), + ); + + try { + await hooksDartToolDirectory.delete(recursive: true); + } catch (_) {} + try { + await hooksBuildDirectory.delete(recursive: true); + } catch (_) {} + + final brick = Brick.path(path.join('test', 'fixtures', 'basic')); + final generator = await MasonGenerator.fromBrick(brick); + await IOOverrides.runZoned( + () async { + // 1st time, fresh run should not retry + try { + await generator.hooks.preGen(); + fail('should throw'); + } catch (error) { + expect(error, isA()); + } + // 2nd time, stale run should retry + try { + await generator.hooks.preGen(); + fail('should throw'); + } catch (error) { + expect(error, isA()); + } + }, + createFile: (p) { + return files.firstWhere( + (f) => path.equals(p, f.path), + orElse: () => tempFile, + ); + }, + ); + try { + tempFile.deleteSync(); + } catch (_) {} + }); + + test('throws HookExecutionException when hook throws', () async { + final brick = Brick.path( + path.join('test', 'fixtures', 'execution_exception'), + ); + final generator = await MasonGenerator.fromBrick(brick); + + try { + await generator.hooks.preGen(); + fail('should throw'); + } catch (error) { + expect(error, isA()); + } + }); + + test( + 'throws HookDependencyInstallFailure ' + 'when dependencies cannot be resolved', () async { + final brick = Brick.path( + path.join('test', 'fixtures', 'dependency_install_failure'), + ); + final generator = await MasonGenerator.fromBrick(brick); + + try { + await generator.hooks.preGen(); + fail('should throw'); + } catch (error) { + expect(error, isA()); + } + }); + + test('compile installs dependencies and compiles hooks only once', + () async { + final hooksBuildDirectory = Directory( + path.join('test', 'fixtures', 'basic', 'hooks', 'build', 'hooks'), + ); + try { + await hooksBuildDirectory.delete(recursive: true); + } catch (_) {} + + final brick = Brick.path(path.join('test', 'fixtures', 'basic')); + final generator = await MasonGenerator.fromBrick(brick); + final logger = _MockLogger(); + final progress = _MockProgress(); + when(() => logger.progress(any())).thenReturn(progress); + + await expectLater(generator.hooks.compile(logger: logger), completes); + + verify(() => logger.progress('Compiling pre_gen.dart')).called(1); + verify(() => progress.complete('Compiled pre_gen.dart')).called(1); + verify(() => logger.progress('Compiling post_gen.dart')).called(1); + verify(() => progress.complete('Compiled post_gen.dart')).called(1); + + await expectLater(generator.hooks.compile(logger: logger), completes); + + verifyNever(() => logger.progress('Compiling pre_gen.dart')); + verifyNever(() => progress.complete('Compiled pre_gen.dart')); + verifyNever(() => logger.progress('Compiling post_gen.dart')); + verifyNever(() => progress.complete('Compiled post_gen.dart')); + }); + + test('compile reports compilation errors', () async { + final brick = Brick.path( + path.join('test', 'fixtures', 'run_exception'), + ); + final generator = await MasonGenerator.fromBrick(brick); + final logger = _MockLogger(); + final progress = _MockProgress(); + when(() => logger.progress(any())).thenReturn(progress); + + try { + await generator.hooks.compile(logger: logger); + fail('should throw'); + } catch (error) { + expect(error, isA()); + } + verify(() => logger.progress('Compiling pre_gen.dart')).called(1); + verify( + () => progress.fail( + any(that: contains("Error: Expected '{' before this.")), + ), + ).called(1); + }); + + test('recovers from cleared pub cache', () async { + final brick = Brick.path(path.join('test', 'fixtures', 'basic')); + final generator = await MasonGenerator.fromBrick(brick); + + await expectLater(generator.hooks.preGen(), completes); + + final result = await Process.run('dart', ['pub', 'cache', 'clean']); + expect(result.exitCode, equals(ExitCode.success.code)); + + await expectLater(generator.hooks.preGen(), completes); + }); + + test('supports relative imports within hooks', () async { + const name = 'Dash'; + final directory = Directory.systemTemp.createTempSync(); + final hooksBuildDirectory = Directory( + path.join( + 'test', + 'fixtures', + 'relative_imports', + 'hooks', + 'build', + 'hooks', + ), + ); + final preGenHookBuildDirectory = Directory( + path.join(hooksBuildDirectory.path, 'pre_gen'), + ); + final postGenHookBuildDirectory = Directory( + path.join(hooksBuildDirectory.path, 'post_gen'), + ); + + try { + await hooksBuildDirectory.delete(recursive: true); + } catch (_) {} + + expect(hooksBuildDirectory.existsSync(), isFalse); + + final brick = Brick.path( + path.join('test', 'fixtures', 'relative_imports'), + ); + final generator = await MasonGenerator.fromBrick(brick); + await generator.hooks.preGen( + vars: {'name': name}, + workingDirectory: directory.path, + ); + final preGenOutput = File(path.join(directory.path, '.pre_gen.txt')); + expect(preGenOutput.existsSync(), isTrue); + expect(preGenOutput.readAsStringSync(), equals('pre_gen: $name')); + expect(hooksBuildDirectory.existsSync(), isTrue); + expect(preGenHookBuildDirectory.existsSync(), isTrue); + expect(postGenHookBuildDirectory.existsSync(), isFalse); + + await generator.hooks.postGen( + vars: {'name': name}, + workingDirectory: directory.path, + ); + final postGenOutput = File(path.join(directory.path, '.post_gen.txt')); + expect(postGenOutput.existsSync(), isTrue); + expect(postGenOutput.readAsStringSync(), equals('post_gen: $name')); + expect(preGenHookBuildDirectory.existsSync(), isTrue); + expect(postGenHookBuildDirectory.existsSync(), isTrue); + }); + + test('recompiles hooks when an IsolateSpawnException occurs', () async { + const name = 'Dash'; + final directory = Directory.systemTemp.createTempSync(); + final hooksBuildDirectory = Directory( + path.join( + 'test', + 'fixtures', + 'relative_imports', + 'hooks', + 'build', + 'hooks', + ), + ); + final preGenHookBuildDirectory = Directory( + path.join(hooksBuildDirectory.path, 'pre_gen'), + ); + final postGenHookBuildDirectory = Directory( + path.join(hooksBuildDirectory.path, 'post_gen'), + ); + + try { + await hooksBuildDirectory.delete(recursive: true); + } catch (_) {} + + expect(hooksBuildDirectory.existsSync(), isFalse); + + final brick = Brick.path( + path.join('test', 'fixtures', 'relative_imports'), + ); + final generator = await MasonGenerator.fromBrick(brick); + + await generator.hooks.preGen( + vars: {'name': name}, + workingDirectory: directory.path, + ); + final preGenOutput = File(path.join(directory.path, '.pre_gen.txt')); + expect(preGenOutput.existsSync(), isTrue); + expect(preGenOutput.readAsStringSync(), equals('pre_gen: $name')); + expect(hooksBuildDirectory.existsSync(), isTrue); + expect(preGenHookBuildDirectory.existsSync(), isTrue); + expect(postGenHookBuildDirectory.existsSync(), isFalse); + + await generator.hooks.postGen( + vars: {'name': name}, + workingDirectory: directory.path, + ); + final postGenOutput = File(path.join(directory.path, '.post_gen.txt')); + expect(postGenOutput.existsSync(), isTrue); + expect(postGenOutput.readAsStringSync(), equals('post_gen: $name')); + expect(preGenHookBuildDirectory.existsSync(), isTrue); + expect(postGenHookBuildDirectory.existsSync(), isTrue); + + File? preGenModule; + File? postGenModule; + final legacyPreGen = File( + path.join( + 'test', + 'fixtures', + 'relative_imports', + 'hooks', + 'legacy', + 'pre_gen.dill', + ), + ); + final legacyPostGen = File( + path.join( + 'test', + 'fixtures', + 'relative_imports', + 'hooks', + 'legacy', + 'post_gen.dill', + ), + ); + final legacyPreGenBytes = legacyPreGen.readAsBytesSync(); + final legacyPostGenBytes = legacyPostGen.readAsBytesSync(); + final files = + hooksBuildDirectory.listSync(recursive: true).whereType(); + for (final file in files) { + if (path.basenameWithoutExtension(file.path).startsWith('pre_gen_')) { + preGenModule = file; + file.writeAsBytesSync(legacyPreGenBytes); } - // 2nd time, stale run should retry - try { - await generator.hooks.preGen(); - fail('should throw'); - } catch (error) { - expect(error, isA()); + if (path + .basenameWithoutExtension(file.path) + .startsWith('post_gen_')) { + postGenModule = file; + file.writeAsBytesSync(legacyPostGenBytes); } - }, - createFile: (p) { - return files.firstWhere( - (f) => path.equals(p, f.path), - orElse: () => tempFile, - ); - }, - ); - try { - tempFile.deleteSync(); - } catch (_) {} - }); - - test('throws HookExecutionException when hook throws', () async { - final brick = Brick.path( - path.join('test', 'fixtures', 'execution_exception'), - ); - final generator = await MasonGenerator.fromBrick(brick); - - try { - await generator.hooks.preGen(); - fail('should throw'); - } catch (error) { - expect(error, isA()); - } - }); - - test( - 'throws HookDependencyInstallFailure ' - 'when dependencies cannot be resolved', () async { - final brick = Brick.path( - path.join('test', 'fixtures', 'dependency_install_failure'), - ); - final generator = await MasonGenerator.fromBrick(brick); - - try { - await generator.hooks.preGen(); - fail('should throw'); - } catch (error) { - expect(error, isA()); - } - }); - - test('compile installs dependencies and compiles hooks only once', - () async { - final hooksBuildDirectory = Directory( - path.join('test', 'fixtures', 'basic', 'hooks', 'build', 'hooks'), - ); - try { - await hooksBuildDirectory.delete(recursive: true); - } catch (_) {} - - final brick = Brick.path(path.join('test', 'fixtures', 'basic')); - final generator = await MasonGenerator.fromBrick(brick); - final logger = _MockLogger(); - final progress = _MockProgress(); - when(() => logger.progress(any())).thenReturn(progress); - - await expectLater(generator.hooks.compile(logger: logger), completes); - - verify(() => logger.progress('Compiling pre_gen.dart')).called(1); - verify(() => progress.complete('Compiled pre_gen.dart')).called(1); - verify(() => logger.progress('Compiling post_gen.dart')).called(1); - verify(() => progress.complete('Compiled post_gen.dart')).called(1); - - await expectLater(generator.hooks.compile(logger: logger), completes); - - verifyNever(() => logger.progress('Compiling pre_gen.dart')); - verifyNever(() => progress.complete('Compiled pre_gen.dart')); - verifyNever(() => logger.progress('Compiling post_gen.dart')); - verifyNever(() => progress.complete('Compiled post_gen.dart')); - }); - - test('compile reports compilation errors', () async { - final brick = Brick.path( - path.join('test', 'fixtures', 'run_exception'), - ); - final generator = await MasonGenerator.fromBrick(brick); - final logger = _MockLogger(); - final progress = _MockProgress(); - when(() => logger.progress(any())).thenReturn(progress); - - try { - await generator.hooks.compile(logger: logger); - fail('should throw'); - } catch (error) { - expect(error, isA()); - } - verify(() => logger.progress('Compiling pre_gen.dart')).called(1); - verify( - () => progress.fail( - any(that: contains("Error: Expected '{' before this.")), - ), - ).called(1); - }); - - test('recovers from cleared pub cache', () async { - final brick = Brick.path(path.join('test', 'fixtures', 'basic')); - final generator = await MasonGenerator.fromBrick(brick); - - await expectLater(generator.hooks.preGen(), completes); - - final result = await Process.run('dart', ['pub', 'cache', 'clean']); - expect(result.exitCode, equals(ExitCode.success.code)); - - await expectLater(generator.hooks.preGen(), completes); - }); - - test('supports relative imports within hooks', () async { - const name = 'Dash'; - final directory = Directory.systemTemp.createTempSync(); - final hooksBuildDirectory = Directory( - path.join( - 'test', - 'fixtures', - 'relative_imports', - 'hooks', - 'build', - 'hooks', - ), - ); - final preGenHookBuildDirectory = Directory( - path.join(hooksBuildDirectory.path, 'pre_gen'), - ); - final postGenHookBuildDirectory = Directory( - path.join(hooksBuildDirectory.path, 'post_gen'), - ); - - try { - await hooksBuildDirectory.delete(recursive: true); - } catch (_) {} - - expect(hooksBuildDirectory.existsSync(), isFalse); - - final brick = Brick.path( - path.join('test', 'fixtures', 'relative_imports'), - ); - final generator = await MasonGenerator.fromBrick(brick); - await generator.hooks.preGen( - vars: {'name': name}, - workingDirectory: directory.path, - ); - final preGenOutput = File(path.join(directory.path, '.pre_gen.txt')); - expect(preGenOutput.existsSync(), isTrue); - expect(preGenOutput.readAsStringSync(), equals('pre_gen: $name')); - expect(hooksBuildDirectory.existsSync(), isTrue); - expect(preGenHookBuildDirectory.existsSync(), isTrue); - expect(postGenHookBuildDirectory.existsSync(), isFalse); - - await generator.hooks.postGen( - vars: {'name': name}, - workingDirectory: directory.path, - ); - final postGenOutput = File(path.join(directory.path, '.post_gen.txt')); - expect(postGenOutput.existsSync(), isTrue); - expect(postGenOutput.readAsStringSync(), equals('post_gen: $name')); - expect(preGenHookBuildDirectory.existsSync(), isTrue); - expect(postGenHookBuildDirectory.existsSync(), isTrue); - }); - - test('recompiles hooks when an IsolateSpawnException occurs', () async { - const name = 'Dash'; - final directory = Directory.systemTemp.createTempSync(); - final hooksBuildDirectory = Directory( - path.join( - 'test', - 'fixtures', - 'relative_imports', - 'hooks', - 'build', - 'hooks', - ), - ); - final preGenHookBuildDirectory = Directory( - path.join(hooksBuildDirectory.path, 'pre_gen'), - ); - final postGenHookBuildDirectory = Directory( - path.join(hooksBuildDirectory.path, 'post_gen'), - ); - - try { - await hooksBuildDirectory.delete(recursive: true); - } catch (_) {} - - expect(hooksBuildDirectory.existsSync(), isFalse); - - final brick = Brick.path( - path.join('test', 'fixtures', 'relative_imports'), - ); - final generator = await MasonGenerator.fromBrick(brick); - - await generator.hooks.preGen( - vars: {'name': name}, - workingDirectory: directory.path, - ); - final preGenOutput = File(path.join(directory.path, '.pre_gen.txt')); - expect(preGenOutput.existsSync(), isTrue); - expect(preGenOutput.readAsStringSync(), equals('pre_gen: $name')); - expect(hooksBuildDirectory.existsSync(), isTrue); - expect(preGenHookBuildDirectory.existsSync(), isTrue); - expect(postGenHookBuildDirectory.existsSync(), isFalse); - - await generator.hooks.postGen( - vars: {'name': name}, - workingDirectory: directory.path, - ); - final postGenOutput = File(path.join(directory.path, '.post_gen.txt')); - expect(postGenOutput.existsSync(), isTrue); - expect(postGenOutput.readAsStringSync(), equals('post_gen: $name')); - expect(preGenHookBuildDirectory.existsSync(), isTrue); - expect(postGenHookBuildDirectory.existsSync(), isTrue); - - File? preGenModule; - File? postGenModule; - final legacyPreGen = File( - path.join( - 'test', - 'fixtures', - 'relative_imports', - 'hooks', - 'legacy', - 'pre_gen.dill', - ), - ); - final legacyPostGen = File( - path.join( - 'test', - 'fixtures', - 'relative_imports', - 'hooks', - 'legacy', - 'post_gen.dill', - ), - ); - final legacyPreGenBytes = legacyPreGen.readAsBytesSync(); - final legacyPostGenBytes = legacyPostGen.readAsBytesSync(); - final files = - hooksBuildDirectory.listSync(recursive: true).whereType(); - for (final file in files) { - if (path.basenameWithoutExtension(file.path).startsWith('pre_gen_')) { - preGenModule = file; - file.writeAsBytesSync(legacyPreGenBytes); } - if (path.basenameWithoutExtension(file.path).startsWith('post_gen_')) { - postGenModule = file; - file.writeAsBytesSync(legacyPostGenBytes); - } - } - - await generator.hooks.preGen( - vars: {'name': name}, - workingDirectory: directory.path, - ); - await generator.hooks.postGen( - vars: {'name': name}, - workingDirectory: directory.path, - ); - - expect( - preGenModule!.readAsBytesSync(), - isNot(equals(legacyPreGenBytes)), - ); - expect( - postGenModule!.readAsBytesSync(), - isNot(equals(legacyPostGenBytes)), - ); - }); - }); + + await generator.hooks.preGen( + vars: {'name': name}, + workingDirectory: directory.path, + ); + await generator.hooks.postGen( + vars: {'name': name}, + workingDirectory: directory.path, + ); + + expect( + preGenModule!.readAsBytesSync(), + isNot(equals(legacyPreGenBytes)), + ); + expect( + postGenModule!.readAsBytesSync(), + isNot(equals(legacyPostGenBytes)), + ); + }); + }, + timeout: const Timeout.factor(2), + ); }