@sentry/wizard
Version:
Sentry wizard helping you to configure your project
131 lines (129 loc) • 5.82 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 });
// @ts-expect-error - clack is ESM and TS complains about that. It works though
const clack = __importStar(require("@clack/prompts"));
const fs = __importStar(require("node:fs"));
const os = __importStar(require("node:os"));
const node_path_1 = __importDefault(require("node:path"));
const vitest_1 = require("vitest");
const configure_sentry_cli_1 = require("../../src/apple/configure-sentry-cli");
vitest_1.vi.mock('@clack/prompts', async () => ({
__esModule: true,
default: await vitest_1.vi.importActual('@clack/prompts'),
}));
(0, vitest_1.describe)('configureSentryCLI', () => {
const authToken = 'test';
let projectDir;
let rcPath;
let gitignorePath;
(0, vitest_1.beforeEach)(() => {
(0, vitest_1.beforeEach)(() => {
vitest_1.vi.spyOn(clack.log, 'warn').mockImplementation(() => {
/* empty */
});
vitest_1.vi.spyOn(clack, 'select').mockResolvedValue(undefined);
});
projectDir = fs.mkdtempSync(node_path_1.default.join(os.tmpdir(), 'project'));
fs.mkdirSync(projectDir, { recursive: true });
rcPath = node_path_1.default.join(projectDir, '.sentryclirc');
gitignorePath = node_path_1.default.join(projectDir, '.gitignore');
});
(0, vitest_1.describe)('.sentryclirc file not exists', () => {
(0, vitest_1.it)('should create the .sentryclirc file', () => {
// -- Arrange --
// Pre-condition is that the .sentryclirc file does not exist
(0, vitest_1.expect)(fs.existsSync(rcPath)).toBe(false);
// -- Act --
(0, configure_sentry_cli_1.configureSentryCLI)({ projectDir, authToken });
// -- Assert --
(0, vitest_1.expect)(fs.existsSync(rcPath)).toBe(true);
(0, vitest_1.expect)(fs.readFileSync(rcPath, 'utf8')).toContain(`token=test`);
});
});
(0, vitest_1.describe)('.sentryclirc file exists', () => {
(0, vitest_1.it)('should update the .sentryclirc file', () => {
// -- Arrange --
// Pre-condition is that the .sentryclirc file exists
fs.writeFileSync(rcPath, `token=old`);
// -- Act --
(0, configure_sentry_cli_1.configureSentryCLI)({ projectDir, authToken });
// -- Assert --
(0, vitest_1.expect)(fs.readFileSync(rcPath, 'utf8')).toContain(`token=${authToken}`);
});
});
(0, vitest_1.describe)('.gitignore file not exists', () => {
(0, vitest_1.it)('should create the .gitignore file', () => {
// -- Arrange --
// Pre-condition is that the .gitignore file does not exist
(0, vitest_1.expect)(fs.existsSync(gitignorePath)).toBe(false);
// -- Act --
(0, configure_sentry_cli_1.configureSentryCLI)({ projectDir, authToken });
// -- Assert --
(0, vitest_1.expect)(fs.existsSync(gitignorePath)).toBe(true);
(0, vitest_1.expect)(fs.readFileSync(gitignorePath, 'utf8')).toContain('.sentryclirc');
});
});
(0, vitest_1.describe)('.gitignore file exists', () => {
(0, vitest_1.describe)("contains '.sentryclirc'", () => {
(0, vitest_1.it)('should not append the .sentryclirc file to the .gitignore file', () => {
// -- Arrange --
// Pre-condition is that the .gitignore file exists and contains '.sentryclirc'
fs.writeFileSync(gitignorePath, `
# Xcode
xcuserdata/
# Sentry
.sentryclirc
`);
// -- Act --
(0, configure_sentry_cli_1.configureSentryCLI)({ projectDir, authToken });
// -- Assert --
(0, vitest_1.expect)(fs.readFileSync(gitignorePath, 'utf8')).toContain('.sentryclirc');
});
});
(0, vitest_1.describe)("does not contain '.sentryclirc'", () => {
(0, vitest_1.it)('should append the .sentryclirc file to the .gitignore file', () => {
// -- Arrange --
// Pre-condition is that the .gitignore file exists and does not contain '.sentryclirc'
fs.writeFileSync(gitignorePath, `
# Xcode
xcuserdata/
`);
// -- Act --
(0, configure_sentry_cli_1.configureSentryCLI)({ projectDir, authToken });
// -- Assert --
(0, vitest_1.expect)(fs.readFileSync(gitignorePath, 'utf8')).toBe(`
# Xcode
xcuserdata/
.sentryclirc
`);
});
});
});
});
//# sourceMappingURL=configure-sentry-cli.test.js.map