Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(mason_cli): refactor setUp in make_test.dart #1130

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
140 changes: 39 additions & 101 deletions packages/mason_cli/test/commands/make_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,108 +46,42 @@ void main() {

setUp(() {
setUpTestingEnvironment(cwd, suffix: '.make');
File(path.join(Directory.current.path, 'mason.yaml')).writeAsStringSync(
'''
bricks:
app_icon:
path: ../../../../../bricks/app_icon
bio:
path: ../../../../../bricks/bio
documentation:
path: ../../../../../bricks/documentation
favorite_color:
path: ../../../../../bricks/favorite_color
favorite_languages:
path: ../../../../../bricks/favorite_languages
flavors:
path: ../../../../../bricks/flavors
greeting:
path: ../../../../../bricks/greeting
legacy:
path: ../../../../../bricks/legacy
hello_world:
path: ../../../../../bricks/hello_world
hooks:
path: ../../../../../bricks/hooks
plugin:
path: ../../../../../bricks/plugin
random_color:
path: ../../../../../bricks/random_color
simple:
path: ../../../../../bricks/simple
todos:
path: ../../../../../bricks/todos
widget:
path: ../../../../../bricks/widget
''',
);
const bricks = {
'app_icon',
'bio',
'documentation',
'favorite_color',
'favorite_languages',
'flavors',
'greeting',
'legacy',
'hello_world',
'hooks',
'plugin',
'random_color',
'simple',
'todos',
'widget',
};
final bricksPath = path.join('..', '..', '..', '..', '..', 'bricks');
final appIconPath = canonicalize(
path.join(Directory.current.path, bricksPath, 'app_icon'),
);
final bioPath = canonicalize(
path.join(Directory.current.path, bricksPath, 'bio'),
);
final docPath = canonicalize(
path.join(Directory.current.path, bricksPath, 'documentation'),
);
final favoriteColorPath = canonicalize(
path.join(Directory.current.path, bricksPath, 'favorite_color'),
);
final favoriteLanguagesPath = canonicalize(
path.join(Directory.current.path, bricksPath, 'favorite_languages'),
);
final flavorsPath = canonicalize(
path.join(Directory.current.path, bricksPath, 'flavors'),
);
final greetingPath = canonicalize(
path.join(Directory.current.path, bricksPath, 'greeting'),
);
final legacyPath = canonicalize(
path.join(Directory.current.path, bricksPath, 'legacy'),
);
final helloWorldPath = canonicalize(
path.join(Directory.current.path, bricksPath, 'hello_world'),
);
final hooksPath = canonicalize(
path.join(Directory.current.path, bricksPath, 'hooks'),
);
final pluginPath = canonicalize(
path.join(Directory.current.path, bricksPath, 'plugin'),
);
final randomColorPath = canonicalize(
path.join(Directory.current.path, bricksPath, 'random_color'),
);
final simplePath = canonicalize(
path.join(Directory.current.path, bricksPath, 'simple'),
);
final todosPath = canonicalize(
path.join(Directory.current.path, bricksPath, 'todos'),
);
final widgetPath = canonicalize(
path.join(Directory.current.path, bricksPath, 'widget'),
);
File(path.join(Directory.current.path, '.mason', 'bricks.json'))
..createSync(recursive: true)
..writeAsStringSync(
json.encode({
'app_icon': appIconPath,
'bio': bioPath,
'documentation': docPath,
'favorite_color': favoriteColorPath,
'favorite_languages': favoriteLanguagesPath,
'flavors': flavorsPath,
'hello_world': helloWorldPath,
'hooks': hooksPath,
'greeting': greetingPath,
'legacy': legacyPath,
'plugin': pluginPath,
'random_color': randomColorPath,
'simple': simplePath,
'todos': todosPath,
'widget': widgetPath,
}),
);
final masonYamlBuffer = StringBuffer('bricks:\n');
for (final brick in bricks) {
masonYamlBuffer.writeln(' $brick: ${path.join(bricksPath, brick)}');
}
File(
path.join(Directory.current.path, 'mason.yaml'),
).writeAsStringSync('$masonYamlBuffer');
final bricksJsonContent = json.encode({
for (final brick in bricks)
brick: canonicalize(
path.join(Directory.current.path, bricksPath, brick),
),
});
final bricksJson =
File(path.join(Directory.current.path, '.mason', 'bricks.json'))
..createSync(recursive: true)
..writeAsStringSync(bricksJsonContent);

printLogs = [];
logger = _MockLogger();
pubUpdater = _MockPubUpdater();
Expand All @@ -164,6 +98,10 @@ bricks:
logger: logger,
pubUpdater: pubUpdater,
);

addTearDown(() {
if (bricksJson.existsSync()) bricksJson.deleteSync(recursive: true);
});
});

tearDown(() {
Expand Down