@sentry/wizard
Version:
Sentry wizard helping you to configure your project
237 lines • 8.93 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 vitest_1 = require("vitest");
const sourcemaps_1 = require("../../../src/angular/codemods/sourcemaps");
const AngularSourceMapsWizard = __importStar(require("../../../src/sourcemaps/tools/angular"));
const { readFileSyncMock, writeFileSyncMock } = vitest_1.vi.hoisted(() => {
return {
readFileSyncMock: vitest_1.vi.fn(),
writeFileSyncMock: vitest_1.vi.fn(),
};
});
vitest_1.vi.mock('fs', async () => {
return {
...(await vitest_1.vi.importActual('fs')),
readFileSync: readFileSyncMock,
writeFileSync: writeFileSyncMock,
};
});
(0, vitest_1.describe)('addSourcemapEntryToAngularJSON', () => {
const configureAngularSourcemapGenerationFlowSpy = vitest_1.vi
.spyOn(AngularSourceMapsWizard, 'configureAngularSourcemapGenerationFlow')
.mockImplementation(() => Promise.resolve());
(0, vitest_1.beforeEach)(() => {
vitest_1.vi.clearAllMocks();
});
(0, vitest_1.it)('reads and writes the `angular.json` file correctly', async () => {
const angularJsonPath = 'angular.json';
const angularJsonContent = JSON.stringify({
projects: {
project1: {
architect: {
build: {
configurations: {
production: {
someKey: 'someValue',
},
},
},
},
},
},
});
readFileSyncMock.mockReturnValue(angularJsonContent);
await (0, sourcemaps_1.addSourcemapEntryToAngularJSON)();
(0, vitest_1.expect)(readFileSyncMock).toHaveBeenCalledWith(vitest_1.expect.stringContaining(angularJsonPath), 'utf-8');
(0, vitest_1.expect)(writeFileSyncMock).toHaveBeenCalledWith(vitest_1.expect.stringContaining(angularJsonPath), JSON.stringify({
projects: {
project1: {
architect: {
build: {
configurations: {
production: {
someKey: 'someValue',
sourceMap: true,
},
},
},
},
},
},
}, null, 2));
});
(0, vitest_1.it)('falls back to printing copy/paste instructions when reading fails', async () => {
readFileSyncMock.mockImplementation(() => {
throw new Error('File not found');
});
await (0, sourcemaps_1.addSourcemapEntryToAngularJSON)();
(0, vitest_1.expect)(configureAngularSourcemapGenerationFlowSpy).toHaveBeenCalledOnce();
(0, vitest_1.expect)(writeFileSyncMock).not.toHaveBeenCalled();
});
(0, vitest_1.it)('falls back to printing copy/paste instructions when writing fails', async () => {
const angularJsonContent = JSON.stringify({
projects: {
project1: {},
},
});
readFileSyncMock.mockReturnValue(angularJsonContent);
writeFileSyncMock.mockImplementation(() => {
throw new Error('Write failed');
});
await (0, sourcemaps_1.addSourcemapEntryToAngularJSON)();
(0, vitest_1.expect)(configureAngularSourcemapGenerationFlowSpy).toHaveBeenCalledOnce();
(0, vitest_1.expect)(writeFileSyncMock).toHaveBeenCalled();
});
(0, vitest_1.it)('falls back to printing copy/paste instructions when angular.json` has no projects', async () => {
const angularJsonContent = JSON.stringify({
projects: {},
});
readFileSyncMock.mockReturnValue(angularJsonContent);
await (0, sourcemaps_1.addSourcemapEntryToAngularJSON)();
(0, vitest_1.expect)(configureAngularSourcemapGenerationFlowSpy).toHaveBeenCalledOnce();
(0, vitest_1.expect)(writeFileSyncMock).not.toHaveBeenCalled();
});
});
(0, vitest_1.describe)('addSourceMapsSetting', () => {
(0, vitest_1.it)('adds sourceMap setting to angular.json', () => {
const angularJson = {
projects: {
project1: {
architect: {
build: {
configurations: {
production: {},
},
},
},
},
project2: {
architect: {},
},
},
};
const updatedAngularJson = (0, sourcemaps_1.addSourceMapsSetting)(angularJson);
(0, vitest_1.expect)(updatedAngularJson).toEqual({
projects: {
project1: {
architect: {
build: {
configurations: {
production: { sourceMap: true },
},
},
},
},
project2: {
architect: {
build: {
configurations: {
production: {
sourceMap: true,
},
},
},
},
},
},
});
});
(0, vitest_1.it)('returns `undefined` if no projects are found', () => {
const angularJson = {};
const updatedAngularJson = (0, sourcemaps_1.addSourceMapsSetting)(angularJson);
(0, vitest_1.expect)(updatedAngularJson).toBeUndefined();
});
(0, vitest_1.it)('returns `undefined` if projects have no architect', () => {
const angularJson = {
projects: {},
};
const updatedAngularJson = (0, sourcemaps_1.addSourceMapsSetting)(angularJson);
(0, vitest_1.expect)(updatedAngularJson).toBeUndefined();
});
vitest_1.it.each([
{
projects: {
project1: {
architect: {
build: {
configurations: {
production: {},
},
},
},
},
},
},
{
projects: {
project1: {
architect: {
build: {
configurations: {},
},
},
},
},
},
{
projects: {
project1: {
architect: {
build: {},
},
},
},
},
{
projects: {
project1: {
architect: {},
},
},
},
{
projects: {
project1: {},
},
},
])('handles incomplete project declarations (%s)', (angularJson) => {
const updatedAngularJson = (0, sourcemaps_1.addSourceMapsSetting)(angularJson);
(0, vitest_1.expect)(updatedAngularJson).toEqual({
projects: {
project1: {
architect: {
build: {
configurations: {
production: { sourceMap: true },
},
},
},
},
},
});
});
});
//# sourceMappingURL=sourcemaps.test.js.map