UNPKG

@sentry/wizard

Version:

Sentry wizard helping you to configure your project

162 lines (158 loc) 4.2 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 fs = __importStar(require("fs")); const vite_1 = require("../../../src/sourcemaps/tools/vite"); const vitest_1 = require("vitest"); function updateFileContent(content) { fileContent = content; } let fileContent = ''; vitest_1.vi.mock('@clack/prompts', () => { return { log: { info: vitest_1.vi.fn(), success: vitest_1.vi.fn(), }, }; }); vitest_1.vi.spyOn(fs.promises, 'readFile').mockImplementation(() => Promise.resolve(fileContent)); const writeFileSpy = vitest_1.vi .spyOn(fs.promises, 'writeFile') .mockImplementation(() => Promise.resolve(void 0)); (0, vitest_1.describe)('addVitePluginToConfig', () => { (0, vitest_1.afterEach)(() => { fileContent = ''; vitest_1.vi.clearAllMocks(); }); vitest_1.it.each([ [ 'no build options', ` export default defineConfig({ plugins: [ vue(), ], }) `, `import { sentryVitePlugin } from "@sentry/vite-plugin"; export default defineConfig({ plugins: [vue(), sentryVitePlugin({ org: "my-org", project: "my-project" })], build: { sourcemap: true } })`, ], [ 'no build.sourcemap options', ` export default defineConfig({ plugins: [ vue(), ], build: { test: 1, } }) `, `import { sentryVitePlugin } from "@sentry/vite-plugin"; export default defineConfig({ plugins: [vue(), sentryVitePlugin({ org: "my-org", project: "my-project" })], build: { test: 1, sourcemap: true } })`, ], [ 'keep sourcemap: "hidden"', ` export default { plugins: [ vue(), ], build: { sourcemap: "hidden", } } `, `import { sentryVitePlugin } from "@sentry/vite-plugin"; export default { plugins: [vue(), sentryVitePlugin({ org: "my-org", project: "my-project" })], build: { sourcemap: "hidden", } }`, ], [ 'rewrite sourcemap: false to true', ` const cfg = { plugins: [ vue(), ], build: { sourcemap: false, } } export default cfg; `, `import { sentryVitePlugin } from "@sentry/vite-plugin"; const cfg = { plugins: [vue(), sentryVitePlugin({ org: "my-org", project: "my-project" })], build: { sourcemap: true, } } export default cfg;`, ], ])('adds the plugin and enables source maps generation (%s)', async (_, originalCode, expectedCode) => { updateFileContent(originalCode); const addedCode = await (0, vite_1.addVitePluginToConfig)('', { authToken: '', orgSlug: 'my-org', projectSlug: 'my-project', selfHosted: false, url: 'https://sentry.io/', }); (0, vitest_1.expect)(writeFileSpy).toHaveBeenCalledTimes(1); const [[, fileContent]] = writeFileSpy.mock.calls; (0, vitest_1.expect)(fileContent).toBe(expectedCode); (0, vitest_1.expect)(addedCode).toBe(true); }); }); //# sourceMappingURL=vite.test.js.map