// src/__tests__/plugin.test.ts import fs from 'fs' import os from 'os' import path from 'path' const withDangerousMod = jest.fn( (config: any, [platform, action]: [string, Function]) => { config.__mods = config.__mods ?? [] config.__mods.push({ platform, action }) return config } ) jest.mock('@expo/config-plugins', () => ({ withDangerousMod: (...a: unknown[]) => (withDangerousMod as any)(...a), })) import withNitroChucker, { editPackageJson } from '../plugin' import { PACKAGE_NAME } from '../plugin/applyExclusion' describe('withNitroChucker', () => { beforeEach(() => jest.clearAllMocks()) it('registers a dangerous mod for ios and android', () => { const config: any = withNitroChucker({ name: 'app' } as any, { enabled: false, }) expect(config.__mods.map((m: any) => m.platform).sort()).toEqual([ 'android', 'ios', ]) }) }) describe('editPackageJson', () => { let dir: string let pkgPath: string beforeEach(() => { dir = fs.mkdtempSync(path.join(os.tmpdir(), 'nc-')) pkgPath = path.join(dir, 'package.json') fs.writeFileSync(pkgPath, JSON.stringify({ name: 'app', version: '1.0.0' })) }) afterEach(() => fs.rmSync(dir, { recursive: true, force: true })) it('writes the exclusion when enabled is false', () => { editPackageJson(dir, { enabled: false }) const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8')) expect(pkg.expo.autolinking.exclude).toContain(PACKAGE_NAME) }) it('does not rewrite the file when nothing changes', () => { const before = fs.readFileSync(pkgPath, 'utf8') editPackageJson(dir, { enabled: true }) // include = no-op on a clean file expect(fs.readFileSync(pkgPath, 'utf8')).toBe(before) }) it('round-trips false then true back to the original content', () => { editPackageJson(dir, { enabled: false }) editPackageJson(dir, { enabled: true }) const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8')) expect(pkg).toEqual({ name: 'app', version: '1.0.0' }) }) })