Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 0 additions & 73 deletions lib/Helper/SentryCli.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
import * as fs from 'node:fs';
import type { Answers } from 'inquirer';
import * as path from 'node:path';

import type { Args } from '../Constants';
import { addToGitignore } from './Git';
import { green, l, nl, red } from './Logging';
import { Config } from '../Types';

const SENTRYCLIRC_FILENAME = '.sentryclirc';
const GITIGNORE_FILENAME = '.gitignore';
const PROPERTIES_FILENAME = 'sentry.properties';

export interface SentryCliProps {
'defaults/url': string;
'defaults/org': string | null;
Expand Down Expand Up @@ -94,70 +87,4 @@ export class SentryCli {
}
return dumpedSections.join('\n');
}

/**
* Creates `.sentryclirc` and `sentry.properties` files with the CLI properties
* obtained from the user answers (or from logging into Sentry).
* The `.sentryclirc` only contains the auth token and will be added to the
* user's `.gitignore` file. The properties file contains the rest of the
* properties (org, project, etc.).
*
* @param sentryCli instance of the Sentry CLI
* @param cliProps the properties to write to the files
*/
public async createSentryCliConfig(cliProps: SentryCliProps): Promise<void> {
const { 'auth/token': authToken, ...cliPropsToWrite } = cliProps;

/**
* To not commit the auth token to the VCS, instead of adding it to the
* properties file (like the rest of props), it's added to the Sentry CLI
* config, which is added to the gitignore. This way makes the properties
* file safe to commit without exposing any auth tokens.
*/
if (authToken) {
try {
await fs.promises.appendFile(
SENTRYCLIRC_FILENAME,
this.dumpConfig({ auth: { 'auth/token': authToken } }),
);
green(`✓ Successfully added the auth token to ${SENTRYCLIRC_FILENAME}`);
} catch {
red(
`⚠ Could not add the auth token to ${SENTRYCLIRC_FILENAME}, ` +
`please add it to identify your user account:\n${authToken}`,
);
nl();
}
} else {
red(
`⚠ Did not find an auth token, please add your token to ${SENTRYCLIRC_FILENAME}`,
);
l(
'To generate an auth token, visit https://sentry.io/settings/account/api/auth-tokens/',
);
l(
'To learn how to configure Sentry CLI, visit ' +
'https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/#configure-sentry-cli',
);
}

await addToGitignore(
SENTRYCLIRC_FILENAME,
`⚠ Could not add ${SENTRYCLIRC_FILENAME} to ${GITIGNORE_FILENAME}, please add it to not commit your auth key.`,
);

try {
await fs.promises.writeFile(
`./${PROPERTIES_FILENAME}`,
this.dumpProperties(cliPropsToWrite),
);
green('✓ Successfully created sentry.properties');
} catch {
red(`⚠ Could not add org and project data to ${PROPERTIES_FILENAME}`);
l(
'See docs for a manual setup: https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/#configure-sentry-cli',
);
}
nl();
}
}
20 changes: 16 additions & 4 deletions src/utils/sentrycli-utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// @ts-expect-error - clack is ESM and TS complains about that. It works though
import clack from '@clack/prompts';
import chalk from 'chalk';
import * as fs from 'fs';
import * as path from 'path';

Expand All @@ -12,12 +15,21 @@
const rcPath = path.join(directory, '.sentryclirc');
fs.writeFileSync(rcPath, '[auth]\ntoken=' + params.auth_token);

