microsoft/vscode-react-native
Publicmirrored from https://github.com/microsoft/vscode-react-nativeAvailable
test/extension/ios/xcodeproj.test.ts
60lines · 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 {Xcodeproj} from "../../../src/extension/ios/xcodeproj"; |
| 5 | |
| 6 | import * as assert from "assert"; |
| 7 | import * as path from "path"; |
| 8 | import * as Q from "q"; |
| 9 | |
| 10 | suite("xcodeproj", function() { |
| 11 | suite("extensionContext", function() { |
| 12 | test("should look in the correct location for xcodeproj files and return one", function() { |
| 13 | const projectRoot = path.join("/", "tmp", "myProject"); |
| 14 | const projectName = "foo"; |
| 15 | const fileType = ".xcodeproj"; |
| 16 | const testFiles = [projectName + fileType]; |
| 17 | const mockFileSystem: any = { |
| 18 | readDir: () => { |
| 19 | return Q(testFiles); |
| 20 | }, |
| 21 | }; |
| 22 | |
| 23 | const xcodeproj = new Xcodeproj({ nodeFileSystem: mockFileSystem }); |
| 24 | |
| 25 | return xcodeproj.findXcodeprojFile(projectRoot) |
| 26 | .then((proj) => { |
| 27 | assert.deepEqual(proj, { |
| 28 | fileName: path.join(projectRoot, testFiles[0]), |
| 29 | fileType, |
| 30 | projectName, |
| 31 | }); |
| 32 | }); |
| 33 | }); |
| 34 | test("should look in the correct location for xcodeproj/xcworkspace files and prefer xcworkspace over xcodeproj", function() { |
| 35 | const projectRoot = path.join("/", "tmp", "myProject"); |
| 36 | const projectName = "foo"; |
| 37 | const xcodeprojFileType = ".xcodeproj"; |
| 38 | const xcworkspaceFileType = ".xcworkspace"; |
| 39 | const xcodeprojFileName = projectName + xcodeprojFileType; |
| 40 | const xcworkspaceFileName = projectName + xcworkspaceFileType; |
| 41 | const testFiles = [xcodeprojFileName, xcworkspaceFileName]; |
| 42 | const mockFileSystem: any = { |
| 43 | readDir: () => { |
| 44 | return Q(testFiles); |
| 45 | }, |
| 46 | }; |
| 47 | |
| 48 | const xcodeproj = new Xcodeproj({ nodeFileSystem: mockFileSystem }); |
| 49 | |
| 50 | return xcodeproj.findXcodeprojFile(projectRoot) |
| 51 | .then((proj) => { |
| 52 | assert.deepEqual(proj, { |
| 53 | fileName: path.join(projectRoot, xcworkspaceFileName), |
| 54 | fileType: xcworkspaceFileType, |
| 55 | projectName, |
| 56 | }); |
| 57 | }); |
| 58 | }); |
| 59 | }); |
| 60 | }); |
| 61 | |