@sentry/wizard
Version:
Sentry wizard helping you to configure your project
218 lines • 11.3 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;
};
Object.defineProperty(exports, "__esModule", { value: true });
const vitest_1 = require("vitest");
const expo_1 = require("../../src/react-native/expo");
const fs = __importStar(require("fs"));
const git = __importStar(require("../../src/react-native/git"));
// Mock modules
vitest_1.vi.mock('fs');
vitest_1.vi.mock('../../src/react-native/git');
(0, vitest_1.describe)('expo', () => {
const MOCK_CONFIG = {
url: 'https://sentry.mock/',
org: 'sentry-mock',
project: 'project-mock',
authToken: 'authToken-mock',
};
(0, vitest_1.beforeEach)(() => {
vitest_1.vi.clearAllMocks();
});
(0, vitest_1.afterEach)(() => {
vitest_1.vi.restoreAllMocks();
});
(0, vitest_1.describe)('addWithSentryToAppConfigJson', () => {
(0, vitest_1.test)('do not add if sentry-expo present', () => {
const appConfigJson = `{
"expo": {
"plugins": ["sentry-expo"]
}
}`;
(0, vitest_1.expect)((0, expo_1.addWithSentryToAppConfigJson)(appConfigJson, MOCK_CONFIG)).toBeNull();
});
(0, vitest_1.test)('do not add if sentry-react-native/expo present', () => {
const appConfigJson = `{
"expo": {
"plugins": ["@sentry/react-native/expo"]
}
}`;
(0, vitest_1.expect)((0, expo_1.addWithSentryToAppConfigJson)(appConfigJson, MOCK_CONFIG)).toBeNull();
});
vitest_1.test.each([
[
`{
"expo": {
"plugins": "should be an array, but it is not"
}
}`,
],
[
`{
"expo": ["should be an object, but it is not"]
}`,
],
])('do not add if plugins is not an array', (appConfigJson) => {
(0, vitest_1.expect)((0, expo_1.addWithSentryToAppConfigJson)(appConfigJson, MOCK_CONFIG)).toBeNull();
});
vitest_1.test.each([
[
`{
"expo": {
"plugins": []
}
}`,
],
[`{}`],
[
`{
"expo": {}
}`,
],
])('add sentry react native expo plugin configuration', (appConfigJson) => {
const result = (0, expo_1.addWithSentryToAppConfigJson)(appConfigJson, MOCK_CONFIG);
(0, vitest_1.expect)(JSON.parse(result ?? '{}')).toStrictEqual({
expo: {
plugins: [
[
'@sentry/react-native/expo',
{
url: 'https://sentry.mock/',
organization: 'sentry-mock',
project: 'project-mock',
},
],
],
},
});
});
});
(0, vitest_1.describe)('isExpoCNG', () => {
(0, vitest_1.test)('returns true when neither ios nor android folders exist', async () => {
vitest_1.vi.mocked(fs.existsSync).mockReturnValue(false);
const result = await (0, expo_1.isExpoCNG)();
(0, vitest_1.expect)(result).toBe(true);
// Should check for ios folder existence
(0, vitest_1.expect)(fs.existsSync).toHaveBeenCalled();
// Should not check gitignore if folders don't exist
(0, vitest_1.expect)(git.isFolderInGitignore).not.toHaveBeenCalled();
});
(0, vitest_1.test)('returns true when only ios exists and is in gitignore (android considered ignored)', async () => {
vitest_1.vi.mocked(fs.existsSync).mockImplementation((path) => path === 'ios');
vitest_1.vi.mocked(git.isFolderInGitignore).mockResolvedValue(true);
const result = await (0, expo_1.isExpoCNG)();
(0, vitest_1.expect)(result).toBe(true);
// Should only check ios since android doesn't exist (auto-resolves to true)
(0, vitest_1.expect)(git.isFolderInGitignore).toHaveBeenCalledTimes(1);
(0, vitest_1.expect)(git.isFolderInGitignore).toHaveBeenCalledWith('ios');
});
(0, vitest_1.test)('returns true when only android exists and is in gitignore (ios considered ignored)', async () => {
vitest_1.vi.mocked(fs.existsSync).mockImplementation((path) => path === 'android');
vitest_1.vi.mocked(git.isFolderInGitignore).mockResolvedValue(true);
const result = await (0, expo_1.isExpoCNG)();
(0, vitest_1.expect)(result).toBe(true);
// Should only check android since ios doesn't exist (auto-resolves to true)
(0, vitest_1.expect)(git.isFolderInGitignore).toHaveBeenCalledTimes(1);
(0, vitest_1.expect)(git.isFolderInGitignore).toHaveBeenCalledWith('android');
});
(0, vitest_1.test)('returns false when only ios exists but is NOT in gitignore', async () => {
vitest_1.vi.mocked(fs.existsSync).mockImplementation((path) => path === 'ios');
vitest_1.vi.mocked(git.isFolderInGitignore).mockResolvedValue(false);
const result = await (0, expo_1.isExpoCNG)();
(0, vitest_1.expect)(result).toBe(false);
(0, vitest_1.expect)(git.isFolderInGitignore).toHaveBeenCalledTimes(1);
(0, vitest_1.expect)(git.isFolderInGitignore).toHaveBeenCalledWith('ios');
});
(0, vitest_1.test)('returns true when both folders exist AND both are in gitignore', async () => {
vitest_1.vi.mocked(fs.existsSync).mockReturnValue(true);
vitest_1.vi.mocked(git.isFolderInGitignore).mockResolvedValue(true);
const result = await (0, expo_1.isExpoCNG)();
(0, vitest_1.expect)(result).toBe(true);
(0, vitest_1.expect)(fs.existsSync).toHaveBeenCalledWith('ios');
(0, vitest_1.expect)(fs.existsSync).toHaveBeenCalledWith('android');
// Should check both folders with Promise.all
(0, vitest_1.expect)(git.isFolderInGitignore).toHaveBeenCalledTimes(2);
(0, vitest_1.expect)(git.isFolderInGitignore).toHaveBeenCalledWith('ios');
(0, vitest_1.expect)(git.isFolderInGitignore).toHaveBeenCalledWith('android');
});
(0, vitest_1.test)('returns false when both folders exist BUT neither is in gitignore', async () => {
vitest_1.vi.mocked(fs.existsSync).mockReturnValue(true);
vitest_1.vi.mocked(git.isFolderInGitignore).mockResolvedValue(false);
const result = await (0, expo_1.isExpoCNG)();
(0, vitest_1.expect)(result).toBe(false);
(0, vitest_1.expect)(git.isFolderInGitignore).toHaveBeenCalledTimes(2);
});
(0, vitest_1.test)('returns false when both folders exist but only ios is in gitignore', async () => {
vitest_1.vi.mocked(fs.existsSync).mockReturnValue(true);
vitest_1.vi.mocked(git.isFolderInGitignore).mockImplementation((folder) => Promise.resolve(folder === 'ios'));
const result = await (0, expo_1.isExpoCNG)();
(0, vitest_1.expect)(result).toBe(false);
(0, vitest_1.expect)(git.isFolderInGitignore).toHaveBeenCalledTimes(2);
});
(0, vitest_1.test)('returns false when both folders exist but only android is in gitignore', async () => {
vitest_1.vi.mocked(fs.existsSync).mockReturnValue(true);
vitest_1.vi.mocked(git.isFolderInGitignore).mockImplementation((folder) => Promise.resolve(folder === 'android'));
const result = await (0, expo_1.isExpoCNG)();
(0, vitest_1.expect)(result).toBe(false);
(0, vitest_1.expect)(git.isFolderInGitignore).toHaveBeenCalledTimes(2);
});
(0, vitest_1.test)('uses Promise.all to check both folders in parallel when both exist', async () => {
vitest_1.vi.mocked(fs.existsSync).mockReturnValue(true);
vitest_1.vi.mocked(git.isFolderInGitignore).mockResolvedValue(true);
await (0, expo_1.isExpoCNG)();
// Should check both folders
(0, vitest_1.expect)(git.isFolderInGitignore).toHaveBeenCalledTimes(2);
(0, vitest_1.expect)(git.isFolderInGitignore).toHaveBeenCalledWith('ios');
(0, vitest_1.expect)(git.isFolderInGitignore).toHaveBeenCalledWith('android');
});
(0, vitest_1.test)('only checks existing folders', async () => {
// Test when only ios exists
vitest_1.vi.mocked(fs.existsSync).mockImplementation((path) => path === 'ios');
vitest_1.vi.mocked(git.isFolderInGitignore).mockResolvedValue(true);
await (0, expo_1.isExpoCNG)();
(0, vitest_1.expect)(git.isFolderInGitignore).toHaveBeenCalledTimes(1);
(0, vitest_1.expect)(git.isFolderInGitignore).toHaveBeenCalledWith('ios');
// Reset and test when only android exists
vitest_1.vi.clearAllMocks();
vitest_1.vi.mocked(fs.existsSync).mockImplementation((path) => path === 'android');
vitest_1.vi.mocked(git.isFolderInGitignore).mockResolvedValue(true);
await (0, expo_1.isExpoCNG)();
(0, vitest_1.expect)(git.isFolderInGitignore).toHaveBeenCalledTimes(1);
(0, vitest_1.expect)(git.isFolderInGitignore).toHaveBeenCalledWith('android');
// Reset and test when neither exists
vitest_1.vi.clearAllMocks();
vitest_1.vi.mocked(fs.existsSync).mockReturnValue(false);
await (0, expo_1.isExpoCNG)();
(0, vitest_1.expect)(git.isFolderInGitignore).not.toHaveBeenCalled();
});
(0, vitest_1.test)('handles errors from isFolderInGitignore gracefully', async () => {
vitest_1.vi.mocked(fs.existsSync).mockReturnValue(true);
vitest_1.vi.mocked(git.isFolderInGitignore).mockRejectedValue(new Error('File system error'));
const result = await (0, expo_1.isExpoCNG)();
// Should catch error and return false instead of throwing
(0, vitest_1.expect)(result).toBe(false);
});
});
});
//# sourceMappingURL=expo.test.js.map