Skip to content

Commit

Permalink
[HOP-79] Add jest setup (#94)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexasselin008 authored Nov 15, 2023
1 parent 8bde51d commit 02e7ed8
Show file tree
Hide file tree
Showing 15 changed files with 2,487 additions and 1,931 deletions.
38 changes: 19 additions & 19 deletions apps/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,35 +14,35 @@
"build:storybook": "storybook build"
},
"dependencies": {
"clsx": "2.0.0",
"contentlayer": "0.3.4",
"next": "13.5.6",
"next-contentlayer": "0.3.4",
"react": "18.2.0",
"react-aria-components": "1.0.0-beta.2",
"next": "14.0.2",
"react-aria-components": "1.0.0-rc.0",
"react-dom": "18.2.0",
"react-toggle": "4.1.3",
"rehype-pretty-code": "0.10.1",
"unist-util-visit": "5.0.0",
"clsx": "2.0.0"
"react": "18.2.0",
"rehype-pretty-code": "0.10.2",
"unist-util-visit": "5.0.0"
},
"devDependencies": {
"@hopper-ui/tokens": "workspace:*",
"@hopper-ui/components": "workspace:*",
"@storybook/addon-essentials": "7.5.1",
"@storybook/addon-interactions": "7.5.1",
"@storybook/addon-links": "7.5.1",
"@storybook/blocks": "7.5.1",
"@storybook/nextjs": "7.5.1",
"@storybook/react": "7.5.1",
"@hopper-ui/tokens": "workspace:*",
"@storybook/addon-essentials": "7.5.3",
"@storybook/addon-interactions": "7.5.3",
"@storybook/addon-links": "7.5.3",
"@storybook/blocks": "7.5.3",
"@storybook/nextjs": "7.5.3",
"@storybook/react": "7.5.3",
"@storybook/testing-library": "0.2.2",
"@svgr/webpack": "8.1.0",
"@types/node": "20.8.9",
"@types/react": "18.2.32",
"@types/react-dom": "18.2.14",
"eslint": "8.52.0",
"eslint-config-next": "13.5.6",
"@types/node": "20.9.0",
"@types/react-dom": "18.2.15",
"@types/react": "18.2.37",
"eslint-config-next": "14.0.2",
"eslint-plugin-storybook": "0.6.15",
"storybook": "7.5.1",
"eslint": "8.53.0",
"storybook": "7.5.3",
"tsconfig-paths-webpack-plugin": "4.1.0",
"typescript": "5.2.2"
}
Expand Down
14 changes: 14 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import type { Config } from "jest";

const config: Config = {
projects: [
"<rootDir>/packages/*"
],
testRegex: "/tests/*/.*\\.test\\.(ts|tsx)$",
testPathIgnorePatterns: ["/node_modules/", "/dist/"],
cacheDirectory: "./node_modules/.cache/jest",
clearMocks: true,
verbose: true
};

