microsoft/vscode-react-native
Publicmirrored from https://github.com/microsoft/vscode-react-nativeAvailable
test/extension/exponent/exponentHelper.test.ts
42lines · 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 { ExponentHelper } from "../../../src/extension/exponent/exponentHelper"; |
| 5 | import * as path from "path"; |
| 6 | import * as assert from "assert"; |
| 7 | import * as sinon from "sinon"; |
| 8 | import * as Q from "q"; |
| 9 | import { FileSystem } from "../../../src/common/node/fileSystem"; |
| 10 | |
| 11 | suite("exponentHelper", function() { |
| 12 | const RESOURCES_ROOT = path.resolve(__dirname, "../../resources/exponentHelper"); |
| 13 | |
| 14 | async function checkIsExpoApp(packageJson: any, expected: boolean) { |
| 15 | let fs = new FileSystem(); |
| 16 | sinon.stub(fs, "readFile", () => Q.resolve(JSON.stringify(packageJson))); |
| 17 | const expoHelper = new ExponentHelper(RESOURCES_ROOT, "", fs); |
| 18 | const result = await expoHelper.isExpoApp(false); |
| 19 | assert.equal(result, expected); |
| 20 | } |
| 21 | |
| 22 | suite("extensionContext", () => { |
| 23 | suite("isExp", () => { |
| 24 | test("should return false if dependencies are empty", async () => { |
| 25 | await checkIsExpoApp({}, false); |
| 26 | }); |
| 27 | test("should return false if (dev)dependencies.expo is missing", async () => { |
| 28 | await checkIsExpoApp({dependencies: {}}, false); |
| 29 | await checkIsExpoApp({devDependencies: {}}, false); |
| 30 | }); |
| 31 | test("should return false if dependencies.react-native is missing or incorrect", async () => { |
| 32 | await checkIsExpoApp({dependencies: {}}, false); |
| 33 | await checkIsExpoApp({dependencies: {"react-native": ""}}, false); |
| 34 | await checkIsExpoApp({dependencies: {"react-native": "0.58.8"}}, false); |
| 35 | }); |
| 36 | test("should return true if (dev)dependencies.expo exists and dependencies.react-native is correct", async () => { |
| 37 | await checkIsExpoApp({dependencies: {expo: "33.0.1", "react-native": "https://github.com/expo/react-native/archive/sdk-31.0.0.tar.gz"}}, true); |
| 38 | await checkIsExpoApp({devDependencies: {expo: "33.0.1"}, dependencies: {"react-native": "https://github.com/expo/react-native/archive/sdk-31.0.0.tar.gz"}}, true); |
| 39 | }); |
| 40 | }); |
| 41 | }); |
| 42 | }); |