Skip to content

Commit 851e4b7

Browse files
claudesinelaw
authored andcommitted
flash tests: place fixtures under harness project root
CI failures on macOS / Windows revealed the root cause of the flash test timeouts: tests opened files via `TestFixture::new` which puts the file in a *separate* OS temp directory. On macOS that path is `/private/var/folders/<32-char-hash>/T/.tmpXXXXXX/test.txt` ≈ 76 chars — long enough to push every other status-bar segment off the visible 120-col area, including the plugin's `Flash[<pattern>]` text the tests wait on. The captured CI screen showed the status truncated to literally `Ln ...`. Per the project convention, files belong **under the harness project root** so the editor renders short relative paths. This matches what the existing `blog_showcase_productivity_flash_jump` test already does (`project_root.join("sample.rs")`). Changes: - flash_harness now returns `(harness, temp_guard, project_root)`. - New helper `write_fixture(project_root, name, content)` replaces `TestFixture::new` for in-project fixtures. - All 6 flash e2e tests rewritten to call `write_fixture` so their test files live under `<project_root>/test.txt`, `<project_root>/left.txt`, etc. Status bar now shows just `test.txt | Ln 1, Col 1 | Flash[hello] LF ASCII Text …`, comfortably within 120 cols on every platform. Tests still pass locally in 0.46s. Width remains 120 — the relative-path fix removes the macOS/Windows-only truncation, no need to bloat terminal dimensions.
1 parent e763034 commit 851e4b7

1 file changed

Lines changed: 63 additions & 26 deletions

File tree

crates/fresh-editor/tests/e2e/flash.rs

Lines changed: 63 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,22 @@
88
//! API #1 (`editor.getNextKey()`) when used by a plugin that does
99
//! NOT also use `defineMode` bindings.
1010
11-
use crate::common::fixtures::TestFixture;
1211
use crate::common::harness::{copy_plugin, copy_plugin_lib, EditorTestHarness};
1312
use crate::common::tracing::init_tracing_from_env;
1413
use crossterm::event::{KeyCode, KeyModifiers};
1514
use std::fs;
15+
use std::path::PathBuf;
1616

