Skip to content

Commit

Permalink
add test to behavior fix
Browse files Browse the repository at this point in the history
Signed-off-by: Mateus Felipe C. C. Pinto <[email protected]>
  • Loading branch information
mateusfccp committed Mar 29, 2024
1 parent 68d413d commit 21c6b38
Showing 1 changed file with 120 additions and 0 deletions.
120 changes: 120 additions & 0 deletions packages/melos/test/commands/bootstrap_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,126 @@ Generating IntelliJ IDE files...
);
});

test('properly compares the path changes on git references', () async {
final temporaryGitRepository = createTestTempDir();

await io.Process.run(
'git',
['init'],
workingDirectory: temporaryGitRepository.absolute.path,
);

await createProject(
io.Directory('${temporaryGitRepository.absolute.path}/dependency1'),
const PubSpec(name: 'dependency'),
);

await createProject(
io.Directory('${temporaryGitRepository.absolute.path}/dependency2'),
const PubSpec(name: 'dependency'),
);

await io.Process.run(
'git',
['add', '-A'],
workingDirectory: temporaryGitRepository.absolute.path,
);

await io.Process.run(
'git',
['commit', '--message="Initial commit"'],
workingDirectory: temporaryGitRepository.absolute.path,
);

final workspaceDirectory = await createTemporaryWorkspace();

final initialReference = {
'git': {
'url': 'file://${temporaryGitRepository.absolute.path}',
'path': 'dependency1/packages/dependency',
},
};

final package = await createProject(
workspaceDirectory,
PubSpec(
name: 'git_references',
dependencies: {
'dependency': GitReference.fromJson(initialReference),
},
),
);

final logger = TestLogger();
final initialConfig = MelosWorkspaceConfig.fromYaml(
{
'name': 'test',
'packages': const ['packages/**'],
'command': {
'bootstrap': {
'dependencies': {
'dependency': initialReference,
},
},
},
},
path: workspaceDirectory.path,
);

final melosBeforeChangingPath = Melos(
logger: logger,
config: initialConfig,
);

await runMelosBootstrap(melosBeforeChangingPath, logger);

final packageConfig = packageConfigForPackageAt(package);
final dependencyPackage = packageConfig.packages.singleWhere(
(package) => package.name == 'dependency',
);

expect(
dependencyPackage.rootUri,
contains('dependency1/packages/dependency'),
);

final configWithChangedPath = MelosWorkspaceConfig.fromYaml(
{
'name': 'test',
'packages': const ['packages/**'],
'command': {
'bootstrap': {
'dependencies': {
'dependency': {
'git': {
'url': 'file://${temporaryGitRepository.absolute.path}',
'path': 'dependency2/packages/dependency',
},
},
},
},
},
},
path: workspaceDirectory.path,
);

final melosAfterChangingPath = Melos(
logger: logger,
config: configWithChangedPath,
);

await runMelosBootstrap(melosAfterChangingPath, logger);

final alteredPackageConfig = packageConfigForPackageAt(package);
final alteredDependencyPackage = alteredPackageConfig.packages
.singleWhere((package) => package.name == 'dependency');

expect(
alteredDependencyPackage.rootUri,
contains('dependency2/packages/dependency'),
);
});

test(
'resolves workspace packages with path dependency',
() async {
Expand Down

0 comments on commit 21c6b38

Please sign in to comment.