Skip to content

Commit

Permalink
Rename lib/shared/info.js -> lib/shared/runtime-info.js
Browse files Browse the repository at this point in the history
  • Loading branch information
kaicataldo committed Sep 16, 2019
1 parent 654d543 commit 7479f90
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
6 changes: 3 additions & 3 deletions lib/cli.js
Expand Up @@ -21,7 +21,7 @@ const fs = require("fs"),
{ CLIEngine } = require("./cli-engine"),
options = require("./options"),
log = require("./shared/logging"),
info = require("./shared/info");
RuntimeInfo = require("./shared/runtime-info");

const debug = require("debug")("eslint:cli");

Expand Down Expand Up @@ -163,10 +163,10 @@ const cli = {
const useStdin = typeof text === "string";

if (currentOptions.version) {
log.info(info.version());
log.info(RuntimeInfo.version());
} else if (currentOptions.info) {
try {
log.info(info.environment());
log.info(RuntimeInfo.environment());
return 0;
} catch (err) {
log.error(err.message);
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions tests/lib/cli.js
Expand Up @@ -34,13 +34,13 @@ describe("cli", () => {
info: sinon.spy(),
error: sinon.spy()
};
const info = {
const RuntimeInfo = {
environment: sinon.stub(),
version: sinon.stub()
};
const cli = proxyquire("../../lib/cli", {
"./shared/logging": log,
"./shared/info": info
"./shared/runtime-info": RuntimeInfo
});

/**
Expand Down Expand Up @@ -339,7 +339,7 @@ describe("cli", () => {
});

it("should print error message and return error code", () => {
info.environment.throws("There was an error!");
RuntimeInfo.environment.throws("There was an error!");

assert.strictEqual(cli.execute("--info"), 2);
assert.strictEqual(log.error.callCount, 1);
Expand Down
24 changes: 12 additions & 12 deletions tests/lib/shared/info.js → tests/lib/shared/runtime-info.js
@@ -1,5 +1,5 @@
/**
* @fileoverview Tests for info util
* @fileoverview Tests for RuntimeInfo util
* @author Kai Cataldo
*/

Expand All @@ -13,7 +13,7 @@ const assert = require("chai").assert;
const sinon = require("sinon");
const spawn = require("cross-spawn");
const { unIndent } = require("../_utils");
const info = require("../../../lib/shared/info");
const RuntimeInfo = require("../../../lib/shared/runtime-info");
const log = require("../../../lib/shared/logging");
const packageJson = require("../../../package.json");

Expand Down Expand Up @@ -44,7 +44,7 @@ function setupSpawnSyncStubReturnVals(stub, returnVals) {
return stubChain;
}

describe("info", () => {
describe("RuntimeInfo", () => {
describe("environment()", () => {
let spawnSyncStub;
let logErrorStub;
Expand Down Expand Up @@ -97,7 +97,7 @@ describe("info", () => {
setupSpawnSyncStubReturnVals(spawnSyncStub, spawnSyncStubArgs);

assert.strictEqual(
info.environment(),
RuntimeInfo.environment(),
unIndent`
Environment Info:
Expand All @@ -114,7 +114,7 @@ describe("info", () => {
process.argv[1] = GLOBAL_ESLINT_BIN_PATH;

assert.strictEqual(
info.environment(),
RuntimeInfo.environment(),
unIndent`
Environment Info:
Expand All @@ -137,7 +137,7 @@ describe("info", () => {
process.argv[1] = GLOBAL_ESLINT_BIN_PATH;

assert.strictEqual(
info.environment(),
RuntimeInfo.environment(),
unIndent`
Environment Info:
Expand All @@ -154,7 +154,7 @@ describe("info", () => {
setupSpawnSyncStubReturnVals(spawnSyncStub, spawnSyncStubArgs);

assert.strictEqual(
info.environment(),
RuntimeInfo.environment(),
unIndent`
Environment Info:
Expand All @@ -172,7 +172,7 @@ describe("info", () => {
spawnSyncStubArgs[1] = expectedErr;
setupSpawnSyncStubReturnVals(spawnSyncStub, spawnSyncStubArgs);

assert.throws(info.environment, expectedErr);
assert.throws(RuntimeInfo.environment, expectedErr);
assert.strictEqual(logErrorStub.args[0][0], "Error finding npm version running the command `npm --version`");
});

Expand All @@ -182,30 +182,30 @@ describe("info", () => {
spawnSyncStubArgs[3] = expectedErr;
setupSpawnSyncStubReturnVals(spawnSyncStub, spawnSyncStubArgs);

assert.throws(info.environment, expectedErr);
assert.throws(RuntimeInfo.environment, expectedErr);
assert.strictEqual(logErrorStub.args[0][0], "Error finding npm binary path when running command `npm bin -g`");
});

it("log and throw an error when checking for local ESLint version when returned output of command is malformed", () => {
spawnSyncStubArgs[2] = "This is not JSON";
setupSpawnSyncStubReturnVals(spawnSyncStub, spawnSyncStubArgs);

assert.throws(info.environment, "Unexpected token T in JSON at position 0");
assert.throws(RuntimeInfo.environment, "Unexpected token T in JSON at position 0");
assert.strictEqual(logErrorStub.args[0][0], "Error finding eslint version running the command `npm ls --depth=0 --json eslint`");
});

it("log and throw an error when checking for global ESLint version when returned output of command is malformed", () => {
spawnSyncStubArgs[4] = "This is not JSON";
setupSpawnSyncStubReturnVals(spawnSyncStub, spawnSyncStubArgs);

assert.throws(info.environment, "Unexpected token T in JSON at position 0");
assert.throws(RuntimeInfo.environment, "Unexpected token T in JSON at position 0");
assert.strictEqual(logErrorStub.args[0][0], "Error finding eslint version running the command `npm ls --depth=0 --json eslint -g`");
});
});

describe("version()", () => {
it("should return the version of the package defined in package.json", () => {
assert.strictEqual(info.version(), `v${packageJson.version}`);
assert.strictEqual(RuntimeInfo.version(), `v${packageJson.version}`);
});
});
});

0 comments on commit 7479f90

Please sign in to comment.