Skip to content

Commit

Permalink
tests for custom config file location
Browse files Browse the repository at this point in the history
  • Loading branch information
chris48s committed Oct 23, 2024
1 parent 921c039 commit f9546ff
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
26 changes: 17 additions & 9 deletions src/bootstrap.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,7 @@ describe("getConfig", function () {
const { config } = await bootstrap(
["node", "index.js", "infile.json"],
undefined,
{
searchPlaces: ["./testfiles/does-not-exist.json"],
cache: false,
},
{ cache: false },
);
assert.equal(config.ignoreErrors, false);
assert.equal(config.cacheTtl, 600);
Expand All @@ -176,9 +173,22 @@ describe("getConfig", function () {
assert(logContainsInfo("No config file found"));
});

it("should throw if V8R_CONFIG_FILE does not exist", async function () {
process.env.V8R_CONFIG_FILE = "./testfiles/does-not-exist.json";
await assert.rejects(
bootstrap(["node", "index.js", "infile.json"], undefined, {
cache: false,
}),
{
name: "Error",
message: "File ./testfiles/does-not-exist.json does not exist.",
},
);
});

it("should read options from config file if available", async function () {
process.env.V8R_CONFIG_FILE = "./testfiles/configs/config.json";
const { config } = await bootstrap(["node", "index.js"], undefined, {
searchPlaces: ["./testfiles/configs/config.json"],
cache: false,
});
assert.equal(config.ignoreErrors, true);
Expand Down Expand Up @@ -208,6 +218,7 @@ describe("getConfig", function () {
});

it("should override options from config file with args if specified", async function () {
process.env.V8R_CONFIG_FILE = "./testfiles/configs/config.json";
const { config } = await bootstrap(
[
"node",
Expand All @@ -219,10 +230,7 @@ describe("getConfig", function () {
"-vv",
],
undefined,
{
searchPlaces: ["./testfiles/configs/config.json"],
cache: false,
},
{ cache: false },
);
assert.deepStrictEqual(config.patterns, ["infile.json"]);
assert.equal(config.ignoreErrors, true);
Expand Down
3 changes: 3 additions & 0 deletions src/test-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import logger from "./logger.js";
const origWriteOut = logger.writeOut;
const origWriteErr = logger.writeErr;
const testCacheName = process.env.V8R_CACHE_NAME;
const env = process.env;

function setUp() {
flatCache.clearCacheById(testCacheName);
logger.resetStdout();
logger.resetStderr();
logger.writeOut = function () {};
logger.writeErr = function () {};
process.env = { ...env };
}

function tearDown() {
Expand All @@ -19,6 +21,7 @@ function tearDown() {
logger.resetStderr();
logger.writeOut = origWriteOut;
logger.writeErr = origWriteErr;
process.env = env;
}

function isString(el) {
Expand Down

0 comments on commit f9546ff

Please sign in to comment.