@sentry/wizard
Version:
Sentry wizard helping you to configure your project
88 lines • 6.08 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const node_path_1 = __importDefault(require("node:path"));
const vitest_1 = require("vitest");
const macos_system_helper_1 = require("../../src/apple/macos-system-helper");
const appleProjectsPath = node_path_1.default.resolve(__dirname, '../../fixtures/test-applications/apple');
const projectWithSynchronizedFolders = node_path_1.default.join(appleProjectsPath, 'xcode-15-compatible-project/Project.xcodeproj');
// The path to the Xcode.app can be different on different machines, therefore me must detect the path
// to the Xcode.app using the `xcode-select` command.
// The same goes for the SDK path, which can be different on different machines depending if the Command Line Tools
// or the full Xcode is installed.
//
// While creating these tests we ensured that the implementation in the tests is correct by comparing.
// We must not change the implementation in the test code unless we are sure that the implementation is correct!
(0, vitest_1.describe)('MacOSSystemHelpers', () => {
(0, vitest_1.afterEach)(() => {
vitest_1.vi.clearAllMocks();
vitest_1.vi.restoreAllMocks();
});
(0, vitest_1.describe)('findSDKRootDirectoryPath', () => {
vitest_1.test.runIf(process.platform === 'darwin')('should return the SDK root directory path', () => {
// -- Act --
const sdkRootDirectoryPath = macos_system_helper_1.MacOSSystemHelpers.findSDKRootDirectoryPath();
// -- Assert --
const candidates = [
// Matches the path for the Command Line Tools, e.g. /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk
/^\/Library\/Developer\/CommandLineTools\/SDKs\/MacOSX\.sdk$/i,
// Matches the path for the default Xcode.app, e.g. /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk
/^\/Applications\/Xcode\.app\/Contents\/Developer\/Platforms\/MacOSX\.platform\/Developer\/SDKs\/MacOSX\.sdk$/i,
// Matches the path for any Xcode.app, e.g. /Applications/Xcode-16.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk
/^\/Applications\/Xcode.+\.app\/Contents\/Developer\/Platforms\/MacOSX\.platform\/Developer\/SDKs\/MacOSX\.sdk$/i,
];
(0, vitest_1.expect)(sdkRootDirectoryPath).toSatisfy((path) => candidates.some((regex) => regex.test(path)));
});
vitest_1.test.runIf(process.platform !== 'darwin')('should return undefined on non-macOS platforms', () => {
// The purpose of this test is to verify that the implementation of findSDKRootDirectoryPath() is still unchanged
// -- Act --
const sdkRootDirectoryPath = macos_system_helper_1.MacOSSystemHelpers.findSDKRootDirectoryPath();
// -- Assert --
(0, vitest_1.expect)(sdkRootDirectoryPath).toBeUndefined();
});
});
(0, vitest_1.describe)('findDeveloperDirectoryPath', () => {
vitest_1.test.runIf(process.platform === 'darwin')('should return the developer directory path', () => {
// -- Act --
const developerDirectoryPath = macos_system_helper_1.MacOSSystemHelpers.findDeveloperDirectoryPath();
// -- Assert --
const candidates = [
// Matches the path for the default Xcode.app, e.g. /Applications/Xcode.app/Contents/Developer
/^\/Applications\/Xcode\.app\/Contents\/Developer$/i,
// Matches the path for any Xcode.app, e.g. /Applications/Xcode-16.0.app/Contents/Developer
/^\/Applications\/Xcode.+\.app\/Contents\/Developer$/i,
];
(0, vitest_1.expect)(developerDirectoryPath).toSatisfy((path) => candidates.some((regex) => regex.test(path)));
});
vitest_1.test.runIf(process.platform !== 'darwin')('should return undefined on non-macOS platforms', () => {
// The purpose of this test is to verify that the implementation of findDeveloperDirectoryPath() is still unchanged
// -- Act --
const developerDirectoryPath = macos_system_helper_1.MacOSSystemHelpers.findDeveloperDirectoryPath();
// -- Assert --
(0, vitest_1.expect)(developerDirectoryPath).toBeUndefined();
});
});
(0, vitest_1.describe)('readXcodeBuildSettings', () => {
vitest_1.test.runIf(process.platform === 'darwin')('should return the build settings', () => {
// -- Act --
const buildSettings = macos_system_helper_1.MacOSSystemHelpers.readXcodeBuildSettings(projectWithSynchronizedFolders);
// -- Assert --
// The build settings are a massive list of key-value pairs, so we'll just check a few of them
// which are relevant for our use cases.
(0, vitest_1.expect)(buildSettings?.['CONFIGURATION_BUILD_DIR']).toEqual(node_path_1.default.join(appleProjectsPath, 'xcode-15-compatible-project/build/Release-unknown'));
(0, vitest_1.expect)(buildSettings?.['TARGET_BUILD_DIR']).toEqual(node_path_1.default.join(appleProjectsPath, 'xcode-15-compatible-project/build/Release-unknown'));
},
// Increased timeout to 10 seconds due to timeout errors for Node 18 and Node 20
10000);
vitest_1.test.runIf(process.platform !== 'darwin')('should return undefined on non-macOS platforms', () => {
// The purpose of this test is to verify that the implementation of readXcodeBuildSettings() is still unchanged
// -- Act --
const buildSettings = macos_system_helper_1.MacOSSystemHelpers.readXcodeBuildSettings(projectWithSynchronizedFolders);
// -- Assert --
(0, vitest_1.expect)(buildSettings).toBeUndefined();
});
});
});
//# sourceMappingURL=macos-system-helper.test.js.map