UNPKG

@sentry/wizard

Version:

Sentry wizard helping you to configure your project

269 lines 13 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; Object.defineProperty(exports, "__esModule", { value: true }); const Sentry = __importStar(require("@sentry/node")); const fs = __importStar(require("fs")); const os = __importStar(require("os")); const path = __importStar(require("path")); const cocoapod_1 = require("../../src/apple/cocoapod"); const bash = __importStar(require("../../src/utils/bash")); // @ts-expect-error - clack is ESM and TS complains about that. It works though const clack = __importStar(require("@clack/prompts")); const vitest_1 = require("vitest"); vitest_1.vi.mock('@clack/prompts', async () => ({ __esModule: true, ...(await vitest_1.vi.importActual('@clack/prompts')), })); vitest_1.vi.mock('../../src/utils/bash'); vitest_1.vi.spyOn(Sentry, 'setTag').mockImplementation(() => { /* empty */ }); vitest_1.vi.spyOn(Sentry, 'captureException').mockImplementation(() => 'id'); const clackSpinnerMock = { start: vitest_1.vi.fn(), stop: vitest_1.vi.fn(), message: vitest_1.vi.fn(), }; (0, vitest_1.describe)('cocoapod', () => { (0, vitest_1.beforeEach)(() => { vitest_1.vi.spyOn(clack, 'spinner').mockReturnValue(clackSpinnerMock); vitest_1.vi.spyOn(clack.log, 'error').mockImplementation(() => { /* empty */ }); }); (0, vitest_1.afterEach)(() => { vitest_1.vi.clearAllMocks(); }); (0, vitest_1.describe)('usesCocoaPod', () => { (0, vitest_1.describe)('Podfile exists', () => { (0, vitest_1.it)('should return true', () => { // -- Arrange -- const projPath = path.join(os.tmpdir(), 'test-project-with-podfile'); const tempDir = fs.mkdtempSync(projPath); const podfile = path.join(tempDir, 'Podfile'); fs.writeFileSync(podfile, ''); // -- Act -- const result = (0, cocoapod_1.usesCocoaPod)(tempDir); // -- Assert -- (0, vitest_1.expect)(result).toBeTruthy(); }); }); (0, vitest_1.describe)('Podfile does not exist', () => { (0, vitest_1.it)('should return false', () => { // -- Arrange -- const projPath = path.join(os.tmpdir(), 'test-project-without-podfile'); const tempDir = fs.mkdtempSync(projPath); // -- Act -- const result = (0, cocoapod_1.usesCocoaPod)(tempDir); // -- Assert -- (0, vitest_1.expect)(result).toBeFalsy(); }); }); }); (0, vitest_1.describe)('addCocoaPods', () => { (0, vitest_1.describe)('Podfile does not exist', () => { (0, vitest_1.it)('should throw an error', async () => { // -- Arrange -- const projPath = path.join(os.tmpdir(), 'test-project-without-podfile'); const tempDir = fs.mkdtempSync(projPath); // -- Act & Assert -- await (0, vitest_1.expect)((0, cocoapod_1.addCocoaPods)(tempDir)).rejects.toThrow('ENOENT: no such file or directory, open'); }); }); (0, vitest_1.describe)('Podfile exists', () => { (0, vitest_1.describe)('Podfile includes Sentry pod', () => { const variations = [ { case: 'simple', content: 'pod "Sentry"', }, { case: 'with-swiftui', content: 'pod "SentrySwiftUI"', }, { case: 'leading-space', content: ' pod "Sentry"', }, { case: 'leading-space-and-swiftui', content: ' pod "SentrySwiftUI"', }, { case: 'trailing-space', content: 'pod "Sentry" ', }, { case: 'trailing-space-and-swiftui', content: 'pod "SentrySwiftUI" ', }, { case: 'single-quotes', content: "pod 'Sentry'", }, { case: 'double-quotes', content: 'pod "Sentry"', }, ]; for (const variation of variations) { (0, vitest_1.it)(`should not change the Podfile for ${variation.case}`, async () => { // -- Arrange -- const projPath = fs.mkdtempSync(path.join(os.tmpdir(), 'project')); fs.mkdirSync(projPath, { recursive: true, }); const podfile = path.join(projPath, 'Podfile'); fs.writeFileSync(podfile, variation.content, 'utf8'); // -- Act -- const result = await (0, cocoapod_1.addCocoaPods)(projPath); // -- Assert -- (0, vitest_1.expect)(result).toBeTruthy(); (0, vitest_1.expect)(fs.readFileSync(podfile, 'utf8')).toBe(variation.content); }); } }); (0, vitest_1.describe)('Podfile includes no other pods', () => { (0, vitest_1.describe)('Podfile does not include use_frameworks!', () => { (0, vitest_1.it)('should not change the Podfile', async () => { // -- Arrange -- const projPath = fs.mkdtempSync(path.join(os.tmpdir(), 'project')); fs.mkdirSync(projPath, { recursive: true, }); const podfile = path.join(projPath, 'Podfile'); fs.writeFileSync(podfile, '', 'utf8'); // -- Act -- const result = await (0, cocoapod_1.addCocoaPods)(projPath); // -- Assert -- (0, vitest_1.expect)(result).toBeFalsy(); (0, vitest_1.expect)(fs.readFileSync(podfile, 'utf8')).toBe(''); }); }); (0, vitest_1.describe)('Podfile includes use_frameworks!', () => { (0, vitest_1.it)('should change the Podfile', async () => { // -- Arrange -- const projPath = fs.mkdtempSync(path.join(os.tmpdir(), 'project')); fs.mkdirSync(projPath, { recursive: true, }); const podfile = path.join(projPath, 'Podfile'); fs.writeFileSync(podfile, `use_frameworks!`, 'utf8'); // -- Act -- const result = await (0, cocoapod_1.addCocoaPods)(projPath); // -- Assert -- (0, vitest_1.expect)(result).toBeTruthy(); (0, vitest_1.expect)(fs.readFileSync(podfile, 'utf8')).toBe(`use_frameworks!\npod 'Sentry'\n`); }); }); }); (0, vitest_1.describe)('Podfile includes other pods', () => { (0, vitest_1.it)('should append Sentry pod after last pod', async () => { // -- Arrange -- const projPath = fs.mkdtempSync(path.join(os.tmpdir(), 'project')); fs.mkdirSync(projPath, { recursive: true, }); const podfile = path.join(projPath, 'Podfile'); fs.writeFileSync(podfile, 'pod "OtherPod"', 'utf8'); // -- Act -- const result = await (0, cocoapod_1.addCocoaPods)(projPath); // -- Assert -- (0, vitest_1.expect)(result).toBeTruthy(); (0, vitest_1.expect)(fs.readFileSync(podfile, 'utf8')).toBe(`pod "OtherPod"\npod 'Sentry'\n`); }); }); }); }); (0, vitest_1.describe)('podInstall', () => { let workDir; (0, vitest_1.beforeEach)(() => { workDir = path.join(os.tmpdir(), 'test-project'); }); (0, vitest_1.describe)('any bash scripts fail', () => { (0, vitest_1.beforeEach)(() => { vitest_1.vi.spyOn(bash, 'execute').mockRejectedValue(new Error('test error')); }); (0, vitest_1.it)('should not throw an error', async () => { // -- Act & Assert -- await (0, vitest_1.expect)((0, cocoapod_1.podInstall)(workDir)).resolves.not.toThrow(); }); (0, vitest_1.it)('should set tag', async () => { // -- Act -- await (0, cocoapod_1.podInstall)(workDir); // -- Assert -- (0, vitest_1.expect)(Sentry.setTag).toHaveBeenCalledWith('pods-installed', false); }); (0, vitest_1.it)('should capture exception', async () => { // -- Act -- await (0, cocoapod_1.podInstall)(workDir); // -- Assert -- (0, vitest_1.expect)(Sentry.captureException).toHaveBeenCalledWith('Sentry pod install failed.'); }); (0, vitest_1.it)('should start and stop spinner', async () => { // -- Act -- await (0, cocoapod_1.podInstall)(workDir); // -- Assert -- (0, vitest_1.expect)(clackSpinnerMock.start).toHaveBeenCalledWith("Running 'pod install'. This may take a few minutes..."); (0, vitest_1.expect)(clackSpinnerMock.stop).toHaveBeenCalledWith('Failed to install pods.'); }); }); (0, vitest_1.describe)('all bash scripts work', () => { (0, vitest_1.beforeEach)(() => { vitest_1.vi.spyOn(bash, 'execute').mockResolvedValue(''); }); (0, vitest_1.it)('should call pod update and install', async () => { // -- Act -- await (0, cocoapod_1.podInstall)(workDir); // -- Assert -- (0, vitest_1.expect)(bash.execute).toHaveBeenCalledWith(`cd ${workDir} && pod repo update`); (0, vitest_1.expect)(bash.execute).toHaveBeenCalledWith(`cd ${workDir} && pod install --silent`); }); (0, vitest_1.it)('should set tag', async () => { // -- Act -- await (0, cocoapod_1.podInstall)(workDir); // -- Assert -- (0, vitest_1.expect)(Sentry.setTag).toHaveBeenCalledWith('pods-installed', true); }); (0, vitest_1.it)('should start and stop spinner', async () => { // -- Act -- await (0, cocoapod_1.podInstall)(workDir); // -- Assert -- (0, vitest_1.expect)(clackSpinnerMock.start).toHaveBeenCalledWith("Running 'pod install'. This may take a few minutes..."); (0, vitest_1.expect)(clackSpinnerMock.stop).toHaveBeenCalledWith('Pods installed.'); }); }); (0, vitest_1.describe)('dir not given', () => { (0, vitest_1.it)('should use current directory', async () => { // -- Act -- await (0, cocoapod_1.podInstall)(); // -- Assert -- (0, vitest_1.expect)(bash.execute).toHaveBeenCalledWith(`cd . && pod repo update`); (0, vitest_1.expect)(bash.execute).toHaveBeenCalledWith(`cd . && pod install --silent`); }); }); }); }); //# sourceMappingURL=cocoapod.test.js.map