UNPKG

@sentry/wizard

Version:

Sentry wizard helping you to configure your project

104 lines 4.99 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 vitest_1 = require("vitest"); const fs = __importStar(require("fs")); const utils_1 = require("../../src/nextjs/utils"); vitest_1.vi.mock('fs', () => ({ existsSync: vitest_1.vi.fn(), lstatSync: vitest_1.vi.fn(), })); (0, vitest_1.describe)('Next.js Utils', () => { (0, vitest_1.describe)('getNextJsVersionBucket', () => { (0, vitest_1.it)('returns "none" for undefined version', () => { (0, vitest_1.expect)((0, utils_1.getNextJsVersionBucket)(undefined)).toBe('none'); }); (0, vitest_1.it)('returns "<11.0.0" for versions below 11', () => { (0, vitest_1.expect)((0, utils_1.getNextJsVersionBucket)('10.0.0')).toBe('<11.0.0'); }); (0, vitest_1.it)('returns major version for versions 11 and above', () => { (0, vitest_1.expect)((0, utils_1.getNextJsVersionBucket)('11.0.0')).toBe('11.x'); (0, vitest_1.expect)((0, utils_1.getNextJsVersionBucket)('11.2.5')).toBe('11.x'); (0, vitest_1.expect)((0, utils_1.getNextJsVersionBucket)('13.5.2')).toBe('13.x'); (0, vitest_1.expect)((0, utils_1.getNextJsVersionBucket)('14.0.0')).toBe('14.x'); }); }); (0, vitest_1.describe)('getMaybeAppDirLocation', () => { const mockCwd = '/mock/cwd'; let originalCwd; (0, vitest_1.beforeEach)(() => { // eslint-disable-next-line @typescript-eslint/unbound-method originalCwd = process.cwd; process.cwd = vitest_1.vi.fn(() => mockCwd); vitest_1.vi.clearAllMocks(); }); (0, vitest_1.afterEach)(() => { process.cwd = originalCwd; }); (0, vitest_1.it)('returns ["app"] when app directory exists in root', () => { fs.existsSync.mockImplementation((filePath) => { return filePath === '/mock/cwd/app'; }); fs.lstatSync.mockImplementation((filePath) => ({ isDirectory: () => filePath === '/mock/cwd/app', })); (0, vitest_1.expect)((0, utils_1.getMaybeAppDirLocation)()).toEqual(['app']); }); (0, vitest_1.it)('returns ["src", "app"] when app directory exists in src', () => { fs.existsSync.mockImplementation((filePath) => { return filePath === '/mock/cwd/src/app'; }); fs.lstatSync.mockImplementation((filePath) => ({ isDirectory: () => filePath === '/mock/cwd/src/app', })); (0, vitest_1.expect)((0, utils_1.getMaybeAppDirLocation)()).toEqual(['src', 'app']); }); (0, vitest_1.it)('returns undefined when no app directory exists', () => { fs.existsSync.mockReturnValue(false); (0, vitest_1.expect)((0, utils_1.getMaybeAppDirLocation)()).toBeUndefined(); }); }); (0, vitest_1.describe)('hasRootLayoutFile', () => { (0, vitest_1.beforeEach)(() => { vitest_1.vi.clearAllMocks(); }); (0, vitest_1.it)('returns true when layout file exists with any supported extension', () => { const mockAppFolderPath = '/mock/app'; const supportedExtensions = ['jsx', 'tsx', 'js']; supportedExtensions.forEach((ext) => { fs.existsSync.mockImplementation((filePath) => { return filePath === `/mock/app/layout.${ext}`; }); (0, vitest_1.expect)((0, utils_1.hasRootLayoutFile)(mockAppFolderPath)).toBe(true); }); }); (0, vitest_1.it)('returns false when no layout file exists', () => { const mockAppFolderPath = '/mock/app'; fs.existsSync.mockReturnValue(false); (0, vitest_1.expect)((0, utils_1.hasRootLayoutFile)(mockAppFolderPath)).toBe(false); }); }); }); //# sourceMappingURL=utils.test.js.map