@sentry/wizard
Version:
Sentry wizard helping you to configure your project
194 lines (177 loc) • 4.75 kB
JavaScript
"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");
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)('enableSourcemaps', () => {
(0, vitest_1.afterEach)(() => {
fileContent = '';
vitest_1.vi.clearAllMocks();
});
vitest_1.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)('');
(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=tsc.test.js.map