Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions apps/amp-plugin/bunfig.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Bun reads only the bunfig.toml in the directory `bun test` runs from, so the
# root preloads are mirrored here for runs from this package directory. Keep in
# step with the root bunfig.toml [test] section (guarded by
# tests/package-bunfig.test.ts).
[test]
preload = ["../../tests/setup/feedback-archive-off.ts", "../../packages/ui/test-setup/happy-dom.ts"]
6 changes: 6 additions & 0 deletions apps/guides-show/bunfig.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Bun reads only the bunfig.toml in the directory `bun test` runs from, so the
# root preloads are mirrored here for runs from this package directory. Keep in
# step with the root bunfig.toml [test] section (guarded by
# tests/package-bunfig.test.ts).
[test]
preload = ["../../tests/setup/feedback-archive-off.ts", "../../packages/ui/test-setup/happy-dom.ts"]
6 changes: 6 additions & 0 deletions apps/hook/bunfig.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Bun reads only the bunfig.toml in the directory `bun test` runs from, so the
# root preloads are mirrored here for runs from this package directory. Keep in
# step with the root bunfig.toml [test] section (guarded by
# tests/package-bunfig.test.ts).
[test]
preload = ["../../tests/setup/feedback-archive-off.ts", "../../packages/ui/test-setup/happy-dom.ts"]
6 changes: 6 additions & 0 deletions apps/marketing/bunfig.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Bun reads only the bunfig.toml in the directory `bun test` runs from, so the
# root preloads are mirrored here for runs from this package directory. Keep in
# step with the root bunfig.toml [test] section (guarded by
# tests/package-bunfig.test.ts).
[test]
preload = ["../../tests/setup/feedback-archive-off.ts", "../../packages/ui/test-setup/happy-dom.ts"]
6 changes: 6 additions & 0 deletions apps/opencode-plugin/bunfig.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Bun reads only the bunfig.toml in the directory `bun test` runs from, so the
# root preloads are mirrored here for runs from this package directory. Keep in
# step with the root bunfig.toml [test] section (guarded by
# tests/package-bunfig.test.ts).
[test]
preload = ["../../tests/setup/feedback-archive-off.ts", "../../packages/ui/test-setup/happy-dom.ts"]
6 changes: 6 additions & 0 deletions apps/paste-service/bunfig.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Bun reads only the bunfig.toml in the directory `bun test` runs from, so the
# root preloads are mirrored here for runs from this package directory. Keep in
# step with the root bunfig.toml [test] section (guarded by
# tests/package-bunfig.test.ts).
[test]
preload = ["../../tests/setup/feedback-archive-off.ts", "../../packages/ui/test-setup/happy-dom.ts"]
6 changes: 6 additions & 0 deletions apps/pi-extension/bunfig.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Bun reads only the bunfig.toml in the directory `bun test` runs from, so the
# root preloads are mirrored here for runs from this package directory. Keep in
# step with the root bunfig.toml [test] section (guarded by
# tests/package-bunfig.test.ts).
[test]
preload = ["../../tests/setup/feedback-archive-off.ts", "../../packages/ui/test-setup/happy-dom.ts"]
6 changes: 6 additions & 0 deletions apps/skills/bunfig.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Bun reads only the bunfig.toml in the directory `bun test` runs from, so the
# root preloads are mirrored here for runs from this package directory. Keep in
# step with the root bunfig.toml [test] section (guarded by
# tests/package-bunfig.test.ts).
[test]
preload = ["../../tests/setup/feedback-archive-off.ts", "../../packages/ui/test-setup/happy-dom.ts"]
6 changes: 6 additions & 0 deletions apps/vscode-extension/bunfig.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Bun reads only the bunfig.toml in the directory `bun test` runs from, so the
# root preloads are mirrored here for runs from this package directory. Keep in
# step with the root bunfig.toml [test] section (guarded by
# tests/package-bunfig.test.ts).
[test]
preload = ["../../tests/setup/feedback-archive-off.ts", "../../packages/ui/test-setup/happy-dom.ts"]
6 changes: 6 additions & 0 deletions packages/ai/bunfig.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Bun reads only the bunfig.toml in the directory `bun test` runs from, so the
# root preloads are mirrored here for runs from this package directory. Keep in
# step with the root bunfig.toml [test] section (guarded by
# tests/package-bunfig.test.ts).
[test]
preload = ["../../tests/setup/feedback-archive-off.ts", "../../packages/ui/test-setup/happy-dom.ts"]
6 changes: 6 additions & 0 deletions packages/core/bunfig.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Bun reads only the bunfig.toml in the directory `bun test` runs from, so the
# root preloads are mirrored here for runs from this package directory. Keep in
# step with the root bunfig.toml [test] section (guarded by
# tests/package-bunfig.test.ts).
[test]
preload = ["../../tests/setup/feedback-archive-off.ts", "../../packages/ui/test-setup/happy-dom.ts"]
6 changes: 6 additions & 0 deletions packages/editor/bunfig.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Bun reads only the bunfig.toml in the directory `bun test` runs from, so the
# root preloads are mirrored here for runs from this package directory. Keep in
# step with the root bunfig.toml [test] section (guarded by
# tests/package-bunfig.test.ts).
[test]
preload = ["../../tests/setup/feedback-archive-off.ts", "../../packages/ui/test-setup/happy-dom.ts"]
6 changes: 6 additions & 0 deletions packages/guide-viewer/bunfig.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Bun reads only the bunfig.toml in the directory `bun test` runs from, so the
# root preloads are mirrored here for runs from this package directory. Keep in
# step with the root bunfig.toml [test] section (guarded by
# tests/package-bunfig.test.ts).
[test]
preload = ["../../tests/setup/feedback-archive-off.ts", "../../packages/ui/test-setup/happy-dom.ts"]
6 changes: 6 additions & 0 deletions packages/review-editor/bunfig.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Bun reads only the bunfig.toml in the directory `bun test` runs from, so the
# root preloads are mirrored here for runs from this package directory. Keep in
# step with the root bunfig.toml [test] section (guarded by
# tests/package-bunfig.test.ts).
[test]
preload = ["../../tests/setup/feedback-archive-off.ts", "../../packages/ui/test-setup/happy-dom.ts"]
6 changes: 6 additions & 0 deletions packages/server/bunfig.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Bun reads only the bunfig.toml in the directory `bun test` runs from, so the
# root preloads are mirrored here for runs from this package directory. Keep in
# step with the root bunfig.toml [test] section (guarded by
# tests/package-bunfig.test.ts).
[test]
preload = ["../../tests/setup/feedback-archive-off.ts", "../../packages/ui/test-setup/happy-dom.ts"]
8 changes: 5 additions & 3 deletions packages/server/storage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import { afterEach, describe, expect, test } from "bun:test";
import { mkdtempSync, rmSync, readFileSync, readdirSync } from "node:fs";
import { tmpdir } from "node:os";
import { homedir, tmpdir } from "node:os";
import { join } from "node:path";
import { generateSlug, getPlanDir, savePlan, saveToHistory, getPlanVersion, getVersionCount, listVersions } from "./storage";

