Skip to content

Commit

Permalink
feat(sessions): mirrored sessions (#740)
Browse files Browse the repository at this point in the history
* feat(sessions): mirrored sessions

* fix(tests): input units

* style(fmt): make rustfmt happy

* fix(tests): make mirrored sessions e2e test more robust

* refactor(sessions): remove force attach

* style(fmt): rustfmtify

* docs(changelog): update change

* fix(e2e): retry on all errors
  • Loading branch information
imsnif authored Sep 27, 2021
1 parent c93a4f1 commit 5c54bf1
Show file tree
Hide file tree
Showing 22 changed files with 722 additions and 316 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
* Feature: Add ability to solely specify the tab name in the `tabs` section (https://github.com/zellij-org/zellij/pull/722)
* Feature: Plugins can be configured and the groundwork for "Headless" plugins has been laid (https://github.com/zellij-org/zellij/pull/660)
* Automatically update `example/default.yaml` on release (https://github.com/zellij-org/zellij/pull/736)
* Feature: allow mirroring sessions in multiple terminal windows (https://github.com/zellij-org/zellij/pull/740)

## [0.17.0] - 2021-09-15
* New panes/tabs now open in CWD of focused pane (https://github.com/zellij-org/zellij/pull/691)
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ args = ["build", "--verbose", "--release", "--target", "${CARGO_MAKE_TASK_ARGS}"
workspace = false
dependencies = ["build-plugins", "build-dev-data-dir"]
command = "cargo"
args = ["build", "--verbose", "--target", "x86_64-unknown-linux-musl"]
args = ["build", "--verbose", "--release", "--target", "x86_64-unknown-linux-musl"]

# Run e2e tests - we mark the e2e tests as "ignored" so they will not be run with the normal ones
[tasks.e2e-test]
Expand Down
15 changes: 3 additions & 12 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ pub fn main() {
};
if let Some(Command::Sessions(Sessions::Attach {
session_name,
force,
create,
options,
})) = opts.command.clone()
Expand All @@ -73,22 +72,14 @@ pub fn main() {
(ClientInfo::New(session_name.unwrap()), layout)
} else {
(
ClientInfo::Attach(
session_name.unwrap(),
force,
config_options.clone(),
),
ClientInfo::Attach(session_name.unwrap(), config_options.clone()),
None,
)
}
} else {
assert_session(session);
(
ClientInfo::Attach(
session_name.unwrap(),
force,
config_options.clone(),
),
ClientInfo::Attach(session_name.unwrap(), config_options.clone()),
None,
)
}
Expand All @@ -106,7 +97,7 @@ pub fn main() {
}
}
ActiveSession::One(session_name) => (
ClientInfo::Attach(session_name, force, config_options.clone()),
ClientInfo::Attach(session_name, config_options.clone()),
None,
),
ActiveSession::Many => {
Expand Down
96 changes: 85 additions & 11 deletions src/tests/e2e/cases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,20 +153,12 @@ pub fn cannot_split_terminals_vertically_when_active_terminal_is_too_small() {
},
})
.add_step(Step {
name: "Send text to terminal",
instruction: |mut remote_terminal: RemoteTerminal| -> bool {
// this is just normal input that should be sent into the one terminal so that we can make
// sure we silently failed to split in the previous step
remote_terminal.send_key("Hi!".as_bytes());
true
},
})
.add_step(Step {
name: "Wait for text to appear",
name: "Make sure only one pane appears",
instruction: |remote_terminal: RemoteTerminal| -> bool {
let mut step_is_complete = false;
if remote_terminal.cursor_position_is(6, 2) && remote_terminal.snapshot_contains("Hi!")
if remote_terminal.cursor_position_is(3, 2) && remote_terminal.snapshot_contains("...")
{
// ... is the truncated tip line
step_is_complete = true;
}
step_is_complete
Expand Down Expand Up @@ -917,3 +909,85 @@ pub fn start_without_pane_frames() {
.run_all_steps();
assert_snapshot!(last_snapshot);
}

#[test]
#[ignore]
pub fn mirrored_sessions() {
let fake_win_size = Size {
cols: 120,
rows: 24,
};
let mut test_attempts = 10;
let session_name = "mirrored_sessions";
let mut last_snapshot = None;
loop {
// we run this test in a loop because there are some edge cases (especially in the CI)
// where the second runner times out and then we also need to restart the first runner
// if no test timed out, we break the loop and assert the snapshot
let mut first_runner =
RemoteRunner::new_with_session_name("mirrored_sessions", fake_win_size, session_name)
.add_step(Step {
name: "Split pane to the right",
instruction: |mut remote_terminal: RemoteTerminal| -> bool {
let mut step_is_complete = false;
if remote_terminal.status_bar_appears()
&& remote_terminal.cursor_position_is(3, 2)
{
remote_terminal.send_key(&PANE_MODE);
remote_terminal.send_key(&SPLIT_RIGHT_IN_PANE_MODE);
// back to normal mode after split
remote_terminal.send_key(&ENTER);
step_is_complete = true;
}
step_is_complete
},
})
.add_step(Step {
name: "Wait for new pane to open",
instruction: |remote_terminal: RemoteTerminal| -> bool {
let mut step_is_complete = false;
if remote_terminal.cursor_position_is(63, 2)
&& remote_terminal.tip_appears()
{
// cursor is in the newly opened second pane
step_is_complete = true;
}
step_is_complete
},
});
first_runner.run_all_steps();

let mut second_runner =
RemoteRunner::new_existing_session("mirrored_sessions", fake_win_size, session_name)
.add_step(Step {
name: "Make sure session appears correctly",
instruction: |remote_terminal: RemoteTerminal| -> bool {
let mut step_is_complete = false;
if remote_terminal.cursor_position_is(63, 2)
&& remote_terminal.tip_appears()
{
// cursor is in the newly opened second pane
step_is_complete = true;
}
step_is_complete
},
});
let last_test_snapshot = second_runner.run_all_steps();

if (first_runner.test_timed_out || second_runner.test_timed_out) && test_attempts >= 0 {
test_attempts -= 1;
continue;
} else {
last_snapshot = Some(last_test_snapshot);
break;
}
}
match last_snapshot {
Some(last_snapshot) => {
assert_snapshot!(last_snapshot);
}
None => {
panic!("test timed out before completing");
}
}
}
Loading

0 comments on commit 5c54bf1

Please sign in to comment.