1717
/// Build a harness with the `flash` plugin loaded into an isolated
18-
/// per-test project directory.
19-
fn flash_harness(width: u16, height: u16) -> (EditorTestHarness, tempfile::TempDir) {
18+
/// per-test project directory. Returns the harness, the TempDir
19+
/// guard (must outlive the harness), and the project root path —
20+
/// callers should put any test fixtures **under that root** so that
21+
/// the editor displays them with short relative paths in the status
22+
/// bar. Long absolute paths (like macOS `/private/var/folders/…`
23+
/// temp paths) push the rest of the status bar off the visible
24+
/// area, including the plugin's own `Flash[…]` text the tests wait
25+
/// on.
26+
fn flash_harness(width: u16, height: u16) -> (EditorTestHarness, tempfile::TempDir, PathBuf) {
2027
init_tracing_from_env();
2128
let temp_dir = tempfile::TempDir::new().unwrap();
2229
let project_root = temp_dir.path().join("project_root");
@@ -31,10 +38,20 @@ fn flash_harness(width: u16, height: u16) -> (EditorTestHarness, tempfile::TempD
3138
width,
3239
height,
3340
Default::default(),
34-
project_root,
41+
project_root.clone(),
3542
)
3643
.unwrap();
37-
(harness, temp_dir)
44+
(harness, temp_dir, project_root)
45+
}
46+
47+
/// Write `content` to `name` inside the harness project root and
48+
/// return the resulting path. Use this in place of
49+
/// `TestFixture::new` so the file lives **under** the editor's
50+
/// working directory and renders with a short relative path.
51+
fn write_fixture(project_root: &std::path::Path, name: &str, content: &str) -> PathBuf {
52+
let path = project_root.join(name);
53+
fs::write(&path, content).unwrap();
54+
path
3855
}
3956

4057
/// Open the command palette, type `Flash: Jump`, press Enter, and
@@ -92,9 +109,13 @@ fn flash_jumps_to_label() {
92109
// the assertion screen-only (CONTRIBUTING rule #2), we then
93110
// insert a marker character and observe where it lands in the
94111
// rendered buffer.
95-
let (mut harness, _temp) = flash_harness(120, 24);
96-
let fixture = TestFixture::new("test.txt", "hello world\nhello there\nhello again\n").unwrap();
97-
harness.open_file(&fixture.path).unwrap();
112+
let (mut harness, _temp, project_root) = flash_harness(120, 24);
113+
let path = write_fixture(
114+
&project_root,
115+
"test.txt",
116+
"hello world\nhello there\nhello again\n",
117+
);
118+
harness.open_file(&path).unwrap();
98119
harness.render().unwrap();
99120

100121
arm_flash(&mut harness);
@@ -123,9 +144,13 @@ fn flash_jumps_to_label() {
123144

124145
#[test]
125146
fn flash_escape_cancels_no_movement() {
126-
let (mut harness, _temp) = flash_harness(120, 24);
127-
let fixture = TestFixture::new("test.txt", "hello world\nhello there\nhello again\n").unwrap();
128-
harness.open_file(&fixture.path).unwrap();
147+
let (mut harness, _temp, project_root) = flash_harness(120, 24);
148+
let path = write_fixture(
149+
&project_root,
150+
"test.txt",
151+
"hello world\nhello there\nhello again\n",
152+
);
153+
harness.open_file(&path).unwrap();
129154
harness.render().unwrap();
130155

131156
arm_flash(&mut harness);
@@ -152,9 +177,13 @@ fn flash_backspace_shrinks_pattern() {
152177
// After Backspace the prior label set should be re-assigned.
153178
// Verify by typing a too-narrow pattern first ("there"), then
154179
// Backspacing back to a multi-match prefix and pressing a label.
155-
let (mut harness, _temp) = flash_harness(120, 24);
156-
let fixture = TestFixture::new("test.txt", "hello world\nhello there\nhello again\n").unwrap();
157-
harness.open_file(&fixture.path).unwrap();
180+
let (mut harness, _temp, project_root) = flash_harness(120, 24);
181+
let path = write_fixture(
182+
&project_root,
183+
"test.txt",
184+
"hello world\nhello there\nhello again\n",
185+
);
186+
harness.open_file(&path).unwrap();
158187
harness.render().unwrap();
159188

160189
arm_flash(&mut harness);
@@ -207,9 +236,13 @@ fn flash_backspace_shrinks_pattern() {
207236
fn flash_label_substitutes_rendered_glyph() {
208237
// Same buffer shape as `flash_jumps_to_label` so the harness
209238
// setup that's already known to work doesn't surprise us.
210-
let (mut harness, _temp) = flash_harness(120, 24);
211-
let fixture = TestFixture::new("test.txt", "hello world\nhello there\nhello again\n").unwrap();
212-
harness.open_file(&fixture.path).unwrap();
239+
let (mut harness, _temp, project_root) = flash_harness(120, 24);
240+
let path = write_fixture(
241+
&project_root,
242+
"test.txt",
243+
"hello world\nhello there\nhello again\n",
244+
);
245+
harness.open_file(&path).unwrap();
213246
harness.render().unwrap();
214247

215248
arm_flash(&mut harness);
@@ -273,13 +306,13 @@ fn flash_jumps_across_splits() {
273306
// each split. The active split's match sorts first (label "a"),
274307
// the other split's match second (label "s"). Pressing "s" must
275308
// (a) focus the other split and (b) place the cursor on its match.
276-
let (mut harness, _temp) = flash_harness(120, 30);
309+
let (mut harness, _temp, project_root) = flash_harness(120, 30);
277310

278-
let temp_files = tempfile::TempDir::new().unwrap();
279-
let f1 = temp_files.path().join("left.txt");
280-
let f2 = temp_files.path().join("right.txt");
281-
fs::write(&f1, "alpha left side\n").unwrap();
282-
fs::write(&f2, "alpha right side\n").unwrap();
311+
// Place both files **under** the harness project root so the
312+
// editor renders short relative paths (`left.txt` / `right.txt`)
313+
// in the status bar. See the comment on `flash_harness`.
314+
let f1 = write_fixture(&project_root, "left.txt", "alpha left side\n");
315+
let f2 = write_fixture(&project_root, "right.txt", "alpha right side\n");
283316

284317
// Open left file in initial split, then create a vertical split
285318
// and open right file in the new (active) split.
@@ -345,9 +378,13 @@ fn flash_jumps_across_splits() {
345378

346379
#[test]
347380
fn flash_enter_jumps_to_closest() {
348-
let (mut harness, _temp) = flash_harness(120, 24);
349-
let fixture = TestFixture::new("test.txt", "hello world\nhello there\nhello again\n").unwrap();
350-
harness.open_file(&fixture.path).unwrap();
381+
let (mut harness, _temp, project_root) = flash_harness(120, 24);
382+
let path = write_fixture(
383+
&project_root,
384+
"test.txt",
385+
"hello world\nhello there\nhello again\n",
386+
);
387+
harness.open_file(&path).unwrap();
351388
harness.render().unwrap();
352389

353390
arm_flash(&mut harness);

0 commit comments

Comments
 (0)