diff --git a/ci/release/changelogs/next.md b/ci/release/changelogs/next.md index b849e05cd..396a9e5f2 100644 --- a/ci/release/changelogs/next.md +++ b/ci/release/changelogs/next.md @@ -14,3 +14,4 @@ - Shadow is cut off when `--pad` is 0. Thank you @LeonardsonCC ! [#1326](https://github.com/terrastruct/d2/pull/1326) - Fixes grid layout overwriting label placements for nested objects. [#1345](https://github.com/terrastruct/d2/pull/1345) - Fixes fonts not rendering correctly on certain platforms. Thanks @mikeday for identifying the solution. [#1356](https://github.com/terrastruct/d2/pull/1356) +- Fixes folders not rendering in animations (`--animate-interval`) [#1357](https://github.com/terrastruct/d2/pull/1357) diff --git a/d2cli/main.go b/d2cli/main.go index 2f87fee80..0db873bc6 100644 --- a/d2cli/main.go +++ b/d2cli/main.go @@ -641,10 +641,9 @@ func render(ctx context.Context, ms *xmain.State, compileDur time.Duration, plug ms.Log.Success.Printf("successfully compiled %s to %s in %s", ms.HumanPath(inputPath), ms.HumanPath(boardOutputPath), dur) } boards = append([][]byte{out}, boards...) - return boards, nil } - return nil, nil + return boards, nil } func _render(ctx context.Context, ms *xmain.State, plugin d2plugin.Plugin, opts d2svg.RenderOpts, outputPath string, bundle, forceAppendix bool, page playwright.Page, ruler *textmeasure.Ruler, diagram *d2target.Diagram) ([]byte, error) { diff --git a/e2etests-cli/main_test.go b/e2etests-cli/main_test.go index 6cb634235..7cd61e150 100644 --- a/e2etests-cli/main_test.go +++ b/e2etests-cli/main_test.go @@ -5,6 +5,7 @@ import ( "context" "os" "path/filepath" + "strings" "testing" "time" @@ -76,6 +77,30 @@ func TestCLI_E2E(t *testing.T) { assert.TestdataDir(t, filepath.Join(dir, "empty-layer")) }, }, + { + // Skip the empty base board so the animation doesn't show blank for 1400ms + name: "empty-base", + run: func(t *testing.T, ctx context.Context, dir string, env *xos.Env) { + writeFile(t, dir, "empty-base.d2", `steps: { + 1: { + a -> b + } + 2: { + b -> d + c -> d + } + 3: { + d -> e + } +}`) + + err := runTestMain(t, ctx, dir, env, "--animate-interval=1400", "empty-base.d2") + assert.Success(t, err) + svg := readFile(t, dir, "empty-base.svg") + assert.Testdata(t, ".svg", svg) + assert.Equal(t, 3, getNumBoards(string(svg))) + }, + }, { name: "animation", run: func(t *testing.T, ctx context.Context, dir string, env *xos.Env) { @@ -447,3 +472,9 @@ func removeD2Files(tb testing.TB, dir string) { func testdataIgnoreDiff(tb testing.TB, ext string, got []byte) { _ = diff.Testdata(filepath.Join("testdata", tb.Name()), ext, got) } + +// getNumBoards gets the number of boards in an SVG file through a non-robust pattern search +// If the renderer changes, this must change +func getNumBoards(svg string) int { + return strings.Count(svg, `class="d2`) +} diff --git a/e2etests-cli/testdata/TestCLI_E2E/empty-base.exp.svg b/e2etests-cli/testdata/TestCLI_E2E/empty-base.exp.svg new file mode 100644 index 000000000..2d74f466f --- /dev/null +++ b/e2etests-cli/testdata/TestCLI_E2E/empty-base.exp.svg @@ -0,0 +1,128 @@ +ab + + +abdc + + +abdce + + + \ No newline at end of file