microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
0.1.1

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/test/common/ios/simulatorPlist.test.ts

76lines · 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 {SimulatorPlist} from "../../../common/ios/simulatorPlist";
5
6import * as assert from "assert";
7import * as path from "path";
8import * as Q from "q";
9import * as sinon from "sinon";
10
11suite("plistBuddy", function() {
12 suite("commonContext", function() {
13 test("findPlistFile should correctly find the NSUserDefaults plist file for the simulator", function() {
14 const projectRoot = path.join("/", "tmp", "myProject");
15
16 const bundleId = "com.contoso.app";
17
18 const findSimulatorHomeCommand = "xcrun simctl getenv booted HOME";
19 // The emulator's home folder is /simulator/home
20 const findSimulatorHomeResult = path.join("/", "Users", "theUser", "Library", "Developer", "CoreSimulaotr", "Devices", "FA511653-BA51-479F-A218-1DBD1910D5E5/data");
21
22 const prefix = path.join("Containers", "Data", "Application");
23 const suffix = path.join("Library", "Preferences");
24
25 // The emulator has 3 apps
26 const appIds = ["17F3AED1-5B1D-4F97-B419-D1F079D9DE2D",
27 "957660FD-3417-474E-B2AC-8AA0A05AD9A0",
28 "18319C8B-0583-4967-8023-15859A0BF0F3"];
29
30 // readdir finds appIds
31 const mockReadDir = sinon.stub();
32 mockReadDir.withArgs(path.join(findSimulatorHomeResult, prefix)).returns(Q.resolve(appIds));
33 mockReadDir.throws();
34
35 // Only the second app has a plist file with thus bundle name
36 const existingPlistFile = path.join(findSimulatorHomeResult, prefix, "957660FD-3417-474E-B2AC-8AA0A05AD9A0", suffix, `${bundleId}.plist`);
37
38 // existsSync only finds existingPlistFile to exist
39 const mockExistsSync = sinon.stub();
40 mockExistsSync.withArgs(existingPlistFile).returns(true);
41 mockExistsSync.returns(false);
42
43 const mockFS: any = {
44 existsSync: mockExistsSync,
45 readDir: mockReadDir
46 };
47
48 // getBundleId returns bundleId
49 const bundleIdStub = sinon.stub();
50 bundleIdStub.withArgs(projectRoot).returns(Q.resolve(bundleId));
51 bundleIdStub.returns(Q.reject("Incorrect project root"));
52
53 const mockPlistBuddy: any = {
54 getBundleId: bundleIdStub
55 };
56
57 // exec-ing the correct command returns the simulator home
58 const execStub = sinon.stub();
59 execStub.withArgs(findSimulatorHomeCommand).returns({ outcome: Q.resolve(findSimulatorHomeResult) });
60 execStub.throws();
61 const mockChildProcess: any = {
62 exec: execStub
63 };
64
65 const simulatorPlist = new SimulatorPlist(projectRoot, {
66 nodeFileSystem: mockFS,
67 plistBuddy: mockPlistBuddy,
68 nodeChildProcess: mockChildProcess
69 });
70
71 return simulatorPlist.findPlistFile().then((plistFile) => {
72 assert(plistFile === existingPlistFile, "Returned incorrect value");
73 });
74 });
75 });
76});