Expand Down Expand Up @@ -61,9 +61,11 @@ describe("getPlanDir", () => {
});

test("expands tilde in custom path", () => {
const result = getPlanDir("~/.plannotator/test-plans");
// getPlanDir mkdirs its result, and os.homedir() ignores a HOME override, so
// expand bare "~": the real home already exists and nothing is created in it.
const result = getPlanDir("~");
expect(result).not.toContain("~");
expect(result).toMatch(/\.plannotator\/test-plans$/);
expect(result).toBe(homedir());
});

test("uses default when no custom path", () => {
Expand Down
6 changes: 6 additions & 0 deletions packages/shared/bunfig.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Bun reads only the bunfig.toml in the directory `bun test` runs from, so the
# root preloads are mirrored here for runs from this package directory. Keep in
# step with the root bunfig.toml [test] section (guarded by
# tests/package-bunfig.test.ts).
[test]
preload = ["../../tests/setup/feedback-archive-off.ts", "../../packages/ui/test-setup/happy-dom.ts"]
6 changes: 6 additions & 0 deletions packages/ui/bunfig.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Bun reads only the bunfig.toml in the directory `bun test` runs from, so the
# root preloads are mirrored here for runs from this package directory. Keep in
# step with the root bunfig.toml [test] section (guarded by
# tests/package-bunfig.test.ts).
[test]
preload = ["../../tests/setup/feedback-archive-off.ts", "../../packages/ui/test-setup/happy-dom.ts"]
55 changes: 55 additions & 0 deletions tests/package-bunfig.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { describe, expect, test } from "bun:test";
import { existsSync, readdirSync, readFileSync, statSync } from "node:fs";
import { join, relative, resolve } from "node:path";

/**
* Bun reads only the bunfig.toml in the directory `bun test` runs from. Without
* a package-level copy, `bun test` inside a package skips the root preloads and
* tests write drafts, history, and feedback into the contributor's real
* ~/.plannotator. Catches a package that gains tests without a bunfig, or a
* package bunfig that drifts from the root preload list.
*/
const repoRoot = resolve(import.meta.dir, "..");

function readPreload(bunfigPath: string): string[] {
const parsed = Bun.TOML.parse(readFileSync(bunfigPath, "utf-8")) as {
test?: { preload?: string[] };
};
return parsed.test?.preload ?? [];
}

function hasTestFiles(dir: string): boolean {
for (const entry of readdirSync(dir)) {
if (entry === "node_modules" || entry === "dist" || entry.startsWith(".")) continue;
const full = join(dir, entry);
if (statSync(full).isDirectory()) {
if (hasTestFiles(full)) return true;
} else if (/\.test\.tsx?$/.test(entry)) {
return true;
}
}
return false;
}

const rootPreload = readPreload(join(repoRoot, "bunfig.toml")).map((p) => resolve(repoRoot, p));

const packageDirs = ["apps", "packages"].flatMap((group) =>
readdirSync(join(repoRoot, group))
.map((name) => join(repoRoot, group, name))
.filter((dir) => statSync(dir).isDirectory() && hasTestFiles(dir)),
);

describe("package-directory bunfig.toml", () => {
test("root preload sandboxes the data dir", () => {
expect(rootPreload).toContain(resolve(repoRoot, "tests/setup/feedback-archive-off.ts"));
});

for (const dir of packageDirs) {
const label = relative(repoRoot, dir);
test(`${label} mirrors the root test preloads`, () => {
const bunfig = join(dir, "bunfig.toml");
expect(existsSync(bunfig)).toBe(true);
expect(readPreload(bunfig).map((p) => resolve(dir, p))).toEqual(rootPreload);
});
}
});
Loading