if (!fs.existsSync('.gitignore')) {
fs.writeFileSync('.gitignore', '.sentryclirc');
const gitignorePath = path.join(directory, '.gitignore');
if (!fs.existsSync(gitignorePath)) {
clack.log.info(

Check failure on line 20 in src/utils/sentrycli-utils.ts

View workflow job for this annotation

GitHub Actions / Node (18) Unit Tests (ubuntu-latest)

test/apple/configure-sentry-cli.test.ts > configureSentryCLI > .sentryclirc file not exists > should create the .sentryclirc file

Error: [vitest] No "default" export is defined on the "@clack/prompts" mock. Did you forget to return it from "vi.mock"? If you need to partially mock a module, you can use "importOriginal" helper inside: vi.mock(import("@clack/prompts"), async (importOriginal) => { const actual = await importOriginal() return { ...actual, // your mocked methods } }) ❯ Module.createSentryCLIRC src/utils/sentrycli-utils.ts:20:5 ❯ Module.configureSentryCLI src/apple/configure-sentry-cli.ts:17:15 ❯ test/apple/configure-sentry-cli.test.ts:42:7

Check failure on line 20 in src/utils/sentrycli-utils.ts

View workflow job for this annotation

GitHub Actions / Node (18) Unit Tests (ubuntu-latest)

test/apple/configure-sentry-cli.test.ts > configureSentryCLI > .sentryclirc file exists > should update the .sentryclirc file

Error: [vitest] No "default" export is defined on the "@clack/prompts" mock. Did you forget to return it from "vi.mock"? If you need to partially mock a module, you can use "importOriginal" helper inside: vi.mock(import("@clack/prompts"), async (importOriginal) => { const actual = await importOriginal() return { ...actual, // your mocked methods } }) ❯ Module.createSentryCLIRC src/utils/sentrycli-utils.ts:20:5 ❯ Module.configureSentryCLI src/apple/configure-sentry-cli.ts:17:15 ❯ test/apple/configure-sentry-cli.test.ts:57:7

Check failure on line 20 in src/utils/sentrycli-utils.ts

View workflow job for this annotation

GitHub Actions / Node (18) Unit Tests (ubuntu-latest)

test/apple/configure-sentry-cli.test.ts > configureSentryCLI > .gitignore file not exists > should create the .gitignore file

Error: [vitest] No "default" export is defined on the "@clack/prompts" mock. Did you forget to return it from "vi.mock"? If you need to partially mock a module, you can use "importOriginal" helper inside: vi.mock(import("@clack/prompts"), async (importOriginal) => { const actual = await importOriginal() return { ...actual, // your mocked methods } }) ❯ Module.createSentryCLIRC src/utils/sentrycli-utils.ts:20:5 ❯ Module.configureSentryCLI src/apple/configure-sentry-cli.ts:17:15 ❯ test/apple/configure-sentry-cli.test.ts:71:7

Check failure on line 20 in src/utils/sentrycli-utils.ts

View workflow job for this annotation

GitHub Actions / Node (18) Unit Tests (macos-15)

test/apple/configure-sentry-cli.test.ts > configureSentryCLI > .sentryclirc file not exists > should create the .sentryclirc file

Error: [vitest] No "default" export is defined on the "@clack/prompts" mock. Did you forget to return it from "vi.mock"? If you need to partially mock a module, you can use "importOriginal" helper inside: vi.mock(import("@clack/prompts"), async (importOriginal) => { const actual = await importOriginal() return { ...actual, // your mocked methods } }) ❯ Module.createSentryCLIRC src/utils/sentrycli-utils.ts:20:5 ❯ Module.configureSentryCLI src/apple/configure-sentry-cli.ts:17:15 ❯ test/apple/configure-sentry-cli.test.ts:42:7

Check failure on line 20 in src/utils/sentrycli-utils.ts

View workflow job for this annotation

GitHub Actions / Node (18) Unit Tests (macos-15)

test/apple/configure-sentry-cli.test.ts > configureSentryCLI > .sentryclirc file exists > should update the .sentryclirc file

Error: [vitest] No "default" export is defined on the "@clack/prompts" mock. Did you forget to return it from "vi.mock"? If you need to partially mock a module, you can use "importOriginal" helper inside: vi.mock(import("@clack/prompts"), async (importOriginal) => { const actual = await importOriginal() return { ...actual, // your mocked methods } }) ❯ Module.createSentryCLIRC src/utils/sentrycli-utils.ts:20:5 ❯ Module.configureSentryCLI src/apple/configure-sentry-cli.ts:17:15 ❯ test/apple/configure-sentry-cli.test.ts:57:7

Check failure on line 20 in src/utils/sentrycli-utils.ts

View workflow job for this annotation

GitHub Actions / Node (18) Unit Tests (macos-15)

test/apple/configure-sentry-cli.test.ts > configureSentryCLI > .gitignore file not exists > should create the .gitignore file

Error: [vitest] No "default" export is defined on the "@clack/prompts" mock. Did you forget to return it from "vi.mock"? If you need to partially mock a module, you can use "importOriginal" helper inside: vi.mock(import("@clack/prompts"), async (importOriginal) => { const actual = await importOriginal() return { ...actual, // your mocked methods } }) ❯ Module.createSentryCLIRC src/utils/sentrycli-utils.ts:20:5 ❯ Module.configureSentryCLI src/apple/configure-sentry-cli.ts:17:15 ❯ test/apple/configure-sentry-cli.test.ts:71:7

Check failure on line 20 in src/utils/sentrycli-utils.ts

View workflow job for this annotation

GitHub Actions / Node (20) Unit Tests (ubuntu-latest)

test/apple/configure-sentry-cli.test.ts > configureSentryCLI > .sentryclirc file not exists > should create the .sentryclirc file

Error: [vitest] No "default" export is defined on the "@clack/prompts" mock. Did you forget to return it from "vi.mock"? If you need to partially mock a module, you can use "importOriginal" helper inside: vi.mock(import("@clack/prompts"), async (importOriginal) => { const actual = await importOriginal() return { ...actual, // your mocked methods } }) ❯ Module.createSentryCLIRC src/utils/sentrycli-utils.ts:20:5 ❯ Module.configureSentryCLI src/apple/configure-sentry-cli.ts:17:15 ❯ test/apple/configure-sentry-cli.test.ts:42:7

Check failure on line 20 in src/utils/sentrycli-utils.ts

View workflow job for this annotation

GitHub Actions / Node (20) Unit Tests (ubuntu-latest)

test/apple/configure-sentry-cli.test.ts > configureSentryCLI > .sentryclirc file exists > should update the .sentryclirc file

Error: [vitest] No "default" export is defined on the "@clack/prompts" mock. Did you forget to return it from "vi.mock"? If you need to partially mock a module, you can use "importOriginal" helper inside: vi.mock(import("@clack/prompts"), async (importOriginal) => { const actual = await importOriginal() return { ...actual, // your mocked methods } }) ❯ Module.createSentryCLIRC src/utils/sentrycli-utils.ts:20:5 ❯ Module.configureSentryCLI src/apple/configure-sentry-cli.ts:17:15 ❯ test/apple/configure-sentry-cli.test.ts:57:7

Check failure on line 20 in src/utils/sentrycli-utils.ts

View workflow job for this annotation

GitHub Actions / Node (20) Unit Tests (ubuntu-latest)

test/apple/configure-sentry-cli.test.ts > configureSentryCLI > .gitignore file not exists > should create the .gitignore file

Error: [vitest] No "default" export is defined on the "@clack/prompts" mock. Did you forget to return it from "vi.mock"? If you need to partially mock a module, you can use "importOriginal" helper inside: vi.mock(import("@clack/prompts"), async (importOriginal) => { const actual = await importOriginal() return { ...actual, // your mocked methods } }) ❯ Module.createSentryCLIRC src/utils/sentrycli-utils.ts:20:5 ❯ Module.configureSentryCLI src/apple/configure-sentry-cli.ts:17:15 ❯ test/apple/configure-sentry-cli.test.ts:71:7

Check failure on line 20 in src/utils/sentrycli-utils.ts

View workflow job for this annotation

GitHub Actions / Node (20) Unit Tests (macos-15)

test/apple/configure-sentry-cli.test.ts > configureSentryCLI > .sentryclirc file not exists > should create the .sentryclirc file

Error: [vitest] No "default" export is defined on the "@clack/prompts" mock. Did you forget to return it from "vi.mock"? If you need to partially mock a module, you can use "importOriginal" helper inside: vi.mock(import("@clack/prompts"), async (importOriginal) => { const actual = await importOriginal() return { ...actual, // your mocked methods } }) ❯ Module.createSentryCLIRC src/utils/sentrycli-utils.ts:20:5 ❯ Module.configureSentryCLI src/apple/configure-sentry-cli.ts:17:15 ❯ test/apple/configure-sentry-cli.test.ts:42:7

Check failure on line 20 in src/utils/sentrycli-utils.ts

View workflow job for this annotation

GitHub Actions / Node (20) Unit Tests (macos-15)

test/apple/configure-sentry-cli.test.ts > configureSentryCLI > .sentryclirc file exists > should update the .sentryclirc file

Error: [vitest] No "default" export is defined on the "@clack/prompts" mock. Did you forget to return it from "vi.mock"? If you need to partially mock a module, you can use "importOriginal" helper inside: vi.mock(import("@clack/prompts"), async (importOriginal) => { const actual = await importOriginal() return { ...actual, // your mocked methods } }) ❯ Module.createSentryCLIRC src/utils/sentrycli-utils.ts:20:5 ❯ Module.configureSentryCLI src/apple/configure-sentry-cli.ts:17:15 ❯ test/apple/configure-sentry-cli.test.ts:57:7

Check failure on line 20 in src/utils/sentrycli-utils.ts

View workflow job for this annotation

GitHub Actions / Node (20) Unit Tests (macos-15)

test/apple/configure-sentry-cli.test.ts > configureSentryCLI > .gitignore file not exists > should create the .gitignore file

Error: [vitest] No "default" export is defined on the "@clack/prompts" mock. Did you forget to return it from "vi.mock"? If you need to partially mock a module, you can use "importOriginal" helper inside: vi.mock(import("@clack/prompts"), async (importOriginal) => { const actual = await importOriginal() return { ...actual, // your mocked methods } }) ❯ Module.createSentryCLIRC src/utils/sentrycli-utils.ts:20:5 ❯ Module.configureSentryCLI src/apple/configure-sentry-cli.ts:17:15 ❯ test/apple/configure-sentry-cli.test.ts:71:7

Check failure on line 20 in src/utils/sentrycli-utils.ts

View workflow job for this annotation

GitHub Actions / Node (22) Unit Tests (ubuntu-latest)

test/apple/configure-sentry-cli.test.ts > configureSentryCLI > .sentryclirc file not exists > should create the .sentryclirc file

Error: [vitest] No "default" export is defined on the "@clack/prompts" mock. Did you forget to return it from "vi.mock"? If you need to partially mock a module, you can use "importOriginal" helper inside: vi.mock(import("@clack/prompts"), async (importOriginal) => { const actual = await importOriginal() return { ...actual, // your mocked methods } }) ❯ Module.createSentryCLIRC src/utils/sentrycli-utils.ts:20:5 ❯ Module.configureSentryCLI src/apple/configure-sentry-cli.ts:17:15 ❯ test/apple/configure-sentry-cli.test.ts:42:7

Check failure on line 20 in src/utils/sentrycli-utils.ts

View workflow job for this annotation

GitHub Actions / Node (22) Unit Tests (ubuntu-latest)

test/apple/configure-sentry-cli.test.ts > configureSentryCLI > .sentryclirc file exists > should update the .sentryclirc file

Error: [vitest] No "default" export is defined on the "@clack/prompts" mock. Did you forget to return it from "vi.mock"? If you need to partially mock a module, you can use "importOriginal" helper inside: vi.mock(import("@clack/prompts"), async (importOriginal) => { const actual = await importOriginal() return { ...actual, // your mocked methods } }) ❯ Module.createSentryCLIRC src/utils/sentrycli-utils.ts:20:5 ❯ Module.configureSentryCLI src/apple/configure-sentry-cli.ts:17:15 ❯ test/apple/configure-sentry-cli.test.ts:57:7

Check failure on line 20 in src/utils/sentrycli-utils.ts

View workflow job for this annotation

GitHub Actions / Node (22) Unit Tests (ubuntu-latest)

test/apple/configure-sentry-cli.test.ts > configureSentryCLI > .gitignore file not exists > should create the .gitignore file

Error: [vitest] No "default" export is defined on the "@clack/prompts" mock. Did you forget to return it from "vi.mock"? If you need to partially mock a module, you can use "importOriginal" helper inside: vi.mock(import("@clack/prompts"), async (importOriginal) => { const actual = await importOriginal() return { ...actual, // your mocked methods } }) ❯ Module.createSentryCLIRC src/utils/sentrycli-utils.ts:20:5 ❯ Module.configureSentryCLI src/apple/configure-sentry-cli.ts:17:15 ❯ test/apple/configure-sentry-cli.test.ts:71:7

Check failure on line 20 in src/utils/sentrycli-utils.ts

View workflow job for this annotation

GitHub Actions / Node (22) Unit Tests (macos-15)

test/apple/configure-sentry-cli.test.ts > configureSentryCLI > .sentryclirc file not exists > should create the .sentryclirc file

Error: [vitest] No "default" export is defined on the "@clack/prompts" mock. Did you forget to return it from "vi.mock"? If you need to partially mock a module, you can use "importOriginal" helper inside: vi.mock(import("@clack/prompts"), async (importOriginal) => { const actual = await importOriginal() return { ...actual, // your mocked methods } }) ❯ Module.createSentryCLIRC src/utils/sentrycli-utils.ts:20:5 ❯ Module.configureSentryCLI src/apple/configure-sentry-cli.ts:17:15 ❯ test/apple/configure-sentry-cli.test.ts:42:7

Check failure on line 20 in src/utils/sentrycli-utils.ts

View workflow job for this annotation

GitHub Actions / Node (22) Unit Tests (macos-15)

test/apple/configure-sentry-cli.test.ts > configureSentryCLI > .sentryclirc file exists > should update the .sentryclirc file

Error: [vitest] No "default" export is defined on the "@clack/prompts" mock. Did you forget to return it from "vi.mock"? If you need to partially mock a module, you can use "importOriginal" helper inside: vi.mock(import("@clack/prompts"), async (importOriginal) => { const actual = await importOriginal() return { ...actual, // your mocked methods } }) ❯ Module.createSentryCLIRC src/utils/sentrycli-utils.ts:20:5 ❯ Module.configureSentryCLI src/apple/configure-sentry-cli.ts:17:15 ❯ test/apple/configure-sentry-cli.test.ts:57:7

Check failure on line 20 in src/utils/sentrycli-utils.ts

View workflow job for this annotation

GitHub Actions / Node (22) Unit Tests (macos-15)

test/apple/configure-sentry-cli.test.ts > configureSentryCLI > .gitignore file not exists > should create the .gitignore file

Error: [vitest] No "default" export is defined on the "@clack/prompts" mock. Did you forget to return it from "vi.mock"? If you need to partially mock a module, you can use "importOriginal" helper inside: vi.mock(import("@clack/prompts"), async (importOriginal) => { const actual = await importOriginal() return { ...actual, // your mocked methods } }) ❯ Module.createSentryCLIRC src/utils/sentrycli-utils.ts:20:5 ❯ Module.configureSentryCLI src/apple/configure-sentry-cli.ts:17:15 ❯ test/apple/configure-sentry-cli.test.ts:71:7
`Creating .gitignore file at path: ${chalk.cyan(gitignorePath)}`,
);
fs.writeFileSync(gitignorePath, '.sentryclirc');
} else {
const gitIgnore = fs.readFileSync('.gitignore').toString();
const gitIgnore = fs.readFileSync(gitignorePath).toString();
if (!gitIgnore.includes('.sentryclirc')) {
fs.appendFileSync('.gitignore', '\n.sentryclirc');
clack.log.info(

Check failure on line 27 in src/utils/sentrycli-utils.ts

View workflow job for this annotation

GitHub Actions / Node (18) Unit Tests (ubuntu-latest)

test/apple/configure-sentry-cli.test.ts > configureSentryCLI > .gitignore file exists > does not contain '.sentryclirc' > should append the .sentryclirc file to the .gitignore file

Error: [vitest] No "default" export is defined on the "@clack/prompts" mock. Did you forget to return it from "vi.mock"? If you need to partially mock a module, you can use "importOriginal" helper inside: vi.mock(import("@clack/prompts"), async (importOriginal) => { const actual = await importOriginal() return { ...actual, // your mocked methods } }) ❯ Module.createSentryCLIRC src/utils/sentrycli-utils.ts:27:7 ❯ Module.configureSentryCLI src/apple/configure-sentry-cli.ts:17:15 ❯ test/apple/configure-sentry-cli.test.ts:118:9

Check failure on line 27 in src/utils/sentrycli-utils.ts

View workflow job for this annotation

GitHub Actions / Node (18) Unit Tests (macos-15)

test/apple/configure-sentry-cli.test.ts > configureSentryCLI > .gitignore file exists > does not contain '.sentryclirc' > should append the .sentryclirc file to the .gitignore file

Error: [vitest] No "default" export is defined on the "@clack/prompts" mock. Did you forget to return it from "vi.mock"? If you need to partially mock a module, you can use "importOriginal" helper inside: vi.mock(import("@clack/prompts"), async (importOriginal) => { const actual = await importOriginal() return { ...actual, // your mocked methods } }) ❯ Module.createSentryCLIRC src/utils/sentrycli-utils.ts:27:7 ❯ Module.configureSentryCLI src/apple/configure-sentry-cli.ts:17:15 ❯ test/apple/configure-sentry-cli.test.ts:118:9

Check failure on line 27 in src/utils/sentrycli-utils.ts

View workflow job for this annotation

GitHub Actions / Node (20) Unit Tests (ubuntu-latest)

test/apple/configure-sentry-cli.test.ts > configureSentryCLI > .gitignore file exists > does not contain '.sentryclirc' > should append the .sentryclirc file to the .gitignore file

Error: [vitest] No "default" export is defined on the "@clack/prompts" mock. Did you forget to return it from "vi.mock"? If you need to partially mock a module, you can use "importOriginal" helper inside: vi.mock(import("@clack/prompts"), async (importOriginal) => { const actual = await importOriginal() return { ...actual, // your mocked methods } }) ❯ Module.createSentryCLIRC src/utils/sentrycli-utils.ts:27:7 ❯ Module.configureSentryCLI src/apple/configure-sentry-cli.ts:17:15 ❯ test/apple/configure-sentry-cli.test.ts:118:9

Check failure on line 27 in src/utils/sentrycli-utils.ts

View workflow job for this annotation

GitHub Actions / Node (20) Unit Tests (macos-15)

test/apple/configure-sentry-cli.test.ts > configureSentryCLI > .gitignore file exists > does not contain '.sentryclirc' > should append the .sentryclirc file to the .gitignore file

Error: [vitest] No "default" export is defined on the "@clack/prompts" mock. Did you forget to return it from "vi.mock"? If you need to partially mock a module, you can use "importOriginal" helper inside: vi.mock(import("@clack/prompts"), async (importOriginal) => { const actual = await importOriginal() return { ...actual, // your mocked methods } }) ❯ Module.createSentryCLIRC src/utils/sentrycli-utils.ts:27:7 ❯ Module.configureSentryCLI src/apple/configure-sentry-cli.ts:17:15 ❯ test/apple/configure-sentry-cli.test.ts:118:9

Check failure on line 27 in src/utils/sentrycli-utils.ts

View workflow job for this annotation

GitHub Actions / Node (22) Unit Tests (ubuntu-latest)

test/apple/configure-sentry-cli.test.ts > configureSentryCLI > .gitignore file exists > does not contain '.sentryclirc' > should append the .sentryclirc file to the .gitignore file

Error: [vitest] No "default" export is defined on the "@clack/prompts" mock. Did you forget to return it from "vi.mock"? If you need to partially mock a module, you can use "importOriginal" helper inside: vi.mock(import("@clack/prompts"), async (importOriginal) => { const actual = await importOriginal() return { ...actual, // your mocked methods } }) ❯ Module.createSentryCLIRC src/utils/sentrycli-utils.ts:27:7 ❯ Module.configureSentryCLI src/apple/configure-sentry-cli.ts:17:15 ❯ test/apple/configure-sentry-cli.test.ts:118:9

Check failure on line 27 in src/utils/sentrycli-utils.ts

View workflow job for this annotation

GitHub Actions / Node (22) Unit Tests (macos-15)

test/apple/configure-sentry-cli.test.ts > configureSentryCLI > .gitignore file exists > does not contain '.sentryclirc' > should append the .sentryclirc file to the .gitignore file

Error: [vitest] No "default" export is defined on the "@clack/prompts" mock. Did you forget to return it from "vi.mock"? If you need to partially mock a module, you can use "importOriginal" helper inside: vi.mock(import("@clack/prompts"), async (importOriginal) => { const actual = await importOriginal() return { ...actual, // your mocked methods } }) ❯ Module.createSentryCLIRC src/utils/sentrycli-utils.ts:27:7 ❯ Module.configureSentryCLI src/apple/configure-sentry-cli.ts:17:15 ❯ test/apple/configure-sentry-cli.test.ts:118:9
`Appending .sentryclirc to .gitignore file at path: ${chalk.cyan(
gitignorePath,
)}`,
);
fs.appendFileSync(gitignorePath, '\n.sentryclirc');
}
}
}
131 changes: 131 additions & 0 deletions test/apple/configure-sentry-cli.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
// @ts-expect-error - clack is ESM and TS complains about that. It works though
import * as clack from '@clack/prompts';
import * as fs from 'node:fs';
import * as os from 'node:os';
import path from 'node:path';
import { beforeEach, describe, expect, it, vi } from 'vitest';
import { configureSentryCLI } from '../../src/apple/configure-sentry-cli';

vi.mock('@clack/prompts', async () => ({
__esModule: true,
...(await vi.importActual<typeof clack>('@clack/prompts')),
}));

describe('configureSentryCLI', () => {
const authToken = 'test';
let projectDir: string;
let rcPath: string;
let gitignorePath: string;

beforeEach(() => {
beforeEach(() => {
vi.spyOn(clack.log, 'warn').mockImplementation(() => {
/* empty */
});
vi.spyOn(clack, 'select').mockResolvedValue(undefined);
});

projectDir = fs.mkdtempSync(path.join(os.tmpdir(), 'project'));
fs.mkdirSync(projectDir, { recursive: true });

rcPath = path.join(projectDir, '.sentryclirc');
gitignorePath = path.join(projectDir, '.gitignore');
});

describe('.sentryclirc file not exists', () => {
it('should create the .sentryclirc file', () => {
// -- Arrange --
// Pre-condition is that the .sentryclirc file does not exist
expect(fs.existsSync(rcPath)).toBe(false);

// -- Act --
configureSentryCLI({ projectDir, authToken });

// -- Assert --
expect(fs.existsSync(rcPath)).toBe(true);
expect(fs.readFileSync(rcPath, 'utf8')).toContain(`token=test`);
});
});

describe('.sentryclirc file exists', () => {
it('should update the .sentryclirc file', () => {
// -- Arrange --
// Pre-condition is that the .sentryclirc file exists
fs.writeFileSync(rcPath, `token=old`);

// -- Act --
configureSentryCLI({ projectDir, authToken });

// -- Assert --
expect(fs.readFileSync(rcPath, 'utf8')).toContain(`token=${authToken}`);
});
});

describe('.gitignore file not exists', () => {
it('should create the .gitignore file', () => {
// -- Arrange --
// Pre-condition is that the .gitignore file does not exist
expect(fs.existsSync(gitignorePath)).toBe(false);

// -- Act --
configureSentryCLI({ projectDir, authToken });

// -- Assert --
expect(fs.existsSync(gitignorePath)).toBe(true);
expect(fs.readFileSync(gitignorePath, 'utf8')).toContain('.sentryclirc');
});
});

describe('.gitignore file exists', () => {
describe("contains '.sentryclirc'", () => {
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 --
configureSentryCLI({ projectDir, authToken });

// -- Assert --
expect(fs.readFileSync(gitignorePath, 'utf8')).toContain(
'.sentryclirc',
);
});
});

describe("does not contain '.sentryclirc'", () => {
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 --
configureSentryCLI({ projectDir, authToken });

// -- Assert --
expect(fs.readFileSync(gitignorePath, 'utf8')).toBe(
`
# Xcode
xcuserdata/
.sentryclirc
`,
);
});
});
});
});
Loading