microsoft/vscode-react-native
Publicmirrored from https://github.com/microsoft/vscode-react-nativeAvailable
test/common/log.test.ts
50lines · 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 * as assert from "assert"; |
| 5 | import * as fs from "fs"; |
| 6 | import * as path from "path"; |
| 7 | import { getLoggingDirectory } from "../../src/extension/log/LogHelper"; |
| 8 | |
| 9 | suite("logHelper", function() { |
| 10 | suite("commonContext", function() { |
| 11 | const REACT_NATIVE_TOOLS_LOGS_DIR = process.env.REACT_NATIVE_TOOLS_LOGS_DIR; |
| 12 | suiteSetup(() => { |
| 13 | delete process.env.REACT_NATIVE_TOOLS_LOGS_DIR; |
| 14 | }); |
| 15 | |
| 16 | suiteTeardown(() => { |
| 17 | process.env.REACT_NATIVE_TOOLS_LOGS_DIR = REACT_NATIVE_TOOLS_LOGS_DIR; |
| 18 | }); |
| 19 | |
| 20 | test("getLoggingDirectory should return null if env variable REACT_NATIVE_TOOLS_LOGS_DIR is not defined", (done: MochaDone) => { |
| 21 | let loggingDir = getLoggingDirectory(); |
| 22 | assert.strictEqual(loggingDir, null); |
| 23 | done(); |
| 24 | }); |
| 25 | |
| 26 | test("getLoggingDirectory should return null if env variable REACT_NATIVE_TOOLS_LOGS_DIR is defined by relative path", (done: MochaDone) => { |
| 27 | process.env.REACT_NATIVE_TOOLS_LOGS_DIR = "./logs"; |
| 28 | let loggingDir = getLoggingDirectory(); |
| 29 | assert.strictEqual(loggingDir, null); |
| 30 | done(); |
| 31 | }); |
| 32 | |
| 33 | test("getLoggingDirectory should return correct value if env variable REACT_NATIVE_TOOLS_LOGS_DIR is defined by absolute path", (done: MochaDone) => { |
| 34 | process.env.REACT_NATIVE_TOOLS_LOGS_DIR = path.join(__dirname, "testFolder"); |
| 35 | let loggingDir = getLoggingDirectory(); |
| 36 | assert.strictEqual(loggingDir, process.env.REACT_NATIVE_TOOLS_LOGS_DIR); |
| 37 | if (loggingDir) { |
| 38 | const checkDir = fs.existsSync(loggingDir); |
| 39 | if (checkDir) { |
| 40 | fs.rmdirSync(loggingDir); |
| 41 | } else { |
| 42 | assert.fail("getLoggingDirectory did not create a directory"); |
| 43 | } |
| 44 | } else { |
| 45 | assert.fail(`${loggingDir} is not a correct path`); |
| 46 | } |
| 47 | done(); |
| 48 | }); |
| 49 | }); |
| 50 | }); |
| 51 | |