UNPKG

@sentry/wizard

Version:

Sentry wizard helping you to configure your project

195 lines (178 loc) 4.61 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 tsc_1 = require("../../../src/sourcemaps/tools/tsc"); function updateFileContent(content) { fileContent = content; } let fileContent = ''; jest.mock('@clack/prompts', () => { return { log: { info: jest.fn(), success: jest.fn(), }, }; }); jest .spyOn(fs.promises, 'readFile') .mockImplementation(() => Promise.resolve(fileContent)); const writeFileSpy = jest .spyOn(fs.promises, 'writeFile') .mockImplementation(() => Promise.resolve(void 0)); describe('enableSourcemaps', () => { afterEach(() => { fileContent = ''; jest.clearAllMocks(); }); it.each([ [ 'no sourcemaps options', ` /** * My TS config with comments */ { "extends": "./tsconfig.build.json", "compilerOptions": { // line comment which should stay "moduleResolution": "node16", "outDir": "dist" // another inline comment }, "include": [ "src/**/*", "test/**/*" ] } `, ` /** * My TS config with comments */ { "extends": "./tsconfig.build.json", "compilerOptions": { // line comment which should stay "moduleResolution": "node16", // another inline comment "outDir": "dist", "sourceMap": true, "inlineSources": true, // Set \`sourceRoot\` to "/" to strip the build path prefix // from generated source code references. // This improves issue grouping in Sentry. "sourceRoot": "/" }, "include": [ "src/**/*", "test/**/*" ] } `, ], [ 'a few sourcemaps options', ` /** * My TS config with comments */ { "extends": "./tsconfig.build.json", "compilerOptions": { // line comment which should stay "moduleResolution": "node16", "outDir": "dist", // another inline comment "sourceMap": false, "sourceRoot": "/src" }, "include": [ "src/**/*", "test/**/*" ] } `, ` /** * My TS config with comments */ { "extends": "./tsconfig.build.json", "compilerOptions": { // line comment which should stay "moduleResolution": "node16", // another inline comment "outDir": "dist", "sourceMap": true, // Set \`sourceRoot\` to "/" to strip the build path prefix // from generated source code references. // This improves issue grouping in Sentry. "sourceRoot": "/", "inlineSources": true }, "include": [ "src/**/*", "test/**/*" ] } `, ], [ 'no compiler options', ` { "include": [ "src/**/*", "test/**/*" ] } `, ` { "include": [ "src/**/*", "test/**/*" ], "compilerOptions": { "sourceMap": true, "inlineSources": true, // Set \`sourceRoot\` to "/" to strip the build path prefix // from generated source code references. // This improves issue grouping in Sentry. "sourceRoot": "/" } } `, ], ])('adds the plugin and enables source maps generation (%s)', async (_, originalCode, expectedCode) => { updateFileContent(originalCode); const addedCode = await (0, tsc_1.enableSourcemaps)(''); expect(writeFileSpy).toHaveBeenCalledTimes(1); const [[, fileContent]] = writeFileSpy.mock.calls; expect(fileContent).toBe(expectedCode); expect(addedCode).toBe(true); }); }); //# sourceMappingURL=tsc.test.js.map