microsoft/vscode-react-native

Public

mirrored from https://github.com/microsoft/vscode-react-nativeAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
7b48f26eb8caae7ed9cc1a09249195dfed76fa76

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

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
4import { MacOSDebugModeManager } from "../../../src/extension/macos/macOSDebugModeManager";
5
6import assert = require("assert");
7import * as path from "path";
8import * as sinon from "sinon";
9import { homedir } from "os";
10
11suite("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