|
| 1 | +import { vol } from 'memfs'; |
| 2 | + |
| 3 | +import { ensureLockfileExistsAsync } from '../validateLockfile'; |
| 4 | + |
| 5 | +jest.mock('fs'); |
| 6 | + |
| 7 | +const mockResolveWorkspaceRoot = jest.fn(); |
| 8 | +jest.mock('@expo/package-manager', () => { |
| 9 | + const actual = jest.requireActual('@expo/package-manager'); |
| 10 | + return { |
| 11 | + ...actual, |
| 12 | + resolveWorkspaceRoot: (...args: unknown[]) => mockResolveWorkspaceRoot(...args), |
| 13 | + }; |
| 14 | +}); |
| 15 | + |
| 16 | +beforeEach(() => { |
| 17 | + vol.reset(); |
| 18 | + mockResolveWorkspaceRoot.mockReturnValue(null); |
| 19 | +}); |
| 20 | + |
| 21 | +describe(ensureLockfileExistsAsync, () => { |
| 22 | + it('passes when package-lock.json exists', async () => { |
| 23 | + vol.fromJSON({ './package-lock.json': '' }, '/app'); |
| 24 | + await expect(ensureLockfileExistsAsync('/app')).resolves.not.toThrow(); |
| 25 | + }); |
| 26 | + |
| 27 | + it('passes when yarn.lock exists', async () => { |
| 28 | + vol.fromJSON({ './yarn.lock': '' }, '/app'); |
| 29 | + await expect(ensureLockfileExistsAsync('/app')).resolves.not.toThrow(); |
| 30 | + }); |
| 31 | + |
| 32 | + it('passes when pnpm-lock.yaml exists', async () => { |
| 33 | + vol.fromJSON({ './pnpm-lock.yaml': '' }, '/app'); |
| 34 | + await expect(ensureLockfileExistsAsync('/app')).resolves.not.toThrow(); |
| 35 | + }); |
| 36 | + |
| 37 | + it('passes when bun.lockb exists', async () => { |
| 38 | + vol.fromJSON({ './bun.lockb': '' }, '/app'); |
| 39 | + await expect(ensureLockfileExistsAsync('/app')).resolves.not.toThrow(); |
| 40 | + }); |
| 41 | + |
| 42 | + it('passes when bun.lock exists', async () => { |
| 43 | + vol.fromJSON({ './bun.lock': '' }, '/app'); |
| 44 | + await expect(ensureLockfileExistsAsync('/app')).resolves.not.toThrow(); |
| 45 | + }); |
| 46 | + |
| 47 | + it('throws when no lockfile exists', async () => { |
| 48 | + vol.fromJSON({ './package.json': '{}' }, '/app'); |
| 49 | + await expect(ensureLockfileExistsAsync('/app')).rejects.toThrow( |
| 50 | + 'No lockfile found in the project directory.' |
| 51 | + ); |
| 52 | + }); |
| 53 | + |
| 54 | + it('passes when lockfile exists in workspace root', async () => { |
| 55 | + vol.fromJSON( |
| 56 | + { |
| 57 | + './packages/my-app/package.json': '{}', |
| 58 | + './yarn.lock': '', |
| 59 | + }, |
| 60 | + '/monorepo' |
| 61 | + ); |
| 62 | + mockResolveWorkspaceRoot.mockReturnValue('/monorepo'); |
| 63 | + await expect( |
| 64 | + ensureLockfileExistsAsync('/monorepo/packages/my-app') |
| 65 | + ).resolves.not.toThrow(); |
| 66 | + }); |
| 67 | + |
| 68 | + it('throws when no lockfile in project dir or workspace root', async () => { |
| 69 | + vol.fromJSON( |
| 70 | + { |
| 71 | + './packages/my-app/package.json': '{}', |
| 72 | + './package.json': '{}', |
| 73 | + }, |
| 74 | + '/monorepo' |
| 75 | + ); |
| 76 | + mockResolveWorkspaceRoot.mockReturnValue('/monorepo'); |
| 77 | + await expect(ensureLockfileExistsAsync('/monorepo/packages/my-app')).rejects.toThrow( |
| 78 | + 'No lockfile found in the project directory.' |
| 79 | + ); |
| 80 | + }); |
| 81 | +}); |
0 commit comments