diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..50ccf80 --- /dev/null +++ b/.eslintignore @@ -0,0 +1,3 @@ +lib/ +test-utils/ +node_modules/ \ No newline at end of file diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000..ae09f00 --- /dev/null +++ b/.eslintrc @@ -0,0 +1,29 @@ +{ + "parser": "babel-eslint", + "parserOptions": { + "sourceType": "module", + "allowImportExportEverywhere": false, + "codeFrame": false + }, + "extends": [ + "airbnb", + "plugin:react/recommended", + "prettier", + "prettier/react" + ], + "env": { + "browser": true, + "jest": true + }, + "rules": { + "import/no-extraneous-dependencies": ["off"], + "react/jsx-fragments": ["off"], + "react/forbid-prop-types": ["off"], + "react/jsx-props-no-spreading": ["off"], + "max-len": ["error", { "code": 100 }], + "prefer-promise-reject-errors": ["off"], + "react/jsx-filename-extension": ["off"], + "react/prop-types": ["warn"], + "no-return-assign": ["off"] + } +} diff --git a/.travis.yml b/.travis.yml index c6b820b..4b7e47e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,14 +4,17 @@ node_js: cache: yarn install: yarn script: - #- yarn lint + - yarn lint + - yarn format - yarn test jobs: include: - stage: npm release if: tag IS present node_js: "12" - script: yarn build + script: + - yarn test + - yarn build deploy: provider: npm email: "$NPM_EMAIL" diff --git a/__tests__/Consumer.Context.test.js b/__tests__/Consumer.Context.test.js index 41a1e2b..2e921c2 100644 --- a/__tests__/Consumer.Context.test.js +++ b/__tests__/Consumer.Context.test.js @@ -1,17 +1,7 @@ -// __tests__/hidden-message.js -// these imports are something you'd normally configure Jest to import for you -// automatically. Learn more in the setup docs: https://testing-library.com/docs/react-testing-library/setup#cleanup -// import "@testing-library/react/cleanup-after-each"; import "@testing-library/jest-dom/extend-expect"; - -// NOTE: jest-dom adds handy assertions to Jest and is recommended, but not required - import React from "react"; -import { fireEvent, cleanup } from "@testing-library/react"; -import { - renderWithProvider, - SampleConsumerContext -} from "../src/utils/test-utils"; +import { fireEvent } from "@testing-library/react"; +import { renderWithProvider, SampleConsumerContext } from "../test-utils"; describe("Toasted Consumer", () => { const { container, getByText } = renderWithProvider( diff --git a/__tests__/Consumer.ContextType.test.js b/__tests__/Consumer.ContextType.test.js index 198916a..00a34d4 100644 --- a/__tests__/Consumer.ContextType.test.js +++ b/__tests__/Consumer.ContextType.test.js @@ -1,17 +1,7 @@ -// __tests__/hidden-message.js -// these imports are something you'd normally configure Jest to import for you -// automatically. Learn more in the setup docs: https://testing-library.com/docs/react-testing-library/setup#cleanup -// import "@testing-library/react/cleanup-after-each"; import "@testing-library/jest-dom/extend-expect"; - -// NOTE: jest-dom adds handy assertions to Jest and is recommended, but not required - import React from "react"; -import { fireEvent, cleanup } from "@testing-library/react"; -import { - renderWithProvider, - SampleConsumerContextType -} from "../src/utils/test-utils"; +import { fireEvent } from "@testing-library/react"; +import { renderWithProvider, SampleConsumerContextType } from "../test-utils"; describe("Toasted Consumer useContext", () => { const { container, getByText } = renderWithProvider( diff --git a/__tests__/Consumer.UseContext.test.js b/__tests__/Consumer.UseContext.test.js index fb56598..be60a16 100644 --- a/__tests__/Consumer.UseContext.test.js +++ b/__tests__/Consumer.UseContext.test.js @@ -1,17 +1,7 @@ -// __tests__/hidden-message.js -// these imports are something you'd normally configure Jest to import for you -// automatically. Learn more in the setup docs: https://testing-library.com/docs/react-testing-library/setup#cleanup -// import "@testing-library/react/cleanup-after-each"; import "@testing-library/jest-dom/extend-expect"; - -// NOTE: jest-dom adds handy assertions to Jest and is recommended, but not required - import React from "react"; -import { fireEvent, cleanup } from "@testing-library/react"; -import { - renderWithProvider, - SampleConsumerUseContext -} from "../src/utils/test-utils"; +import { fireEvent } from "@testing-library/react"; +import { renderWithProvider, SampleConsumerUseContext } from "../test-utils"; describe("Toasted Consumer useContext", () => { const { container, getByText } = renderWithProvider( diff --git a/__tests__/Consumer.test.txt b/__tests__/Consumer.test.txt deleted file mode 100644 index 25c1659..0000000 --- a/__tests__/Consumer.test.txt +++ /dev/null @@ -1,55 +0,0 @@ -// __tests__/hidden-message.js -// these imports are something you'd normally configure Jest to import for you -// automatically. Learn more in the setup docs: https://testing-library.com/docs/react-testing-library/setup#cleanup -// import "@testing-library/react/cleanup-after-each"; -import "@testing-library/jest-dom/extend-expect"; - -// NOTE: jest-dom adds handy assertions to Jest and is recommended, but not required - -import React from "react"; -import { fireEvent, cleanup } from "@testing-library/react"; -import { - renderWithProvider, - SampleConsumerContext, - WithToastedComponent -} from "../test-utils"; -import { withToasted } from "../src/index"; - -describe("Toasted Consumer", () => { - const { container, getByText } = renderWithProvider( - - ); - test("add", () => { - fireEvent.click(getByText(/Create Toast/)); - expect(container.innerHTML).toMatch("First Toast"); - }); - test("remove", () => { - fireEvent.click(getByText(/Remove Toast/)); - expect(container.innerHTML).not.toMatch("First Toast"); - }); - test("removeAll", () => { - expect(container.innerHTML).toMatch("Second Toast"); - fireEvent.click(getByText(/Remove All/)); - expect(container.innerHTML).toMatch("Second Toast"); - }); -}); - -describe("Toasted withToasted", () => { - cleanup(); - - const { container, getByText } = renderWithProvider(); - test("add", () => { - console.log(container.innerHTML); - fireEvent.click(getByText(/Create Toast/)); - expect(container.innerHTML).toMatch("React Context Consumer Message"); - }); - test("remove", () => { - fireEvent.click(getByText(/Remove Toast/)); - expect(container.innerHTML).not.toMatch("React Context Consumer Message"); - }); - test("removeAll", () => { - expect(container.innerHTML).toMatch("Second Toast"); - fireEvent.click(getByText(/Remove All/)); - expect(container.innerHTML).not.toMatch("Second Toast"); - }); -}); diff --git a/__tests__/Provider.test.js b/__tests__/Provider.test.js index 263124b..12d114a 100644 --- a/__tests__/Provider.test.js +++ b/__tests__/Provider.test.js @@ -1,10 +1,5 @@ -// __tests__/hidden-message.js -// these imports are something you'd normally configure Jest to import for you -// automatically. Learn more in the setup docs: https://testing-library.com/docs/react-testing-library/setup#cleanup -// import "@testing-library/react/cleanup-after-each"; import "@testing-library/jest-dom/extend-expect"; - -import { renderWithProvider } from "../src/utils/test-utils"; +import { renderWithProvider } from "../test-utils"; describe("Toasted Provider Snapshot", () => { test("it has to match snapshot", () => { diff --git a/__tests__/Toast.test.js b/__tests__/Toast.test.js index 2972433..7371878 100644 --- a/__tests__/Toast.test.js +++ b/__tests__/Toast.test.js @@ -1,13 +1,6 @@ -// __tests__/hidden-message.js -// these imports are something you'd normally configure Jest to import for you -// automatically. Learn more in the setup docs: https://testing-library.com/docs/react-testing-library/setup#cleanup -// import "@testing-library/react/cleanup-after-each"; import "@testing-library/jest-dom/extend-expect"; - -// NOTE: jest-dom adds handy assertions to Jest and is recommended, but not required - import React from "react"; -import { render, fireEvent, cleanup } from "@testing-library/react"; +import { render, fireEvent } from "@testing-library/react"; import Toast from "../src/components/Toast"; describe("Toast Component Snapshot", () => { @@ -37,12 +30,12 @@ describe("Toast Component Snapshot", () => { }); }); describe("Toast Events", () => { - let toastMessage = "Message"; - let onCreated = jest.fn(); - let onClicked = jest.fn(); - let onMouseOver = jest.fn(); - let onMouseOut = jest.fn(); - let onDestroyed = jest.fn(); + const toastMessage = "Message"; + const onCreated = jest.fn(); + const onClicked = jest.fn(); + const onMouseOver = jest.fn(); + const onMouseOut = jest.fn(); + const onDestroyed = jest.fn(); const { getByText, unmount } = render( { onCreated={onCreated} onClick={onClicked} onMouseOver={onMouseOver} + onFocus={onMouseOver} onMouseOut={onMouseOut} + onBlur={onMouseOut} onDestroyed={onDestroyed} /> ); diff --git a/__tests__/ToastContainer.test.js b/__tests__/ToastContainer.test.js index 6b25215..4e5d52a 100644 --- a/__tests__/ToastContainer.test.js +++ b/__tests__/ToastContainer.test.js @@ -1,13 +1,6 @@ -// __tests__/hidden-message.js -// these imports are something you'd normally configure Jest to import for you -// automatically. Learn more in the setup docs: https://testing-library.com/docs/react-testing-library/setup#cleanup -// import "@testing-library/react/cleanup-after-each"; import "@testing-library/jest-dom/extend-expect"; - -// NOTE: jest-dom adds handy assertions to Jest and is recommended, but not required - import React from "react"; -import { render, fireEvent, cleanup } from "@testing-library/react"; +import { render } from "@testing-library/react"; import ToastContainer from "../src/components/ToastContainer"; describe("ToastContainer Snapshot", () => { @@ -29,7 +22,7 @@ describe("ToastContainer Snapshot", () => { defaultProgressBarValue: 0, defaultPreventDuplicates: false, defaultStyle: {} - //defaultPositions: positions + // defaultPositions: positions }} /> ); @@ -42,6 +35,7 @@ describe("ToastContainer Functions", () => { const { container } = render( { defaultProgressBarValue: 0, defaultPreventDuplicates: false, defaultStyle: {} - //defaultPositions: positions + // defaultPositions: positions }} /> ); - let component = ref.current; + const component = ref.current; test("it tests short functions", () => { component.s("Success Message"); component.i("Information Message"); @@ -77,10 +71,10 @@ describe("ToastContainer Functions", () => { }); test("it tests add and remove function", () => { - let msg = "Hello Dear"; + const msg = "Hello Dear"; component.add({ name: "mytoast", - msg: msg + msg }); expect(container.innerHTML).toMatch(msg); diff --git a/__tests__/ToastProgress.test.js b/__tests__/ToastProgress.test.js index 50f60a8..effdf40 100644 --- a/__tests__/ToastProgress.test.js +++ b/__tests__/ToastProgress.test.js @@ -1,11 +1,4 @@ -// __tests__/hidden-message.js -// these imports are something you'd normally configure Jest to import for you -// automatically. Learn more in the setup docs: https://testing-library.com/docs/react-testing-library/setup#cleanup -// import "@testing-library/react/cleanup-after-each"; import "@testing-library/jest-dom/extend-expect"; - -// NOTE: jest-dom adds handy assertions to Jest and is recommended, but not required - import React from "react"; import { render } from "@testing-library/react"; import ToastProgress from "../src/components/ToastProgress"; diff --git a/__tests__/__snapshots__/Toast.test.js.snap b/__tests__/__snapshots__/Toast.test.js.snap index c8a666a..0ef635b 100644 --- a/__tests__/__snapshots__/Toast.test.js.snap +++ b/__tests__/__snapshots__/Toast.test.js.snap @@ -4,6 +4,7 @@ exports[`Toast Component Snapshot basic toast snapshot 1`] = `