|
| 1 | +import { describe, expect, test } from "bun:test" |
| 2 | +import { existsSync, readFileSync } from "fs" |
| 3 | +import { join } from "path" |
| 4 | + |
| 5 | +const packagePath = join(process.cwd(), "package.json") |
| 6 | +const releaseWorkflowPath = join(process.cwd(), ".github", "workflows", "publish.yml") |
| 7 | + |
| 8 | +type PackageJson = { |
| 9 | + main?: string |
| 10 | + types?: string |
| 11 | + exports?: unknown |
| 12 | + files?: string[] |
| 13 | + scripts?: Record<string, string> |
| 14 | +} |
| 15 | + |
| 16 | +describe("package publish config", () => { |
| 17 | + test("publishes compiled entrypoints from dist and builds before packing", () => { |
| 18 | + expect(existsSync(packagePath)).toBe(true) |
| 19 | + |
| 20 | + const pkg = JSON.parse(readFileSync(packagePath, "utf-8")) as PackageJson |
| 21 | + |
| 22 | + expect(pkg.main).toBe("dist/index.js") |
| 23 | + expect(pkg.types).toBe("dist/index.d.ts") |
| 24 | + expect(pkg.exports).toEqual({ |
| 25 | + ".": { |
| 26 | + types: "./dist/index.d.ts", |
| 27 | + import: "./dist/index.js", |
| 28 | + default: "./dist/index.js", |
| 29 | + }, |
| 30 | + }) |
| 31 | + expect(pkg.files).toEqual(["dist"]) |
| 32 | + expect(pkg.scripts?.build).toBe("tsc -p tsconfig.json") |
| 33 | + expect(pkg.scripts?.prepack).toBe("npm run build") |
| 34 | + }) |
| 35 | + |
| 36 | + test("installs dependencies before semantic-release publishes", () => { |
| 37 | + expect(existsSync(releaseWorkflowPath)).toBe(true) |
| 38 | + |
| 39 | + const workflow = readFileSync(releaseWorkflowPath, "utf-8") |
| 40 | + |
| 41 | + expect(workflow).toContain("oven-sh/setup-bun") |
| 42 | + expect(workflow).toContain("bun install") |
| 43 | + expect(workflow).toContain("npx semantic-release@25") |
| 44 | + }) |
| 45 | +}) |
0 commit comments