UNPKG

@sentry/wizard

Version:

Sentry wizard helping you to configure your project

302 lines (267 loc) 8.35 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 webpack_1 = require("../../../src/sourcemaps/tools/webpack"); 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(), }, select: vitest_1.vi.fn().mockImplementation(() => Promise.resolve(true)), isCancel: vitest_1.vi.fn().mockReturnValue(false), }; }); 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)); const noSourcemapNoPluginsPojo = `module.exports = { entry: "./src/index.js", output: { filename: "main.js", path: path.resolve(__dirname, "build"), }, };`; const noSourcemapNoPluginsPojoResult = `const { sentryWebpackPlugin } = require("@sentry/webpack-plugin"); module.exports = { entry: "./src/index.js", output: { filename: "main.js", path: path.resolve(__dirname, "build"), }, devtool: "source-map", plugins: [sentryWebpackPlugin({ authToken: process.env.SENTRY_AUTH_TOKEN, org: "my-org", project: "my-project" })] };`; const noSourcemapsNoPluginsId = `const config = { entry: "./src/index.js", output: { filename: "main.js", path: path.resolve(__dirname, "build"), }, }; module.exports = config;`; const noSourcemapsNoPluginsIdResult = `const { sentryWebpackPlugin } = require("@sentry/webpack-plugin"); const config = { entry: "./src/index.js", output: { filename: "main.js", path: path.resolve(__dirname, "build"), }, devtool: "source-map", plugins: [sentryWebpackPlugin({ authToken: process.env.SENTRY_AUTH_TOKEN, org: "my-org", project: "my-project" })] }; module.exports = config;`; const hiddenSourcemapNoPluginsId = `const config = { entry: "./src/index.js", output: { filename: "main.js", path: path.resolve(__dirname, "build"), }, devtool: "hidden-cheap-source-map", }; module.exports = config; `; const hiddenSourcemapNoPluginsIdResult = `const { sentryWebpackPlugin } = require("@sentry/webpack-plugin"); const config = { entry: "./src/index.js", output: { filename: "main.js", path: path.resolve(__dirname, "build"), }, devtool: "hidden-source-map", plugins: [sentryWebpackPlugin({ authToken: process.env.SENTRY_AUTH_TOKEN, org: "my-org", project: "my-project" })] }; module.exports = config;`; const arbitrarySourcemapNoPluginsId = ` const config = { entry: "./src/index.js", output: { filename: "main.js", path: path.resolve(__dirname, "build"), }, devtool: getSourcemapSetting(), }; module.exports = config; `; const arbitrarySourcemapNoPluginsIdResult = `const { sentryWebpackPlugin } = require("@sentry/webpack-plugin"); const config = { entry: "./src/index.js", output: { filename: "main.js", path: path.resolve(__dirname, "build"), }, devtool: "source-map", plugins: [sentryWebpackPlugin({ authToken: process.env.SENTRY_AUTH_TOKEN, org: "my-org", project: "my-project" })] }; module.exports = config;`; const noSourcemapUndefinedPluginsPojo = `module.exports = { entry: "./src/index.js", plugins: undefined, output: { filename: "main.js", path: path.resolve(__dirname, "build"), }, };`; const noSourcemapUndefinedPluginsPojoResult = `const { sentryWebpackPlugin } = require("@sentry/webpack-plugin"); module.exports = { entry: "./src/index.js", plugins: [sentryWebpackPlugin({ authToken: process.env.SENTRY_AUTH_TOKEN, org: "my-org", project: "my-project" })], output: { filename: "main.js", path: path.resolve(__dirname, "build"), }, devtool: "source-map" };`; const noSourcemapPluginsPojo = `module.exports = { entry: "./src/index.js", plugins: [ new HtmlWebpackPlugin(), new MiniCssExtractPlugin(), ], output: { filename: "main.js", path: path.resolve(__dirname, "build"), }, };`; const noSourcemapPluginsPojoResult = `const { sentryWebpackPlugin } = require("@sentry/webpack-plugin"); module.exports = { entry: "./src/index.js", plugins: [new HtmlWebpackPlugin(), new MiniCssExtractPlugin(), sentryWebpackPlugin({ authToken: process.env.SENTRY_AUTH_TOKEN, org: "my-org", project: "my-project" })], output: { filename: "main.js", path: path.resolve(__dirname, "build"), }, devtool: "source-map" };`; (0, vitest_1.describe)('modifyWebpackConfig', () => { (0, vitest_1.afterEach)(() => { fileContent = ''; vitest_1.vi.clearAllMocks(); }); vitest_1.it.each([ [ 'no sourcemap option, no plugins, object', noSourcemapNoPluginsPojo, noSourcemapNoPluginsPojoResult, ], [ 'no sourcemap option, no plugins, identifier', noSourcemapsNoPluginsId, noSourcemapsNoPluginsIdResult, ], [ 'hidden sourcemap option, no plugins, identifier', hiddenSourcemapNoPluginsId, hiddenSourcemapNoPluginsIdResult, ], [ 'arbitrary sourcemap option, no plugins, identifier', arbitrarySourcemapNoPluginsId, arbitrarySourcemapNoPluginsIdResult, ], [ 'no sourcemap option, plugins, object', noSourcemapUndefinedPluginsPojo, noSourcemapUndefinedPluginsPojoResult, ], [ 'no sourcemap option, plugins, object', noSourcemapPluginsPojo, noSourcemapPluginsPojoResult, ], ])('adds plugin and source maps emission to the webpack config (%s)', async (_, originalCode, expectedCode) => { updateFileContent(originalCode); // updateFileContent(originalCode); const addedCode = await (0, webpack_1.modifyWebpackConfig)('', { 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); }); (0, vitest_1.it)('adds the url parameter to the webpack plugin options if self-hosted', async () => { updateFileContent(noSourcemapNoPluginsPojo); const addedCode = await (0, webpack_1.modifyWebpackConfig)('', { authToken: '', orgSlug: 'my-org', projectSlug: 'my-project', selfHosted: true, url: 'https://santry.io/', }); (0, vitest_1.expect)(writeFileSpy).toHaveBeenCalledTimes(1); const [[, fileContent]] = writeFileSpy.mock.calls; (0, vitest_1.expect)(fileContent).toContain('url: "https://santry.io/"'); (0, vitest_1.expect)(addedCode).toBe(true); }); }); //# sourceMappingURL=webpack.test.js.map