profile-resolution-worker-bootstrap.spec.ts 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /** Worker bootstrap installs only the generation inherited from its parent. */
  2. import { beforeEach, expect, it, vi } from 'vitest'
  3. import type { ProfileResolutionGeneration } from '../src/profile.ts'
  4. const harness = vi.hoisted(() => ({
  5. data: undefined as {
  6. generation: ProfileResolutionGeneration
  7. behavior: 'enforce' | 'verify'
  8. } | undefined,
  9. install: vi.fn(),
  10. }))
  11. vi.mock('node:worker_threads', () => ({
  12. getEnvironmentData: () => harness.data,
  13. }))
  14. vi.mock('../src/profile-resolution/resolver.ts', () => ({
  15. installProfileResolution: harness.install,
  16. }))
  17. beforeEach(() => {
  18. harness.data = undefined
  19. harness.install.mockReset()
  20. vi.resetModules()
  21. })
  22. it('does nothing without inherited profile resolution data', async () => {
  23. await import('../src/profile-resolution/worker-bootstrap.ts')
  24. expect(harness.install).not.toHaveBeenCalled()
  25. })
  26. it('installs the inherited generation and behavior', async () => {
  27. const generation: ProfileResolutionGeneration = {
  28. profilesDir: '/profiles',
  29. profileDir: '/profiles/test',
  30. localPackageNames: [],
  31. entries: [],
  32. }
  33. harness.data = { generation, behavior: 'verify' }
  34. await import('../src/profile-resolution/worker-bootstrap.ts')
  35. expect(harness.install).toHaveBeenCalledWith(generation, 'verify')
  36. })