-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathinit.test.ts
More file actions
30 lines (26 loc) · 935 Bytes
/
Copy pathinit.test.ts
File metadata and controls
30 lines (26 loc) · 935 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { beforeEach, afterEach, test, expect } from "bun:test"
import fs from "fs"
import os from "os"
import path from "path"
import { initPgstrap } from "../src/init"
let testDir: string
beforeEach(() => {
testDir = fs.mkdtempSync(path.join(os.tmpdir(), "pgstrap-test-"))
fs.writeFileSync(
path.join(testDir, "package.json"),
JSON.stringify({ name: "some-package" }),
)
})
afterEach(() => {
fs.rmSync(testDir, { recursive: true, force: true })
})
test("initPgstrap writes scripts to package.json", async () => {
await initPgstrap({ cwd: testDir })
const pkg = JSON.parse(
fs.readFileSync(path.join(testDir, "package.json"), "utf8"),
)
expect(pkg.scripts["db:migrate"]).toBe("pgstrap migrate")
expect(pkg.scripts["db:reset"]).toBe("pgstrap reset")
expect(pkg.scripts["db:generate"]).toBe("pgstrap generate --pglite")
expect(pkg.scripts["db:create-migration"]).toBe("pgstrap create-migration")
})