diff --git a/package.json b/package.json index b07d14017..047772c94 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ "dist", "lib", "lib/constants", + "lib/icons", "lib/utils" ], "types": "./lib/index.d.ts", @@ -30,7 +31,7 @@ "build:icons:deprecated": "svgr --expand-props none --template src/utils/svgToIconTemplate/index.js -d src/icons/ src/svgs/deprecated/", "build:icons:index": "create-index src/icons/", "build:rollup": "rollup -c", - "build:babel": "babel src -d lib --extensions '.js,.ts,.tsx'", + "build:babel": "babel src -d lib --extensions '.js,.ts,.tsx' --ignore '**/*.test.{js,ts,tsx}'", "build:svgs:index": "create-index src/svgs/ --recursive --update --extensions svg", "publish-package": "run-s build && yarn publish", "heroku-postbuild": "yarn run build:icons && yarn run build:icons:index && yarn run build-storybook", diff --git a/shared/tsconfig.json b/shared/tsconfig.json index ca63e7921..0e28a69dd 100644 --- a/shared/tsconfig.json +++ b/shared/tsconfig.json @@ -13,8 +13,8 @@ "noUnusedLocals": true, "noUnusedParameters": true, "paths": { - "emotion-theming": ["types/emotion-theming"], - "@emotion/styled": ["types/@emotion/styled"] + "emotion-theming": ["src/types/emotion-theming"], + "@emotion/styled": ["src/types/@emotion/styled"] }, "resolveJsonModule": true, "skipLibCheck": true, diff --git a/src/shared-components/accordion/test.tsx b/src/shared-components/accordion/test.tsx index 1ce71a5ce..bb0680997 100644 --- a/src/shared-components/accordion/test.tsx +++ b/src/shared-components/accordion/test.tsx @@ -1,7 +1,7 @@ import React from 'react'; import renderer from 'react-test-renderer'; import { mount } from 'enzyme'; -import { decorateWithThemeProvider } from 'tests/utils/decorateWithThemeProvider'; +import { decorateWithThemeProvider } from 'src/tests/decorateWithThemeProvider'; import { Accordion } from './index'; diff --git a/src/shared-components/alert/test.tsx b/src/shared-components/alert/test.tsx index 4b7e0b921..3a737ebab 100644 --- a/src/shared-components/alert/test.tsx +++ b/src/shared-components/alert/test.tsx @@ -1,6 +1,6 @@ import React, { ReactElement } from 'react'; import TestRenderer from 'react-test-renderer'; -import { decorateWithThemeProvider } from 'tests/utils/decorateWithThemeProvider'; +import { decorateWithThemeProvider } from 'src/tests/decorateWithThemeProvider'; import { Alert } from './index'; diff --git a/src/shared-components/avatar/test.tsx b/src/shared-components/avatar/test.tsx index d1128cb68..397bb74a3 100644 --- a/src/shared-components/avatar/test.tsx +++ b/src/shared-components/avatar/test.tsx @@ -1,6 +1,6 @@ import React from 'react'; import renderer from 'react-test-renderer'; -import { decorateWithThemeProvider } from 'tests/utils/decorateWithThemeProvider'; +import { decorateWithThemeProvider } from 'src/tests/decorateWithThemeProvider'; import { Avatar } from '.'; diff --git a/src/shared-components/banner/test.tsx b/src/shared-components/banner/test.tsx index d9fdec45a..a87774961 100644 --- a/src/shared-components/banner/test.tsx +++ b/src/shared-components/banner/test.tsx @@ -1,6 +1,6 @@ import React from 'react'; import TestRenderer from 'react-test-renderer'; -import { decorateWithThemeProvider } from 'tests/utils/decorateWithThemeProvider'; +import { decorateWithThemeProvider } from 'src/tests/decorateWithThemeProvider'; import { Banner } from './index'; diff --git a/src/shared-components/button/components/linkButton/test.tsx b/src/shared-components/button/components/linkButton/test.tsx index 71c175012..6fef8eeef 100644 --- a/src/shared-components/button/components/linkButton/test.tsx +++ b/src/shared-components/button/components/linkButton/test.tsx @@ -1,7 +1,7 @@ import React from 'react'; import { mount } from 'enzyme'; import renderer from 'react-test-renderer'; -import { decorateWithThemeProvider } from 'tests/utils/decorateWithThemeProvider'; +import { decorateWithThemeProvider } from 'src/tests/decorateWithThemeProvider'; import { LinkButton } from './index'; diff --git a/src/shared-components/button/components/roundButton/test.tsx b/src/shared-components/button/components/roundButton/test.tsx index 9c71f7403..a414018dd 100644 --- a/src/shared-components/button/components/roundButton/test.tsx +++ b/src/shared-components/button/components/roundButton/test.tsx @@ -1,7 +1,7 @@ import React from 'react'; import { mount } from 'enzyme'; import renderer from 'react-test-renderer'; -import { decorateWithThemeProvider } from 'tests/utils/decorateWithThemeProvider'; +import { decorateWithThemeProvider } from 'src/tests/decorateWithThemeProvider'; import CameraIcon from '../../../../svgs/icons/camera-icon.svg'; diff --git a/src/shared-components/button/components/textButton/test.tsx b/src/shared-components/button/components/textButton/test.tsx index 153205e23..d9bbc6b38 100644 --- a/src/shared-components/button/components/textButton/test.tsx +++ b/src/shared-components/button/components/textButton/test.tsx @@ -1,7 +1,7 @@ import React from 'react'; import { mount } from 'enzyme'; import renderer from 'react-test-renderer'; -import { decorateWithThemeProvider } from 'tests/utils/decorateWithThemeProvider'; +import { decorateWithThemeProvider } from 'src/tests/decorateWithThemeProvider'; import { TextButton } from './index'; diff --git a/src/shared-components/button/test.tsx b/src/shared-components/button/test.tsx index 233538437..5faebdd61 100644 --- a/src/shared-components/button/test.tsx +++ b/src/shared-components/button/test.tsx @@ -1,7 +1,7 @@ import React from 'react'; import { mount } from 'enzyme'; import renderer from 'react-test-renderer'; -import { decorateWithThemeProvider } from 'tests/utils/decorateWithThemeProvider'; +import { decorateWithThemeProvider } from 'src/tests/decorateWithThemeProvider'; import { primaryTheme } from 'src/constants/themes'; import CameraIcon from '../../svgs/icons/camera-icon.svg'; diff --git a/src/shared-components/callout/test.tsx b/src/shared-components/callout/test.tsx index eb45159ee..504ddc9a4 100644 --- a/src/shared-components/callout/test.tsx +++ b/src/shared-components/callout/test.tsx @@ -1,7 +1,7 @@ import React from 'react'; import renderer from 'react-test-renderer'; import { primaryTheme } from 'src/constants/themes'; -import { decorateWithThemeProvider } from 'tests/utils/decorateWithThemeProvider'; +import { decorateWithThemeProvider } from 'src/tests/decorateWithThemeProvider'; import NeckGlyph from '../../svgs/glyphs/neck-glyph.svg'; diff --git a/src/shared-components/carousel/arrow/test.tsx b/src/shared-components/carousel/arrow/test.tsx index 28f316782..774aee595 100644 --- a/src/shared-components/carousel/arrow/test.tsx +++ b/src/shared-components/carousel/arrow/test.tsx @@ -1,6 +1,6 @@ import React from 'react'; import renderer from 'react-test-renderer'; -import { decorateWithThemeProvider } from 'tests/utils/decorateWithThemeProvider'; +import { decorateWithThemeProvider } from 'src/tests/decorateWithThemeProvider'; import Arrow from './index'; diff --git a/src/shared-components/carousel/test.tsx b/src/shared-components/carousel/test.tsx index 338e32c62..66bef2188 100644 --- a/src/shared-components/carousel/test.tsx +++ b/src/shared-components/carousel/test.tsx @@ -1,6 +1,6 @@ import React from 'react'; import renderer from 'react-test-renderer'; -import { decorateWithThemeProvider } from 'tests/utils/decorateWithThemeProvider'; +import { decorateWithThemeProvider } from 'src/tests/decorateWithThemeProvider'; import { Carousel } from './index'; diff --git a/src/shared-components/chip/test.tsx b/src/shared-components/chip/test.tsx index 9d596e178..018ae1949 100644 --- a/src/shared-components/chip/test.tsx +++ b/src/shared-components/chip/test.tsx @@ -1,6 +1,6 @@ import React from 'react'; import renderer from 'react-test-renderer'; -import { decorateWithThemeProvider } from 'tests/utils/decorateWithThemeProvider'; +import { decorateWithThemeProvider } from 'src/tests/decorateWithThemeProvider'; import { Chip } from './index'; diff --git a/src/shared-components/container/test.tsx b/src/shared-components/container/test.tsx index 0ed099b4b..b11aa127e 100644 --- a/src/shared-components/container/test.tsx +++ b/src/shared-components/container/test.tsx @@ -1,6 +1,6 @@ import React from 'react'; import renderer from 'react-test-renderer'; -import { decorateWithThemeProvider } from 'tests/utils/decorateWithThemeProvider'; +import { decorateWithThemeProvider } from 'src/tests/decorateWithThemeProvider'; import { Container } from './index'; diff --git a/src/shared-components/dialogModal/test.tsx b/src/shared-components/dialogModal/test.tsx index 0d3951853..f4a3c8ae5 100644 --- a/src/shared-components/dialogModal/test.tsx +++ b/src/shared-components/dialogModal/test.tsx @@ -1,6 +1,6 @@ import React from 'react'; import { mount } from 'enzyme'; -import { decorateWithThemeProvider } from 'tests/utils/decorateWithThemeProvider'; +import { decorateWithThemeProvider } from 'src/tests/decorateWithThemeProvider'; import { ModalTitle } from './style'; diff --git a/src/shared-components/dropdown/test.tsx b/src/shared-components/dropdown/test.tsx index d4d4384af..54f6c6fe2 100644 --- a/src/shared-components/dropdown/test.tsx +++ b/src/shared-components/dropdown/test.tsx @@ -1,7 +1,7 @@ import React from 'react'; import renderer from 'react-test-renderer'; import { mount } from 'enzyme'; -import { decorateWithThemeProvider } from 'tests/utils/decorateWithThemeProvider'; +import { decorateWithThemeProvider } from 'src/tests/decorateWithThemeProvider'; import { DesktopDropdown } from './desktopDropdown'; import { MobileDropdown } from './mobileDropdown'; diff --git a/src/shared-components/field/test.tsx b/src/shared-components/field/test.tsx index 72bb685ac..a793bb8da 100644 --- a/src/shared-components/field/test.tsx +++ b/src/shared-components/field/test.tsx @@ -1,7 +1,7 @@ import React from 'react'; import renderer from 'react-test-renderer'; import { mount } from 'enzyme'; -import { decorateWithThemeProvider } from 'tests/utils/decorateWithThemeProvider'; +import { decorateWithThemeProvider } from 'src/tests/decorateWithThemeProvider'; import { MessageItem } from '../verificationMessages/style'; diff --git a/src/shared-components/immersiveModal/test.tsx b/src/shared-components/immersiveModal/test.tsx index d95733f55..1143a3878 100644 --- a/src/shared-components/immersiveModal/test.tsx +++ b/src/shared-components/immersiveModal/test.tsx @@ -1,6 +1,6 @@ import React from 'react'; import { mount } from 'enzyme'; -import { decorateWithThemeProvider } from 'tests/utils/decorateWithThemeProvider'; +import { decorateWithThemeProvider } from 'src/tests/decorateWithThemeProvider'; import { ModalTitle } from './style'; diff --git a/src/shared-components/indicator/test.tsx b/src/shared-components/indicator/test.tsx index 263a2e5eb..9c14d4204 100644 --- a/src/shared-components/indicator/test.tsx +++ b/src/shared-components/indicator/test.tsx @@ -1,6 +1,6 @@ import React from 'react'; import renderer from 'react-test-renderer'; -import { decorateWithThemeProvider } from 'tests/utils/decorateWithThemeProvider'; +import { decorateWithThemeProvider } from 'src/tests/decorateWithThemeProvider'; import { Indicator } from './index'; diff --git a/src/shared-components/loadingSpinner/test.tsx b/src/shared-components/loadingSpinner/test.tsx index 44bc9417a..27551b8e0 100644 --- a/src/shared-components/loadingSpinner/test.tsx +++ b/src/shared-components/loadingSpinner/test.tsx @@ -1,7 +1,7 @@ import React from 'react'; import renderer from 'react-test-renderer'; import { primaryTheme } from 'src/constants/themes'; -import { decorateWithThemeProvider } from 'tests/utils/decorateWithThemeProvider'; +import { decorateWithThemeProvider } from 'src/tests/decorateWithThemeProvider'; import { LoadingSpinner } from './index'; diff --git a/src/shared-components/optionButton/test.tsx b/src/shared-components/optionButton/test.tsx index 75c8e9481..c1396cb8e 100644 --- a/src/shared-components/optionButton/test.tsx +++ b/src/shared-components/optionButton/test.tsx @@ -1,7 +1,7 @@ import React from 'react'; import { mount } from 'enzyme'; import renderer from 'react-test-renderer'; -import { decorateWithThemeProvider } from 'tests/utils/decorateWithThemeProvider'; +import { decorateWithThemeProvider } from 'src/tests/decorateWithThemeProvider'; import AcneGlyph from '../../svgs/glyphs/acne-glyph.svg'; diff --git a/src/shared-components/progressBar/test.tsx b/src/shared-components/progressBar/test.tsx index 0c50c9623..3445a2c8f 100644 --- a/src/shared-components/progressBar/test.tsx +++ b/src/shared-components/progressBar/test.tsx @@ -1,7 +1,7 @@ import React from 'react'; import renderer from 'react-test-renderer'; import { primaryTheme } from 'src/constants/themes'; -import { decorateWithThemeProvider } from 'tests/utils/decorateWithThemeProvider'; +import { decorateWithThemeProvider } from 'src/tests/decorateWithThemeProvider'; import { ProgressBar } from './index'; diff --git a/src/shared-components/selectorButton/test.tsx b/src/shared-components/selectorButton/test.tsx index 539e2d06a..8e61ba5c3 100644 --- a/src/shared-components/selectorButton/test.tsx +++ b/src/shared-components/selectorButton/test.tsx @@ -1,7 +1,7 @@ import React from 'react'; import { mount } from 'enzyme'; import renderer from 'react-test-renderer'; -import { decorateWithThemeProvider } from 'tests/utils/decorateWithThemeProvider'; +import { decorateWithThemeProvider } from 'src/tests/decorateWithThemeProvider'; import AcneOneGlyph from '../../svgs/glyphs/acne-one-glyph.svg'; diff --git a/src/shared-components/tabs/test.tsx b/src/shared-components/tabs/test.tsx index a030c3a91..a9e073ec2 100644 --- a/src/shared-components/tabs/test.tsx +++ b/src/shared-components/tabs/test.tsx @@ -1,7 +1,7 @@ import React from 'react'; import renderer from 'react-test-renderer'; import { mount } from 'enzyme'; -import { decorateWithThemeProvider } from 'tests/utils/decorateWithThemeProvider'; +import { decorateWithThemeProvider } from 'src/tests/decorateWithThemeProvider'; import { TabItem } from './style'; diff --git a/src/shared-components/toggle/test.tsx b/src/shared-components/toggle/test.tsx index 31a64f458..6609b3557 100644 --- a/src/shared-components/toggle/test.tsx +++ b/src/shared-components/toggle/test.tsx @@ -1,7 +1,7 @@ import React from 'react'; import { shallow, mount } from 'enzyme'; import renderer from 'react-test-renderer'; -import { decorateWithThemeProvider } from 'tests/utils/decorateWithThemeProvider'; +import { decorateWithThemeProvider } from 'src/tests/decorateWithThemeProvider'; import { Toggle } from './index'; diff --git a/src/shared-components/tooltip/test.tsx b/src/shared-components/tooltip/test.tsx index ee44e81f1..0152906d1 100644 --- a/src/shared-components/tooltip/test.tsx +++ b/src/shared-components/tooltip/test.tsx @@ -1,6 +1,6 @@ import React from 'react'; import renderer from 'react-test-renderer'; -import { decorateWithThemeProvider } from 'tests/utils/decorateWithThemeProvider'; +import { decorateWithThemeProvider } from 'src/tests/decorateWithThemeProvider'; import { Tooltip } from './index'; diff --git a/src/shared-components/verificationMessages/test.tsx b/src/shared-components/verificationMessages/test.tsx index a968f3cbe..430cdcfc1 100644 --- a/src/shared-components/verificationMessages/test.tsx +++ b/src/shared-components/verificationMessages/test.tsx @@ -1,7 +1,7 @@ import React from 'react'; import renderer from 'react-test-renderer'; import { shallow } from 'enzyme'; -import { decorateWithThemeProvider } from 'tests/utils/decorateWithThemeProvider'; +import { decorateWithThemeProvider } from 'src/tests/decorateWithThemeProvider'; import { VerificationMessages } from './index'; diff --git a/src/tests/README.md b/src/tests/README.md new file mode 100644 index 000000000..082560c23 --- /dev/null +++ b/src/tests/README.md @@ -0,0 +1,3 @@ +We write test helpers in `src/tests` instead of the `tests` directory at the root because in order for our TypeScript declaration files to not be deeply nested (e.g. `lib/src/constants`, instead of `lib/constants`, which is where we output our non-declaration source), `src` must be the "The longest common path of all non-declaration input files". + +See: https://www.typescriptlang.org/tsconfig#outDir and https://www.typescriptlang.org/tsconfig#rootDir \ No newline at end of file diff --git a/tests/utils/decorateWithThemeProvider.tsx b/src/tests/decorateWithThemeProvider.tsx similarity index 78% rename from tests/utils/decorateWithThemeProvider.tsx rename to src/tests/decorateWithThemeProvider.tsx index 428c8dd6a..11b8a57af 100644 --- a/tests/utils/decorateWithThemeProvider.tsx +++ b/src/tests/decorateWithThemeProvider.tsx @@ -1,8 +1,8 @@ import React from 'react'; import { ThemeProvider } from 'emotion-theming'; -import { primaryTheme } from '../../src/constants/themes'; -import type { ThemeType } from '../../src/constants/themes/types'; +import { primaryTheme } from '../constants/themes'; +import type { ThemeType } from '../constants/themes/types'; type PropsType = Record; diff --git a/types/@emotion/styled/index.ts b/src/types/@emotion/styled/index.ts similarity index 89% rename from types/@emotion/styled/index.ts rename to src/types/@emotion/styled/index.ts index 6117abc76..8df2d7a44 100644 --- a/types/@emotion/styled/index.ts +++ b/src/types/@emotion/styled/index.ts @@ -9,7 +9,7 @@ import { ThemeType } from 'src/constants/themes/types'; import styled, { CreateStyled, StyledComponent, -} from '../../../node_modules/@emotion/styled'; +} from '../../../../node_modules/@emotion/styled'; export default styled as CreateStyled; diff --git a/src/types/README.md b/src/types/README.md new file mode 100644 index 000000000..ab3da3b88 --- /dev/null +++ b/src/types/README.md @@ -0,0 +1,3 @@ +We write global `types` in `src/types` instead of a `types` directory at the root because in order for our TypeScript declaration files to not be deeply nested (e.g. `lib/src/constants`, instead of `lib/constants`, which is where we output our non-declaration source), `src` must be the "The longest common path of all non-declaration input files". + +See: https://www.typescriptlang.org/tsconfig#outDir and https://www.typescriptlang.org/tsconfig#rootDir \ No newline at end of file diff --git a/types/emotion-theming/index.ts b/src/types/emotion-theming/index.ts similarity index 90% rename from types/emotion-theming/index.ts rename to src/types/emotion-theming/index.ts index a28b225c2..1cb51860e 100644 --- a/types/emotion-theming/index.ts +++ b/src/types/emotion-theming/index.ts @@ -9,7 +9,7 @@ import { ThemeType } from 'src/constants/themes/types'; import { useTheme as useEmotionTheme, ThemeProvider, -} from '../../node_modules/emotion-theming'; +} from '../../../node_modules/emotion-theming'; export const useTheme = () => useEmotionTheme(); diff --git a/types/global.d.ts b/src/types/global.d.ts similarity index 100% rename from types/global.d.ts rename to src/types/global.d.ts diff --git a/src/types/tsconfig.json b/src/types/tsconfig.json new file mode 100644 index 000000000..00cd7b9fa --- /dev/null +++ b/src/types/tsconfig.json @@ -0,0 +1,9 @@ +{ + "extends": "../tsconfig", + "compilerOptions": {}, + "references": [ + { + "path": "../src" + } + ] +} diff --git a/tests/setupTests.ts b/tests/setupTests.ts index 759f5bd4d..d2fb06442 100644 --- a/tests/setupTests.ts +++ b/tests/setupTests.ts @@ -1,7 +1,6 @@ import { configure } from 'enzyme'; import Adapter from 'enzyme-adapter-react-16'; -// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call configure({ adapter: new Adapter() }); window.matchMedia = @@ -9,7 +8,12 @@ window.matchMedia = function () { return { matches: false, + dispatchEvent: () => false, addListener: () => undefined, removeListener: () => undefined, + media: '', + onchange: () => undefined, + addEventListener: () => undefined, + removeEventListener: () => undefined, }; }; diff --git a/tsconfig.json b/tsconfig.json index ef4ad7086..40e62ebdf 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,16 +3,13 @@ "compilerOptions": { "baseUrl": "./", "declaration": true, + "declarationMap": true, "emitDeclarationOnly": true, "outDir": "lib", - "rootDirs": ["src"] + // The folder structure in outDir is based on "The longest common path of all non-declaration input files." + // To match our babel output, we need to compile everything in `src` without also nesting it in a folder named `src`. + // Setting the `rootDir` to `src` will guarantee this behavior, and raise compilation errors if violated. + "rootDir": "src" }, - "include": [ - "src/**/*.ts", - "src/**/*.js", - "src/**/*.tsx", - "tests/**/*.ts", - "tests/**/*.tsx", - "types/**/*.ts" - ] + "include": ["src/**/*.ts", "src/**/*.js", "src/**/*.tsx"] }