Skip to content

Commit

Permalink
fix: Propagate error code when fail fast is enabled (#762)
Browse files Browse the repository at this point in the history
<!--
  Thanks for contributing!

Provide a description of your changes below and a general summary in the
title

Please look at the following checklist to ensure that your PR can be
accepted quickly:
-->

## Description

When `--fail-fast` is enabled we should propagate the error code.
Fixes: #527 

## Type of Change

<!--- Put an `x` in all the boxes that apply: -->

- [ ] ✨ `feat` -- New feature (non-breaking change which adds
functionality)
- [x] 🛠️ `fix` -- Bug fix (non-breaking change which fixes an issue)
- [ ] ❌ `!` -- Breaking change (fix or feature that would cause existing
functionality to change)
- [ ] 🧹 `refactor` -- Code refactor
- [ ] ✅ `ci` -- Build configuration change
- [ ] 📝 `docs` -- Documentation
- [ ] 🗑️ `chore` -- Chore
  • Loading branch information
spydon authored Oct 7, 2024
1 parent cec45d7 commit ed6243b
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/melos/lib/src/commands/exec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ mixin _ExecMixin on _Melos {
}
}

exitCode = 1;
exitCode = failFast ? failures[failures.keys.first]! : 1;
} else {
resultLogger.child(successLabel);
}
Expand Down
85 changes: 85 additions & 0 deletions packages/melos/test/commands/exec_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,91 @@ ${'-' * terminalWidth}
});
});

group('fail fast', () {
test('print error codes correctly', () async {
final workspaceDir = await createTemporaryWorkspace();

await createProject(
workspaceDir,
const PubSpec(name: 'a'),
);

await createProject(
workspaceDir,
const PubSpec(name: 'b'),
);

await createProject(
workspaceDir,
const PubSpec(name: 'c'),
);

final logger = TestLogger();
final config = await MelosWorkspaceConfig.fromWorkspaceRoot(
workspaceDir,
);
final melos = Melos(
logger: logger,
config: config,
);

await melos.exec(
['exit', '2'],
failFast: true,
);

expect(
logger.output.normalizeNewLines(),
ignoringAnsii(
'''
\$ melos exec
└> exit 2
└> RUNNING (in 3 packages)
${'-' * terminalWidth}
${'-' * terminalWidth}
\$ melos exec
└> exit 2
└> FAILED (in 1 packages)
└> a (with exit code 2)
└> CANCELED (in 2 packages)
└> b (due to failFast)
└> c (due to failFast)
''',
),
);
});

test('propagate error code when fail fast is enabled', () async {
final workspaceDir = await createTemporaryWorkspace();

await createProject(
workspaceDir,
const PubSpec(name: 'a'),
);

await createProject(
workspaceDir,
const PubSpec(name: 'b'),
);

await createProject(
workspaceDir,
const PubSpec(name: 'c'),
);

final result = await Process.run(
'melos',
['exec', '--fail-fast', 'exit', '2'],
workingDirectory: workspaceDir.path,
runInShell: Platform.isWindows,
);

expect(result.exitCode, equals(2));
});
});

group('order dependents', () {
test('sorts execution order topologically', () async {
final workspaceDir = await createTemporaryWorkspace();
Expand Down

0 comments on commit ed6243b

Please sign in to comment.