@sentry/wizard
Version:
Sentry wizard helping you to configure your project
161 lines • 8.02 kB
JavaScript
;
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;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
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 = __importStar(require("../../src/apple/cocoapod"));
const configure_package_manager_1 = require("../../src/apple/configure-package-manager");
// @ts-expect-error - clack is ESM and TS complains about that. It works though
const prompts_1 = __importDefault(require("@clack/prompts"));
const vitest_1 = require("vitest");
vitest_1.vi.mock('@clack/prompts', () => ({
__esModule: true,
default: {
log: {
warn: vitest_1.vi.fn(),
step: vitest_1.vi.fn(),
},
select: vitest_1.vi.fn(),
},
}));
vitest_1.vi.mock('../../src/apple/cocoapod');
vitest_1.vi.mock('../../src/utils/clack', () => ({
abortIfCancelled: vitest_1.vi.fn((value) => Promise.resolve(value)),
}));
vitest_1.vi.mock('../../src/telemetry', () => ({
traceStep: vitest_1.vi.fn(async (_name, fn) => await fn()),
}));
vitest_1.vi.mock('../../src/utils/debug', () => ({
debug: vitest_1.vi.fn(),
}));
vitest_1.vi.mock('@sentry/node', async () => {
const actual = await vitest_1.vi.importActual('@sentry/node');
return {
...actual,
setTag: vitest_1.vi.fn(),
captureException: vitest_1.vi.fn(() => 'id'),
};
});
(0, vitest_1.describe)('configurePackageManager', () => {
let projectDir;
(0, vitest_1.beforeEach)(() => {
projectDir = fs.mkdtempSync(path.join(os.tmpdir(), 'test-project'));
vitest_1.vi.clearAllMocks();
});
(0, vitest_1.afterEach)(() => {
vitest_1.vi.clearAllMocks();
});
(0, vitest_1.describe)('when CocoaPods is not available', () => {
(0, vitest_1.it)('should default to SPM and not prompt user', async () => {
// -- Arrange --
vitest_1.vi.spyOn(cocoapod, 'usesCocoaPod').mockReturnValue(false);
// -- Act --
const result = await (0, configure_package_manager_1.configurePackageManager)({ projectDir });
// -- Assert --
(0, vitest_1.expect)(result.shouldUseSPM).toBe(true);
(0, vitest_1.expect)(prompts_1.default.select).not.toHaveBeenCalled();
(0, vitest_1.expect)(prompts_1.default.log.warn).not.toHaveBeenCalled();
(0, vitest_1.expect)(Sentry.setTag).toHaveBeenCalledWith('cocoapod-exists', false);
(0, vitest_1.expect)(Sentry.setTag).toHaveBeenCalledWith('package-manager', 'SPM');
});
});
(0, vitest_1.describe)('when CocoaPods is available', () => {
(0, vitest_1.beforeEach)(() => {
vitest_1.vi.spyOn(cocoapod, 'usesCocoaPod').mockReturnValue(true);
});
(0, vitest_1.it)('should show deprecation warning', async () => {
// -- Arrange --
vitest_1.vi.mocked(prompts_1.default.select).mockResolvedValue('SPM');
// -- Act --
await (0, configure_package_manager_1.configurePackageManager)({ projectDir });
// -- Assert --
(0, vitest_1.expect)(prompts_1.default.log.warn).toHaveBeenCalledWith('CocoaPods is being deprecated. No new updates will be released after June 2026.\nWe recommend migrating to Swift Package Manager (SPM).');
});
(0, vitest_1.it)('should prompt user to choose package manager', async () => {
// -- Arrange --
vitest_1.vi.mocked(prompts_1.default.select).mockResolvedValue('SPM');
// -- Act --
await (0, configure_package_manager_1.configurePackageManager)({ projectDir });
// -- Assert --
(0, vitest_1.expect)(prompts_1.default.select).toHaveBeenCalledWith({
message: 'Which package manager would you like to use to add Sentry?',
options: [
{
value: 'SPM',
label: 'Swift Package Manager',
hint: 'Recommended',
},
{
value: 'CocoaPods',
label: 'CocoaPods',
hint: 'Deprecated - no updates after June 2026',
},
],
});
});
(0, vitest_1.it)('should use SPM when user selects SPM', async () => {
// -- Arrange --
vitest_1.vi.mocked(prompts_1.default.select).mockResolvedValue('SPM');
// -- Act --
const result = await (0, configure_package_manager_1.configurePackageManager)({ projectDir });
// -- Assert --
(0, vitest_1.expect)(result.shouldUseSPM).toBe(true);
(0, vitest_1.expect)(cocoapod.addCocoaPods).not.toHaveBeenCalled();
(0, vitest_1.expect)(Sentry.setTag).toHaveBeenCalledWith('cocoapod-exists', true);
(0, vitest_1.expect)(Sentry.setTag).toHaveBeenCalledWith('package-manager', 'SPM');
});
(0, vitest_1.it)('should use CocoaPods when user selects CocoaPods', async () => {
// -- Arrange --
vitest_1.vi.mocked(prompts_1.default.select).mockResolvedValue('CocoaPods');
vitest_1.vi.spyOn(cocoapod, 'addCocoaPods').mockResolvedValue(true);
// -- Act --
const result = await (0, configure_package_manager_1.configurePackageManager)({ projectDir });
// -- Assert --
(0, vitest_1.expect)(result.shouldUseSPM).toBe(false);
(0, vitest_1.expect)(cocoapod.addCocoaPods).toHaveBeenCalledWith(projectDir);
(0, vitest_1.expect)(Sentry.setTag).toHaveBeenCalledWith('cocoapod-exists', true);
(0, vitest_1.expect)(Sentry.setTag).toHaveBeenCalledWith('cocoapod-added', true);
(0, vitest_1.expect)(Sentry.setTag).toHaveBeenCalledWith('package-manager', 'CocoaPods');
});
(0, vitest_1.it)('should handle CocoaPods addition failure', async () => {
// -- Arrange --
vitest_1.vi.mocked(prompts_1.default.select).mockResolvedValue('CocoaPods');
vitest_1.vi.spyOn(cocoapod, 'addCocoaPods').mockResolvedValue(false);
// -- Act --
const result = await (0, configure_package_manager_1.configurePackageManager)({ projectDir });
// -- Assert --
(0, vitest_1.expect)(result.shouldUseSPM).toBe(false);
(0, vitest_1.expect)(cocoapod.addCocoaPods).toHaveBeenCalledWith(projectDir);
(0, vitest_1.expect)(Sentry.setTag).toHaveBeenCalledWith('cocoapod-added', false);
(0, vitest_1.expect)(Sentry.setTag).toHaveBeenCalledWith('package-manager', 'CocoaPods');
});
});
});
//# sourceMappingURL=configure-package-manager.test.js.map