|
1 | | -import { join } from "node:path"; |
2 | | -import { describe, expect, test } from "bun:test"; |
| 1 | +import { mkdir, rm, writeFile } from "node:fs/promises"; |
| 2 | +import { join, resolve } from "node:path"; |
| 3 | +import { tmpdir } from "node:os"; |
| 4 | +import { describe, expect, test, afterEach } from "bun:test"; |
3 | 5 |
|
4 | 6 | const CLI_PATH = join(import.meta.dir, "../../src/cli.ts"); |
5 | 7 | const FIXTURE_PATH = join(import.meta.dir, "../fixtures/sample-project"); |
@@ -114,4 +116,36 @@ describe("cli", () => { |
114 | 116 | expect(result.stderr).toContain("Unknown bundle: unknown"); |
115 | 117 | }); |
116 | 118 | }); |
| 119 | + |
| 120 | + describe("absolute outDir with custom root", () => { |
| 121 | + const tempRoot = join(tmpdir(), `srcpack-test-${Date.now()}`); |
| 122 | + const tempOutDir = join(tmpdir(), `srcpack-out-${Date.now()}`); |
| 123 | + |
| 124 | + afterEach(async () => { |
| 125 | + await rm(tempRoot, { recursive: true, force: true }); |
| 126 | + await rm(tempOutDir, { recursive: true, force: true }); |
| 127 | + }); |
| 128 | + |
| 129 | + test("should write to absolute outDir when root is also specified", async () => { |
| 130 | + // Setup: create temp project with config using absolute outDir |
| 131 | + await mkdir(join(tempRoot, "src"), { recursive: true }); |
| 132 | + await writeFile(join(tempRoot, "src/index.ts"), "export const x = 1;"); |
| 133 | + await writeFile( |
| 134 | + join(tempRoot, "srcpack.config.ts"), |
| 135 | + `export default { |
| 136 | + outDir: ${JSON.stringify(tempOutDir)}, |
| 137 | + bundles: { app: "src/**/*" }, |
| 138 | + };`, |
| 139 | + ); |
| 140 | + |
| 141 | + const result = await runCli([], { cwd: tempRoot }); |
| 142 | + |
| 143 | + expect(result.exitCode).toBe(0); |
| 144 | + expect(result.stdout).toContain("app"); |
| 145 | + |
| 146 | + // Verify file was written to absolute outDir, not joined with root |
| 147 | + const outFile = Bun.file(join(tempOutDir, "app.txt")); |
| 148 | + expect(await outFile.exists()).toBe(true); |
| 149 | + }); |
| 150 | + }); |
117 | 151 | }); |
0 commit comments