microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
0.4.1

Branches

Tags

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

Clone

HTTPS

Download ZIP

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

77lines · modeblame

db80cd4eJimmy Thomson10 years ago1// 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
f5edf87fJimmy Thomson10 years ago6import * as assert from "assert";
db80cd4eJimmy Thomson10 years ago7import * as path from "path";
8import * as Q from "q";
9import * as sinon from "sinon";
10
11suite("plistBuddy", function() {
12suite("commonContext", function() {
2bc72bf2Jimmy Thomson10 years ago13test("findPlistFile should correctly find the NSUserDefaults plist file for the simulator", function() {
14const projectRoot = path.join("/", "tmp", "myProject");
db80cd4eJimmy Thomson10 years ago15
16const bundleId = "com.contoso.app";
17
18const findSimulatorHomeCommand = "xcrun simctl getenv booted HOME";
19// The emulator's home folder is /simulator/home
2bc72bf2Jimmy Thomson10 years ago20const findSimulatorHomeResult = path.join("/", "Users", "theUser", "Library", "Developer", "CoreSimulaotr", "Devices", "FA511653-BA51-479F-A218-1DBD1910D5E5/data");
db80cd4eJimmy Thomson10 years ago21
22const prefix = path.join("Containers", "Data", "Application");
23const suffix = path.join("Library", "Preferences");
24
2bc72bf2Jimmy Thomson10 years ago25// The emulator has 3 apps
26const appIds = ["17F3AED1-5B1D-4F97-B419-D1F079D9DE2D",
27"957660FD-3417-474E-B2AC-8AA0A05AD9A0",
cdf34447digeff10 years ago28"18319C8B-0583-4967-8023-15859A0BF0F3",
29];
db80cd4eJimmy Thomson10 years ago30
31// readdir finds appIds
32const mockReadDir = sinon.stub();
33mockReadDir.withArgs(path.join(findSimulatorHomeResult, prefix)).returns(Q.resolve(appIds));
34mockReadDir.throws();
35
2bc72bf2Jimmy Thomson10 years ago36// Only the second app has a plist file with thus bundle name
37const existingPlistFile = path.join(findSimulatorHomeResult, prefix, "957660FD-3417-474E-B2AC-8AA0A05AD9A0", suffix, `${bundleId}.plist`);
db80cd4eJimmy Thomson10 years ago38
39// existsSync only finds existingPlistFile to exist
40const mockExistsSync = sinon.stub();
41mockExistsSync.withArgs(existingPlistFile).returns(true);
42mockExistsSync.returns(false);
43
44const mockFS: any = {
45existsSync: mockExistsSync,
cdf34447digeff10 years ago46readDir: mockReadDir,
db80cd4eJimmy Thomson10 years ago47};
48
49// getBundleId returns bundleId
50const bundleIdStub = sinon.stub();
51bundleIdStub.withArgs(projectRoot).returns(Q.resolve(bundleId));
52bundleIdStub.returns(Q.reject("Incorrect project root"));
53
54const mockPlistBuddy: any = {
cdf34447digeff10 years ago55getBundleId: bundleIdStub,
db80cd4eJimmy Thomson10 years ago56};
57
58// exec-ing the correct command returns the simulator home
59const execStub = sinon.stub();
60execStub.withArgs(findSimulatorHomeCommand).returns({ outcome: Q.resolve(findSimulatorHomeResult) });
61execStub.throws();
62const mockChildProcess: any = {
cdf34447digeff10 years ago63exec: execStub,
db80cd4eJimmy Thomson10 years ago64};
65
66const simulatorPlist = new SimulatorPlist(projectRoot, {
67nodeFileSystem: mockFS,
68plistBuddy: mockPlistBuddy,
cdf34447digeff10 years ago69nodeChildProcess: mockChildProcess,
db80cd4eJimmy Thomson10 years ago70});
71
72return simulatorPlist.findPlistFile().then((plistFile) => {
f5edf87fJimmy Thomson10 years ago73assert(plistFile === existingPlistFile, "Returned incorrect value");
db80cd4eJimmy Thomson10 years ago74});
75});
76});
77});