Skip to content

Commit

Permalink
test: validate configuration search
Browse files Browse the repository at this point in the history
  • Loading branch information
KamiKillertO committed Jul 30, 2020
1 parent 2f68ead commit e01e235
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { config_from_path, find_local_config } = require("./cli/read-config");
const { config_from_path, find_local_config } = require("./read-config");
const Linter = require("./linter");
const LegacyLinter = require("./legacy/linter");
const presets = require("./presets").presets;
Expand Down
4 changes: 2 additions & 2 deletions lib/cli/read-config.js → lib/read-config.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const { cosmiconfigSync } = require("cosmiconfig");
const path = require("path");
const fs = require("fs");
const CustomError = require("../utils/custom-errors");
const CustomError = require("./utils/custom-errors");

const explorer = cosmiconfigSync("linthtml", { /* stopDir: process.cwd(), */ packageProp: "linthtmlConfig" });

module.exports.config_from_path = function(file_path) {
const config_path = path.join(process.cwd(), file_path);
const config_path = path.resolve(process.cwd(), file_path);
let isConfigDirectory = false;
try {
let config = null;
Expand Down
4 changes: 4 additions & 0 deletions lib/utils/custom-errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ class CustomError extends Error {
this.code = code;
this.meta = meta;
}

get [Symbol.toStringTag]() {
return "CustomError";
}
}

module.exports = CustomError;
43 changes: 43 additions & 0 deletions test/unit/config_reader/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
const { expect } = require("chai");
const { config_from_path, find_local_config } = require("../../../lib/read-config");
const path = require("path");

describe("Get config from path", function() {
it("Report an error if path provided does not exist", function() {
try {
config_from_path("unknow_file");
} catch (error) {
expect(error).to.be.a("CustomError");
expect(error)
.to
.have
.property("code", "CLI-02");
expect(error)
.to
.have
.deep
.property("meta", {
config_path: path.join(process.cwd(), "unknow_file")
});
}
});

it("Report an error when there's no config file in the folder provided", function() {
try {
config_from_path(__dirname);
} catch (error) {
expect(error).to.be.a("CustomError");
expect(error)
.to
.have
.property("code", "CLI-01");
expect(error)
.to
.have
.deep
.property("meta", {
config_path: __dirname
});
}
});
});

0 comments on commit e01e235

Please sign in to comment.