bun.test.ts 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import { describe, expect, test } from "bun:test"
  2. import fs from "fs/promises"
  3. import path from "path"
  4. describe("BunProc registry configuration", () => {
  5. test("should not contain hardcoded registry parameters", async () => {
  6. // Read the bun/index.ts file
  7. const bunIndexPath = path.join(__dirname, "../src/bun/index.ts")
  8. const content = await fs.readFile(bunIndexPath, "utf-8")
  9. // Verify that no hardcoded registry is present
  10. expect(content).not.toContain("--registry=")
  11. expect(content).not.toContain("hasNpmRcConfig")
  12. expect(content).not.toContain("NpmRc")
  13. })
  14. test("should use Bun's default registry resolution", async () => {
  15. // Read the bun/index.ts file
  16. const bunIndexPath = path.join(__dirname, "../src/bun/index.ts")
  17. const content = await fs.readFile(bunIndexPath, "utf-8")
  18. // Verify that it uses Bun's default resolution
  19. expect(content).toContain("Bun's default registry resolution")
  20. expect(content).toContain("Bun will use them automatically")
  21. expect(content).toContain("No need to pass --registry flag")
  22. })
  23. test("should have correct command structure without registry", async () => {
  24. // Read the bun/index.ts file
  25. const bunIndexPath = path.join(__dirname, "../src/bun/index.ts")
  26. const content = await fs.readFile(bunIndexPath, "utf-8")
  27. // Extract the install function
  28. const installFunctionMatch = content.match(/export async function install[\s\S]*?^ }/m)
  29. expect(installFunctionMatch).toBeTruthy()
  30. if (installFunctionMatch) {
  31. const installFunction = installFunctionMatch[0]
  32. // Verify expected arguments are present
  33. expect(installFunction).toContain('"add"')
  34. expect(installFunction).toContain('"--force"')
  35. expect(installFunction).toContain('"--exact"')
  36. expect(installFunction).toContain('"--cwd"')
  37. expect(installFunction).toContain("Global.Path.cache")
  38. expect(installFunction).toContain('pkg + "@" + version')
  39. // Verify no registry argument is added
  40. expect(installFunction).not.toContain('"--registry"')
  41. expect(installFunction).not.toContain('args.push("--registry')
  42. }
  43. })
  44. })