microsoft/vscode-react-native
Publicmirrored from https://github.com/microsoft/vscode-react-nativeAvailable
test/extension/macos/macOSDebugModeManager.test.ts
57lines · modecode
| 1 | // Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | // Licensed under the MIT license. See LICENSE file in the project root for details. |
| 3 | |
| 4 | import { MacOSDebugModeManager } from "../../../src/extension/macos/macOSDebugModeManager"; |
| 5 | |
| 6 | import assert = require("assert"); |
| 7 | import * as path from "path"; |
| 8 | import * as sinon from "sinon"; |
| 9 | import { homedir } from "os"; |
| 10 | |
| 11 | suite("macOSDebugModeManager", function () { |
| 12 | suite("extensionContext", function () { |
| 13 | test("findPlistFile should correctly find the NSUserDefaults plist file for an app", async function () { |
| 14 | const projectRoot = path.join("/", "tmp"); |
| 15 | const macosProjectRoot = path.join(projectRoot, "myProject"); |
| 16 | const bundleId = "org.reactjs.native.rn-macos"; |
| 17 | |
| 18 | const existingPlistFilePath = path.join( |
| 19 | homedir(), |
| 20 | "Library", |
| 21 | "Preferences", |
| 22 | `${bundleId}.plist`, |
| 23 | ); |
| 24 | |
| 25 | // "exists" only finds existingPlistFile file |
| 26 | const mockExists = sinon.stub(); |
| 27 | mockExists.withArgs(existingPlistFilePath).returns(Promise.resolve(true)); |
| 28 | mockExists.returns(Promise.resolve(false)); |
| 29 | |
| 30 | const mockFS: any = { |
| 31 | exists: mockExists, |
| 32 | }; |
| 33 | |
| 34 | // getBundleId returns bundleId |
| 35 | const bundleIdStub = sinon.stub(); |
| 36 | bundleIdStub.withArgs(macosProjectRoot).returns(Promise.resolve(bundleId)); |
| 37 | bundleIdStub.returns(Promise.reject("Incorrect project root")); |
| 38 | |
| 39 | const mockPlistBuddy: any = { |
| 40 | getBundleId: bundleIdStub, |
| 41 | }; |
| 42 | |
| 43 | let macOSDebugModeManager = new MacOSDebugModeManager( |
| 44 | macosProjectRoot, |
| 45 | projectRoot, |
| 46 | undefined, |
| 47 | { |
| 48 | nodeFileSystem: mockFS, |
| 49 | plistBuddy: mockPlistBuddy, |
| 50 | }, |
| 51 | ); |
| 52 | |
| 53 | const plistFile = await (macOSDebugModeManager as any).findPlistFile(); |
| 54 | assert(plistFile === existingPlistFilePath, "Returned incorrect value"); |
| 55 | }); |
| 56 | }); |
| 57 | }); |
| 58 | |