Skip to content

Commit

Permalink
fix: re-establish 100% test coverage and improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
moritzjacobs committed Sep 18, 2020
1 parent 2f1d1a5 commit 7618d01
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/cliConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ export default (argv: Array<string>): CliConfig => {

program.parse(argv);

const cliConfig: CliConfig = { packageFile };
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
const cliConfig: CliConfig = { packageFile: packageFile ?? process.cwd() };

if (program.fix !== undefined) {
cliConfig.fix = program.fix;
Expand Down
3 changes: 2 additions & 1 deletion src/cliModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export default (argv: Array<string>) => {

const userConfig = loadUserConfig();
const cliConfig = loadCliConfig(argv);

const config = {
...DEFAULT_CONFIG,
...{ json: false },
Expand All @@ -50,7 +51,7 @@ export default (argv: Array<string>) => {
writePackageScripts,
readPackageScripts,
} = userPackageScriptContext(
makePackageFilePath(config.packageFile ?? process.cwd())
makePackageFilePath(config.packageFile)
);

const scripts = readPackageScripts(config.ignoreScripts);
Expand Down
2 changes: 1 addition & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const DEFAULT_CONFIG: Config = {
fix: false,
json: false,
config: false,
packageFile: undefined,
packageFile: process.cwd(),
rules: {},
customRules: [],
ignoreScripts: [],
Expand Down
2 changes: 1 addition & 1 deletion src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default (moduleConfig: Partial<Config>) => {

if (!moduleConfig.packageScripts && moduleConfig.packageFile) {
const { readPackageScripts } = userPackageScriptContext(
makePackageFilePath(config.packageFile ?? "")
makePackageFilePath(config.packageFile)
);

scripts = readPackageScripts(config.ignoreScripts);
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export type PackageScripts = {

export type Config = {
strict: boolean;
packageFile?: string;
packageFile: string;
packageScripts?: PackageScripts;
fix: boolean;
json: boolean;
Expand Down
2 changes: 1 addition & 1 deletion tests/cliConfig.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe("cliConfig.ts", () => {
"-f",
]);

expect(packageFile).not.toBeDefined();
expect(packageFile).toEqual(process.cwd());

expect(config).toEqual({
fix: true,
Expand Down
3 changes: 2 additions & 1 deletion tests/userConfig.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const validConfig = {
strict: true,
fix: false,
json: false,
packageFile: "/foo/bar/baz",
config: false,
rules: { foo: "bar" },
ignoreScripts: ["foo"],
Expand Down Expand Up @@ -41,7 +42,7 @@ describe("userConfig.ts", () => {
test("loadConfig()", () => {
const loaded = loadConfig();

expect(loaded).toMatchSnapshot();
expect({...loaded, packageFile: undefined}).toMatchSnapshot();
});

test("loadConfig() with config missing", () => {
Expand Down

0 comments on commit 7618d01

Please sign in to comment.