export default config;
33 changes: 17 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"doc:start": "pnpm --filter=docs dev",
"doc:storybook": "pnpm --filter=docs storybook",
"doc:build": "pnpm --filter=docs build",
"test": "echo \"no test specified\"",
"test": "jest",
"build": "pnpm -r build ",
"build:tokens": "pnpm --filter=\"@hopper-ui/tokens\" build",
"build:pkg": "pnpm -r --filter \"{packages/**}\" build ",
Expand All @@ -33,32 +33,33 @@
"storybook": "storybook dev -p 6006",
"build-storybook": "storybook build"
},
"dependencies": {
"@changesets/cli": "^2.26.2",
"@netlify/plugin-nextjs": "4.41.1",
"@types/node": "20.8.8",
"storybook": "7.5.1"
},
"devDependencies": {
"@changesets/cli": "2.26.2",
"@hopper-ui/tokens": "workspace:*",
"@storybook/addon-essentials": "7.5.1",
"@storybook/addon-interactions": "7.5.1",
"@storybook/addon-links": "7.5.1",
"@storybook/addon-mdx-gfm": "7.5.1",
"@storybook/blocks": "7.5.1",
"@storybook/react": "7.5.1",
"@storybook/react-vite": "7.5.1",
"@netlify/plugin-nextjs": "4.41.1",
"@storybook/addon-essentials": "7.5.3",
"@storybook/addon-interactions": "7.5.3",
"@storybook/addon-links": "7.5.3",
"@storybook/addon-mdx-gfm": "7.5.3",
"@storybook/blocks": "7.5.3",
"@storybook/react-vite": "7.5.3",
"@storybook/react": "7.5.3",
"@storybook/testing-library": "0.2.2",
"@types/jest": "29.5.8",
"@types/node": "20.9.0",
"@workleap/eslint-plugin": "3.0.0",
"@workleap/stylelint-configs": "2.0.0",
"@workleap/typescript-configs": "3.0.2",
"eslint-plugin-storybook": "0.6.15",
"jest": "29.7.0",
"prettier": "2.8.8",
"prop-types": "15.8.1",
"react": "18.2.0",
"react-dom": "18.2.0",
"ts-jest": "29.1.1",
"react": "18.2.0",
"storybook": "7.5.3",
"stylelint": "15.11.0",
"ts-jest": "29.1.1",
"ts-node": "10.9.1",
"vite-plugin-turbosnap": "1.0.3",
"vite-tsconfig-paths": "4.2.1"
},
Expand Down
16 changes: 8 additions & 8 deletions packages/components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,24 @@
"@hopper-ui/styled-system": "workspace:*"
},
"devDependencies": {
"@swc/core": "1.3.95",
"@swc/core": "1.3.96",
"@swc/helpers": "0.5.3",
"@swc/jest": "0.2.29",
"@testing-library/jest-dom": "6.1.4",
"@testing-library/react": "14.0.0",
"@types/jest": "29.5.6",
"@types/react": "18.2.32",
"@types/react-dom": "18.2.14",
"@types/react-test-renderer": "18.0.5",
"@testing-library/react": "14.1.0",
"@types/jest": "29.5.8",
"@types/react-dom": "18.2.15",
"@types/react-test-renderer": "18.0.6",
"@types/react": "18.2.37",
"@workleap/eslint-plugin": "3.0.0",
"@workleap/swc-configs": "2.1.2",
"@workleap/tsup-configs": "3.0.1",
"@workleap/typescript-configs": "3.0.2",
"jest": "29.7.0",
"jest-environment-jsdom": "29.7.0",
"react": "18.2.0",
"jest": "29.7.0",
"react-dom": "18.2.0",
"react-test-renderer": "18.2.0",
"react": "18.2.0",
"ts-jest": "29.1.1",
"ts-node": "10.9.1",
"tsup": "7.2.0",
Expand Down
22 changes: 22 additions & 0 deletions packages/styled-system/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import type { Config } from "jest";
import { pathsToModuleNameMapper } from "ts-jest";
import { swcConfig } from "./swc.jest.ts";
import { compilerOptions } from "./tsconfig.json";

const config: Config = {
testEnvironment: "jsdom",
transform: {
"^.+\\.(js|ts|tsx)$": ["@swc/jest", swcConfig as Record<string, unknown>]
},
moduleNameMapper: {
"\\.css$": "identity-obj-proxy", // https://jestjs.io/docs/webpack#mocking-css-modules
...pathsToModuleNameMapper(compilerOptions.paths, {
prefix: "<rootDir>"
})
}
// setupFilesAfterEnv: [
// "@testing-library/jest-dom/extend-expect"
// ]
};

export default config;
29 changes: 15 additions & 14 deletions packages/styled-system/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,36 +40,37 @@
"react-dom": "*"
},
"dependencies": {
"react-aria": "3.29.1",
"clsx": "2.0.0"
"clsx": "2.0.0",
"react-aria": "3.30.0"
},
"devDependencies": {
"@hopper-ui/tokens": "workspace:*",
"@swc/core": "1.3.95",
"@swc/core": "1.3.96",
"@swc/helpers": "0.5.3",
"@swc/jest": "0.2.29",
"@testing-library/jest-dom": "6.1.4",
"@testing-library/react": "14.0.0",
"@types/jest": "29.5.6",
"@types/react": "18.2.32",
"@types/react-dom": "18.2.14",
"@types/react-test-renderer": "18.0.5",
"@testing-library/react": "14.1.0",
"@types/jest": "29.5.8",
"@types/react-dom": "18.2.15",
"@types/react-test-renderer": "18.0.6",
"@types/react": "18.2.37",
"@workleap/eslint-plugin": "3.0.0",
"@workleap/swc-configs": "2.1.2",
"@workleap/tsup-configs": "3.0.1",
"@workleap/typescript-configs": "3.0.2",
"jest": "29.7.0",
"identity-obj-proxy": "3.0.0",
"jest-environment-jsdom": "29.7.0",
"react": "18.2.0",
"jest": "29.7.0",
"postcss-modules": "6.0.0",
"postcss": "8.4.31",
"react-dom": "18.2.0",
"react-test-renderer": "18.2.0",
"react": "18.2.0",
"ts-jest": "29.1.1",
"ts-node": "10.9.1",
"tsup": "7.2.0",
"type-fest": "4.6.0",
"typescript": "5.2.2",
"postcss": "8.4.31",
"postcss-modules": "6.0.0"
"type-fest": "4.7.1",
"typescript": "5.2.2"
},
"engines": {
"node": ">=18.0.0"
Expand Down
6 changes: 6 additions & 0 deletions packages/styled-system/swc.jest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { defineJestConfig } from "@workleap/swc-configs";

export const swcConfig = defineJestConfig({
react: true
});

14 changes: 14 additions & 0 deletions packages/styled-system/tests/jest/useColorSchemeValue.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { renderHookWithTheme } from "@hopper-ui/test-utils";
import { useColorSchemeValue } from "../../src/index.ts";

test("return the light color value when the color scheme is light", async () => {
const { result } = renderHookWithTheme(() => useColorSchemeValue("light-color", "dark-color"), undefined, { colorScheme: "light" });

expect(result.current).toBe("light-color");
});

test("return the dark color value when the color scheme is dark", async () => {
const { result } = renderHookWithTheme(() => useColorSchemeValue("light-color", "dark-color"), undefined, { colorScheme: "dark" });

expect(result.current).toBe("dark-color");
});
3 changes: 2 additions & 1 deletion packages/styled-system/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"compilerOptions": {
"paths": {
"@hopper-ui/components": ["../components/src/index.ts"],
"@hopper-ui/styled-system": ["./src/index.ts"]
"@hopper-ui/styled-system": ["./src/index.ts"],
"@hopper-ui/test-utils": ["../../test-utils/index.ts"]
}
}
}
2 changes: 1 addition & 1 deletion packages/tokens/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"build": "node --loader ts-node/esm src/style-dictionary/build.ts"
},
"devDependencies": {
"@types/node": "20.8.10",
"@types/node": "20.9.0",
"@workleap/eslint-plugin": "3.0.0",
"@workleap/tsup-configs": "3.0.1",
"@workleap/typescript-configs": "3.0.2",
Expand Down
3 changes: 2 additions & 1 deletion packages/tokens/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"extends": "@workleap/typescript-configs/library.json",
"exclude": ["node_modules"]
"exclude": ["node_modules"],
"include": ["**/*", "../../types/*"],
}
Loading

0 comments on commit 02e7ed8

Please sign in to comment.