Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve project configuration #7

Merged
merged 5 commits into from
May 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,19 @@
"jest": true
},
"rules": {
"semi": ["error", "always"]
"semi": ["error", "always"],
"unicorn/filename-case": ["error", { "case": "camelCase" }],
"unicorn/catch-error-name": ["error", { "caughtErrorsIgnorePattern": "^(e|error)$" }],
"unicorn/prevent-abbreviations": [
"error",
{
"whitelist": {
"e": true,
"args": true,
"obj": true
}
}
]
},
"extends": ["eslint:recommended", "prettier"]
}
"extends": ["eslint:recommended", "plugin:prettier/recommended", "plugin:unicorn/recommended"]
}
3 changes: 1 addition & 2 deletions .huskyrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"hooks": {
"pre-commit": "lint-staged && npm run test",
"pre-push": "lint-staged && npm run test"
"pre-commit": "lint-staged"
}
}
2 changes: 1 addition & 1 deletion .lintstagedrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"*.js": ["npx eslint --fix", "npx prettier --write", "git add"]
"*.js": ["npx eslint", "git add"]
}
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.vscode
node_modules
coverage
5 changes: 5 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"printWidth": 120,
"useTabs": true,
"tabWidth": 4
}
33 changes: 33 additions & 0 deletions __tests__/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"parserOptions": {
"ecmaVersion": 2017,
"sourceType": "module"
},
"env": {
"es6": true,
"browser": true,
"node": true,
"jest": true
},
"rules": {
"semi": ["error", "always"],
"unicorn/filename-case": ["error", { "case": "camelCase" }],
"unicorn/catch-error-name": ["error", { "caughtErrorsIgnorePattern": "^(e|error)$" }],
"unicorn/prevent-abbreviations": [
"error",
{
"whitelist": {
"e": true,
"args": true,
"obj": true
}
}
]
},
"extends": [
"eslint:recommended",
"plugin:prettier/recommended",
"plugin:unicorn/recommended",
"plugin:jest/recommended"
]
}
72 changes: 36 additions & 36 deletions __tests__/acatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ describe("acatch tests", () => {
const catchInCatchBlockFn = getMockFn(jest)(() => input * 17, "catchInCatchBlockFn");
const result = await acatch(catchFn)(input).catch(catchInCatchBlockFn);
expect(result).toBe(input);
expect(catchFn).not.toBeCalled();
expect(catchInCatchBlockFn).not.toBeCalled();
expect(catchFn).not.toHaveBeenCalled();
expect(catchInCatchBlockFn).not.toHaveBeenCalled();
});
it("should work for case with promise on input without reject", async () => {
expect.assertions(6);
Expand All @@ -26,8 +26,8 @@ describe("acatch tests", () => {
expect(result).toBe(8);
mockFnExpectations(increment, 1, 8, input);
expect(increment).toHaveBeenCalledTimes(1);
expect(catchFn).not.toBeCalled();
expect(catchInCatchBlockFn).not.toBeCalled();
expect(catchFn).not.toHaveBeenCalled();
expect(catchInCatchBlockFn).not.toHaveBeenCalled();
});
it("should catch for case with rejected promise on input", async () => {
expect.assertions(6);
Expand All @@ -37,10 +37,10 @@ describe("acatch tests", () => {
const catchInCatchBlockFn = getMockFn(jest)(() => input * 17, "catchInCatchBlockFn");
const result = await acatch(catchFn)(createAsyncPromise(increment, false)(input)).catch(catchInCatchBlockFn);
expect(result).toBe(28);
expect(increment).not.toBeCalled();
expect(increment).not.toHaveBeenCalled();
mockFnExpectations(catchFn, 1, 28, getError(input));
expect(catchFn).toHaveBeenCalledTimes(1);
expect(catchInCatchBlockFn).not.toBeCalled();
expect(catchInCatchBlockFn).not.toHaveBeenCalled();
});
it("should work for reject in promise on input and promise in fallback", async () => {
expect.assertions(6);
Expand All @@ -52,10 +52,10 @@ describe("acatch tests", () => {
catchInCatchBlockFn
);
expect(result).toBe(28);
expect(increment).not.toBeCalled();
expect(increment).not.toHaveBeenCalled();
mockFnExpectations(catchFn, 1, 28, getError(input));
expect(catchFn).toHaveBeenCalledTimes(1);
expect(catchInCatchBlockFn).not.toBeCalled();
expect(catchInCatchBlockFn).not.toHaveBeenCalled();
});
it("should reject for rejection in fallback function", async () => {
expect.assertions(6);
Expand All @@ -67,8 +67,8 @@ describe("acatch tests", () => {
createSyncPromise(increment, false)(input)
).catch(catchInCatchBlockFn);
expect(result).toBe(119);
expect(increment).not.toBeCalled();
expect(catchFn).not.toBeCalled();
expect(increment).not.toHaveBeenCalled();
expect(catchFn).not.toHaveBeenCalled();
mockFnExpectations(catchInCatchBlockFn, 1, 119, getError(getError(input)));
expect(catchInCatchBlockFn).toHaveBeenCalledTimes(1);
});
Expand All @@ -83,8 +83,8 @@ describe("acatch in acompose tests", () => {
const catchInCatchBlockFn = getMockFn(jest)(() => input * 17, "catchInCatchBlockFn");
const result = await acompose(acatch(catchFn), increment2, increment1)(input).catch(catchInCatchBlockFn);
expect(result).toBe(9);
expect(catchFn).not.toBeCalled();
expect(catchInCatchBlockFn).not.toBeCalled();
expect(catchFn).not.toHaveBeenCalled();
expect(catchInCatchBlockFn).not.toHaveBeenCalled();
});
it("should work for case with reject in acompose chain", async () => {
expect.assertions(9);
Expand All @@ -98,12 +98,12 @@ describe("acatch in acompose tests", () => {
expect(result).toBe(28);
expect(catchFn).toHaveBeenCalledTimes(1);
mockFnExpectations(catchFn, 1, 28, getError(input + 1));
expect(catchInCatchBlockFn).not.toBeCalled();
expect(increment2).not.toBeCalled();
expect(catchInCatchBlockFn).not.toHaveBeenCalled();
expect(increment2).not.toHaveBeenCalled();
expect(increment1).toHaveBeenCalledTimes(1);
mockFnExpectations(increment1, 1, 8, input);
});
it("should work for case with reject in acompose chain", async () => {
it("should work for case with reject in acompose chain for first argument", async () => {
expect.assertions(7);
const input = 7;
const increment1 = incrementMock(jest, "increment1");
Expand All @@ -115,9 +115,9 @@ describe("acatch in acompose tests", () => {
expect(result).toBe(28);
expect(catchFn).toHaveBeenCalledTimes(1);
mockFnExpectations(catchFn, 1, 28, getError(input));
expect(catchInCatchBlockFn).not.toBeCalled();
expect(increment1).not.toBeCalled();
expect(increment2).not.toBeCalled();
expect(catchInCatchBlockFn).not.toHaveBeenCalled();
expect(increment1).not.toHaveBeenCalled();
expect(increment2).not.toHaveBeenCalled();
});
it("should work for case with reject in input", async () => {
expect.assertions(7);
Expand All @@ -134,9 +134,9 @@ describe("acatch in acompose tests", () => {
expect(result).toBe(28);
expect(catchFn).toHaveBeenCalledTimes(1);
mockFnExpectations(catchFn, 1, 28, getError(input));
expect(increment1).not.toBeCalled();
expect(increment2).not.toBeCalled();
expect(catchInCatchBlockFn).not.toBeCalled();
expect(increment1).not.toHaveBeenCalled();
expect(increment2).not.toHaveBeenCalled();
expect(catchInCatchBlockFn).not.toHaveBeenCalled();
});
it("should work for case with reject in acompose chain and acatch in middle", async () => {
expect.assertions(8);
Expand All @@ -149,8 +149,8 @@ describe("acatch in acompose tests", () => {
const result = await acompose(increment2, acatch(catchFn), increment1Promise)(input).catch(catchInCatchBlockFn);
expect(result).toBe(29);
mockFnExpectations(catchFn, 1, 28, getError(input));
expect(catchInCatchBlockFn).not.toBeCalled();
expect(increment1).not.toBeCalled();
expect(catchInCatchBlockFn).not.toHaveBeenCalled();
expect(increment1).not.toHaveBeenCalled();
expect(increment2).toHaveBeenCalledTimes(1);
mockFnExpectations(increment2, 1, 29, 28);
});
Expand All @@ -165,8 +165,8 @@ describe("acatch in apipe tests", () => {
const catchInCatchBlockFn = getMockFn(jest)(() => input * 17, "catchInCatchBlockFn");
const result = await apipe(increment1, increment2, acatch(catchFn))(input).catch(catchInCatchBlockFn);
expect(result).toBe(9);
expect(catchFn).not.toBeCalled();
expect(catchInCatchBlockFn).not.toBeCalled();
expect(catchFn).not.toHaveBeenCalled();
expect(catchInCatchBlockFn).not.toHaveBeenCalled();
});
it("should work for case with reject in apipe chain", async () => {
expect.assertions(9);
Expand All @@ -180,12 +180,12 @@ describe("acatch in apipe tests", () => {
expect(result).toBe(28);
expect(catchFn).toHaveBeenCalledTimes(1);
mockFnExpectations(catchFn, 1, 28, getError(input + 1));
expect(catchInCatchBlockFn).not.toBeCalled();
expect(increment2).not.toBeCalled();
expect(catchInCatchBlockFn).not.toHaveBeenCalled();
expect(increment2).not.toHaveBeenCalled();
expect(increment1).toHaveBeenCalledTimes(1);
mockFnExpectations(increment1, 1, 8, input);
});
it("should work for case with reject in apipe chain", async () => {
it("should work for case with reject in apipe chain for first argument", async () => {
expect.assertions(7);
const input = 7;
const increment1 = incrementMock(jest, "increment1");
Expand All @@ -197,9 +197,9 @@ describe("acatch in apipe tests", () => {
expect(result).toBe(28);
expect(catchFn).toHaveBeenCalledTimes(1);
mockFnExpectations(catchFn, 1, 28, getError(input));
expect(catchInCatchBlockFn).not.toBeCalled();
expect(increment1).not.toBeCalled();
expect(increment2).not.toBeCalled();
expect(catchInCatchBlockFn).not.toHaveBeenCalled();
expect(increment1).not.toHaveBeenCalled();
expect(increment2).not.toHaveBeenCalled();
});
it("should work for case with reject in input", async () => {
expect.assertions(7);
Expand All @@ -216,9 +216,9 @@ describe("acatch in apipe tests", () => {
expect(result).toBe(28);
expect(catchFn).toHaveBeenCalledTimes(1);
mockFnExpectations(catchFn, 1, 28, getError(input));
expect(increment1).not.toBeCalled();
expect(increment2).not.toBeCalled();
expect(catchInCatchBlockFn).not.toBeCalled();
expect(increment1).not.toHaveBeenCalled();
expect(increment2).not.toHaveBeenCalled();
expect(catchInCatchBlockFn).not.toHaveBeenCalled();
});
it("should work for case with reject in apipe chain and acatch in middle", async () => {
expect.assertions(8);
Expand All @@ -231,8 +231,8 @@ describe("acatch in apipe tests", () => {
const result = await apipe(increment1Promise, acatch(catchFn), increment2)(input).catch(catchInCatchBlockFn);
expect(result).toBe(29);
mockFnExpectations(catchFn, 1, 28, getError(input));
expect(catchInCatchBlockFn).not.toBeCalled();
expect(increment1).not.toBeCalled();
expect(catchInCatchBlockFn).not.toHaveBeenCalled();
expect(increment1).not.toHaveBeenCalled();
expect(increment2).toHaveBeenCalledTimes(1);
mockFnExpectations(increment2, 1, 29, 28);
});
Expand Down
4 changes: 2 additions & 2 deletions __tests__/acompose.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ describe("Tests for asynchronous compose utility", () => {
expect(e).toBeInstanceOf(Error);
expect(e.message).toBe(getErrorMessage(inputValue));
expect(increment).not.toHaveBeenCalled();
expect(thenHandler).not.toBeCalled();
expect(thenHandler).not.toHaveBeenCalled();
});
});
it("should reject properly with rejection in one of the compose functions traditional way", () => {
Expand All @@ -243,7 +243,7 @@ describe("Tests for asynchronous compose utility", () => {
mockFnExpectations(increment, 1, 5, inputValue);
mockFnArgumentsExpectations(undefinedErrorFn, 1, 5);
expect(incrementInCompose).not.toHaveBeenCalled();
expect(thenHandler).not.toBeCalled();
expect(thenHandler).not.toHaveBeenCalled();
});
});
});
4 changes: 2 additions & 2 deletions __tests__/apipe.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ describe("Tests for asynchronous pipe utility", () => {
expect(e).toBeInstanceOf(Error);
expect(e.message).toBe(getErrorMessage(inputValue));
expect(increment).not.toHaveBeenCalled();
expect(thenHandler).not.toBeCalled();
expect(thenHandler).not.toHaveBeenCalled();
});
});
it("should reject properly with rejection in one of the pipe functions traditional way", () => {
Expand All @@ -243,7 +243,7 @@ describe("Tests for asynchronous pipe utility", () => {
mockFnExpectations(increment, 1, 5, inputValue);
mockFnArgumentsExpectations(undefinedErrorFn, 1, 5);
expect(incrementInCompose).not.toHaveBeenCalled();
expect(thenHandler).not.toBeCalled();
expect(thenHandler).not.toHaveBeenCalled();
});
});
});
Loading